本文整理汇总了C++中CodeGenerator::getContext方法的典型用法代码示例。如果您正苦于以下问题:C++ CodeGenerator::getContext方法的具体用法?C++ CodeGenerator::getContext怎么用?C++ CodeGenerator::getContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator::getContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outputSwigFFIStub
void MethodStatement::outputSwigFFIStub(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
bool varArgs = funcScope->isVariableArgument();
bool ret = funcScope->getReturnType();
string fname = funcScope->getId();
string originalName = funcScope->getOriginalName();
int ac = funcScope->getMaxParamCount();
if (cg.getContext() == CodeGenerator::SwigFFIImpl) {
printSource(cg);
}
cg.printf("Variant *%s(HphpSession *s", originalName.c_str());
ostringstream args;
bool first = true;
for (int i = 0; i < ac; i++) {
cg.printf(", Variant *a%d", i);
if (first) first = false;
else args << ", ";
args << "a" << i;
}
if (varArgs) {
cg.printf(", Variant *va");
if (!first) args << ", ";
args << "va";
}
if (cg.getContext() == CodeGenerator::SwigFFIDecl) {
cg.printf(");\n\n");
return;
}
cg.indentBegin(") {\n");
if (ret) {
cg.printf("void *result;\n");
cg.printf("int kind = ");
cg.printf("%s%s(&result", Option::FFIFnPrefix, fname.c_str());
if (ac > 0 || varArgs) cg.printf(", ");
} else {
cg.printf("%s%s(", Option::FFIFnPrefix, fname.c_str());
}
cg.printf("%s);\n", args.str().c_str());
cg.printf("Variant *ret = ");
if (ret) {
cg.printf("hphpBuildVariant(kind, result);\n");
cg.printf("s->addVariant(ret);\n");
} else {
cg.printf("hphpBuildVariant(0, 0);\n");
cg.printf("s->addVariant(ret);\n");
}
cg.printf("return ret;\n");
cg.indentEnd("}\n\n");
}
示例2: outputCPPImpl
void ParameterExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr func =
dynamic_pointer_cast<FunctionScope>(ar->getScope());
VariableTablePtr variables = func->getVariables();
TypePtr paramType = func->getParamType(cg.getItemIndex());
bool isCVarRef = false;
if (cg.getContext() == CodeGenerator::CppStaticMethodWrapper ||
(!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);
} else {
paramType->outputCPPDecl(cg, ar);
}
cg_printf(" %s%s", Option::VariablePrefix, m_name.c_str());
if (m_defaultValue) {
CodeGenerator::Context context = cg.getContext();
bool comment = 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");
}
}
}
示例3: outputPHP
void StatementList::outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) {
for (unsigned int i = 0; i < m_stmts.size(); i++) {
StatementPtr stmt = m_stmts[i];
switch (cg.getContext()) {
case CodeGenerator::NoContext:
stmt->outputPHP(cg, ar);
break;
case CodeGenerator::PhpDeclaration:
if (stmt->is(Statement::KindOfFunctionStatement) ||
stmt->is(Statement::KindOfClassStatement) ||
stmt->is(Statement::KindOfInterfaceStatement)) {
cg.setContext(CodeGenerator::PhpImplementation);
stmt->outputPHP(cg, ar);
cg.setContext(CodeGenerator::PhpDeclaration);
}
break;
case CodeGenerator::PhpImplementation:
if (!stmt->is(Statement::KindOfFunctionStatement) &&
!stmt->is(Statement::KindOfClassStatement) &&
!stmt->is(Statement::KindOfInterfaceStatement)) {
stmt->outputPHP(cg, ar);
}
break;
default:
ASSERT(false);
}
}
}
示例4: outputCPPImpl
void ClassConstantExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
const char *globals = "g";
if (cg.getContext() == CodeGenerator::CppParameterDefaultValueDecl ||
cg.getContext() == CodeGenerator::CppParameterDefaultValueImpl) {
globals = cg.getGlobals();
}
if (m_valid) {
ClassScopePtr foundCls;
string trueClassName;
for (ClassScopePtr cls = ar->findClass(m_className);
cls; cls = cls->getParentScope(ar)) {
if (cls->getConstants()->isPresent(m_varName)) {
foundCls = cls;
trueClassName = cls->getName();
break;
}
}
ASSERT(!trueClassName.empty());
ConstructPtr decl = foundCls->getConstants()->getValue(m_varName);
if (decl) {
decl->outputCPP(cg, ar);
if (cg.getContext() == CodeGenerator::CppImplementation ||
cg.getContext() == CodeGenerator::CppParameterDefaultValueImpl) {
cg.printf("(%s::%s)", m_className.c_str(), m_varName.c_str());
} else {
cg.printf("/* %s::%s */", m_className.c_str(), m_varName.c_str());
}
} else {
if (foundCls->getConstants()->isDynamic(m_varName)) {
cg.printf("%s%s::lazy_initializer(%s)->", Option::ClassPrefix,
trueClassName.c_str(), globals);
}
cg.printf("%s%s_%s", Option::ClassConstantPrefix, trueClassName.c_str(),
m_varName.c_str());
}
} else if (m_redeclared) {
cg.printf("%s->%s%s->os_constant(\"%s\")", globals,
Option::ClassStaticsObjectPrefix,
m_className.c_str(), m_varName.c_str());
} else {
cg.printf("throw_fatal(\"unknown class constant %s::%s\")",
m_className.c_str(), m_varName.c_str());
}
}
示例5: outputFFI
bool MethodStatement::outputFFI(CodeGenerator &cg, AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
ClassScopePtr clsScope = ar->getClassScope();
bool pseudoMain = funcScope->inPseudoMain();
bool inClass = !m_className.empty();
// only expose public methods, and ignore those in redeclared classes
bool inaccessible =
inClass && (!m_modifiers->isPublic() || clsScope->isRedeclaring());
// skip constructors
bool isConstructor = inClass && funcScope->isConstructor(clsScope);
bool valid = !pseudoMain && !inaccessible && !isConstructor;
if (cg.getContext() == CodeGenerator::CppFFIDecl ||
cg.getContext() == CodeGenerator::CppFFIImpl) {
if (valid) outputCPPFFIStub(cg, ar);
return true;
}
if (cg.getContext() == CodeGenerator::HsFFI) {
if (valid) outputHSFFIStub(cg, ar);
return true;
}
if (cg.getContext() == CodeGenerator::JavaFFI
|| cg.getContext() == CodeGenerator::JavaFFIInterface) {
if (valid) outputJavaFFIStub(cg, ar);
return true;
}
if (cg.getContext() == CodeGenerator::JavaFFICppDecl
|| cg.getContext() == CodeGenerator::JavaFFICppImpl) {
if (valid) outputJavaFFICPPStub(cg, ar);
return true;
}
if (cg.getContext() == CodeGenerator::SwigFFIDecl
|| cg.getContext() == CodeGenerator::SwigFFIImpl) {
if (valid) outputSwigFFIStub(cg, ar);
return true;
}
return false;
}
示例6: 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");
}
}
示例7: outputCPPStaticMethodWrapper
void MethodStatement::outputCPPStaticMethodWrapper(CodeGenerator &cg,
AnalysisResultPtr ar,
const char *cls) {
if (!m_modifiers->isStatic() || !m_stmt) return;
CodeGenerator::Context context = cg.getContext();
FunctionScopePtr funcScope = m_funcScope.lock();
bool isWrapper = context == CodeGenerator::CppTypedParamsWrapperDecl ||
context == CodeGenerator::CppTypedParamsWrapperImpl;
bool needsWrapper = isWrapper ||
(Option::HardTypeHints && funcScope->needsTypeCheckWrapper());
m_modifiers->outputCPP(cg, ar);
TypePtr type = funcScope->getReturnType();
if (type) {
type->outputCPPDecl(cg, ar);
} else {
cg_printf("void");
}
cg_printf(" %s%s(", needsWrapper && !isWrapper ?
Option::TypedMethodPrefix : Option::MethodPrefix,
cg.formatLabel(m_name).c_str());
if (!isWrapper) cg.setContext(CodeGenerator::CppStaticMethodWrapper);
funcScope->outputCPPParamsDecl(cg, ar, m_params, true);
cg_printf(") { %s%s%s(", type ? "return " : "",
needsWrapper && !isWrapper ?
Option::TypedMethodImplPrefix : Option::MethodImplPrefix,
cg.formatLabel(m_name).c_str());
cg_printf("%s%s::s_class_name", Option::ClassPrefix, cls);
cg.setContext(context);
if (funcScope->isVariableArgument()) {
cg_printf(", num_args");
}
if (m_params) {
for (int i = 0; i < m_params->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
ASSERT(param);
cg_printf(", %s%s", Option::VariablePrefix, param->getName().c_str());
}
}
if (funcScope->isVariableArgument()) {
cg_printf(", args");
}
cg_printf("); }\n");
if (!isWrapper && needsWrapper) {
cg.setContext(CodeGenerator::CppTypedParamsWrapperDecl);
outputCPPStaticMethodWrapper(cg, ar, cls);
cg.setContext(context);
}
}
示例8: outputJavaFFICPPCreator
void ClassStatement::outputJavaFFICPPCreator(CodeGenerator &cg,
AnalysisResultPtr ar,
FunctionScopePtr cons) {
ClassScopePtr cls = m_classScope.lock();
string packageName = Option::JavaFFIRootPackage;
int ac = cons ? cons->getMaxParamCount() : 0;
bool varArgs = cons && cons->isVariableArgument();
const char *clsName = getOriginalName().c_str();
string mangledName = "Java_" + packageName + "_" + clsName + "_create";
Util::replaceAll(mangledName, ".", "_");
cg.printf("JNIEXPORT jlong JNICALL\n");
cg.printf("%s(JNIEnv *env, jclass cls", mangledName.c_str());
ostringstream args;
bool first = true;
if (varArgs) {
args << ac << " + (((Variant *)va)->isNull() ? 0"
<< " : ((Variant *)va)->getArrayData()->size())";
first = false;
}
for (int i = 0; i < ac; i++) {
if (first) first = false;
else {
args << ", ";
}
cg.printf(", jlong a%d", i);
args << "*(Variant *)a" << i;
}
if (varArgs) {
if (!first) {
args << ", ";
}
cg.printf(", jlong va");
args << "((Variant *)va)->toArray()";
}
if (cg.getContext() == CodeGenerator::JavaFFICppDecl) {
// java_stubs.h
cg.printf(");\n\n");
return;
}
cg.indentBegin(") {\n");
cg.printf("ObjectData *obj = ");
cg.printf("(NEW(%s%s)())->create(%s);\n",
Option::ClassPrefix, cls->getId().c_str(), args.str().c_str());
cg.printf("obj->incRefCount();\n");
cg.printf("return (jlong)(NEW(Variant)(obj));\n");
cg.indentEnd("}\n\n");
}
示例9: outputCPP
void ConstantTable::outputCPP(CodeGenerator &cg, AnalysisResultPtr ar) {
bool decl = true;
if (cg.getContext() == CodeGenerator::CppConstantsDecl) {
decl = false;
}
bool printed = false;
for (StringToConstructPtrMap::const_iterator iter = m_declarations.begin();
iter != m_declarations.end(); ++iter) {
const string &name = iter->first;
if (isSystem(name) && cg.getOutput() != CodeGenerator::SystemCPP) continue;
ConstructPtr value = getValue(name);
if (isDynamic(name)) continue;
printed = true;
cg.printf(decl ? "extern const " : "const ");
TypePtr type = getFinalType(name);
if (type->is(Type::KindOfString)) {
cg.printf("StaticString");
} else {
type->outputCPPDecl(cg, ar);
}
const char *nameStr = name.c_str();
if (decl) {
cg.printf(" %s%s", Option::ConstantPrefix, nameStr);
} else {
cg.printf(" %s%s = ", Option::ConstantPrefix, nameStr);
if (value) {
ExpressionPtr exp = dynamic_pointer_cast<Expression>(value);
ASSERT(!exp->getExpectedType());
exp->outputCPP(cg, ar);
} else {
cg.printf("\"%s\"", nameStr);
}
}
cg.printf(";\n");
}
if (printed) {
cg.printf("\n");
}
}
示例10: outputCPPStaticMethodWrapper
void MethodStatement::outputCPPStaticMethodWrapper(CodeGenerator &cg,
AnalysisResultPtr ar,
const char *cls) {
if (!m_modifiers->isStatic() || !m_stmt) return;
FunctionScopePtr funcScope = m_funcScope.lock();
ar->pushScope(funcScope);
m_modifiers->outputCPP(cg, ar);
TypePtr type = funcScope->getReturnType();
if (type) {
type->outputCPPDecl(cg, ar);
} else {
cg.printf("void");
}
cg.printf(" %s%s(", Option::MethodPrefix, m_name.c_str());
CodeGenerator::Context old = cg.getContext();
cg.setContext(CodeGenerator::CppStaticMethodWrapper);
funcScope->outputCPPParamsDecl(cg, ar, m_params, true);
cg.setContext(old);
cg.printf(") { %s%s%s(\"%s\"", type ? "return " : "",
Option::MethodImplPrefix, m_name.c_str(),
cls);
if (funcScope->isVariableArgument()) {
cg.printf(", num_args");
}
if (m_params) {
for (int i = 0; i < m_params->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_params)[i]);
ASSERT(param);
cg.printf(", %s%s", Option::VariablePrefix, param->getName().c_str());
}
}
if (funcScope->isVariableArgument()) {
cg.printf(", args");
}
cg.printf("); }\n");
ar->popScope();
}
示例11: outputCPPImpl
void ClassVariable::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
ClassScopePtr scope = ar->getClassScope();
bool derivFromRedec = scope->derivesFromRedeclaring() &&
!m_modifiers->isPrivate();
for (int i = 0; i < m_declaration->getCount(); i++) {
ExpressionPtr exp = (*m_declaration)[i];
SimpleVariablePtr var;
TypePtr type;
switch (cg.getContext()) {
case CodeGenerator::CppConstructor:
if (m_modifiers->isStatic()) continue;
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
var = dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
value->outputCPPBegin(cg, ar);
if (derivFromRedec) {
cg_printf("%sset(\"%s\",-1, ", Option::ObjectPrefix,
var->getName().c_str());
value->outputCPP(cg, ar);
cg_printf(")");
} else {
cg_printf("%s%s = ", Option::PropertyPrefix, var->getName().c_str());
value->outputCPP(cg, ar);
}
cg_printf(";\n");
value->outputCPPEnd(cg, ar);
} else {
var = dynamic_pointer_cast<SimpleVariable>(exp);
if (derivFromRedec) {
cg_printf("%sset(\"%s\",-1, null);\n", Option::ObjectPrefix,
var->getName().c_str());
} else {
type = scope->getVariables()->getFinalType(var->getName());
const char *initializer = type->getCPPInitializer();
if (initializer) {
cg_printf("%s%s = %s;\n", Option::PropertyPrefix,
var->getName().c_str(), initializer);
}
}
}
break;
case CodeGenerator::CppStaticInitializer:
{
if (!m_modifiers->isStatic()) continue;
VariableTablePtr variables = scope->getVariables();
if (exp->is(Expression::KindOfAssignmentExpression)) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
var = dynamic_pointer_cast<SimpleVariable>
(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
if (value->containsDynamicConstant(ar)) continue;
cg_printf("g->%s%s%s%s = ",
Option::StaticPropertyPrefix, scope->getId(cg).c_str(),
Option::IdPrefix.c_str(), var->getName().c_str());
value->outputCPP(cg, ar);
} else {
var = dynamic_pointer_cast<SimpleVariable>(exp);
type = scope->getVariables()->getFinalType(var->getName());
const char *initializer = type->getCPPInitializer();
if (initializer) {
cg_printf("g->%s%s%s%s = %s",
Option::StaticPropertyPrefix, scope->getId(cg).c_str(),
Option::IdPrefix.c_str(), var->getName().c_str(),
initializer);
}
}
cg_printf(";\n");
}
break;
case CodeGenerator::CppLazyStaticInitializer:
{
if (!m_modifiers->isStatic()) continue;
if (!exp->is(Expression::KindOfAssignmentExpression)) continue;
VariableTablePtr variables = scope->getVariables();
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>(exp);
var = dynamic_pointer_cast<SimpleVariable>(assignment->getVariable());
ExpressionPtr value = assignment->getValue();
if (!value->containsDynamicConstant(ar)) continue;
value->outputCPPBegin(cg, ar);
cg_printf("g->%s%s%s%s = ",
Option::StaticPropertyPrefix, scope->getId(cg).c_str(),
Option::IdPrefix.c_str(), var->getName().c_str());
value->outputCPP(cg, ar);
cg_printf(";\n");
value->outputCPPEnd(cg, ar);
}
break;
default:
//.........这里部分代码省略.........
示例12: outputJavaFFIStub
/**
* Generates the Java stub method for a PHP toplevel function.
*
* @author qixin
*/
void MethodStatement::outputJavaFFIStub(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
bool varArgs = funcScope->isVariableArgument();
bool ret = funcScope->getReturnType();
bool inClass = !m_className.empty();
bool isStatic = !inClass || m_modifiers->isStatic();
string fname = funcScope->getId();
string originalName = funcScope->getOriginalName();
if (originalName.length() < fname.length()) {
// if there are functions of the same name, fname may contain "$$..."
// in the end
originalName += fname.substr(originalName.length());
}
if (originalName == "clone" || originalName == "equals"
|| originalName == "finalize" || originalName == "getClass"
|| originalName == "hashCode" || originalName == "notify"
|| originalName == "notifyAll" || originalName == "toString"
|| originalName == "wait") {
// not to clash with Java method names
originalName = "_" + originalName;
}
if (cg.getContext() == CodeGenerator::JavaFFIInterface
|| inClass && m_modifiers->isAbstract()) {
// skip all the abstract methods, because php overriding is not very
// compatible with Java
return;
}
if (!inClass) printSource(cg);
// This Java method extracts the Variant pointer from the HphpVariant
// argument as a 64-bit integer, and then calls the native version.
bool exposeNative = false;
int ac = funcScope->getMaxParamCount();
if (ac > 0 || varArgs || !isStatic || !ret && inClass
|| cg.getContext() == CodeGenerator::JavaFFIInterface) {
// make methods always return something, so that they can override
// each other
cg.printf("public %s%s %s(",
(isStatic ? "static " : ""),
(!ret && !inClass ? "void" : "HphpVariant"),
originalName.c_str());
ostringstream args;
bool first = true;
if (!isStatic) {
// instance method has an additional parameter
args << "this.getVariantPtr()";
}
for (int i = 0; i < ac; i++) {
if (first) {
first = false;
if (!isStatic) args << ", ";
}
else {
cg.printf(", ");
args << ", ";
}
cg.printf("HphpVariant a%d", i);
args << "a" << i << ".getVariantPtr()";
}
if (varArgs) {
if (!first) {
cg.printf(", ");
args << ", ";
}
else if (!isStatic) {
args << ", ";
}
cg.printf("HphpVariant va");
args << "va.getVariantPtr()";
}
if (cg.getContext() == CodeGenerator::JavaFFIInterface) {
cg.printf(");\n\n");
return;
}
cg.indentBegin(") {\n");
cg.printf("%s%s_native(%s);\n", (ret ? "return " : ""),
originalName.c_str(),
args.str().c_str());
if (!ret && inClass) {
cg.printf("return HphpNull.phpNull();\n");
}
cg.indentEnd("}\n\n");
}
else {
exposeNative = true;
}
// the native method stub
cg.printf("%s %snative %s %s%s(",
//.........这里部分代码省略.........
示例13: outputCPPFFIStub
void MethodStatement::outputCPPFFIStub(CodeGenerator &cg,
AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
bool varArgs = funcScope->isVariableArgument();
bool ret = funcScope->getReturnType();
string fname = funcScope->getId();
bool inClass = !m_className.empty();
bool isStatic = !inClass || m_modifiers->isStatic();
if (inClass && m_modifiers->isAbstract()) {
return;
}
if (fname == "__lval" || fname == "__offsetget_lval") {
return;
}
if (ret) {
cg.printf("int");
} else {
cg.printf("void");
}
cg.printf(" %s%s%s(", Option::FFIFnPrefix,
(inClass ? (m_className + "_cls_").c_str() : ""), fname.c_str());
if (ret) {
cg.printf("void** res");
}
bool first = !ret;
if (!isStatic) {
// instance methods need one additional parameter for the target
if (first) {
first = false;
}
else {
cg.printf(", ");
}
cg.printf("Variant *target");
}
int ac = funcScope->getMaxParamCount();
for (int i = 0; i < ac; ++i) {
if (first) {
first = false;
} else {
cg.printf(", ");
}
cg.printf("Variant *a%d", i);
}
if (varArgs) {
if (!first) {
cg.printf(", ");
}
cg.printf("Variant *va");
}
cg.printf(")");
if (cg.getContext() == CodeGenerator::CppFFIDecl) {
cg.printf(";\n");
} else {
cg.indentBegin(" {\n");
if (ret) {
cg.printf("return hphp_ffi_exportVariant(");
}
if (!inClass) {
// simple function call
cg.printf("%s%s(", Option::FunctionPrefix, fname.c_str());
}
else if (isStatic) {
// static method call
cg.printf("%s%s::%s%s(", Option::ClassPrefix, m_className.c_str(),
Option::MethodPrefix, fname.c_str());
}
else {
// instance method call
cg.printf("dynamic_cast<%s%s *>(target->getObjectData())->",
Option::ClassPrefix, m_className.c_str());
cg.printf("%s%s(", Option::MethodPrefix, fname.c_str());
}
first = true;
if (varArgs) {
cg.printf("%d + (va->isNull() ? 0 : va->getArrayData()->size())", ac);
first = false;
}
for (int i = 0; i < ac; ++i) {
if (first) {
first = false;
} else {
cg.printf(", ");
}
cg.printf("*a%d", i);
}
if (varArgs) {
cg.printf(", va->toArray()");
}
if (ret) {
cg.printf("), res");
//.........这里部分代码省略.........
示例14: outputCPPImpl
void FunctionStatement::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
CodeGenerator::Context context = cg.getContext();
FunctionScopeRawPtr funcScope = getFunctionScope();
string fname = funcScope->getId(cg);
bool pseudoMain = funcScope->inPseudoMain();
string origFuncName = !pseudoMain ? funcScope->getOriginalName() :
("run_init::" + funcScope->getContainingFile()->getName());
string funcSection;
if (outputFFI(cg, ar)) return;
if (context == CodeGenerator::NoContext) {
string rname = cg.formatLabel(m_name);
if (funcScope->isRedeclaring()) {
cg.printf("g->GCI(%s) = &%s%s;\n", m_name.c_str(),
Option::CallInfoPrefix, fname.c_str());
}
if (funcScope->isVolatile()) {
cg_printf("g->declareFunctionLit(");
cg_printString(m_name, ar, shared_from_this());
cg_printf(");\n");
cg_printf("g->FVF(%s) = true;\n", rname.c_str());
}
return;
}
if (context == CodeGenerator::CppDeclaration &&
!funcScope->isInlined()) return;
if (context == CodeGenerator::CppPseudoMain &&
!pseudoMain) return;
if (context == CodeGenerator::CppImplementation &&
(funcScope->isInlined() || pseudoMain)) return;
cg.setPHPLineNo(-1);
if (pseudoMain && !Option::GenerateCPPMain) {
if (context == CodeGenerator::CppPseudoMain) {
if (cg.getOutput() != CodeGenerator::SystemCPP) {
cg.setContext(CodeGenerator::NoContext); // no inner functions/classes
funcScope->getVariables()->setAttribute(VariableTable::ForceGlobal);
outputCPPStmt(cg, ar);
funcScope->getVariables()->clearAttribute(VariableTable::ForceGlobal);
cg.setContext(CodeGenerator::CppPseudoMain);
return;
}
} else if (context == CodeGenerator::CppForwardDeclaration &&
cg.getOutput() != CodeGenerator::SystemCPP) {
return;
}
}
if (context == CodeGenerator::CppImplementation) {
printSource(cg);
} else if (context == CodeGenerator::CppForwardDeclaration &&
Option::GenerateCppLibCode) {
cg_printf("\n");
printSource(cg);
cg.printDocComment(funcScope->getDocComment());
}
bool isWrapper = context == CodeGenerator::CppTypedParamsWrapperDecl ||
context == CodeGenerator::CppTypedParamsWrapperImpl;
bool needsWrapper = isWrapper ||
(Option::HardTypeHints && funcScope->needsTypeCheckWrapper());
if (funcScope->isInlined()) cg_printf("inline ");
TypePtr type = funcScope->getReturnType();
if (type) {
type->outputCPPDecl(cg, ar, getScope());
} else {
cg_printf("void");
}
funcSection = Option::FunctionSections[origFuncName];
if (!funcSection.empty()) {
cg_printf(" __attribute__ ((section (\".text.%s\")))",
funcSection.c_str());
}
if (pseudoMain) {
cg_printf(" %s%s(", Option::PseudoMainPrefix,
funcScope->getContainingFile()->pseudoMainName().c_str());
} else {
cg_printf(" %s%s(",
needsWrapper && !isWrapper ?
Option::TypedFunctionPrefix : Option::FunctionPrefix,
fname.c_str());
}
switch (context) {
case CodeGenerator::CppForwardDeclaration:
case CodeGenerator::CppTypedParamsWrapperDecl:
funcScope->outputCPPParamsDecl(cg, ar, m_params, true);
cg_printf(");\n");
if (!isWrapper) {
//.........这里部分代码省略.........
示例15: outputCPPImpl
void UnaryOpExpression::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
if ((m_op == T_INC || m_op == T_DEC) && outputCPPImplOpEqual(cg, ar)) {
return;
}
if (m_op == T_ARRAY &&
(getContext() & (RefValue|LValue)) == 0 &&
!ar->getInsideScalarArray()) {
int id = -1;
int hash = -1;
int index = -1;
string text;
if (m_exp) {
ExpressionListPtr pairs = dynamic_pointer_cast<ExpressionList>(m_exp);
Variant v;
if (pairs && pairs->isScalarArrayPairs() && pairs->getScalarValue(v)) {
id = ar->registerScalarArray(getFileScope(), m_exp, hash, index, text);
}
} else {
id = ar->registerScalarArray(getFileScope(), m_exp,
hash, index, text); // empty array
}
if (id != -1) {
if (Option::UseNamedScalarArray &&
cg.getContext() == CodeGenerator::CppParameterDefaultValueDecl) {
getFileScope()->addUsedDefaultValueScalarArray(text);
}
ar->outputCPPScalarArrayId(cg, id, hash, index);
return;
}
}
if ((m_op == T_ISSET || m_op == T_EMPTY || m_op == T_UNSET) && m_exp) {
if (m_exp->is(Expression::KindOfExpressionList)) {
ExpressionListPtr exps = dynamic_pointer_cast<ExpressionList>(m_exp);
if (exps->getListKind() == ExpressionList::ListKindParam) {
int count = exps->getCount();
if (count > 1) {
cg_printf("(");
}
for (int i = 0; i < count; i++) {
if (m_op == T_UNSET) {
if (i > 0) cg_printf(", ");
(*exps)[i]->outputCPPUnset(cg, ar);
} else {
if (i > 0) cg_printf(" && ");
(*exps)[i]->outputCPPExistTest(cg, ar, m_op);
}
}
if (exps->getCount() > 1) {
cg_printf(")");
}
return;
}
}
if (m_op == T_UNSET) {
m_exp->outputCPPUnset(cg, ar);
} else {
m_exp->outputCPPExistTest(cg, ar, m_op);
}
return;
}
if (m_front) {
switch (m_op) {
case T_CLONE: cg_printf("f_clone("); break;
case T_INC: cg_printf("++"); break;
case T_DEC: cg_printf("--"); break;
case '+': cg_printf("+"); break;
case '-': cg_printf("negate("); break;
case '!': cg_printf("!("); break;
case '~': cg_printf("~"); break;
case '(': cg_printf("("); break;
case T_INT_CAST: cg_printf("("); break;
case T_DOUBLE_CAST: cg_printf("("); break;
case T_STRING_CAST: cg_printf("("); break;
case T_ARRAY_CAST: cg_printf("("); break;
case T_OBJECT_CAST: cg_printf("("); break;
case T_BOOL_CAST: cg_printf("("); break;
case T_UNSET_CAST:
if (m_exp->hasCPPTemp()) {
cg_printf("(id(");
} else {
cg_printf("(");
}
break;
case T_EXIT: cg_printf("f_exit("); break;
case T_ARRAY:
cg_printf("Array(");
break;
case T_PRINT: cg_printf("print("); break;
case T_EVAL:
if (Option::EnableEval > Option::NoEval) {
bool instance;
if (getClassScope()) {
FunctionScopePtr fs = getFunctionScope();
instance = fs && !fs->isStatic();
} else {
instance = false;
}
//.........这里部分代码省略.........