本文整理汇总了C++中AnalysisResultPtr::isFirstPass方法的典型用法代码示例。如果您正苦于以下问题:C++ AnalysisResultPtr::isFirstPass方法的具体用法?C++ AnalysisResultPtr::isFirstPass怎么用?C++ AnalysisResultPtr::isFirstPass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnalysisResultPtr
的用法示例。
在下文中一共展示了AnalysisResultPtr::isFirstPass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inferTypes
TypePtr NewObjectExpression::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
reset();
ConstructPtr self = shared_from_this();
if (!m_name.empty()) {
ClassScopePtr cls = ar->resolveClass(m_name);
if (cls) {
m_name = cls->getName();
}
if (!cls || cls->isRedeclaring()) {
if (cls) {
m_redeclared = true;
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
if (!cls && ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UnknownClass, self);
}
if (m_params) m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
return NEW_TYPE(Object);
}
if (cls->isVolatile()) {
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
m_dynamic = cls->derivesFromRedeclaring();
m_validClass = true;
FunctionScopePtr func = cls->findConstructor(ar, true);
if (!func) {
if (m_params) {
if (!m_dynamic && m_params->getCount()) {
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::BadConstructorCall,
self);
}
m_params->setOutputCount(0);
}
m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
}
} else {
m_extraArg = func->inferParamTypes(ar, self, m_params,
m_validClass);
m_variableArgument = func->isVariableArgument();
}
return Type::CreateObjectType(m_name);
} else {
ar->containsDynamicClass();
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UseDynamicClass,
self);
}
if (m_params) {
m_params->markParams(false);
}
}
m_nameExp->inferAndCheck(ar, Type::String, false);
if (m_params) m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
return Type::Variant;//NEW_TYPE(Object);
}
示例2: inferTypes
void CatchStatement::inferTypes(AnalysisResultPtr ar) {
ClassScopePtr cls = ar->findClass(m_className);
TypePtr type;
m_valid = cls;
if (!m_valid) {
if (ar->isFirstPass()) {
ConstructPtr self = shared_from_this();
ar->getCodeError()->record(self, CodeError::UnknownClass, self);
}
type = NEW_TYPE(Object);
} else if (cls->isRedeclaring()) {
type = NEW_TYPE(Object);
} else {
type = Type::CreateObjectType(m_className);
}
BlockScopePtr scope = ar->getScope();
VariableTablePtr variables = scope->getVariables();
variables->add(m_variable, type, false, ar, shared_from_this(),
ModifierExpressionPtr(), false);
if (ar->isFirstPass()) {
FunctionScopePtr func = dynamic_pointer_cast<FunctionScope>(scope);
if (func && variables->isParameter(m_variable)) {
variables->addLvalParam(m_variable);
}
}
if (m_stmt) m_stmt->inferTypes(ar);
}
示例3: inferTypes
TypePtr DynamicFunctionCall::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
reset();
ConstructPtr self = shared_from_this();
if (!m_className.empty()) {
ClassScopePtr cls = ar->resolveClass(m_className);
if (!cls || cls->isRedeclaring()) {
if (cls) {
m_redeclared = true;
ar->getScope()->getVariables()->
setAttribute(VariableTable::NeedGlobalPointer);
}
if (!cls && ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UnknownClass, self);
}
} else {
m_validClass = true;
}
}
ar->containsDynamicFunctionCall();
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UseDynamicFunction, self);
}
m_nameExp->inferAndCheck(ar, Type::String, false);
if (m_params) {
for (int i = 0; i < m_params->getCount(); i++) {
(*m_params)[i]->inferAndCheck(ar, Type::Variant, true);
}
}
return Type::Variant;
}
示例4: inferTypes
void SwitchStatement::inferTypes(AnalysisResultPtr ar) {
// we optimize the most two common cases of switch statements
bool allInteger = true;
bool allString = true;
if (m_cases && m_cases->getCount()) {
for (int i = 0; i < m_cases->getCount(); i++) {
CaseStatementPtr stmt =
dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
if (!stmt->getCondition()) {
if (m_cases->getCount() == 1) allInteger = allString = false;
} else {
if (!stmt->isLiteralInteger()) allInteger = false;
if (!stmt->isLiteralString()) allString = false;
}
}
}
if (allInteger && allString) {
allInteger = allString = false;
}
TypePtr ret;
if (allInteger) {
ret = m_exp->inferAndCheck(ar, Type::Int64, false);
} else if (allString) {
// We're not able to do this, because switch($obj) may work on an object
// that didn't implement __toString(), throwing an exception, which isn't
// consistent with PHP.
//ret = m_exp->inferAndCheck(ar, Type::String, false);
ret = m_exp->inferAndCheck(ar, NEW_TYPE(Some), false);
} else {
ret = m_exp->inferAndCheck(ar, NEW_TYPE(Some), false);
}
if (ret->is(Type::KindOfObject) && ret->isSpecificObject()) {
m_exp->setExpectedType(NEW_TYPE(Object));
}
ConstructPtr self = shared_from_this();
if (m_cases && m_cases->getCount()) {
bool checking = false;
vector<int> defaults;
int defaultCount = 0;
for (int i = 0; i < m_cases->getCount(); i++) {
CaseStatementPtr stmt =
dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
stmt->inferAndCheck(ar, NEW_TYPE(Some), false);
ExpressionPtr cond = stmt->getCondition();
if (!cond) {
checking = true;
defaultCount++;
} else if (checking && cond && ar->isFirstPass()) {
defaults.push_back(i);
ar->getCodeError()->record(self, CodeError::CaseAfterDefault, stmt);
}
}
if (defaultCount > 1 && ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::MoreThanOneDefault, m_cases);
}
}
}
示例5: getTypeSpec
TypePtr ParameterExpression::getTypeSpec(AnalysisResultPtr ar, bool error) {
TypePtr ret;
if (m_type.empty() || m_defaultValue) {
ret = Type::Some;
} else if (m_type == "array") {
ret = Type::Array;
} else {
ClassScopePtr cls = ar->findClass(m_type);
if (!cls || cls->isRedeclaring()) {
if (error && !cls && ar->isFirstPass()) {
ConstructPtr self = shared_from_this();
ar->getCodeError()->record(self, CodeError::UnknownClass, self);
}
ret = Type::Some;
} else {
ret = Type::CreateObjectType(m_type);
}
}
// we still want the above to run, so to record errors and infer defaults
if (m_ref) {
ret = Type::Variant;
}
return ret;
}
示例6: add
TypePtr ConstantTable::add(const std::string &name, TypePtr type,
ExpressionPtr exp, AnalysisResultPtr ar,
ConstructPtr construct) {
if (name == "true" || name == "false") {
return Type::Boolean;
}
StringToConstructPtrMap::const_iterator iter = m_values.find(name);
if (iter == m_values.end()) {
setType(ar, name, type, true);
m_declarations[name] = construct;
m_values[name] = exp;
return type;
}
if (ar->isFirstPass()) {
if (exp != iter->second) {
ar->getCodeError()->record(CodeError::DeclaredConstantTwice, construct,
m_declarations[name]);
m_dynamic.insert(name);
type = Type::Variant;
}
setType(ar, name, type, true);
}
return type;
}
示例7: inferTypes
void ForEachStatement::inferTypes(AnalysisResultPtr ar) {
if (ar->isFirstPass() &&
!m_array->is(Expression::KindOfSimpleVariable) &&
!m_array->is(Expression::KindOfArrayElementExpression) &&
!m_array->is(Expression::KindOfObjectPropertyExpression)) {
ConstructPtr self = shared_from_this();
ar->getCodeError()->record(self, CodeError::ComplexForEach, self);
}
m_array->inferAndCheck(ar, Type::Array, true);
if (m_name) {
m_name->inferAndCheck(ar, NEW_TYPE(Primitive), true);
}
m_value->inferAndCheck(ar, Type::Variant, true);
if (m_ref) {
TypePtr actualType = m_array->getActualType();
if (!actualType ||
actualType->is(Type::KindOfVariant) ||
actualType->is(Type::KindOfObject)) {
ar->forceClassVariants();
}
}
if (m_stmt) {
ar->getScope()->incLoopNestedLevel();
m_stmt->inferTypes(ar);
ar->getScope()->decLoopNestedLevel();
}
}
示例8: add
TypePtr ConstantTable::add(const std::string &name, TypePtr type,
ExpressionPtr exp, AnalysisResultPtr ar,
ConstructPtr construct) {
if (name == "true" || name == "false") {
return Type::Boolean;
}
Symbol *sym = getSymbol(name, true);
if (!sym->declarationSet()) {
setType(ar, sym, type, true);
sym->setDeclaration(construct);
sym->setValue(exp);
return type;
}
if (ar->isFirstPass()) {
if (exp != sym->getValue()) {
ar->getCodeError()->record(CodeError::DeclaredConstantTwice, construct,
sym->getDeclaration());
sym->setDynamic();
m_hasDynamic = true;
type = Type::Variant;
}
setType(ar, sym, type, true);
}
return type;
}
示例9: analyzeProgramImpl
void CatchStatement::analyzeProgramImpl(AnalysisResultPtr ar) {
addUserClass(ar, m_className);
if (ar->isFirstPass()) {
ar->getScope()->getVariables()->addUsed(m_variable);
}
if (m_stmt) m_stmt->analyzeProgram(ar);
}
示例10: analyzeProgramImpl
void StatementList::analyzeProgramImpl(AnalysisResultPtr ar) {
m_included = true;
for (unsigned int i = 0; i < m_stmts.size(); i++) {
StatementPtr stmt = m_stmts[i];
// effect testing
if (ar->isFirstPass() && !stmt->hasEffect() &&
!stmt->is(Statement::KindOfStatementList)) {
ar->getCodeError()->record(shared_from_this(),
CodeError::StatementHasNoEffect, stmt);
}
// changing AUTOLOAD to includes
if (ar->getPhase() == AnalysisResult::AnalyzeInclude &&
stmt->is(Statement::KindOfExpStatement)) {
ExpStatementPtr expStmt = dynamic_pointer_cast<ExpStatement>(stmt);
if (stmt->isFileLevel()) {
expStmt->analyzeAutoload(ar);
}
expStmt->analyzeShortCircuit(ar);
}
bool scopeStmt = stmt->is(Statement::KindOfFunctionStatement) ||
stmt->is(Statement::KindOfClassStatement) ||
stmt->is(Statement::KindOfInterfaceStatement);
if (ar->getPhase() != AnalysisResult::AnalyzeTopLevel || !scopeStmt) {
/* Recurse when analyzing include/all OR when not a scope */
stmt->analyzeProgram(ar);
}
}
}
示例11: ExpressionPtr
TypePtr AssignmentExpression::
inferTypesImpl(AnalysisResultPtr ar, TypePtr type, bool coerce,
ExpressionPtr variable,
ExpressionPtr value /* = ExpressionPtr() */) {
TypePtr ret = type;
if (value) {
if (coerce) {
ret = value->inferAndCheck(ar, type, coerce);
} else {
ret = value->inferAndCheck(ar, NEW_TYPE(Some), coerce);
}
}
BlockScopePtr scope = ar->getScope();
if (variable->is(Expression::KindOfConstantExpression)) {
// ...as in ClassConstant statement
ConstantExpressionPtr exp =
dynamic_pointer_cast<ConstantExpression>(variable);
bool p;
scope->getConstants()->check(exp->getName(), ret, true, ar, variable, p);
} else if (variable->is(Expression::KindOfDynamicVariable)) {
// simptodo: not too sure about this
ar->getFileScope()->setAttribute(FileScope::ContainsLDynamicVariable);
} else if (variable->is(Expression::KindOfSimpleVariable)) {
SimpleVariablePtr var = dynamic_pointer_cast<SimpleVariable>(variable);
if (var->getName() == "this" && ar->getClassScope()) {
if (ar->isFirstPass()) {
ar->getCodeError()->record(variable, CodeError::ReassignThis,
variable);
}
}
if (ar->getPhase() == AnalysisResult::LastInference && value) {
if (!value->getExpectedType()) {
value->setExpectedType(variable->getActualType());
}
}
}
// if the value may involve object, consider the variable as "referenced"
// so that objects are not destructed prematurely.
bool referenced = true;
if (value && value->isScalar()) referenced = false;
if (ret && ret->isNoObjectInvolved()) referenced = false;
if (referenced && variable->is(Expression::KindOfSimpleVariable)) {
SimpleVariablePtr var =
dynamic_pointer_cast<SimpleVariable>(variable);
const std::string &name = var->getName();
VariableTablePtr variables = ar->getScope()->getVariables();
variables->addReferenced(name);
}
TypePtr vt = variable->inferAndCheck(ar, ret, true);
if (!coerce && type->is(Type::KindOfAny)) {
ret = vt;
}
return ret;
}
示例12: analyzeProgramImpl
void MethodStatement::analyzeProgramImpl(AnalysisResultPtr ar) {
FunctionScopePtr funcScope = m_funcScope.lock();
// registering myself as a parent in dependency graph, so that
// (1) we can tell orphaned parents
// (2) overwrite non-master copy of function declarations
if (ar->isFirstPass()) {
ar->getDependencyGraph()->addParent(DependencyGraph::KindOfFunctionCall,
"", getFullName(), shared_from_this());
if (Option::AllDynamic || hasHphpNote("Dynamic") ||
funcScope->isSepExtension() ||
BuiltinSymbols::IsDeclaredDynamic(m_name) ||
Option::IsDynamicFunction(m_method, m_name)) {
funcScope->setDynamic();
}
if (hasHphpNote("Volatile")) funcScope->setVolatile();
}
funcScope->setIncludeLevel(ar->getIncludeLevel());
ar->pushScope(funcScope);
if (m_params) {
m_params->analyzeProgram(ar);
if (Option::GenRTTIProfileData &&
ar->getPhase() == AnalysisResult::AnalyzeFinal) {
addParamRTTI(ar);
}
}
if (m_stmt) m_stmt->analyzeProgram(ar);
if (ar->isFirstPass()) {
if (!funcScope->isStatic() && ar->getClassScope() &&
funcScope->getVariables()->
getAttribute(VariableTable::ContainsDynamicVariable)) {
// Add this to variable table if we'll need it in a lookup table
// Use object because there's no point to specializing, just makes
// code gen harder when dealing with redeclared classes.
TypePtr tp(NEW_TYPE(Object));
funcScope->getVariables()->add("this", tp, true, ar, shared_from_this(),
ModifierExpressionPtr());
}
FunctionScope::RecordRefParamInfo(m_name, funcScope);
}
ar->popScope();
}
示例13: inferTypes
TypePtr DynamicVariable::inferTypes(AnalysisResultPtr ar, TypePtr type,
bool coerce) {
ConstructPtr self = shared_from_this();
if (m_context & (LValue | RefValue)) {
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UseLDynamicVariable, self);
}
ar->getScope()->getVariables()->forceVariants(ar);
ar->getScope()->
getVariables()->setAttribute(VariableTable::ContainsLDynamicVariable);
} else {
if (ar->isFirstPass()) {
ar->getCodeError()->record(self, CodeError::UseRDynamicVariable, self);
}
}
m_exp->inferAndCheck(ar, Type::String, false);
return m_implementedType = Type::Variant;
}
示例14: analyzeProgram
void ParameterExpression::analyzeProgram(AnalysisResultPtr ar) {
if (!m_type.empty()) addUserClass(ar, m_type);
if (m_defaultValue) m_defaultValue->analyzeProgram(ar);
if (ar->isFirstPass()) {
// Have to use non const ref params for magic methods
FunctionScopePtr fs = ar->getFunctionScope();
if (fs->isMagicMethod() || fs->getName() == "offsetget") {
fs->getVariables()->addLvalParam(m_name);
}
}
}
示例15: check
TypePtr ConstantTable::check(const std::string &name, TypePtr type,
bool coerce, AnalysisResultPtr ar,
ConstructPtr construct, bool &present) {
TypePtr actualType;
present = true;
if (name == "true" || name == "false") {
actualType = Type::Boolean;
} else if (!ar->isFirstPass() && m_values.find(name) == m_values.end()) {
ClassScopePtr parent = findParent(ar, name);
if (parent) {
return parent->checkConst(name, type, coerce, ar,
construct, present);
}
ar->getCodeError()->record(CodeError::UseUndeclaredConstant,
construct);
if (m_blockScope.is(BlockScope::ClassScope)) {
actualType = Type::Variant;
} else {
actualType = Type::String;
}
setType(ar, name, actualType, true);
present = false;
} else {
StringToTypePtrMap::const_iterator iter = m_coerced.find(name);
if (iter != m_coerced.end()) {
actualType = iter->second;
if (actualType->is(Type::KindOfSome) ||
actualType->is(Type::KindOfAny)) {
setType(ar, name, type, true);
return type;
}
} else {
ClassScopePtr parent = findParent(ar, name);
if (parent) {
return parent->checkConst(name, type, coerce, ar,
construct, present);
}
present = false;
actualType = NEW_TYPE(Some);
setType(ar, name, actualType, true);
m_declarations[name] = construct;
}
}
if (Type::IsBadTypeConversion(ar, actualType, type, coerce)) {
ar->getCodeError()->record(construct, type->getKindOf(),
actualType->getKindOf());
}
return actualType;
}