本文整理汇总了C++中FunctionScopePtr::isVariableArgument方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionScopePtr::isVariableArgument方法的具体用法?C++ FunctionScopePtr::isVariableArgument怎么用?C++ FunctionScopePtr::isVariableArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FunctionScopePtr
的用法示例。
在下文中一共展示了FunctionScopePtr::isVariableArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: 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");
}
示例3: checkParamsAndReturn
TypePtr FunctionCall::checkParamsAndReturn(AnalysisResultPtr ar,
TypePtr type, bool coerce,
FunctionScopePtr func) {
ConstructPtr self = shared_from_this();
ar->getDependencyGraph()->add(DependencyGraph::KindOfFunctionCall,
ar->getName(), getText(),
self, func->getFullName(), func->getStmt());
TypePtr frt = func->getReturnType();
if (!frt) {
m_voidReturn = true;
setActualType(TypePtr());
if (!type->is(Type::KindOfAny)) {
if (!m_allowVoidReturn && ar->isSecondPass() && !func->isAbstract()) {
ar->getCodeError()->record(self, CodeError::UseVoidReturn, self);
}
m_voidWrapper = true;
}
} else {
m_voidReturn = false;
m_voidWrapper = false;
type = checkTypesImpl(ar, type, frt, coerce);
}
m_extraArg = func->inferParamTypes(ar, self, m_params, m_valid);
m_variableArgument = func->isVariableArgument();
if (m_valid) {
m_implementedType.reset();
} else {
m_implementedType = Type::Variant;
}
return type;
}
示例4: matchParams
bool FunctionScope::matchParams(FunctionScopePtr func) {
// leaving them alone for now
if (m_overriding || func->m_overriding) return false;
if (isStatic() || func->isStatic()) return false;
// conservative here, as we could normalize them into same counts.
if (m_minParam != func->m_minParam || m_maxParam != func->m_maxParam) {
return false;
}
if (isVariableArgument() != func->isVariableArgument() ||
isReferenceVariableArgument() != func->isReferenceVariableArgument() ||
isMixedVariableArgument() != func->isMixedVariableArgument()) {
return false;
}
// needs perfect match for ref, hint and defaults
for (int i = 0; i < m_maxParam; i++) {
if (m_refs[i] != func->m_refs[i]) return false;
TypePtr type1 = m_paramTypeSpecs[i];
TypePtr type2 = func->m_paramTypeSpecs[i];
if ((type1 && !type2) || (!type1 && type2) ||
(type1 && type2 && !Type::SameType(type1, type2))) return false;
if (m_paramDefaults[i] != func->m_paramDefaults[i]) return false;
}
return true;
}
示例5: inferTypes
TypePtr NewObjectExpression::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
reset();
ConstructPtr self = shared_from_this();
if (!m_name.empty()) {
ClassScopePtr cls = ar->resolveClass(m_name);
if (cls) {
m_name = cls->getName();
}
if (!cls || cls->isRedeclaring()) {
if (cls) {
m_redeclared = true;
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
if (!cls && ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UnknownClass, self);
}
if (m_params) m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
return NEW_TYPE(Object);
}
if (cls->isVolatile()) {
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
m_dynamic = cls->derivesFromRedeclaring();
m_validClass = true;
FunctionScopePtr func = cls->findConstructor(ar, true);
if (!func) {
if (m_params) {
if (!m_dynamic && m_params->getCount()) {
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::BadConstructorCall,
self);
}
m_params->setOutputCount(0);
}
m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
}
} else {
m_extraArg = func->inferParamTypes(ar, self, m_params,
m_validClass);
m_variableArgument = func->isVariableArgument();
}
return Type::CreateObjectType(m_name);
} else {
ar->containsDynamicClass();
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UseDynamicClass,
self);
}
if (m_params) {
m_params->markParams(false);
}
}
m_nameExp->inferAndCheck(ar, Type::String, false);
if (m_params) m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
return Type::Variant;//NEW_TYPE(Object);
}
示例6: checkParamsAndReturn
TypePtr FunctionCall::checkParamsAndReturn(AnalysisResultPtr ar,
TypePtr type, bool coerce,
FunctionScopePtr func,
bool arrayParams) {
ConstructPtr self = shared_from_this();
TypePtr frt = func->getReturnType();
if (!frt) {
m_voidReturn = true;
setActualType(TypePtr());
if (!type->is(Type::KindOfAny)) {
if (!m_allowVoidReturn && !func->isFirstPass() && !func->isAbstract()) {
Compiler::Error(Compiler::UseVoidReturn, self);
}
m_voidWrapper = true;
}
} else {
m_voidReturn = false;
m_voidWrapper = false;
type = checkTypesImpl(ar, type, frt, coerce);
}
if (arrayParams) {
m_extraArg = 0;
(*m_params)[0]->inferAndCheck(ar, Type::Array, false);
} else {
m_extraArg = func->inferParamTypes(ar, self, m_params, m_valid);
}
m_variableArgument = func->isVariableArgument();
if (m_valid) {
m_implementedType.reset();
} else {
m_implementedType = Type::Variant;
}
return type;
}
示例7: 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");
}
示例8: checkParamsAndReturn
TypePtr FunctionCall::checkParamsAndReturn(AnalysisResultPtr ar,
TypePtr type, bool coerce,
FunctionScopePtr func,
bool arrayParams) {
#ifdef HPHP_DETAILED_TYPE_INF_ASSERT
assert(func->hasUser(getScope(), BlockScope::UseKindCaller));
#endif /* HPHP_DETAILED_TYPE_INF_ASSERT */
ConstructPtr self = shared_from_this();
TypePtr frt;
{
TRY_LOCK(func);
func->getInferTypesMutex().assertOwnedBySelf();
assert(!func->inVisitScopes() || getScope() == func);
frt = func->getReturnType();
}
if (!frt) {
m_voidReturn = true;
setActualType(TypePtr());
if (!isUnused() && !type->is(Type::KindOfAny)) {
if (!hasContext(ReturnContext) &&
!func->isFirstPass() && !func->isAbstract()) {
if (Option::WholeProgram || !func->getContainingClass() ||
func->isStatic() || func->isFinal() || func->isPrivate()) {
Compiler::Error(Compiler::UseVoidReturn, self);
}
}
if (!Type::IsMappedToVariant(type)) {
setExpectedType(type);
}
m_voidWrapper = true;
}
} else {
m_voidReturn = false;
m_voidWrapper = false;
type = checkTypesImpl(ar, type, frt, coerce);
assert(m_actualType);
}
if (arrayParams) {
m_extraArg = 0;
(*m_params)[0]->inferAndCheck(ar, Type::Array, false);
} else {
m_extraArg = func->inferParamTypes(ar, self, m_params, m_valid);
}
m_variableArgument = func->isVariableArgument();
if (m_valid) {
m_implementedType.reset();
} else {
m_implementedType = Type::Variant;
}
assert(type);
return type;
}
示例9: 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");
}
示例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: outputJavaFFIConstructor
void ClassStatement::outputJavaFFIConstructor(CodeGenerator &cg,
AnalysisResultPtr ar,
FunctionScopePtr cons) {
int ac = cons ? cons->getMaxParamCount() : 0;
bool varArgs = cons && cons->isVariableArgument();
// generates the constructor
cg_printf("public %s(", getOriginalName().c_str());
ostringstream args;
ostringstream params;
bool first = true;
for (int i = 0; i < ac; i++) {
if (first) {
first = false;
}
else {
cg_printf(", ");
args << ", ";
params << ", ";
}
cg_printf("HphpVariant a%d", i);
args << "a" << i << ".getVariantPtr()";
params << "long a" << i;
}
if (varArgs) {
if (!first) {
cg_printf(", ");
args << ", ";
params << ", ";
}
cg_printf("HphpVariant va");
args << "va.getVariantPtr()";
params << "long va";
}
cg_indentBegin(") {\n");
cg_printf("this(create(%s));\n", args.str().c_str());
cg_indentEnd("}\n\n");
// generates the native method stub for creating the object
cg_printf("private static native long create(%s);\n\n",
params.str().c_str());
}
示例12: outputJavaFFICPPStub
void MethodStatement::outputJavaFFICPPStub(CodeGenerator &cg,
AnalysisResultPtr ar) {
// TODO translate PHP namespace once that is supported
string packageName = Option::JavaFFIRootPackage;
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();
int ac = funcScope->getMaxParamCount();
bool exposeNative = !(ac > 0 || varArgs || !isStatic || !ret && inClass);
if (inClass && m_modifiers->isAbstract()) {
// skip all the abstract methods, because hphp doesn't generate code
// for them
return;
}
if (fname == "__lval" || fname == "__offsetget_lval") return;
const char *clsName;
if (inClass) {
// uses capitalized original class name
ClassScopePtr cls = ar->findClass(m_className);
clsName = cls->getOriginalName();
}
else {
clsName = "HphpMain";
}
string mangledName = "Java." + packageName + "." + clsName + "." + fname
+ (exposeNative ? "" : "_native");
// all the existing "_" are replaced as "_1"
Util::replaceAll(mangledName, "_", "_1");
Util::replaceAll(mangledName, ".", "_");
cg.printf("JNIEXPORT %s JNICALL\n", ret ? "jobject" : "void");
cg.printf("%s(JNIEnv *env, %s target", mangledName.c_str(),
(isStatic ? "jclass" : "jobject"));
ostringstream args;
bool first = true;
if (!isStatic) {
// instance method also gets an additional argument, which is a Variant
// pointer to the target, encoded in int64
first = false;
cg.printf(", jlong targetPtr");
args << "(Variant *)targetPtr";
}
for (int i = 0; i < ac; i++) {
cg.printf(", jlong a%d", i);
if (first) first = false;
else args << ", ";
args << "(Variant *)a" << i;
}
if (varArgs) {
cg.printf(", jlong va");
if (!first) args << ", ";
args << "(Variant *)va";
}
if (cg.getContext() == CodeGenerator::JavaFFICppDecl) {
// java_stubs.h
cg.printf(");\n\n");
return;
}
cg.indentBegin(") {\n");
// support static/instance methods
if (ret) {
cg.printf("void *result;\n");
cg.printf("int kind = ");
cg.printf("%s%s%s(&result",
Option::FFIFnPrefix,
(inClass ? (m_className + "_cls_").c_str() : ""), fname.c_str());
if (!isStatic || ac > 0 || varArgs) cg.printf(", ");
}
else {
cg.printf("%s%s%s(", Option::FFIFnPrefix,
(inClass ? (m_className + "_cls_").c_str() : ""),
fname.c_str());
}
cg.printf("%s);\n", args.str().c_str());
if (ret) {
if (!inClass) {
// HphpMain extends hphp.Hphp.
cg.printf("jclass hphp = env->GetSuperclass(target);\n");
}
else {
cg.printf("jclass hphp = env->FindClass(\"hphp/Hphp\");\n");
}
cg.printf("return exportVariantToJava(env, hphp, result, kind);\n");
}
cg.indentEnd("} /* function */\n\n");
}
示例13: inferTypes
TypePtr NewObjectExpression::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
reset();
m_classScope.reset();
m_funcScope.reset();
ConstructPtr self = shared_from_this();
if (!m_name.empty()) {
ClassScopePtr cls = resolveClass(getScope());
m_name = m_className;
if (!cls) {
if (isRedeclared()) {
getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
} else if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::UnknownClass, self);
}
if (m_params) m_params->inferAndCheck(ar, Type::Any, false);
return Type::Object;
}
if (cls->isVolatile() && !isPresent()) {
getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
m_dynamic = cls->derivesFromRedeclaring();
bool valid = true;
FunctionScopePtr func = cls->findConstructor(ar, true);
if (!func) {
if (m_params) {
if (!m_dynamic && m_params->getCount()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::BadConstructorCall, self);
}
m_params->setOutputCount(0);
}
m_params->inferAndCheck(ar, Type::Some, false);
}
} else {
m_extraArg = func->inferParamTypes(ar, self, m_params,
valid);
m_variableArgument = func->isVariableArgument();
}
if (valid) {
m_classScope = cls;
m_funcScope = func;
}
if (!valid || m_dynamic) {
m_implementedType = Type::Object;
} else {
m_implementedType.reset();
}
return Type::CreateObjectType(m_name);
} else {
ar->containsDynamicClass();
if (m_params) {
m_params->markParams(false);
}
}
m_implementedType.reset();
m_nameExp->inferAndCheck(ar, Type::String, false);
if (m_params) m_params->inferAndCheck(ar, Type::Any, false);
return Type::Object;
}
示例14: inferTypes
TypePtr NewObjectExpression::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
reset();
m_classScope.reset();
FunctionScopePtr prev = m_funcScope;
m_funcScope.reset();
ConstructPtr self = shared_from_this();
if (!m_name.empty() && !isStatic()) {
ClassScopePtr cls = resolveClassWithChecks();
m_name = m_className;
if (!cls) {
if (m_params) m_params->inferAndCheck(ar, Type::Any, false);
return Type::Object;
}
if (getScope()->isFirstPass() &&
(cls->isTrait() ?
!isSelf() && !isParent() :
cls->isInterface() || cls->isAbstract())) {
Compiler::Error(Compiler::InvalidInstantiation, self);
}
if (cls->isVolatile() && !isPresent()) {
getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
m_dynamic = cls->derivesFromRedeclaring();
bool valid = true;
FunctionScopePtr func = cls->findConstructor(ar, true);
if (!func) {
if (m_params) {
if (!m_dynamic && m_params->getCount()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::BadConstructorCall, self);
}
}
m_params->inferAndCheck(ar, Type::Some, false);
}
} else {
if (func != prev) func->addNewObjCaller(getScope());
m_extraArg = func->inferParamTypes(ar, self, m_params, valid);
m_variableArgument = func->isVariableArgument();
}
if (valid) {
m_classScope = cls;
m_funcScope = func;
}
if (!valid || m_dynamic) {
m_implementedType = Type::Object;
} else {
m_implementedType.reset();
}
return Type::CreateObjectType(m_name);
} else {
if (m_params) {
m_params->markParams(canInvokeFewArgs());
}
}
m_implementedType.reset();
m_nameExp->inferAndCheck(ar, Type::String, false);
if (m_params) m_params->inferAndCheck(ar, Type::Any, false);
return Type::Object;
}
示例15: 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(",
//.........这里部分代码省略.........