本文整理汇总了C++中ConstantTablePtr类的典型用法代码示例。如果您正苦于以下问题:C++ ConstantTablePtr类的具体用法?C++ ConstantTablePtr怎么用?C++ ConstantTablePtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConstantTablePtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onParseRecur
void ClassConstant::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ConstantTablePtr constants = scope->getConstants();
if (scope->isTrait()) {
parseTimeFatal(Compiler::InvalidTraitStatement,
"Traits cannot have constants");
}
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
if (constants->isPresent(name)) {
assignment->parseTimeFatal(Compiler::DeclaredConstantTwice,
"Cannot redeclare %s::%s",
scope->getOriginalName().c_str(),
name.c_str());
} else {
assignment->onParseRecur(ar, scope);
}
}
}
示例2: onParseRecur
void ClassConstant::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ConstantTablePtr constants = scope->getConstants();
if (scope->isTrait()) {
parseTimeFatal(Compiler::InvalidTraitStatement,
"Traits cannot have constants");
}
if (isAbstract()) {
for (int i = 0; i < m_exp->getCount(); i++) {
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>((*m_exp)[i]);
const std::string &name = exp->getName();
if (constants->isPresent(name)) {
exp->parseTimeFatal(Compiler::DeclaredConstantTwice,
"Cannot redeclare %s::%s",
scope->getOriginalName().c_str(),
name.c_str());
}
// HACK: break attempts to write global constants here;
// see ConstantExpression::preOptimize
exp->setContext(Expression::LValue);
// Unlike with assignment expression below, nothing needs to be added
// to the scope's constant table
}
} else {
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
if (constants->isPresent(name)) {
assignment->parseTimeFatal(Compiler::DeclaredConstantTwice,
"Cannot redeclare %s::%s",
scope->getOriginalName().c_str(),
name.c_str());
} else {
if (isTypeconst()) {
// We do not want type constants to be available at run time.
// To ensure this we do not want them to be added to the constants
// table. The constants table is used to inline values for expressions
// See ClassConstantExpression::preOptimize.
// AssignmentExpression::onParseRecur essentially adds constants to
// the constant table so we skip it.
continue;
}
assignment->onParseRecur(ar, scope);
}
}
}
}
示例3: 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;
}
示例4: findBase
ClassScopeRawPtr ConstantTable::findBase(
AnalysisResultConstPtr ar, const std::string &name,
const std::vector<std::string> &bases) const {
for (int i = bases.size(); i--; ) {
ClassScopeRawPtr p = ar->findClass(bases[i]);
if (!p || p->isRedeclaring()) continue;
if (p->hasConst(name)) return p;
ConstantTablePtr constants = p->getConstants();
p = constants->findBase(ar, name, p->getBases());
if (p) return p;
}
return ClassScopeRawPtr();
}
示例5: ExpressionPtr
ExpressionPtr ClassConstantExpression::preOptimize(AnalysisResultConstPtr ar) {
if (ar->getPhase() < AnalysisResult::FirstPreOptimize) {
return ExpressionPtr();
}
if (m_class) {
updateClassName();
if (m_class) {
return ExpressionPtr();
}
}
ClassScopePtr cls = resolveClass();
if (!cls || (cls->isVolatile() && !isPresent())) {
if (cls && !m_depsSet) {
cls->addUse(getScope(), BlockScope::UseKindConstRef);
m_depsSet = true;
}
return ExpressionPtr();
}
ConstantTablePtr constants = cls->getConstants();
ClassScopePtr defClass = cls;
ConstructPtr decl = constants->getValueRecur(ar, m_varName, defClass);
if (decl) {
BlockScope::s_constMutex.lock();
ExpressionPtr value = dynamic_pointer_cast<Expression>(decl);
BlockScope::s_constMutex.unlock();
if (!value->isScalar() &&
(value->is(KindOfClassConstantExpression) ||
value->is(KindOfConstantExpression))) {
std::set<ExpressionPtr> seen;
do {
if (!seen.insert(value).second) return ExpressionPtr();
value = value->preOptimize(ar);
if (!value) return ExpressionPtr();
} while (!value->isScalar() &&
(value->is(KindOfClassConstantExpression) ||
value->is(KindOfConstantExpression)));
}
ExpressionPtr rep = Clone(value, getScope());
rep->setComment(getText());
copyLocationTo(rep);
return replaceValue(rep);
}
return ExpressionPtr();
}
示例6: LoadConstants
void BuiltinSymbols::LoadConstants(AnalysisResultPtr ar,
ConstantTablePtr constants) {
assert(Loaded);
if (s_constants) {
constants->import(s_constants);
}
}
示例7: ImportNativeConstants
void BuiltinSymbols::ImportNativeConstants(AnalysisResultPtr ar,
ConstantTablePtr dest) {
for (auto cnsPair : Native::getConstants()) {
dest->add(cnsPair.first->data(),
typePtrFromDataType(cnsPair.second.m_type, Type::Variant),
ExpressionPtr(), ar, ConstructPtr());
}
}
示例8: onParseRecur
void ClassConstant::onParseRecur(AnalysisResultConstPtr ar,
ClassScopePtr scope) {
ConstantTablePtr constants = scope->getConstants();
for (int i = 0; i < m_exp->getCount(); i++) {
AssignmentExpressionPtr assignment =
dynamic_pointer_cast<AssignmentExpression>((*m_exp)[i]);
ExpressionPtr var = assignment->getVariable();
const std::string &name =
dynamic_pointer_cast<ConstantExpression>(var)->getName();
if (constants->isPresent(name)) {
Compiler::Error(Compiler::DeclaredConstantTwice, assignment);
m_exp->removeElement(i--);
} else {
assignment->onParseRecur(ar, scope);
}
}
}
示例9: ImportNativeConstants
void BuiltinSymbols::ImportNativeConstants(AnalysisResultPtr ar,
ConstantTablePtr dest) {
LocationPtr loc(new Location);
for (auto cnsPair : Native::getConstants()) {
ExpressionPtr e(Expression::MakeScalarExpression(
ar, ar, loc, tvAsVariant(&cnsPair.second)));
dest->add(cnsPair.first->data(),
Type::FromDataType(cnsPair.second.m_type, Type::Variant),
e, ar, e);
}
}
示例10: ExpressionPtr
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();
}
示例11: ImportExtConstants
void BuiltinSymbols::ImportExtConstants(AnalysisResultPtr ar,
ConstantTablePtr dest,
ClassInfo *cls) {
ClassInfo::ConstantVec src = cls->getConstantsVec();
for (auto it = src.begin(); it != src.end(); ++it) {
// We make an assumption that if the constant is a callback type
// (e.g. STDIN, STDOUT, STDERR) then it will return an Object.
// And that if it's deferred (SID, PHP_SAPI, etc.) it'll be a String.
ClassInfo::ConstantInfo *cinfo = *it;
dest->add(cinfo->name.data(),
cinfo->isDeferred() ?
(cinfo->isCallback() ? Type::Object : Type::String) :
typePtrFromDataType(cinfo->getValue().getType(), Type::Variant),
ExpressionPtr(), ar, ConstructPtr());
}
}
示例12: ImportExtConstants
void BuiltinSymbols::ImportExtConstants(AnalysisResultPtr ar,
ConstantTablePtr dest,
ClassInfo *cls) {
LocationPtr loc(new Location);
for (auto cinfo : cls->getConstantsVec()) {
ExpressionPtr e;
TypePtr t;
if (cinfo->isDeferred()) {
// We make an assumption that if the constant is a callback type
// (e.g. STDIN, STDOUT, STDERR) then it will return an Object.
// Otherwise, if it's deferred (SID, PHP_SAPI, etc.) it'll be a String.
t = cinfo->isCallback() ? Type::Object : Type::String;
} else {
t = Type::FromDataType(cinfo->getValue().getType(), Type::Variant);
e = Expression::MakeScalarExpression(ar, ar, loc, cinfo->getValue());
}
dest->add(cinfo->name.data(), t, e, ar, e);
}
}
示例13: reset
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;
}
//.........这里部分代码省略.........
示例14: ImportExtFunctions
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;
}
示例15: outputCPPClassDecl
void ClassStatement::outputCPPClassDecl(CodeGenerator &cg,
AnalysisResultPtr ar,
const char *clsName,
const char *originalName,
const char *parent) {
ClassScopePtr classScope = m_classScope.lock();
VariableTablePtr variables = classScope->getVariables();
ConstantTablePtr constants = classScope->getConstants();
if (variables->hasAllJumpTables() && constants->hasJumpTable() &&
classScope->hasAllJumpTables()) {
cg_printf("DECLARE_CLASS(%s, %s, %s)\n", clsName, originalName, parent);
return;
}
// Now we start to break down DECLARE_CLASS into lines of code that could
// be generated differently...
cg_printf("DECLARE_CLASS_COMMON(%s, %s)\n", clsName, originalName);
cg_printf("DECLARE_INVOKE_EX(%s, %s, %s)\n",
clsName, originalName, parent);
cg.printSection("DECLARE_STATIC_PROP_OPS");
cg_printf("public:\n");
if (classScope->needStaticInitializer()) {
cg_printf("static void os_static_initializer();\n");
}
if (variables->hasJumpTable(VariableTable::JumpTableClassStaticGetInit)) {
cg_printf("static Variant os_getInit(const char *s, int64 hash);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_STATIC_GETINIT_%s 1\n", clsName);
}
if (variables->hasJumpTable(VariableTable::JumpTableClassStaticGet)) {
cg_printf("static Variant os_get(const char *s, int64 hash);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_STATIC_GET_%s 1\n", clsName);
}
if (variables->hasJumpTable(VariableTable::JumpTableClassStaticLval)) {
cg_printf("static Variant &os_lval(const char *s, int64 hash);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_STATIC_LVAL_%s 1\n", clsName);
}
if (constants->hasJumpTable()) {
cg_printf("static Variant os_constant(const char *s);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_CONSTANT_%s 1\n", clsName);
}
cg.printSection("DECLARE_INSTANCE_PROP_OPS");
cg_printf("public:\n");
cg_printf("virtual bool o_exists(CStrRef s, int64 hash,\n");
cg_printf(" const char *context = NULL) const;\n");
cg_printf("bool o_existsPrivate(CStrRef s, int64 hash) const;\n");
cg_printf("virtual void o_get(Array &props) const;\n");
cg_printf("virtual Variant o_get(CStrRef s, int64 hash, "
"bool error = true,\n");
cg_printf(" const char *context = NULL);\n");
cg_printf("Variant o_getPrivate(CStrRef s, int64 hash, "
"bool error = true);\n");
cg_printf("virtual Variant o_set(CStrRef s, int64 hash, CVarRef v,\n");
cg_printf(" bool forInit = false,\n");
cg_printf(" const char *context = NULL);\n");
cg_printf("Variant o_setPrivate(CStrRef s, int64 hash, CVarRef v, "
"bool forInit);\n");
cg_printf("virtual Variant &o_lval(CStrRef s, int64 hash,\n");
cg_printf(" const char *context = NULL);\n");
cg_printf("Variant &o_lvalPrivate(CStrRef s, int64 hash);\n");
cg.printSection("DECLARE_INSTANCE_PUBLIC_PROP_OPS");
cg_printf("public:\n");
if (variables->hasJumpTable(VariableTable::JumpTableClassExistsPublic)) {
cg_printf("virtual bool o_existsPublic(CStrRef s, int64 hash) const;\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_exists_PUBLIC_%s 1\n", clsName);
}
if (variables->hasJumpTable(VariableTable::JumpTableClassGetPublic)) {
cg_printf("virtual Variant o_getPublic(CStrRef s, int64 hash,\n");
cg_printf(" bool error = true);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_get_PUBLIC_%s 1\n", clsName);
}
if (variables->hasJumpTable(VariableTable::JumpTableClassSetPublic)) {
cg_printf("virtual Variant o_setPublic(CStrRef s, int64 hash,\n");
cg_printf(" CVarRef v, bool forInit);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_set_PUBLIC_%s 1\n", clsName);
}
if (variables->hasJumpTable(VariableTable::JumpTableClassLvalPublic)) {
cg_printf("virtual Variant &o_lvalPublic(CStrRef s, int64 hash);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_lval_PUBLIC_%s 1\n", clsName);
}
cg.printSection("DECLARE_COMMON_INVOKE");
if (classScope->hasJumpTable(ClassScope::JumpTableStaticInvoke)) {
cg_printf("static Variant os_invoke(const char *c, const char *s,\n");
cg_printf(" CArrRef ps, int64 h, "
"bool f = true);\n");
} else {
cg_printf("#define OMIT_JUMP_TABLE_CLASS_STATIC_INVOKE_%s 1\n", clsName);
}
//.........这里部分代码省略.........