void SimpleVariable::analyzeProgram(AnalysisResultPtr ar) { Expression::analyzeProgram(ar); if (m_name == "argc" || m_name == "argv") { // special case: they are NOT superglobals when not in global scope if (ar->getScope() == ar) { m_superGlobal = BuiltinSymbols::IsSuperGlobal(m_name); m_superGlobalType = BuiltinSymbols::GetSuperGlobalType(m_name); } } else { m_superGlobal = BuiltinSymbols::IsSuperGlobal(m_name); m_superGlobalType = BuiltinSymbols::GetSuperGlobalType(m_name); } if (m_superGlobal) { ar->getScope()->getVariables()-> setAttribute(VariableTable::NeedGlobalPointer); } if (m_name == "this" && ar->getClassScope()) { FunctionScopePtr func = dynamic_pointer_cast<FunctionScope>(ar->getScope()); func->setContainsThis(); m_this = true; } else if (m_name == "GLOBALS") { m_globals = true; } if (!(m_context & AssignmentLHS)) { BlockScopePtr scope = ar->getScope(); FunctionScopePtr func = dynamic_pointer_cast<FunctionScope>(scope); if (func) { func->getVariables()->addUsed(m_name); } } }
void FunctionScope::setContainsThis(bool f /* = true */) { m_containsThis = f; BlockScopePtr bs(this->getOuterScope()); while (bs && bs->is(BlockScope::FunctionScope)) { FunctionScopePtr fs = static_pointer_cast<FunctionScope>(bs); if (!fs->isClosure()) { break; } fs->setContainsThis(f); bs = bs->getOuterScope(); } for (auto it = m_clonedTraitOuterScope.begin(); it != m_clonedTraitOuterScope.end(); it++) { (*it)->setContainsThis(f); } }