本文整理汇总了C++中FunctionScopePtr::isStatic方法的典型用法代码示例。如果您正苦于以下问题:C++ FunctionScopePtr::isStatic方法的具体用法?C++ FunctionScopePtr::isStatic怎么用?C++ FunctionScopePtr::isStatic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FunctionScopePtr
的用法示例。
在下文中一共展示了FunctionScopePtr::isStatic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: RecordFunctionInfo
void FunctionScope::RecordFunctionInfo(std::string fname,
FunctionScopePtr func) {
VariableTablePtr variables = func->getVariables();
if (Option::WholeProgram) {
Lock lock(s_refParamInfoLock);
FunctionInfoPtr &info = s_refParamInfo[fname];
if (!info) {
info = std::make_shared<FunctionInfo>();
}
if (func->isStatic()) {
info->setMaybeStatic();
}
if (func->isRefReturn()) {
info->setMaybeRefReturn();
}
if (func->isReferenceVariableArgument()) {
info->setRefVarArg(func->getMaxParamCount());
}
for (int i = 0; i < func->getMaxParamCount(); i++) {
if (func->isRefParam(i)) info->setRefParam(i);
}
}
auto limit = func->getDeclParamCount();
for (int i = 0; i < limit; i++) {
variables->addParam(func->getParamName(i),
AnalysisResultPtr(), ConstructPtr());
}
}
示例3: analyzeProgramImpl
void MethodStatement::analyzeProgramImpl(AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
if (ar->isAnalyzeInclude()) {
if (funcScope->isSepExtension() ||
BuiltinSymbols::IsDeclaredDynamic(m_name) ||
Option::IsDynamicFunction(m_method, m_name) || Option::AllDynamic) {
funcScope->setDynamic();
}
}
funcScope->setIncludeLevel(ar->getIncludeLevel());
if (m_params) {
m_params->analyzeProgram(ar);
if (Option::GenRTTIProfileData &&
ar->getPhase() == AnalysisResult::AnalyzeFinal) {
addParamRTTI(ar);
}
}
if (m_stmt) m_stmt->analyzeProgram(ar);
if (ar->isAnalyzeInclude()) {
if (!funcScope->isStatic() && getClassScope() &&
funcScope->getVariables()->
getAttribute(VariableTable::ContainsDynamicVariable)) {
// Add this to variable table if we'll need it in a lookup table
// Use object because there's no point to specializing, just makes
// code gen harder when dealing with redeclared classes.
TypePtr tp(Type::Object);
funcScope->getVariables()->add("this", tp, true, ar, shared_from_this(),
ModifierExpressionPtr());
}
FunctionScope::RecordRefParamInfo(m_name, funcScope);
}
}
示例4: 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;
}
示例5: analyzeProgramImpl
void MethodStatement::analyzeProgramImpl(AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
// registering myself as a parent in dependency graph, so that
// (1) we can tell orphaned parents
// (2) overwrite non-master copy of function declarations
if (ar->isFirstPass()) {
ar->getDependencyGraph()->addParent(DependencyGraph::KindOfFunctionCall,
"", getFullName(), shared_from_this());
if (Option::AllDynamic || hasHphpNote("Dynamic") ||
funcScope->isSepExtension() ||
BuiltinSymbols::IsDeclaredDynamic(m_name) ||
Option::IsDynamicFunction(m_method, m_name)) {
funcScope->setDynamic();
}
if (hasHphpNote("Volatile")) funcScope->setVolatile();
}
funcScope->setIncludeLevel(ar->getIncludeLevel());
ar->pushScope(funcScope);
if (m_params) {
m_params->analyzeProgram(ar);
if (Option::GenRTTIProfileData &&
ar->getPhase() == AnalysisResult::AnalyzeFinal) {
addParamRTTI(ar);
}
}
if (m_stmt) m_stmt->analyzeProgram(ar);
if (ar->isFirstPass()) {
if (!funcScope->isStatic() && ar->getClassScope() &&
funcScope->getVariables()->
getAttribute(VariableTable::ContainsDynamicVariable)) {
// Add this to variable table if we'll need it in a lookup table
// Use object because there's no point to specializing, just makes
// code gen harder when dealing with redeclared classes.
TypePtr tp(NEW_TYPE(Object));
funcScope->getVariables()->add("this", tp, true, ar, shared_from_this(),
ModifierExpressionPtr());
}
FunctionScope::RecordRefParamInfo(m_name, funcScope);
}
ar->popScope();
}
示例6: setStaticDynamic
void ClassScope::setStaticDynamic(AnalysisResultConstPtr ar) {
for (FunctionScopePtrVec::const_iterator iter =
m_functionsVec.begin(); iter != m_functionsVec.end(); ++iter) {
FunctionScopePtr fs = *iter;
if (fs->isStatic()) fs->setDynamic();
}
if (!m_parent.empty()) {
if (derivesFromRedeclaring() == Derivation::Redeclaring) {
const ClassScopePtrVec &parents = ar->findRedeclaredClasses(m_parent);
for (ClassScopePtr cl: parents) {
cl->setStaticDynamic(ar);
}
} else {
ClassScopePtr parent = ar->findClass(m_parent);
if (parent) {
parent->setStaticDynamic(ar);
}
}
}
}
示例7: outputCPPUnset
void ObjectPropertyExpression::outputCPPUnset(CodeGenerator &cg,
AnalysisResultPtr ar) {
bool bThis = m_object->isThis();
if (bThis) {
FunctionScopePtr func = ar->getFunctionScope();
if (func && func->isStatic()) {
cg.printf("GET_THIS_ARROW()");
}
} else {
m_object->outputCPP(cg, ar);
cg_printf("->");
}
cg_printf("t___unset(");
bool direct = m_property->isUnquotedScalar();
if (direct) {
cg_printf("\"");
}
m_property->outputCPP(cg, ar);
if (direct) {
cg_printf("\"");
}
cg_printf(")");
}
示例8: inferTypes
TypePtr ObjectPropertyExpression::inferTypes(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
m_valid = false;
ConstructPtr self = shared_from_this();
TypePtr objectType = m_object->inferAndCheck(ar, NEW_TYPE(Object), false);
if (!m_property->is(Expression::KindOfScalarExpression)) {
// if dynamic property or method, we have nothing to find out
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UseDynamicProperty, self);
}
m_property->inferAndCheck(ar, Type::String, false);
// we also lost track of which class variable an expression is about, hence
// any type inference could be wrong. Instead, we just force variants on
// all class variables.
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants();
}
return Type::Variant; // we have to use a variant to hold dynamic value
}
ScalarExpressionPtr exp = dynamic_pointer_cast<ScalarExpression>(m_property);
string name = exp->getString();
ASSERT(!name.empty());
m_property->inferAndCheck(ar, Type::String, false);
ClassScopePtr cls;
if (objectType && !objectType->getName().empty()) {
// what object-> has told us
cls = ar->findExactClass(objectType->getName());
} else {
// what ->property has told us
cls = ar->findClass(name, AnalysisResult::PropertyName);
if (cls) {
objectType =
m_object->inferAndCheck(ar, Type::CreateObjectType(cls->getName()),
false);
}
if ((m_context & LValue) &&
objectType && !objectType->is(Type::KindOfObject) &&
!objectType->is(Type::KindOfVariant) &&
!objectType->is(Type::KindOfSome) &&
!objectType->is(Type::KindOfAny)) {
m_object->inferAndCheck(ar, NEW_TYPE(Object), true);
}
}
if (!cls) {
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants(name);
}
return Type::Variant;
}
const char *accessorName = hasContext(DeepAssignmentLHS) ? "__set" :
hasContext(ExistContext) ? "__isset" :
hasContext(UnsetContext) ? "__unset" : "__get";
if (!cls->implementsAccessor(ar, accessorName)) clearEffect(AccessorEffect);
// resolved to this class
int present = 0;
if (m_context & RefValue) {
type = Type::Variant;
coerce = true;
}
// use $this inside a static function
if (m_object->isThis()) {
FunctionScopePtr func = ar->getFunctionScope();
if (func->isStatic()) {
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::MissingObjectContext,
self);
}
m_actualType = Type::Variant;
return m_actualType;
}
}
TypePtr ret;
if (!cls->derivesFromRedeclaring()) { // Have to use dynamic.
ret = cls->checkProperty(name, type, coerce, ar, self, present);
// Private only valid if in the defining class
if (present && (getOriginalScope(ar) == cls ||
!(present & VariableTable::VariablePrivate))) {
m_valid = true;
m_static = present & VariableTable::VariableStatic;
if (m_static) {
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
m_class = cls;
}
}
// get() will return Variant
//.........这里部分代码省略.........
示例9: 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;
}
//.........这里部分代码省略.........
示例10: inferTypes
TypePtr ObjectPropertyExpression::inferTypes(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
m_valid = false;
ConstructPtr self = shared_from_this();
TypePtr objectType = m_object->inferAndCheck(ar, Type::Some, false);
if (!m_property->is(Expression::KindOfScalarExpression)) {
m_property->inferAndCheck(ar, Type::String, false);
// we also lost track of which class variable an expression is about, hence
// any type inference could be wrong. Instead, we just force variants on
// all class variables.
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants(getOriginalClass(), false);
}
return Type::Variant; // we have to use a variant to hold dynamic value
}
ScalarExpressionPtr exp = dynamic_pointer_cast<ScalarExpression>(m_property);
string name = exp->getString();
ASSERT(!name.empty());
m_property->inferAndCheck(ar, Type::String, false);
ClassScopePtr cls;
if (objectType && !objectType->getName().empty()) {
// what object-> has told us
cls = ar->findExactClass(shared_from_this(), objectType->getName());
} else {
if ((m_context & LValue) && objectType &&
!objectType->is(Type::KindOfObject) &&
!objectType->is(Type::KindOfVariant) &&
!objectType->is(Type::KindOfSome) &&
!objectType->is(Type::KindOfAny)) {
m_object->inferAndCheck(ar, Type::Object, true);
}
}
if (!cls) {
if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
ar->forceClassVariants(name, getOriginalClass(), false);
}
return Type::Variant;
}
int prop = hasContext(AssignmentLHS) ? ClassScope::MayHaveUnknownPropSetter :
hasContext(ExistContext) ? ClassScope::MayHaveUnknownPropTester :
hasContext(UnsetContext) && hasContext(LValue) ?
ClassScope::MayHavePropUnsetter : ClassScope::MayHaveUnknownPropGetter;
if ((m_context & (AssignmentLHS|OprLValue)) ||
!cls->implementsAccessor(prop)) {
clearEffect(AccessorEffect);
}
// resolved to this class
if (m_context & RefValue) {
type = Type::Variant;
coerce = true;
}
// use $this inside a static function
if (m_object->isThis()) {
FunctionScopePtr func = m_object->getOriginalFunction();
if (!func || func->isStatic()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::MissingObjectContext, self);
}
m_actualType = Type::Variant;
return m_actualType;
}
}
if (!m_propSym || cls != m_objectClass.lock()) {
m_objectClass = cls;
ClassScopePtr parent;
m_propSym = cls->findProperty(parent, name, ar, self);
assert(m_propSym);
if (!parent) {
parent = cls;
}
m_propSymValid = m_propSym->isPresent() &&
(!m_propSym->isPrivate() ||
getOriginalClass() == parent) &&
!m_propSym->isStatic();
if (m_propSymValid) {
parent->addUse(getScope(), BlockScope::UseKindNonStaticRef);
}
}
TypePtr ret;
if (m_propSymValid && (!cls->derivesFromRedeclaring() ||
m_propSym->isPrivate())) {
ret = cls->checkProperty(m_propSym, type, coerce, ar);
assert(m_object->getType()->isSpecificObject());
m_valid = true;
clearEffect(AccessorEffect);
//.........这里部分代码省略.........
示例11: inferAndCheck
TypePtr ObjectMethodExpression::inferAndCheck(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
assert(type);
IMPLEMENT_INFER_AND_CHECK_ASSERT(getScope());
resetTypes();
reset();
ConstructPtr self = shared_from_this();
TypePtr objectType = m_object->inferAndCheck(ar, Type::Some, false);
m_valid = true;
m_bindClass = true;
if (m_name.empty()) {
m_nameExp->inferAndCheck(ar, Type::Some, false);
setInvokeParams(ar);
// we have to use a variant to hold dynamic value
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
ClassScopePtr cls;
if (objectType && !objectType->getName().empty()) {
if (m_classScope && !strcasecmp(objectType->getName().c_str(),
m_classScope->getName().c_str())) {
cls = m_classScope;
} else {
cls = ar->findExactClass(shared_from_this(), objectType->getName());
}
}
if (!cls) {
m_classScope.reset();
m_funcScope.reset();
m_valid = false;
setInvokeParams(ar);
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
if (m_classScope != cls) {
m_classScope = cls;
m_funcScope.reset();
}
FunctionScopePtr func = m_funcScope;
if (!func) {
func = cls->findFunction(ar, m_name, true, true);
if (!func) {
if (!cls->isTrait() &&
!cls->getAttribute(ClassScope::MayHaveUnknownMethodHandler) &&
!cls->getAttribute(ClassScope::HasUnknownMethodHandler) &&
!cls->getAttribute(ClassScope::InheritsUnknownMethodHandler)) {
if (ar->classMemberExists(m_name, AnalysisResult::MethodName)) {
if (!Option::AllDynamic) {
setDynamicByIdentifier(ar, m_name);
}
} else {
Compiler::Error(Compiler::UnknownObjectMethod, self);
}
}
m_valid = false;
setInvokeParams(ar);
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
m_funcScope = func;
func->addCaller(getScope(), !type->is(Type::KindOfAny));
}
bool valid = true;
m_bindClass = func->isStatic();
// use $this inside a static function
if (m_object->isThis()) {
FunctionScopePtr localfunc = getFunctionScope();
if (localfunc->isStatic()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::MissingObjectContext, self);
}
valid = false;
}
}
// invoke() will return Variant
if (cls->isInterface() ||
(func->isVirtual() &&
(!Option::WholeProgram || func->isAbstract() ||
(func->hasOverride() && cls->getAttribute(ClassScope::NotFinal))) &&
!func->isPerfectVirtual())) {
valid = false;
}
if (!valid) {
setInvokeParams(ar);
checkTypesImpl(ar, type, Type::Variant, coerce);
m_valid = false; // so we use invoke() syntax
if (!Option::AllDynamic) {
func->setDynamic();
}
assert(m_actualType);
return m_actualType;
//.........这里部分代码省略.........
示例12: outputCPPImpl
void MethodStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
ClassScopePtr scope = ar->getClassScope();
string origFuncName;
ar->pushScope(funcScope);
if (outputFFI(cg, ar)) return;
cg.setPHPLineNo(-1);
if (cg.getContext() == CodeGenerator::CppImplementation) {
printSource(cg);
}
switch (cg.getContext()) {
case CodeGenerator::CppDeclaration:
{
if (!m_stmt) {
cg.printf("// ");
}
m_modifiers->outputCPP(cg, ar);
if (m_name == "__offsetget_lval") {
cg.printf("virtual ");
}
TypePtr type = funcScope->getReturnType();
if (type) {
type->outputCPPDecl(cg, ar);
} else {
cg.printf("void");
}
if (m_name == "__lval") {
cg.printf(" &___lval(");
} else if (m_name == "__offsetget_lval") {
cg.printf(" &___offsetget_lval(");
} else if (m_modifiers->isStatic() && m_stmt) {
// Static method wrappers get generated as support methods
cg.printf(" %s%s(const char* cls%s", Option::MethodImplPrefix,
m_name.c_str(),
funcScope->isVariableArgument() ||
(m_params && m_params->getCount()) ? ", " : "");
} else {
cg.printf(" %s%s(", Option::MethodPrefix, m_name.c_str());
}
funcScope->outputCPPParamsDecl(cg, ar, m_params, true);
if (m_stmt) {
cg.printf(");\n");
} else {
cg.printf(") = 0;\n");
}
if (funcScope->isConstructor(scope)
&& !funcScope->isAbstract() && !scope->isInterface()) {
funcScope->outputCPPCreateDecl(cg, ar);
}
}
break;
case CodeGenerator::CppImplementation:
if (m_stmt) {
TypePtr type = funcScope->getReturnType();
if (type) {
type->outputCPPDecl(cg, ar);
} else {
cg.printf("void");
}
origFuncName = std::string(scope->getOriginalName()) +
"::" + m_originalName;
if (Option::HotFunctions.find(origFuncName) !=
Option::HotFunctions.end()) {
cg.printf(" __attribute((__section__(\".text.hot\")))");
} else if (Option::ColdFunctions.find(origFuncName) !=
Option::ColdFunctions.end()) {
cg.printf(" __attribute((__section__(\".text.cold\")))");
}
if (m_name == "__lval") {
cg.printf(" &%s%s::___lval(",
Option::ClassPrefix, scope->getId().c_str());
} else if (m_name == "__offsetget_lval") {
cg.printf(" &%s%s::___offsetget_lval(",
Option::ClassPrefix, scope->getId().c_str());
} else if (m_modifiers->isStatic()) {
cg.printf(" %s%s::%s%s(const char* cls%s", Option::ClassPrefix,
scope->getId().c_str(),
Option::MethodImplPrefix, m_name.c_str(),
funcScope->isVariableArgument() ||
(m_params && m_params->getCount()) ? ", " : "");
} else {
cg.printf(" %s%s::%s%s(", Option::ClassPrefix, scope->getId().c_str(),
Option::MethodPrefix, m_name.c_str());
}
funcScope->outputCPPParamsDecl(cg, ar, m_params, false);
cg.indentBegin(") {\n");
if (m_modifiers->isStatic()) {
cg.printf("STATIC_METHOD_INJECTION(%s, %s::%s);\n",
scope->getOriginalName(), scope->getOriginalName(),
m_originalName.c_str());
} else {
cg.printf("INSTANCE_METHOD_INJECTION(%s, %s::%s);\n",
scope->getOriginalName(), scope->getOriginalName(),
m_originalName.c_str());
//.........这里部分代码省略.........
示例13: inferTypes
TypePtr ObjectPropertyExpression::inferTypes(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
m_valid = false;
ConstructPtr self = shared_from_this();
TypePtr objectType = m_object->inferAndCheck(ar, Type::Some, false);
if (!m_property->is(Expression::KindOfScalarExpression)) {
m_property->inferAndCheck(ar, Type::String, false);
// we also lost track of which class variable an expression is about, hence
// any type inference could be wrong. Instead, we just force variants on
// all class variables.
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants(getOriginalClass(), false, true);
}
return Type::Variant; // we have to use a variant to hold dynamic value
}
ScalarExpressionPtr exp = dynamic_pointer_cast<ScalarExpression>(m_property);
const string &name = exp->getLiteralString();
if (name.empty()) {
m_property->inferAndCheck(ar, Type::String, false);
if (m_context & (LValue | RefValue)) {
ar->forceClassVariants(getOriginalClass(), false, true);
}
return Type::Variant; // we have to use a variant to hold dynamic value
}
m_property->inferAndCheck(ar, Type::String, false);
ClassScopePtr cls;
if (objectType && !objectType->getName().empty()) {
// what object-> has told us
cls = ar->findExactClass(shared_from_this(), objectType->getName());
} else {
if ((m_context & LValue) && objectType &&
!objectType->is(Type::KindOfObject) &&
!objectType->is(Type::KindOfVariant) &&
!objectType->is(Type::KindOfSome) &&
!objectType->is(Type::KindOfAny)) {
m_object->inferAndCheck(ar, Type::Object, true);
}
}
if (!cls) {
if (m_context & (LValue | RefValue | DeepReference | UnsetContext)) {
ar->forceClassVariants(name, getOriginalClass(), false, true);
}
return Type::Variant;
}
// resolved to this class
if (m_context & RefValue) {
type = Type::Variant;
coerce = true;
}
// use $this inside a static function
if (m_object->isThis()) {
FunctionScopePtr func = m_object->getOriginalFunction();
if (!func || func->isStatic()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::MissingObjectContext, self);
}
m_actualType = Type::Variant;
return m_actualType;
}
}
assert(cls);
if (!m_propSym || cls != m_objectClass.lock()) {
m_objectClass = cls;
ClassScopePtr parent;
m_propSym = cls->findProperty(parent, name, ar);
if (m_propSym) {
if (!parent) {
parent = cls;
}
m_symOwner = parent;
always_assert(m_propSym->isPresent());
m_propSymValid =
(!m_propSym->isPrivate() || getOriginalClass() == parent) &&
!m_propSym->isStatic();
if (m_propSymValid) {
m_symOwner->addUse(getScope(),
BlockScope::GetNonStaticRefUseKind(
m_propSym->getHash()));
}
}
}
TypePtr ret;
if (m_propSymValid && (!cls->derivesFromRedeclaring() ||
m_propSym->isPrivate())) {
always_assert(m_symOwner);
TypePtr t(m_propSym->getType());
if (t && t->is(Type::KindOfVariant)) {
// only check property if we could possibly do some work
ret = t;
//.........这里部分代码省略.........
示例14: inferAndCheck
TypePtr SimpleVariable::inferAndCheck(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
TypePtr ret;
ConstructPtr construct = shared_from_this();
BlockScopePtr scope = ar->getScope();
VariableTablePtr variables = scope->getVariables();
// check function parameter that can occur in lval context
if (m_context & (LValue | RefValue | UnsetContext | InvokeArgument)) {
FunctionScopePtr func = dynamic_pointer_cast<FunctionScope>(scope);
if (func) {
if (variables->isParameter(m_name)) {
variables->addLvalParam(m_name);
}
}
}
if (m_name == "this") {
ClassScopePtr cls = getOriginalScope(ar);
if (cls) {
bool isStaticFunc = false;
FunctionScopePtr func = dynamic_pointer_cast<FunctionScope>(scope);
if (func->isStatic()) isStaticFunc = true;
if (cls->isRedeclaring()) {
ret = Type::Variant;
} else {
ret = Type::CreateObjectType(cls->getName());
}
if (!isStaticFunc || (m_context & ObjectContext)) m_this = true;
}
}
if ((m_context & (LValue|Declaration)) && !(m_context & ObjectContext)) {
if (m_superGlobal) {
ret = m_superGlobalType;
} else if (m_superGlobalType) { // For system
if (!m_this) {
ret = variables->add(m_name, m_superGlobalType,
((m_context & Declaration) != Declaration), ar,
construct, scope->getModifiers());
}
} else {
if (m_globals) {
ret = Type::Variant; // this can happen with "unset($GLOBALS)"
} else if (!m_this) {
ret = variables->add(m_name, type,
((m_context & Declaration) != Declaration), ar,
construct, scope->getModifiers());
}
}
} else {
if (!m_this) {
if (m_superGlobalType) {
ret = m_superGlobalType;
} else if (m_globals) {
ret = Type::Array;
} else if (scope->is(BlockScope::ClassScope)) {
// ClassVariable expression will come to this block of code
int properties;
ret = variables->checkProperty(m_name, type, true, ar, construct,
properties);
} else {
TypePtr tmpType = type;
if (m_context & RefValue) {
tmpType = Type::Variant;
coerce = true;
}
int p;
ret = variables->checkVariable(m_name, tmpType, coerce, ar, construct,
p);
}
}
}
TypePtr actual = propagateTypes(ar, ret);
setTypes(actual, type);
if (Type::SameType(actual, ret)) {
m_implementedType.reset();
} else {
m_implementedType = ret;
}
return actual;
}
示例15: inferAndCheck
TypePtr ObjectMethodExpression::inferAndCheck(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
reset();
ConstructPtr self = shared_from_this();
TypePtr objectType = m_object->inferAndCheck(ar, Type::Object, false);
m_valid = true;
m_bindClass = true;
if (m_name.empty()) {
m_nameExp->inferAndCheck(ar, Type::String, false);
setInvokeParams(ar);
// we have to use a variant to hold dynamic value
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
ClassScopePtr cls;
if (objectType && !objectType->getName().empty()) {
if (m_classScope && !strcasecmp(objectType->getName().c_str(),
m_classScope->getName().c_str())) {
cls = m_classScope;
} else {
cls = ar->findExactClass(shared_from_this(), objectType->getName());
}
}
if (!cls) {
if (getScope()->isFirstPass()) {
// call resolveClass to mark functions as dynamic
// but we cant do anything else with the result.
resolveClass(ar, m_name);
if (!ar->classMemberExists(m_name, AnalysisResult::MethodName)) {
Compiler::Error(Compiler::UnknownObjectMethod, self);
}
}
m_classScope.reset();
m_funcScope.reset();
setInvokeParams(ar);
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
if (m_classScope != cls) {
m_classScope = cls;
m_funcScope.reset();
}
FunctionScopePtr func = m_funcScope;
if (!func) {
func = cls->findFunction(ar, m_name, true, true);
if (!func) {
if (!cls->hasAttribute(ClassScope::HasUnknownMethodHandler, ar)) {
if (ar->classMemberExists(m_name, AnalysisResult::MethodName)) {
setDynamicByIdentifier(ar, m_name);
} else {
Compiler::Error(Compiler::UnknownObjectMethod, self);
}
}
m_valid = false;
setInvokeParams(ar);
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
m_funcScope = func;
func->addCaller(getScope());
}
bool valid = true;
m_bindClass = func->isStatic();
// use $this inside a static function
if (m_object->isThis()) {
FunctionScopePtr localfunc = getFunctionScope();
if (localfunc->isStatic()) {
if (getScope()->isFirstPass()) {
Compiler::Error(Compiler::MissingObjectContext, self);
}
valid = false;
}
}
// invoke() will return Variant
if (!m_object->getType()->isSpecificObject() ||
(func->isVirtual() && !func->isPerfectVirtual())) {
valid = false;
}
if (!valid) {
setInvokeParams(ar);
checkTypesImpl(ar, type, Type::Variant, coerce);
m_valid = false; // so we use invoke() syntax
func->setDynamic();
return m_actualType;
}
return checkParamsAndReturn(ar, type, coerce, func, false);
}