Example #1
0
bool VariableTable::isLocal(const Symbol *sym) const {
  if (!sym) return false;
  if (getScopePtr()->is(BlockScope::FunctionScope)) {
    /*
      isSuperGlobal is not wanted here. It just means that
      $GLOBALS[name] was referenced in this scope.
      It doesnt say anything about the variable $name.
    */
    return (!sym->isStatic() &&
            !sym->isGlobal() &&
            !sym->isParameter());
  }
  return false;
}
void VariableTable::getLocalVariableNames(vector<string> &syms) const {
  FunctionScopeRawPtr fs = getScopePtr()->getContainingFunction();
  bool dollarThisIsSpecial = (fs->getContainingClass() ||
                              fs->inPseudoMain());

  for (unsigned int i = 0; i < m_symbolVec.size(); i++) {
    const string& name = m_symbolVec[i]->getName();
    if (name == "this" && dollarThisIsSpecial) {
      // The "this" variable in methods and pseudo-main is special and is
      // handled separately below.
      continue;
    }
    syms.push_back(name);
  }

  if (fs->needsLocalThis()) {
    assert(dollarThisIsSpecial);
    // We only need a local variable named "this" if the current function
    // contains an occurrence of "$this" that is not part of a property
    // expression or object method call expression
    syms.push_back("this");
  }
}