本文整理汇总了C++中ScalarExpressionPtr::getCPPLiteralString方法的典型用法代码示例。如果您正苦于以下问题:C++ ScalarExpressionPtr::getCPPLiteralString方法的具体用法?C++ ScalarExpressionPtr::getCPPLiteralString怎么用?C++ ScalarExpressionPtr::getCPPLiteralString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScalarExpressionPtr
的用法示例。
在下文中一共展示了ScalarExpressionPtr::getCPPLiteralString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outputCPP
void ConstantTable::outputCPP(CodeGenerator &cg, AnalysisResultPtr ar) {
bool decl = true;
if (cg.getContext() == CodeGenerator::CppConstantsDecl) {
decl = false;
}
bool printed = false;
for (StringToSymbolMap::iterator iter = m_symbolMap.begin(),
end = m_symbolMap.end(); iter != end; ++iter) {
Symbol *sym = &iter->second;
if (!sym->declarationSet() || sym->isDynamic()) continue;
if (sym->isSystem() && cg.getOutput() != CodeGenerator::SystemCPP) continue;
const string &name = sym->getName();
ConstructPtr value = sym->getValue();
printed = true;
cg_printf(decl ? "extern const " : "const ");
TypePtr type = sym->getFinalType();
bool isString = type->is(Type::KindOfString);
if (isString) {
cg_printf("StaticString");
} else {
type->outputCPPDecl(cg, ar);
}
if (decl) {
cg_printf(" %s%s", Option::ConstantPrefix,
cg.formatLabel(name).c_str());
} else {
cg_printf(" %s%s", Option::ConstantPrefix,
cg.formatLabel(name).c_str());
cg_printf(isString ? "(" : " = ");
if (value) {
ExpressionPtr exp = dynamic_pointer_cast<Expression>(value);
ASSERT(!exp->getExpectedType());
ScalarExpressionPtr scalarExp =
dynamic_pointer_cast<ScalarExpression>(exp);
if (isString && scalarExp) {
cg_printf("LITSTR_INIT(%s)",
scalarExp->getCPPLiteralString(cg).c_str());
} else {
exp->outputCPP(cg, ar);
}
} else {
cg_printf("\"%s\"", cg.escapeLabel(name).c_str());
}
if (isString) {
cg_printf(")");
}
}
cg_printf(";\n");
}
if (printed) {
cg_printf("\n");
}
}
示例2: outputCPPImpl
void ClassConstant::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
if (cg.getContext() != CodeGenerator::CppClassConstantsDecl &&
cg.getContext() != CodeGenerator::CppClassConstantsImpl) {
return;
}
ClassScopePtr scope = getClassScope();
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr exp =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ConstantExpressionPtr var =
dynamic_pointer_cast<ConstantExpression>(exp->getVariable());
TypePtr type = scope->getConstants()->getFinalType(var->getName());
ExpressionPtr value = exp->getValue();
if (scope->getConstants()->isDynamic(var->getName())) {
continue;
}
switch (cg.getContext()) {
case CodeGenerator::CppClassConstantsDecl:
cg_printf("extern const ");
if (type->is(Type::KindOfString)) {
cg_printf("StaticString");
} else {
type->outputCPPDecl(cg, ar, getScope());
}
cg_printf(" %s%s%s%s;\n",
Option::ClassConstantPrefix, scope->getId().c_str(),
Option::IdPrefix.c_str(), var->getName().c_str());
break;
case CodeGenerator::CppClassConstantsImpl: {
bool isString = type->is(Type::KindOfString);
bool isVariant = Type::IsMappedToVariant(type);
ScalarExpressionPtr scalarExp =
dynamic_pointer_cast<ScalarExpression>(value);
bool stringForVariant = false;
if (isVariant && scalarExp &&
scalarExp->getActualType() &&
scalarExp->getActualType()->is(Type::KindOfString)) {
cg_printf("static const StaticString %s%s%s%s%sv(LITSTR_INIT(%s));\n",
Option::ClassConstantPrefix, scope->getId().c_str(),
Option::IdPrefix.c_str(), var->getName().c_str(),
Option::IdPrefix.c_str(),
scalarExp->getCPPLiteralString().c_str());
stringForVariant = true;
}
cg_printf("const ");
if (isString) {
cg_printf("StaticString");
} else {
type->outputCPPDecl(cg, ar, getScope());
}
value->outputCPPBegin(cg, ar);
cg_printf(" %s%s%s%s",
Option::ClassConstantPrefix, scope->getId().c_str(),
Option::IdPrefix.c_str(), var->getName().c_str());
cg_printf(isString ? "(" : " = ");
if (stringForVariant) {
cg_printf("%s%s%s%s%sv",
Option::ClassConstantPrefix, scope->getId().c_str(),
Option::IdPrefix.c_str(), var->getName().c_str(),
Option::IdPrefix.c_str());
} else if (isString && scalarExp) {
cg_printf("LITSTR_INIT(%s)",
scalarExp->getCPPLiteralString().c_str());
} else {
value->outputCPP(cg, ar);
}
cg_printf(isString ? ");\n" : ";\n");
value->outputCPPEnd(cg, ar);
break;
}
default:
assert(false);
}
}
}
示例3: outputCPPImpl
void ClassConstant::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
bool lazyInit = cg.getContext() == CodeGenerator::CppLazyStaticInitializer;
if (cg.getContext() != CodeGenerator::CppClassConstantsDecl &&
cg.getContext() != CodeGenerator::CppClassConstantsImpl &&
!lazyInit) {
return;
}
ClassScopePtr scope = getClassScope();
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr exp =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ConstantExpressionPtr var =
dynamic_pointer_cast<ConstantExpression>(exp->getVariable());
TypePtr type = scope->getConstants()->getFinalType(var->getName());
ExpressionPtr value = exp->getValue();
if (!scope->getConstants()->isDynamic(var->getName()) == lazyInit) {
continue;
}
switch (cg.getContext()) {
case CodeGenerator::CppClassConstantsDecl:
cg_printf("extern const ");
if (type->is(Type::KindOfString)) {
cg_printf("StaticString");
} else {
type->outputCPPDecl(cg, ar, getScope());
}
cg_printf(" %s%s_%s;\n", Option::ClassConstantPrefix,
scope->getId(cg).c_str(),
var->getName().c_str());
break;
case CodeGenerator::CppClassConstantsImpl: {
cg_printf("const ");
bool isString = type->is(Type::KindOfString);
if (isString) {
cg_printf("StaticString");
} else {
type->outputCPPDecl(cg, ar, getScope());
}
value->outputCPPBegin(cg, ar);
cg_printf(" %s%s_%s", Option::ClassConstantPrefix,
scope->getId(cg).c_str(),
var->getName().c_str());
cg_printf(isString ? "(" : " = ");
ScalarExpressionPtr scalarExp =
dynamic_pointer_cast<ScalarExpression>(value);
if (isString && scalarExp) {
cg_printf("LITSTR_INIT(%s)",
scalarExp->getCPPLiteralString(cg).c_str());
} else {
value->outputCPP(cg, ar);
}
cg_printf(isString ? ");\n" : ";\n");
value->outputCPPEnd(cg, ar);
break;
}
case CodeGenerator::CppLazyStaticInitializer:
value->outputCPPBegin(cg, ar);
cg_printf("g->%s%s_%s = ", Option::ClassConstantPrefix,
scope->getId(cg).c_str(),
var->getName().c_str());
value->outputCPP(cg, ar);
cg_printf(";\n");
value->outputCPPEnd(cg, ar);
break;
default:
ASSERT(false);
}
}
}