本文整理汇总了C++中FunctionScopePtr::getParamTypeSpec方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionScopePtr::getParamTypeSpec方法的具体用法?C++ FunctionScopePtr::getParamTypeSpec怎么用?C++ FunctionScopePtr::getParamTypeSpec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FunctionScopePtr
的用法示例。
在下文中一共展示了FunctionScopePtr::getParamTypeSpec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outputCPPTypeCheckWrapper
void MethodStatement::outputCPPTypeCheckWrapper(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr funcScope = getFunctionScope();
TypePtr type = funcScope->getReturnType();
bool isMethod = getClassScope();
string fname = isMethod ? funcScope->getName() : funcScope->getId(cg);
funcScope->outputCPP(cg, ar);
cg_printf("%s%s%s(", type ? "return " : "",
(isMethod ? (m_modifiers->isStatic() ?
Option::TypedMethodImplPrefix :
Option::TypedMethodPrefix) :
Option::TypedFunctionPrefix),
fname.c_str());
if (getClassScope() && m_modifiers->isStatic()) {
cg_printf("cls, ");
}
if (funcScope->isVariableArgument()) {
cg_printf("num_args, ");
}
assert(m_params);
for (int i = 0; i < m_params->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
ASSERT(param);
if (i) cg_printf(", ");
cg_printf("%s%s", Option::VariablePrefix,
param->getName().c_str());
if (TypePtr spec = funcScope->getParamTypeSpec(i)) {
if (Type::SameType(spec, funcScope->getParamType(i))) {
if (spec->is(Type::KindOfArray)) {
cg_printf(".getArrayData()");
} else {
ClassScopePtr cls = ar->findClass(spec->getName());
assert(cls && !cls->isRedeclaring());
cg_printf(".getObjectData()");
}
}
}
}
if (funcScope->isVariableArgument()) {
cg_printf(", args");
}
cg_printf(");\n");
}
示例2: outputCPPImpl
void ParameterExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr func = getFunctionScope();
VariableTablePtr variables = func->getVariables();
Symbol *sym = variables->getSymbol(m_name);
assert(sym && sym->isParameter());
bool inHeader = cg.isFileOrClassHeader();
cg.setFileOrClassHeader(true);
CodeGenerator::Context context = cg.getContext();
bool typedWrapper = (context == CodeGenerator::CppTypedParamsWrapperImpl ||
context == CodeGenerator::CppTypedParamsWrapperDecl);
TypePtr paramType =
typedWrapper && func->getParamTypeSpec(sym->getParameterIndex()) ?
Type::Variant : func->getParamType(sym->getParameterIndex());
bool wrapper = typedWrapper ||
context == CodeGenerator::CppFunctionWrapperImpl ||
context == CodeGenerator::CppFunctionWrapperDecl;
bool isCVarRef = false;
const char *prefix = "";
if (m_ref) {
cg_printf("VRefParam");
if (!wrapper) {
prefix = "r";
}
} else if (wrapper ||
(!variables->isLvalParam(m_name) &&
!variables->getAttribute(VariableTable::ContainsDynamicVariable) &&
!variables->getAttribute(VariableTable::ContainsExtract))) {
if (paramType->is(Type::KindOfVariant) ||
paramType->is(Type::KindOfSome)) {
cg_printf("CVarRef");
isCVarRef = true;
}
else if (paramType->is(Type::KindOfArray)) cg_printf("CArrRef");
else if (paramType->is(Type::KindOfString)) cg_printf("CStrRef");
else paramType->outputCPPDecl(cg, ar, getScope());
} else {
paramType->outputCPPDecl(cg, ar, getScope());
}
cg_printf(" %s%s%s",
prefix, Option::VariablePrefix,
CodeGenerator::FormatLabel(m_name).c_str());
if (m_defaultValue && sym->getParameterIndex() >= func->getMinParamCount()) {
bool comment = context == CodeGenerator::CppTypedParamsWrapperImpl ||
context == CodeGenerator::CppFunctionWrapperImpl ||
context == CodeGenerator::CppImplementation ||
(context == CodeGenerator::CppDeclaration && func->isInlined());
if (comment) {
cg_printf(" // ");
}
cg_printf(" = ");
ConstantExpressionPtr con =
dynamic_pointer_cast<ConstantExpression>(m_defaultValue);
bool done = false;
if (con && con->isNull()) {
done = true;
if (isCVarRef) {
cg_printf("null_variant");
} else if (paramType->is(Type::KindOfVariant) ||
paramType->is(Type::KindOfSome)) {
cg_printf("null");
} else if (paramType->is(Type::KindOfObject)) {
cg_printf("Object()");
} else if (paramType->is(Type::KindOfArray)) {
cg_printf("Array()");
} else if (paramType->is(Type::KindOfString)) {
cg_printf("String()");
} else {
done = false;
}
}
if (!done) {
if (comment) {
cg.setContext(CodeGenerator::CppParameterDefaultValueImpl);
} else {
cg.setContext(CodeGenerator::CppParameterDefaultValueDecl);
}
bool isScalar = m_defaultValue->isScalar();
if (isCVarRef && isScalar) {
ASSERT(!cg.hasScalarVariant());
cg.setScalarVariant();
}
m_defaultValue->outputCPP(cg, ar);
if (isCVarRef && isScalar) cg.clearScalarVariant();
ASSERT(!cg.hasScalarVariant());
cg.setContext(context);
}
if (comment) {
cg_printf("\n");
}
}
cg.setFileOrClassHeader(inHeader);
}
示例3: outputCPPImpl
void ParameterExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr func = getFunctionScope();
VariableTablePtr variables = func->getVariables();
Symbol *sym = variables->getSymbol(m_name);
assert(sym && sym->isParameter());
CodeGenerator::Context context = cg.getContext();
bool typedWrapper = (context == CodeGenerator::CppTypedParamsWrapperImpl ||
context == CodeGenerator::CppTypedParamsWrapperDecl);
TypePtr paramType =
typedWrapper && func->getParamTypeSpec(sym->getParameterIndex()) ?
Type::Variant : func->getParamType(sym->getParameterIndex());
bool isCVarRef = false;
if (cg.getContext() == CodeGenerator::CppStaticMethodWrapper ||
typedWrapper ||
(!variables->isLvalParam(m_name) &&
!variables->getAttribute(VariableTable::ContainsDynamicVariable) &&
!variables->getAttribute(VariableTable::ContainsExtract) &&
!m_ref)) {
if (paramType->is(Type::KindOfVariant) ||
paramType->is(Type::KindOfSome)) {
cg_printf("CVarRef");
isCVarRef = true;
}
else if (paramType->is(Type::KindOfArray)) cg_printf("CArrRef");
else if (paramType->is(Type::KindOfString)) cg_printf("CStrRef");
else paramType->outputCPPDecl(cg, ar, getScope());
} else {
paramType->outputCPPDecl(cg, ar, getScope());
}
cg_printf(" %s%s", Option::VariablePrefix, m_name.c_str());
if (m_defaultValue && sym->getParameterIndex() >= func->getMinParamCount()) {
bool comment = context == CodeGenerator::CppTypedParamsWrapperImpl ||
context == CodeGenerator::CppImplementation ||
(context == CodeGenerator::CppDeclaration && func->isInlined());
if (comment) {
cg_printf(" // ");
}
cg_printf(" = ");
ConstantExpressionPtr con =
dynamic_pointer_cast<ConstantExpression>(m_defaultValue);
if (isCVarRef && con && con->isNull()) {
cg_printf("null_variant");
} else {
if (comment) {
cg.setContext(CodeGenerator::CppParameterDefaultValueImpl);
} else {
cg.setContext(CodeGenerator::CppParameterDefaultValueDecl);
}
m_defaultValue->outputCPP(cg, ar);
cg.setContext(context);
}
if (comment) {
cg_printf("\n");
}
}
}