Class Scope

java.lang.Object
com.oracle.js.parser.ir.Scope

public final class Scope extends Object
Represents a binding scope (corresponds to LexicalEnvironment or VariableEnvironment).
  • Field Details

    • symbols

      protected final org.graalvm.collections.EconomicMap<String,Symbol> symbols
      Symbol table - keys must be returned in the order they were put in.
    • uses

      protected org.graalvm.collections.EconomicMap<String, com.oracle.js.parser.ir.Scope.UseInfo> uses
      Use map.
  • Method Details

    • createGlobal

      public static Scope createGlobal()
    • createModule

      public static Scope createModule()
    • createFunctionBody

      public static Scope createFunctionBody(Scope parent, int functionFlags, boolean functionTopScope)
    • createFunctionBody

      public static Scope createFunctionBody(Scope parent)
    • createBlock

      public static Scope createBlock(Scope parent)
    • createCatchParameter

      public static Scope createCatchParameter(Scope parent)
    • createFunctionParameter

      public static Scope createFunctionParameter(Scope parent, int functionFlags)
    • createSwitchBlock

      public static Scope createSwitchBlock(Scope parent)
    • createClassHead

      public static Scope createClassHead(Scope parent)
    • createClassBody

      public static Scope createClassBody(Scope parent)
    • createEval

      public static Scope createEval(Scope parent, boolean strict)
    • getParent

      public Scope getParent()
    • getSymbols

      public Iterable<Symbol> getSymbols()
      Get all the symbols defined in this block, in definition order.
      Returns:
      symbol iterator
    • getExistingSymbol

      public Symbol getExistingSymbol(String name)
      Retrieves an existing symbol defined in the current block.
      Parameters:
      name - the name of the symbol
      Returns:
      an existing symbol with the specified name defined in the current block, or null if this block doesn't define a symbol with this name.
    • hasSymbol

      public boolean hasSymbol(String name)
      Test if a symbol with this name is defined in the current block.
      Parameters:
      name - the name of the symbol
    • getSymbolCount

      public int getSymbolCount()
      Get the number of symbols defined in this block.
    • putSymbol

      public Symbol putSymbol(Symbol symbol)
      Add symbol to the scope if it does not already exist.
    • hasBlockScopedOrRedeclaredSymbols

      public boolean hasBlockScopedOrRedeclaredSymbols()
    • hasPrivateNames

      public boolean hasPrivateNames()
    • hasDeclarations

      public boolean hasDeclarations()
    • isLexicallyDeclaredName

      public boolean isLexicallyDeclaredName(String varName, boolean annexB, boolean includeParameters)
      Returns true if the name is lexically declared in this scope or any of its enclosing scopes within this function.
      Parameters:
      varName - the declared name
      annexB - if true, ignore catch parameters
      includeParameters - include parameter scope?
    • findBlockScopedSymbolInFunction

      public Symbol findBlockScopedSymbolInFunction(String varName)
      Returns a block scoped symbol in this scope or any of its enclosing scopes within this function.
      Parameters:
      varName - the symbol name
    • addPrivateName

      public boolean addPrivateName(com.oracle.truffle.api.strings.TruffleString name, int symbolFlags)
      Add a private bound identifier.
      Returns:
      true if the private name was added, false if it was already declared (duplicate name)
    • findPrivateName

      public boolean findPrivateName(String name)
    • isBlockScope

      public boolean isBlockScope()
    • isFunctionBodyScope

      public boolean isFunctionBodyScope()
    • isFunctionParameterScope

      public boolean isFunctionParameterScope()
    • isCatchParameterScope

      public boolean isCatchParameterScope()
    • isGlobalScope

      public boolean isGlobalScope()
    • isModuleScope

      public boolean isModuleScope()
    • isFunctionTopScope

      public boolean isFunctionTopScope()
    • isSwitchBlockScope

      public boolean isSwitchBlockScope()
    • isClassBodyScope

      public boolean isClassBodyScope()
    • isClassHeadScope

      public boolean isClassHeadScope()
    • isEvalScope

      public boolean isEvalScope()
    • isArrowFunctionParameterScope

      public boolean isArrowFunctionParameterScope()
    • inFunction

      public boolean inFunction()
    • inMethod

      public boolean inMethod()
    • inDerivedConstructor

      public boolean inDerivedConstructor()
    • inClassFieldInitializer

      public boolean inClassFieldInitializer()
    • close

      public void close()
      Closes the scope for symbol registration.
    • isClosed

      public boolean isClosed()
    • kill

      public void kill()
      Clears defined symbols and moves any local uses into the parent scope.
    • addIdentifierReference

      public void addIdentifierReference(String name)
      Records the use of an identifier reference in this scope to be resolved.
    • resolveUses

      public void resolveUses()
      Resolves free variables in this scope and forwards unresolved uses to the parent scope.
    • hasClosures

      public boolean hasClosures()
      Returns true if the scope has closed over variables.
    • hasEval

      public boolean hasEval()
      Does this scope contain a direct eval.
    • setHasEval

      public void setHasEval()
      Marks this scope as containing a direct eval.
    • hasNestedEval

      public boolean hasNestedEval()
      Does this scope or any nested scopes contain a direct eval.
    • setHasNestedEval

      public void setHasNestedEval()
    • toString

      public String toString()
      Overrides:
      toString in class Object