本文整理汇总了C++中AnalysisResultPtr::getConstants方法的典型用法代码示例。如果您正苦于以下问题:C++ AnalysisResultPtr::getConstants方法的具体用法?C++ AnalysisResultPtr::getConstants怎么用?C++ AnalysisResultPtr::getConstants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnalysisResultPtr
的用法示例。
在下文中一共展示了AnalysisResultPtr::getConstants方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isDefineWithoutImpl
bool SimpleFunctionCall::isDefineWithoutImpl(AnalysisResultPtr ar) {
if (!m_className.empty()) return false;
if (m_type == DefineFunction && m_params && m_params->getCount() >= 2) {
if (m_dynamicConstant) return false;
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
if (!name) return false;
string varName = name->getIdentifier();
if (varName.empty()) return false;
if (ar->getConstants()->isSystem(varName)) return true;
ExpressionPtr value = (*m_params)[1];
return (!ar->isConstantRedeclared(varName)) && value->isScalar();
} else {
return false;
}
}
示例2: Load
bool BuiltinSymbols::Load(AnalysisResultPtr ar) {
if (Loaded) return true;
Loaded = true;
if (g_context.isNull()) init_thread_locals();
ClassInfo::Load();
// load extension functions first, so system/php may call them
ImportExtFunctions(ar, ClassInfo::GetSystem());
ConstantTablePtr cns = ar->getConstants();
// load extension constants, classes and dynamics
ImportNativeConstants(ar, cns);
ImportExtConstants(ar, cns, ClassInfo::GetSystem());
ImportExtClasses(ar);
Array constants = ClassInfo::GetSystemConstants();
LocationPtr loc(new Location);
for (ArrayIter it = constants.begin(); it; ++it) {
CVarRef key = it.first();
if (!key.isString()) continue;
std::string name = key.toCStrRef().data();
if (cns->getSymbol(name)) continue;
if (name == "true" || name == "false" || name == "null") continue;
CVarRef value = it.secondRef();
if (!value.isInitialized() || value.isObject()) continue;
ExpressionPtr e = Expression::MakeScalarExpression(ar, ar, loc, value);
TypePtr t =
value.isNull() ? Type::Null :
value.isBoolean() ? Type::Boolean :
value.isInteger() ? Type::Int64 :
value.isDouble() ? Type::Double :
value.isArray() ? Type::Array : Type::Variant;
cns->add(key.toCStrRef().data(), t, e, ar, e);
}
for (int i = 0, n = NumGlobalNames(); i < n; ++i) {
ar->getVariables()->add(GlobalNames[i], Type::Variant, false, ar,
ConstructPtr(), ModifierExpressionPtr());
}
cns->setDynamic(ar, "PHP_BINARY", true);
cns->setDynamic(ar, "PHP_BINDIR", true);
cns->setDynamic(ar, "PHP_OS", true);
cns->setDynamic(ar, "PHP_SAPI", true);
cns->setDynamic(ar, "SID", true);
// Systemlib files were all parsed by hphp_process_init
const StringToFileScopePtrMap &files = ar->getAllFiles();
for (const auto& file : files) {
file.second->setSystem();
const auto& classes = file.second->getClasses();
for (const auto& clsVec : classes) {
assert(clsVec.second.size() == 1);
auto cls = clsVec.second[0];
cls->setSystem();
ar->addSystemClass(cls);
for (const auto& func : cls->getFunctions()) {
FunctionScope::RecordFunctionInfo(func.first, func.second);
}
}
const auto& functions = file.second->getFunctions();
for (const auto& func : functions) {
func.second->setSystem();
ar->addSystemFunction(func.second);
FunctionScope::RecordFunctionInfo(func.first, func.second);
}
}
return true;
}
示例3: outputCPPImpl
void SimpleFunctionCall::outputCPPImpl(CodeGenerator &cg,
AnalysisResultPtr ar) {
bool linemap = outputLineMap(cg, ar, true);
if (!m_lambda.empty()) {
cg.printf("\"%s\"", m_lambda.c_str());
if (linemap) cg.printf(")");
return;
}
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();
ExpressionPtr value = (*m_params)[1];
if (varName.empty()) {
cg.printf("throw_fatal(\"bad define\")");
} else if (m_dynamicConstant) {
cg.printf("g->declareConstant(\"%s\", g->%s%s, ",
varName.c_str(), Option::ConstantPrefix,
varName.c_str());
value->outputCPP(cg, ar);
cg.printf(")");
} else {
bool needAssignment = true;
bool isSystem = ar->getConstants()->isSystem(varName);
if (isSystem ||
((!ar->isConstantRedeclared(varName)) && value->isScalar())) {
needAssignment = false;
}
if (needAssignment) {
cg.printf("%s%s = ", Option::ConstantPrefix, varName.c_str());
value->outputCPP(cg, ar);
}
}
} else {
cg.printf("throw_fatal(\"bad define\")");
}
if (linemap) cg.printf(")");
return;
}
if (m_name == "func_num_args") {
cg.printf("num_args");
if (linemap) cg.printf(")");
return;
}
switch (m_type) {
case VariableArgumentFunction:
{
FunctionScopePtr func =
dynamic_pointer_cast<FunctionScope>(ar->getScope());
if (func) {
cg.printf("%s(", m_name.c_str());
func->outputCPPParamsCall(cg, ar, true);
if (m_params) {
cg.printf(",");
m_params->outputCPP(cg, ar);
}
cg.printf(")");
if (linemap) cg.printf(")");
return;
}
}
break;
case FunctionExistsFunction:
case ClassExistsFunction:
case InterfaceExistsFunction:
{
bool literalString = false;
string symbol;
if (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()) {
literalString = true;
symbol = name->getLiteralString();
}
}
}
if (literalString) {
switch (m_type) {
case FunctionExistsFunction:
{
const std::string &lname = Util::toLower(symbol);
bool dynInvoke = Option::DynamicInvokeFunctions.find(lname) !=
Option::DynamicInvokeFunctions.end();
if (!dynInvoke) {
FunctionScopePtr func = ar->findFunction(lname);
if (func) {
if (!func->isDynamic()) {
if (func->isRedeclaring()) {
const char *name = func->getName().c_str();
cg.printf("(%s->%s%s != invoke_failed_%s)",
cg.getGlobals(ar), Option::InvokePrefix,
//.........这里部分代码省略.........
示例4: 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;
}
//.........这里部分代码省略.........
示例5: 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();
}
示例6: analyzeProgram
void SimpleFunctionCall::analyzeProgram(AnalysisResultPtr ar) {
if (m_className.empty()) {
addUserFunction(ar, m_name);
} else if (m_className != "parent") {
addUserClass(ar, m_className);
} else {
m_parentClass = true;
}
if (ar->getPhase() == AnalysisResult::AnalyzeInclude) {
CHECK_HOOK(onSimpleFunctionCallAnalyzeInclude);
ConstructPtr self = shared_from_this();
// We need to know the name of the constant so that we can associate it
// with this file before we do type inference.
if (m_className.empty() && m_type == DefineFunction) {
ScalarExpressionPtr name =
dynamic_pointer_cast<ScalarExpression>((*m_params)[0]);
string varName;
if (name) {
varName = name->getIdentifier();
if (!varName.empty()) {
ar->getFileScope()->declareConstant(ar, varName);
}
}
// handling define("CONSTANT", ...);
if (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];
ConstantTablePtr constants =
ar->findConstantDeclarer(varName)->getConstants();
if (constants != ar->getConstants()) {
constants->add(varName, NEW_TYPE(Some), value, ar, self);
if (name->hasHphpNote("Dynamic")) {
constants->setDynamic(ar, varName);
}
}
}
}
}
}
if (m_type == UnserializeFunction) {
ar->forceClassVariants();
}
}
if (ar->getPhase() == AnalysisResult::AnalyzeAll) {
// Look up the corresponding FunctionScope and ClassScope
// for this function call
{
FunctionScopePtr func;
ClassScopePtr cls;
if (m_className.empty()) {
func = ar->findFunction(m_name);
} else {
cls = ar->resolveClass(m_className);
if (cls) {
if (m_name == "__construct") {
func = cls->findConstructor(ar, true);
} else {
func = cls->findFunction(ar, m_name, true, true);
}
}
}
if (func && !func->isRedeclaring()) {
if (m_funcScope != func) {
m_funcScope = func;
Construct::recomputeEffects();
}
}
if (cls && !cls->isRedeclaring())
m_classScope = cls;
}
// check for dynamic constant and volatile function/class
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();
if (!constants->isPresent(symbol)) {
// user constant
//.........这里部分代码省略.........