FunctionScopePtr FileScope::createPseudoMain(AnalysisResultConstPtr ar) { StatementListPtr st = m_tree; auto labelScope = std::make_shared<LabelScope>(); auto f = std::make_shared<FunctionStatement>( BlockScopePtr(), labelScope, Location::Range(), ModifierExpressionPtr(), false, pseudoMainName(), ExpressionListPtr(), TypeAnnotationPtr(), st, 0, "", ExpressionListPtr()); f->setFileLevel(); auto pseudoMain = std::make_shared<HPHP::FunctionScope>( ar, true, pseudoMainName().c_str(), f, false, 0, 0, ModifierExpressionPtr(), m_attributes[0], "", shared_from_this(), vector<UserAttributePtr>(), true); f->setBlockScope(pseudoMain); auto& fs = m_functions[pseudoMainName()]; always_assert(!fs); fs = pseudoMain; m_pseudoMain = pseudoMain; return pseudoMain; }
TypePtr VariableTable::addParam(const string &name, TypePtr type, AnalysisResultConstPtr ar, ConstructPtr construct) { Symbol *sym = addDeclaredSymbol(name, construct); if (!sym->isParameter()) { sym->setParameterIndex(m_nextParam++); } return type ? add(sym, type, false, ar, construct, ModifierExpressionPtr()) : type; }
TypePtr VariableTable::addParamLike(const string &name, TypePtr type, AnalysisResultPtr ar, ConstructPtr construct, bool firstPass) { TypePtr ret = type; if (firstPass) { ret = add(name, ret, false, ar, construct, ModifierExpressionPtr()); } else { ret = checkVariable(name, ret, true, ar, construct); if (ret->is(Type::KindOfSome)) { // This is probably too conservative. The problem is that // a function never called will have parameter types of Any. // Functions that it calls won't be able to accept variant unless // it is forced here. forceVariant(ar, name, VariableTable::AnyVars); ret = Type::Variant; } } return ret; }