本文整理汇总了C++中AnalysisResultPtr类的典型用法代码示例。如果您正苦于以下问题:C++ AnalysisResultPtr类的具体用法?C++ AnalysisResultPtr怎么用?C++ AnalysisResultPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnalysisResultPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
int process(const ProgramOptions &po) {
if (po.coredump) {
#if defined(__APPLE__)
struct rlimit rl;
getrlimit(RLIMIT_CORE, &rl);
rl.rlim_cur = 80000000LL;
if (rl.rlim_max < rl.rlim_cur) {
rl.rlim_max = rl.rlim_cur;
}
setrlimit(RLIMIT_CORE, &rl);
#else
struct rlimit64 rl;
getrlimit64(RLIMIT_CORE, &rl);
rl.rlim_cur = 8000000000LL;
if (rl.rlim_max < rl.rlim_cur) {
rl.rlim_max = rl.rlim_cur;
}
setrlimit64(RLIMIT_CORE, &rl);
#endif
}
// lint doesn't need analysis
if (po.target == "lint") {
return lintTarget(po);
}
Timer timer(Timer::WallTime);
AnalysisResultPtr ar;
// prepare a package
Package package(po.inputDir.c_str());
ar = package.getAnalysisResult();
std::string errs;
if (!AliasManager::parseOptimizations(po.optimizations, errs)) {
cerr << errs << "\n";
return false;
}
if (po.target != "php" || po.format != "pickled") {
if (!BuiltinSymbols::Load(ar, po.target == "cpp" && po.format == "sys")) {
return false;
}
ar->loadBuiltins();
}
{
Timer timer(Timer::WallTime, "parsing inputs");
if (!po.inputs.empty() && po.target == "php" && po.format == "pickled") {
for (unsigned int i = 0; i < po.inputs.size(); i++) {
package.addSourceFile(po.inputs[i].c_str());
}
if (!package.parse()) {
return 1;
}
} else {
ar->setPackage(&package);
ar->setParseOnDemand(po.parseOnDemand);
if (!po.parseOnDemand) {
ar->setParseOnDemandDirs(Option::ParseOnDemandDirs);
}
if (po.modules.empty() && po.fmodules.empty() &&
po.ffiles.empty() && po.inputs.empty() && po.inputList.empty()) {
package.addAllFiles(false);
} else {
for (unsigned int i = 0; i < po.modules.size(); i++) {
package.addDirectory(po.modules[i], false);
}
for (unsigned int i = 0; i < po.fmodules.size(); i++) {
package.addDirectory(po.fmodules[i], true);
}
for (unsigned int i = 0; i < po.ffiles.size(); i++) {
package.addSourceFile(po.ffiles[i].c_str());
}
for (unsigned int i = 0; i < po.cmodules.size(); i++) {
package.addStaticDirectory(po.cmodules[i].c_str());
}
for (unsigned int i = 0; i < po.cfiles.size(); i++) {
package.addStaticFile(po.cfiles[i].c_str());
}
for (unsigned int i = 0; i < po.inputs.size(); i++) {
package.addSourceFile(po.inputs[i].c_str());
}
if (!po.inputList.empty()) {
package.addInputList(po.inputList.c_str());
}
}
}
if (po.target != "filecache") {
if (!package.parse()) {
return 1;
}
ar->analyzeProgram();
}
}
// saving file cache
AsyncFileCacheSaver fileCacheThread(&package, po.filecache.c_str());
if (!po.filecache.empty()) {
fileCacheThread.start();
//.........这里部分代码省略.........
示例2: importUsedTraits
void ClassScope::importUsedTraits(AnalysisResultPtr ar) {
// Trait flattening is supposed to happen only when we have awareness of
// the whole program.
assert(Option::WholeProgram);
if (m_traitStatus == FLATTENED) return;
if (m_traitStatus == BEING_FLATTENED) {
getStmt()->analysisTimeFatal(
Compiler::CyclicDependentTraits,
"Cyclic dependency between traits involving %s",
getOriginalName().c_str()
);
return;
}
if (m_usedTraitNames.size() == 0) {
m_traitStatus = FLATTENED;
return;
}
m_traitStatus = BEING_FLATTENED;
// First, make sure that parent classes have their traits imported
if (!m_parent.empty()) {
ClassScopePtr parent = ar->findClass(m_parent);
if (parent) {
parent->importUsedTraits(ar);
}
}
if (isTrait()) {
for (auto const& req : getTraitRequiredExtends()) {
ClassScopePtr rCls = ar->findClass(req);
if (!rCls || rCls->isFinal() || rCls->isInterface()) {
getStmt()->analysisTimeFatal(
Compiler::InvalidDerivation,
Strings::TRAIT_BAD_REQ_EXTENDS,
m_originalName.c_str(),
req.c_str(),
req.c_str()
);
}
}
for (auto const& req : getTraitRequiredImplements()) {
ClassScopePtr rCls = ar->findClass(req);
if (!rCls || !(rCls->isInterface())) {
getStmt()->analysisTimeFatal(
Compiler::InvalidDerivation,
Strings::TRAIT_BAD_REQ_IMPLEMENTS,
m_originalName.c_str(),
req.c_str(),
req.c_str()
);
}
}
}
// Find trait methods to be imported
for (unsigned i = 0; i < m_usedTraitNames.size(); i++) {
ClassScopePtr tCls = ar->findClass(m_usedTraitNames[i]);
if (!tCls || !(tCls->isTrait())) {
setAttribute(UsesUnknownTrait); // XXX: is this useful ... for anything?
getStmt()->analysisTimeFatal(
Compiler::UnknownTrait,
Strings::TRAITS_UNKNOWN_TRAIT,
m_usedTraitNames[i].c_str()
);
}
// First, make sure the used trait is flattened
tCls->importUsedTraits(ar);
findTraitMethodsToImport(ar, tCls);
// Import any interfaces implemented
tCls->getInterfaces(ar, m_bases, false);
}
for (unsigned i = 0; i < m_usedTraitNames.size(); i++) {
// Requirements must be checked in a separate loop because the
// interfaces required by one trait may be implemented by another trait
// whose "use" appears later in the class' scope
ClassScopePtr tCls = ar->findClass(m_usedTraitNames[i]);
importTraitRequirements(ar, tCls);
}
// Apply rules
applyTraitRules(ar);
// Remove trait abstract methods provided by other traits and duplicates
removeSpareTraitAbstractMethods(ar);
// Apply precedence of current class over used traits
for (MethodToTraitListMap::iterator iter = m_importMethToTraitMap.begin();
iter != m_importMethToTraitMap.end(); ) {
MethodToTraitListMap::iterator thisiter = iter;
iter++;
if (findFunction(ar, thisiter->first, 0, 0) != FunctionScopePtr()) {
m_importMethToTraitMap.erase(thisiter);
}
}
std::map<string, MethodStatementPtr> importedTraitMethods;
std::vector<std::pair<string,const TraitMethod*>> importedTraitsWithOrigName;
//.........这里部分代码省略.........
示例3: outputCPPImpl
void InterfaceStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
ClassScopePtr classScope = m_classScope.lock();
if (cg.getContext() == CodeGenerator::NoContext) {
if (classScope->isVolatile()) {
cg_printf("g->CDEC(%s) = true;\n", cg.formatLabel(m_name).c_str());
}
return;
}
string clsNameStr = classScope->getId(cg);
const char *clsName = clsNameStr.c_str();
switch (cg.getContext()) {
case CodeGenerator::CppForwardDeclaration:
if (Option::GenerateCPPMacros) {
if (!Option::UseVirtualDispatch ||
classScope->isRedeclaring()) {
cg_printf("FORWARD_DECLARE_GENERIC_INTERFACE(%s);\n", clsName);
} else {
cg_printf("FORWARD_DECLARE_INTERFACE(%s);\n", clsName);
}
}
break;
case CodeGenerator::CppDeclaration:
{
printSource(cg);
cg_printf("class %s%s", Option::ClassPrefix, clsName);
if (m_base && Option::UseVirtualDispatch &&
!classScope->isRedeclaring()) {
const char *sep = " :";
for (int i = 0; i < m_base->getCount(); i++) {
ScalarExpressionPtr exp =
dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
const char *intf = exp->getString().c_str();
ClassScopePtr intfClassScope = ar->findClass(intf);
if (intfClassScope && !intfClassScope->isRedeclaring() &&
classScope->derivesDirectlyFrom(ar, intf)) {
string id = intfClassScope->getId(cg);
cg_printf("%s public %s%s", sep, Option::ClassPrefix, id.c_str());
sep = ",";
}
}
}
cg_indentBegin(" {\n");
if (m_stmt) m_stmt->outputCPP(cg, ar);
cg_indentEnd("};\n");
}
break;
case CodeGenerator::CppImplementation:
// do nothing
break;
case CodeGenerator::CppFFIDecl:
case CodeGenerator::CppFFIImpl:
// do nothing
break;
case CodeGenerator::JavaFFI:
{
// TODO support PHP namespaces, once HPHP supports it
string packageName = Option::JavaFFIRootPackage;
string packageDir = packageName;
Util::replaceAll(packageDir, ".", "/");
string outputDir = ar->getOutputPath() + "/" + Option::FFIFilePrefix +
packageDir + "/";
Util::mkdir(outputDir);
// uses a different cg to generate a separate file for each PHP class
string clsFile = outputDir + getOriginalName() + ".java";
ofstream fcls(clsFile.c_str());
CodeGenerator cgCls(&fcls, CodeGenerator::FileCPP);
cgCls.setContext(CodeGenerator::JavaFFIInterface);
cgCls.printf("package %s;\n\n", packageName.c_str());
cgCls.printf("import hphp.*;\n\n");
cgCls.printf("public interface %s", getOriginalName().c_str());
if (m_base) {
bool first = true;
for (int i = 0; i < m_base->getCount(); i++) {
ScalarExpressionPtr exp =
dynamic_pointer_cast<ScalarExpression>((*m_base)[i]);
const char *intf = exp->getString().c_str();
ClassScopePtr intfClassScope = ar->findClass(intf);
if (intfClassScope && classScope->derivesFrom(ar, intf, false, false)
&& intfClassScope->isUserClass()) {
if (first) {
cgCls.printf(" extends ");
first = false;
}
else {
cgCls.printf(", ");
}
cgCls.printf(intfClassScope->getOriginalName().c_str());
}
}
}
cgCls.indentBegin(" {\n");
if (m_stmt) m_stmt->outputCPP(cgCls, ar);
cgCls.indentEnd("}\n");
//.........这里部分代码省略.........
示例4: inferAndCheck
TypePtr ObjectMethodExpression::inferAndCheck(AnalysisResultPtr ar,
TypePtr type, bool coerce) {
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::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) {
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->getAttribute(ClassScope::MayHaveUnknownMethodHandler) &&
!cls->getAttribute(ClassScope::HasUnknownMethodHandler) &&
!cls->getAttribute(ClassScope::InheritsUnknownMethodHandler)) {
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 (cls->isInterface() ||
(func->isVirtual() &&
(ar->isSystem() || 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
func->setDynamic();
return m_actualType;
}
return checkParamsAndReturn(ar, type, coerce, func, false);
}
示例5: ParseExtFunctions
bool BuiltinSymbols::Load(AnalysisResultPtr ar, bool extOnly /* = false */) {
if (Loaded) return true;
Loaded = true;
// load extension functions first, so system/classes may call them
ParseExtFunctions(ar, ExtensionFunctions, false);
AnalysisResultPtr ar2 = AnalysisResultPtr(new AnalysisResult());
s_variables = VariableTablePtr(new VariableTable(*ar2.get()));
s_constants = ConstantTablePtr(new ConstantTable(*ar2.get()));
// parse all PHP files under system/classes
if (!extOnly) {
ar = AnalysisResultPtr(new AnalysisResult());
ar->loadBuiltinFunctions();
string slib = systemlib_path();
if (slib.empty()) {
for (const char **cls = SystemClasses; *cls; cls++) {
string phpBaseName = "/system/classes/";
phpBaseName += *cls;
phpBaseName += ".php";
Parse(ar, phpBaseName, Option::GetSystemRoot() + phpBaseName);
}
} else {
Parse(ar, slib, slib);
}
ar->analyzeProgram(true);
ar->inferTypes();
const StringToFileScopePtrMap &files = ar->getAllFiles();
for (StringToFileScopePtrMap::const_iterator iterFile = files.begin();
iterFile != files.end(); iterFile++) {
const StringToClassScopePtrVecMap &classes =
iterFile->second->getClasses();
for (StringToClassScopePtrVecMap::const_iterator iter = classes.begin();
iter != classes.end(); ++iter) {
assert(iter->second.size() == 1);
iter->second[0]->setSystem();
assert(!s_classes[iter->first]);
s_classes[iter->first] = iter->second[0];
}
}
} else {
NoSuperGlobals = true;
}
// load extension constants, classes and dynamics
ParseExtConsts(ar, ExtensionConsts, false);
ParseExtClasses(ar, ExtensionClasses, false);
for (unsigned int i = 0; i < Option::SepExtensions.size(); i++) {
Option::SepExtensionOptions &options = Option::SepExtensions[i];
string soname = options.soname;
if (soname.empty()) {
soname = string("lib") + options.name + ".so";
}
if (!options.lib_path.empty()) {
soname = options.lib_path + "/" + soname;
}
if (!LoadSepExtensionSymbols(ar, options.name, soname)) {
return false;
}
}
if (!extOnly) {
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 (s_constants->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(ar2, ar2, 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;
s_constants->add(key.toCStrRef().data(), t, e, ar2, e);
}
s_variables = ar2->getVariables();
for (int i = 0, n = NumGlobalNames(); i < n; ++i) {
s_variables->add(GlobalNames[i], Type::Variant, false, ar,
ConstructPtr(), ModifierExpressionPtr());
}
}
s_constants->setDynamic(ar, "SID", true);
return true;
}
示例6: importUsedTraits
void ClassScope::importUsedTraits(AnalysisResultPtr ar) {
// Trait flattening is supposed to happen only when we have awareness of the
// whole program.
assert(Option::WholeProgram);
if (m_traitStatus == FLATTENED) return;
if (m_traitStatus == BEING_FLATTENED) {
getStmt()->analysisTimeFatal(
Compiler::CyclicDependentTraits,
"Cyclic dependency between traits involving %s",
getScopeName().c_str()
);
return;
}
if (m_usedTraitNames.size() == 0) {
m_traitStatus = FLATTENED;
return;
}
m_traitStatus = BEING_FLATTENED;
m_numDeclMethods = m_functionsVec.size();
// First, make sure that parent classes have their traits imported.
if (!m_parent.empty()) {
ClassScopePtr parent = ar->findClass(m_parent);
if (parent) {
parent->importUsedTraits(ar);
}
}
TMIData tmid;
if (isTrait()) {
for (auto const& req : getClassRequiredExtends()) {
ClassScopePtr rCls = ar->findClass(req);
if (!rCls || rCls->isFinal() || rCls->isInterface()) {
getStmt()->analysisTimeFatal(
Compiler::InvalidDerivation,
Strings::TRAIT_BAD_REQ_EXTENDS,
m_scopeName.c_str(),
req.c_str(),
req.c_str()
);
}
}
for (auto const& req : getClassRequiredImplements()) {
ClassScopePtr rCls = ar->findClass(req);
if (!rCls || !(rCls->isInterface())) {
getStmt()->analysisTimeFatal(
Compiler::InvalidDerivation,
Strings::TRAIT_BAD_REQ_IMPLEMENTS,
m_scopeName.c_str(),
req.c_str(),
req.c_str()
);
}
}
}
// Find trait methods to be imported.
for (unsigned i = 0; i < m_usedTraitNames.size(); i++) {
ClassScopePtr tCls = ar->findClass(m_usedTraitNames[i]);
if (!tCls || !(tCls->isTrait())) {
setAttribute(UsesUnknownTrait); // XXX: is this useful ... for anything?
getStmt()->analysisTimeFatal(
Compiler::UnknownTrait,
Strings::TRAITS_UNKNOWN_TRAIT,
m_usedTraitNames[i].c_str()
);
}
// First, make sure the used trait is flattened.
tCls->importUsedTraits(ar);
findTraitMethodsToImport(ar, tCls, tmid);
importClassRequirements(ar, tCls);
// Don't import interfaces here. Interfaces from traits are
// treated differently from directly declared interfaces. We'll
// explicitly pull in the trait interfaces when constructing the
// class.
}
// Apply rules.
applyTraitRules(tmid);
// Remove methods declared on the current class from the trait import list;
// the class methods take precedence.
for (auto const& methName : tmid.methodNames()) {
if (findFunction(ar, methName, false /* recursive */,
false /* exclIntfBase */)) {
// This does not affect the methodNames() vector.
tmid.erase(methName);
}
}
auto traitMethods = tmid.finish(this);
std::map<std::string, MethodStatementPtr, stdltistr> importedTraitMethods;
//.........这里部分代码省略.........
示例7: outputCPPImpl
void ForEachStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
cg_indentBegin("{\n");
int labelId = cg.createNewLocalId(ar);
cg.pushBreakScope(labelId);
int mapId = cg.createNewLocalId(ar);
bool passTemp = true;
bool isArray = false;
if (m_ref ||
!m_array->is(Expression::KindOfSimpleVariable) ||
m_array->isThis()) {
cg_printf("Variant %s%d", Option::MapPrefix, mapId);
bool wrap = m_array->preOutputCPP(cg, ar, 0);
if (wrap) {
cg_printf(";\n");
m_array->outputCPPBegin(cg, ar);
cg_printf("%s%d", Option::MapPrefix, mapId);
}
if (m_ref) {
cg_printf(" = ref(");
m_array->outputCPPImpl(cg, ar);
cg.printf(");\n");
cg.printf("%s%d.escalate(true);\n", Option::MapPrefix, mapId);
} else {
TypePtr expectedType = m_array->getExpectedType();
// Clear m_expectedType to avoid type cast (toArray).
m_array->setExpectedType(TypePtr());
cg_printf(" = ");
m_array->outputCPP(cg, ar);
cg_printf(";\n");
m_array->setExpectedType(expectedType);
}
if (wrap) {
m_array->outputCPPEnd(cg, ar);
}
} else {
passTemp = false;
}
cppDeclareBufs(cg, ar);
int iterId = cg.createNewLocalId(ar);
cg_printf("for (");
if (m_ref) {
cg_printf("MutableArrayIterPtr %s%d = %s%d.begin(",
Option::IterPrefix, iterId, Option::MapPrefix, mapId);
if (m_name) {
cg_printf("&");
m_name->outputCPP(cg, ar);
} else {
cg_printf("NULL");
}
cg_printf(", ");
m_value->outputCPP(cg, ar);
cg_printf("); %s%d->advance();", Option::IterPrefix, iterId);
} else {
if (passTemp) {
cg_printf("ArrayIterPtr %s%d = %s%d.begin(",
Option::IterPrefix, iterId,
Option::MapPrefix, mapId);
ClassScopePtr cls = ar->getClassScope();
if (cls) {
cg_printf("%sclass_name", Option::StaticPropertyPrefix);
}
cg_printf("); ");
cg_printf("!%s%d->end(); %s%d->next()",
Option::IterPrefix, iterId,
Option::IterPrefix, iterId);
} else {
TypePtr actualType = m_array->getActualType();
if (actualType && actualType->is(Type::KindOfArray)) {
isArray = true;
cg_printf("ArrayIter %s%d = ", Option::IterPrefix, iterId);
} else {
cg_printf("ArrayIterPtr %s%d = ", Option::IterPrefix, iterId);
}
TypePtr expectedType = m_array->getExpectedType();
// Clear m_expectedType to avoid type cast (toArray).
m_array->setExpectedType(TypePtr());
m_array->outputCPP(cg, ar);
m_array->setExpectedType(expectedType);
cg_printf(".begin(");
ClassScopePtr cls = ar->getClassScope();
if (cls) {
cg_printf("%sclass_name", Option::StaticPropertyPrefix);
}
cg_printf("); ");
if (isArray) {
cg_printf("!%s%d.end(); ", Option::IterPrefix, iterId);
cg_printf("++%s%d", Option::IterPrefix, iterId);
} else {
cg_printf("!%s%d->end(); ", Option::IterPrefix, iterId);
cg_printf("%s%d->next()", Option::IterPrefix, iterId);
}
}
}
cg_indentBegin(") {\n");
cg_printf("LOOP_COUNTER_CHECK(%d);\n", labelId);
if (!m_ref) {
//.........这里部分代码省略.........
示例8: postOptimize
StatementPtr DoStatement::postOptimize(AnalysisResultPtr ar) {
ar->postOptimize(m_stmt);
ar->postOptimize(m_condition);
return StatementPtr();
}
示例9: postOptimize
ExpressionPtr ParameterExpression::postOptimize(AnalysisResultPtr ar) {
ar->postOptimize(m_defaultValue);
return ExpressionPtr();
}
示例10: 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;
}
示例11: while
bool BuiltinSymbols::Load(AnalysisResultPtr ar, bool extOnly /* = false */) {
if (Loaded) return true;
Loaded = true;
// Build function scopes for some of the runtime helper functions
// declared in "runtime/base/builtin_functions.h"
const char **helper = HelperFunctions;
while (*helper) {
FunctionScopePtr f = ParseHelperFunction(ar, helper);
ASSERT(!s_helperFunctions[f->getName()]);
s_helperFunctions[f->getName()] = f;
}
// load extension functions first, so system/classes may call them
ParseExtFunctions(ar, ExtensionFunctions, false);
// parse all PHP files under system/classes
if (!extOnly) {
ar = AnalysisResultPtr(new AnalysisResult());
ar->loadBuiltinFunctions();
for (const char **cls = SystemClasses; *cls; cls++) {
string phpBaseName = "/system/classes/";
phpBaseName += *cls;
phpBaseName += ".php";
string phpFileName = Option::GetSystemRoot() + phpBaseName;
const char *baseName = s_strings.add(phpBaseName.c_str());
const char *fileName = s_strings.add(phpFileName.c_str());
try {
Scanner scanner(fileName, Option::ScannerType);
Compiler::Parser parser(scanner, baseName, ar);
if (!parser.parse()) {
Logger::Error("Unable to parse file %s: %s", fileName,
parser.getMessage().c_str());
ASSERT(false);
}
} catch (FileOpenException &e) {
Logger::Error("%s", e.getMessage().c_str());
}
}
ar->analyzeProgram(true);
ar->inferTypes();
const StringToFileScopePtrMap &files = ar->getAllFiles();
for (StringToFileScopePtrMap::const_iterator iterFile = files.begin();
iterFile != files.end(); iterFile++) {
const StringToClassScopePtrVecMap &classes =
iterFile->second->getClasses();
for (StringToClassScopePtrVecMap::const_iterator iter = classes.begin();
iter != classes.end(); ++iter) {
ASSERT(iter->second.size() == 1);
iter->second[0]->setSystem();
ASSERT(!s_classes[iter->first]);
s_classes[iter->first] = iter->second[0];
}
}
// parse globals/variables.php and globals/constants.php
NoSuperGlobals = true;
s_variables = LoadGlobalSymbols("symbols.php")->getVariables();
const FileScopePtrVec &fileScopes =
LoadGlobalSymbols("constants.php")->getAllFilesVector();
if (!fileScopes.empty()) {
s_constants = fileScopes[0]->getConstants();
} else {
AnalysisResult ar2;
s_constants = ConstantTablePtr(new ConstantTable(ar2));
}
NoSuperGlobals = false;
} else {
AnalysisResult ar2;
s_variables = VariableTablePtr(new VariableTable(ar2));
s_constants = ConstantTablePtr(new ConstantTable(ar2));
NoSuperGlobals = true;
}
s_constants->setDynamic(ar, "SID");
// load extension constants, classes and dynamics
ParseExtConsts(ar, ExtensionConsts, false);
ParseExtClasses(ar, ExtensionClasses, false);
ParseExtDynamics(ar, ExtensionDeclaredDynamic, false);
for (unsigned int i = 0; i < Option::SepExtensions.size(); i++) {
Option::SepExtensionOptions &options = Option::SepExtensions[i];
string soname = options.soname;
if (soname.empty()) {
soname = string("lib") + options.name + ".so";
}
if (!options.lib_path.empty()) {
soname = options.lib_path + "/" + soname;
}
if (!LoadSepExtensionSymbols(ar, options.name, soname)) {
return false;
}
}
return true;
}
示例12: generateSepExtCpp
int generateSepExtCpp(const ProgramOptions &po, AnalysisResultPtr ar) {
ar->outputCPPSepExtensionImpl(po.outputFile);
return 0;
}
示例13: cppTarget
int cppTarget(const ProgramOptions &po, AnalysisResultPtr ar,
bool allowSys /* = true */) {
int ret = 0;
int clusterCount = po.clusterCount;
// format
CodeGenerator::Output format = CodeGenerator::InvalidOutput;
if (po.format == "file") {
clusterCount = 0;
format = CodeGenerator::FileCPP;
} else if (po.format == "cluster") {
format = CodeGenerator::ClusterCPP;
} else if (po.format == "sys" && allowSys) {
clusterCount = 0;
format = CodeGenerator::SystemCPP;
ar->setSystem();
} else if (po.format == "exe" || po.format == "lib") {
format = CodeGenerator::ClusterCPP;
}
if (format == CodeGenerator::InvalidOutput) {
Logger::Error("Unknown format for CPP target: %s", po.format.c_str());
return 1;
}
if (!po.noTypeInference) {
Option::GenerateInferredTypes = true;
}
if (Option::PreOptimization) {
Timer timer(Timer::WallTime, "pre-optimizing");
ar->preOptimize();
}
if (!Option::RTTIOutputFile.empty()) {
if (!po.rttiDirectory.empty()) {
Option::UseRTTIProfileData = true;
ar->cloneRTTIFuncs(po.rttiDirectory.c_str());
} else {
Option::GenRTTIProfileData = true;
}
}
if (Option::GenerateInferredTypes) {
Timer timer(Timer::WallTime, "inferring types");
ar->inferTypes();
}
if (Option::PostOptimization) {
Timer timer(Timer::WallTime, "post-optimizing");
ar->postOptimize();
}
ar->analyzeProgramFinal();
//MethodSlot::genMethodSlot(ar);
{
Timer timer(Timer::WallTime, "creating CPP files");
if (po.syncDir.empty()) {
ar->setOutputPath(po.outputDir);
ar->outputAllCPP(format, clusterCount, NULL);
} else {
ar->setOutputPath(po.syncDir);
ar->outputAllCPP(format, clusterCount, &po.outputDir);
Util::syncdir(po.outputDir, po.syncDir);
boost::filesystem::remove_all(po.syncDir);
}
}
return ret;
}
示例14: phpTarget
int phpTarget(const ProgramOptions &po, AnalysisResultPtr ar) {
int ret = 0;
// format
int formatCount = 0;
if (po.format.find("pickled") != string::npos) {
Option::GeneratePickledPHP = true;
formatCount++;
}
if (po.format.find("inlined") != string::npos) {
Option::GenerateInlinedPHP = true;
formatCount++;
}
if (po.format.find("trimmed") != string::npos) {
Option::GenerateTrimmedPHP = true;
formatCount++;
}
if (po.format.find("typeinfo") != string::npos) {
Option::GenerateInferredTypes = true;
}
if (formatCount == 0) {
Logger::Error("Unknown format for PHP target: %s", po.format.c_str());
return 1;
}
// analyze
if (Option::GenerateInferredTypes || Option::ConvertSuperGlobals) {
Logger::Info("inferring types...");
ar->inferTypes();
}
// generate
ar->setOutputPath(po.outputDir);
if (Option::GeneratePickledPHP) {
Logger::Info("creating pickled PHP files...");
string outputDir = po.outputDir;
if (formatCount > 1) outputDir += "/pickled";
mkdir(outputDir.c_str(), 0777);
ar->outputAllPHP(CodeGenerator::PickledPHP);
}
if (Option::GenerateInlinedPHP) {
Logger::Info("creating inlined PHP files...");
string outputDir = po.outputDir;
if (formatCount > 1) outputDir += "/inlined";
mkdir(outputDir.c_str(), 0777);
if (!ar->outputAllPHP(CodeGenerator::InlinedPHP)) {
ret = -1;
}
}
if (Option::GenerateTrimmedPHP) {
Logger::Info("creating trimmed PHP files...");
string outputDir = po.outputDir;
if (formatCount > 1) outputDir += "/trimmed";
mkdir(outputDir.c_str(), 0777);
if (!ar->outputAllPHP(CodeGenerator::TrimmedPHP)) {
ret = -1;
}
}
return ret;
}
示例15: preOutputCPP
bool UnaryOpExpression::preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
int state) {
if (m_op == T_ISSET && m_exp && m_exp->is(Expression::KindOfExpressionList)) {
ExpressionListPtr exps = dynamic_pointer_cast<ExpressionList>(m_exp);
int count = exps->getCount();
if (count > 1) {
bool fix_e1 = (*exps)[0]->preOutputCPP(cg, ar, 0);
bool inExpression = ar->inExpression();
ar->setInExpression(false);
bool fix_en = false;
for (int i = 1; i < count; i++) {
if ((*exps)[i]->preOutputCPP(cg, ar, 0)) {
fix_en = true;
break;
}
}
ar->setInExpression(inExpression);
if (inExpression && fix_en) {
ar->wrapExpressionBegin(cg);
std::string tmp = genCPPTemp(cg, ar);
cg_printf("bool %s = (", tmp.c_str());
(*exps)[0]->outputCPPExistTest(cg, ar, m_op);
cg_printf(");\n");
for (int i = 1; i < count; i++) {
cg_indentBegin("if (%s) {\n", tmp.c_str());
ExpressionPtr e = (*exps)[i];
e->preOutputCPP(cg, ar, 0);
cg_printf("%s = (", tmp.c_str());
e->outputCPPExistTest(cg, ar, m_op);
cg_printf(");\n");
}
for (int i = 1; i < count; i++) {
cg_indentEnd("}\n");
}
m_cppTemp = tmp;
} else if (state & FixOrder) {
preOutputStash(cg, ar, state);
fix_e1 = true;
}
return fix_e1 || fix_en;
}
}
if (m_op == '@') {
bool inExpression = ar->inExpression();
bool doit = state & FixOrder;
if (!doit) {
ar->setInExpression(false);
if (m_exp->preOutputCPP(cg, ar, state)) {
doit = true;
}
ar->setInExpression(inExpression);
}
if (doit && inExpression) {
cg_printf("%s%d.enable();\n", Option::SilencerPrefix, m_silencer);
m_exp->preOutputCPP(cg, ar, 0);
int s = m_silencer;
m_silencer = -1;
this->preOutputStash(cg, ar, state | FixOrder);
m_silencer = s;
cg_printf("%s%d.disable();\n", Option::SilencerPrefix, m_silencer);
}
return doit;
} else if (m_op == T_PRINT && m_exp && !m_exp->hasEffect()) {
ExpressionPtrVec ev;
bool hasVoid = false, hasLit = false;
if (BinaryOpExpression::getConcatList(ev, m_exp, hasVoid, hasLit) > 1 ||
hasVoid || hasLit) {
if (!ar->inExpression()) return true;
ar->wrapExpressionBegin(cg);
for (int i = 0, s = ev.size(); i < s; i++) {
ExpressionPtr e = ev[i];
e->preOutputCPP(cg, ar, 0);
cg_printf("print(");
e->outputCPP(cg, ar);
cg_printf(");\n");
}
m_cppTemp = "1";
return true;
}
}
return Expression::preOutputCPP(cg, ar, state);
}