本文整理汇总了C++中ConstantTablePtr::isDynamic方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstantTablePtr::isDynamic方法的具体用法?C++ ConstantTablePtr::isDynamic怎么用?C++ ConstantTablePtr::isDynamic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstantTablePtr
的用法示例。
在下文中一共展示了ConstantTablePtr::isDynamic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inferAndCheck
TypePtr SimpleFunctionCall::inferAndCheck(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
reset();
ConstructPtr self = shared_from_this();
// handling define("CONSTANT", ...);
if (m_className.empty()) {
if (m_type == DefineFunction && m_params && m_params->getCount() >= 2) {
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
string varName;
if (name) {
varName = name->getIdentifier();
if (!varName.empty()) {
ExpressionPtr value = (*m_params)[1];
TypePtr varType = value->inferAndCheck(ar, NEW_TYPE(Some), false);
ar->getDependencyGraph()->
addParent(DependencyGraph::KindOfConstant,
ar->getName(), varName, self);
ConstantTablePtr constants =
ar->findConstantDeclarer(varName)->getConstants();
if (constants != ar->getConstants()) {
if (value && !value->isScalar()) {
constants->setDynamic(ar, varName);
varType = Type::Variant;
}
if (constants->isDynamic(varName)) {
m_dynamicConstant = true;
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
} else {
constants->setType(ar, varName, varType, true);
}
// in case the old 'value' has been optimized
constants->setValue(ar, varName, value);
}
return checkTypesImpl(ar, type, Type::Boolean, coerce);
}
}
if (varName.empty() && ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::BadDefine, self);
}
} else if (m_type == ExtractFunction) {
ar->getScope()->getVariables()->forceVariants(ar);
}
}
FunctionScopePtr func;
// avoid raising both MissingObjectContext and UnknownFunction
bool errorFlagged = false;
if (m_className.empty()) {
func = ar->findFunction(m_name);
} else {
ClassScopePtr cls = ar->resolveClass(m_className);
if (cls && cls->isVolatile()) {
ar->getScope()->getVariables()
->setAttribute(VariableTable::NeedGlobalPointer);
}
if (!cls || cls->isRedeclaring()) {
if (cls) {
m_redeclaredClass = true;
}
if (!cls && ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UnknownClass, self);
}
if (m_params) {
m_params->inferAndCheck(ar, NEW_TYPE(Some), false);
}
return checkTypesImpl(ar, type, Type::Variant, coerce);
}
m_derivedFromRedeclaring = cls->derivesFromRedeclaring();
m_validClass = true;
if (m_name == "__construct") {
// if the class is known, php will try to identify class-name ctor
func = cls->findConstructor(ar, true);
}
else {
func = cls->findFunction(ar, m_name, true, true);
}
if (func && !func->isStatic()) {
ClassScopePtr clsThis = ar->getClassScope();
FunctionScopePtr funcThis = ar->getFunctionScope();
if (!clsThis ||
(clsThis->getName() != m_className &&
!clsThis->derivesFrom(ar, m_className)) ||
funcThis->isStatic()) {
// set the method static to avoid "unknown method" runtime exception
if (Option::StaticMethodAutoFix && !func->containsThis()) {
func->setStatic();
}
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::MissingObjectContext,
self);
errorFlagged = true;
}
//.........这里部分代码省略.........
示例2: preOptimize
ExpressionPtr SimpleFunctionCall::preOptimize(AnalysisResultPtr ar) {
ar->preOptimize(m_nameExp);
ar->preOptimize(m_params);
if (ar->getPhase() != AnalysisResult::SecondPreOptimize) {
return ExpressionPtr();
}
// optimize away various "exists" functions, this may trigger
// dead code elimination and improve type-inference.
if (m_className.empty() &&
(m_type == DefinedFunction ||
m_type == FunctionExistsFunction ||
m_type == ClassExistsFunction ||
m_type == InterfaceExistsFunction) &&
m_params && m_params->getCount() == 1) {
ExpressionPtr value = (*m_params)[0];
if (value->isScalar()) {
ScalarExpressionPtr name = dynamic_pointer_cast<ScalarExpression>(value);
if (name && name->isLiteralString()) {
string symbol = name->getLiteralString();
switch (m_type) {
case DefinedFunction: {
ConstantTablePtr constants = ar->getConstants();
// system constant
if (constants->isPresent(symbol)) {
return CONSTANT("true");
}
// user constant
BlockScopePtr block = ar->findConstantDeclarer(symbol);
// not found (i.e., undefined)
if (!block) {
if (symbol.find("::") == std::string::npos) {
return CONSTANT("false");
} else {
// e.g., defined("self::ZERO")
return ExpressionPtr();
}
}
constants = block->getConstants();
// already set to be dynamic
if (constants->isDynamic(symbol)) return ExpressionPtr();
ConstructPtr decl = constants->getValue(symbol);
ExpressionPtr constValue = dynamic_pointer_cast<Expression>(decl);
if (constValue->isScalar()) {
return CONSTANT("true");
} else {
return ExpressionPtr();
}
break;
}
case FunctionExistsFunction: {
const std::string &lname = Util::toLower(symbol);
if (Option::DynamicInvokeFunctions.find(lname) ==
Option::DynamicInvokeFunctions.end()) {
FunctionScopePtr func = ar->findFunction(lname);
if (!func) {
return CONSTANT("false");
} else if (!func->isVolatile()) {
return CONSTANT("true");
}
}
break;
}
case InterfaceExistsFunction: {
ClassScopePtr cls = ar->findClass(Util::toLower(symbol));
if (!cls || !cls->isInterface()) {
return CONSTANT("false");
} else if (!cls->isVolatile()) {
return CONSTANT("true");
}
break;
}
case ClassExistsFunction: {
ClassScopePtr cls = ar->findClass(Util::toLower(symbol));
if (!cls || cls->isInterface()) {
return CONSTANT("false");
} else if (!cls->isVolatile()) {
return CONSTANT("true");
}
break;
}
default:
ASSERT(false);
}
}
}
}
return ExpressionPtr();
}