本文整理汇总了C++中ConstantTablePtr::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstantTablePtr::getValue方法的具体用法?C++ ConstantTablePtr::getValue怎么用?C++ ConstantTablePtr::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstantTablePtr
的用法示例。
在下文中一共展示了ConstantTablePtr::getValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isConstantDeclared
bool AnalysisResult::isConstantDeclared(const std::string &constName) const {
if (m_constants->isPresent(constName)) return true;
auto const iter = m_constDecs.find(constName);
if (iter == m_constDecs.end()) return false;
FileScopePtr fileScope = iter->second;
ConstantTablePtr constants = fileScope->getConstants();
ConstructPtr decl = constants->getValue(constName);
if (decl) return true;
return false;
}
示例2: preOptimize
ExpressionPtr ClassConstantExpression::preOptimize(AnalysisResultPtr ar) {
if (ar->getPhase() < AnalysisResult::FirstPreOptimize) {
return ExpressionPtr();
}
if (m_redeclared) return ExpressionPtr();
ClassScopePtr cls = ar->resolveClass(m_className);
if (!cls || cls->isRedeclaring()) return ExpressionPtr();
ConstantTablePtr constants = cls->getConstants();
if (constants->isExplicitlyDeclared(m_varName)) {
ConstructPtr decl = constants->getValue(m_varName);
if (decl) {
ExpressionPtr value = dynamic_pointer_cast<Expression>(decl);
if (!m_visited) {
m_visited = true;
ar->pushScope(cls);
ExpressionPtr optExp = value->preOptimize(ar);
ar->popScope();
m_visited = false;
if (optExp) value = optExp;
}
if (value->isScalar()) {
// inline the value
if (value->is(Expression::KindOfScalarExpression)) {
ScalarExpressionPtr exp =
dynamic_pointer_cast<ScalarExpression>(Clone(value));
exp->setComment(getText());
return exp;
} else if (value->is(Expression::KindOfConstantExpression)) {
// inline the value
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>(Clone(value));
exp->setComment(getText());
return exp;
}
}
}
}
return ExpressionPtr();
}
示例3: 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();
}