Class Symbol

java.lang.Object
com.oracle.js.parser.ir.Symbol
All Implemented Interfaces:
Comparable<Symbol>

public final class Symbol extends Object implements Comparable<Symbol>
Symbol is a symbolic address for a value ("variable" if you wish). Identifiers in JavaScript source, as well as certain synthetic variables created by the compiler are represented by Symbol objects. Symbols can address either local variable slots in bytecode ("slotted symbol"), or properties in scope objects ("scoped symbol"). A symbol can also end up being defined but then not used during symbol assignment calculations; such symbol will be neither scoped, nor slotted; it represents a dead variable (it might be written to, but is never read). Finally, a symbol can be both slotted and in scope. This special case can only occur with bytecode method parameters. They all come in as slotted, but if they are used by a nested function (or eval) then they will be copied into the scope object, and used from there onwards. Two further special cases are parameters stored in NativeArguments objects and parameters stored in Object[] parameter to variable-arity functions. Those use the #getFieldIndex() property to refer to their location.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Is this symbol already declared? Used for block scoped LET and CONST symbols only.
    static final int
    Is this symbol the function 'arguments' binding?
    static final int
    Is this symbol a block function declaration?
    static final int
    Is this symbol a catch parameter binding?
    static final int
    Is this symbol closed over by an inner function closure?
    static final int
    Is this a const binding
    static final int
    Is this symbol declared in an unprotected switch case context?
    static final int
    Is this a function self-reference symbol
    static final int
    Is this a global binding
    static final int
    Is this a hoistable var declaration?
    static final int
    Is this symbol a block function declaration hoisted into the body scope.
    static final int
    Is this symbol an indirect import binding of a module environment?
    static final int
    Is this an internal symbol, never represented explicitly in source code
    static final int
    Is this a let binding
    static final int
    Is this the new.target.
    static final int
    Is this a parameter
    static final int
    Is this symbol a private name?
    static final int
    Is this symbol a private name associated with an accessor?
    static final int
    Is this symbol a private name associated with a method?
    static final int
    Is this symbol a private name associated with a static member?
    static final int
    Is this a program level symbol?
    static final int
    Is this the home object, used by super property accesses.
    static final int
    Is this a this symbol
    static final int
    Is this symbol used?
    static final int
    Is this symbol used by an inner scope within the same function?
    static final int
    Is this a var binding
    static final int
    Is this symbol a var declaration binding that needs to be initialized with the value of the parent's scope's binding with the same name? Used for parameter bindings that are replicated in the body's VariableEnvironment.
    static final int
    Mask for kind flags
  • Constructor Summary

    Constructors
    Constructor
    Description
    Symbol(com.oracle.truffle.api.strings.TruffleString name, int flags)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
    Get the symbol flags
    Get the name of this symbol
    com.oracle.truffle.api.strings.TruffleString
     
    boolean
    Returns true if this symbol can be assumed to have already been declared and initialized in the declaring scope, i.e., it does not have or need a temporal dead zone.
    boolean
    Is this symbol the function 'arguments' binding.
    boolean
    Is this symbol a block function declaration.
    boolean
    Is this a block scoped symbol
    boolean
     
    boolean
    Is this symbol captured by a closure.
    boolean
    Check if this symbol is a constant
    boolean
    Has this symbol been declared
    boolean
    Flag this symbol as a function's self-referencing symbol.
    boolean
    Check if this symbol is a global (undeclared) variable
    boolean
    Check if this symbol is a hoistable var declaration.
    boolean
    Is this symbol a hoisted block function declaration.
    boolean
     
    boolean
    Check if this is an internal symbol, without an explicit JavaScript source code equivalent
    boolean
    Check if this symbol is a let
    boolean
    Check if this symbol represents new.target
    boolean
    Check if this symbol is a function parameter
    boolean
    Is this symbol a private name associated with an accessor.
    boolean
    Is this symbol a private name associated with a field.
    boolean
    Is this symbol a private name associated with a method.
    boolean
    Is this symbol a private name.
    boolean
    Is this symbol a private name associated with a static member.
    boolean
    Check if this is a program (script) level definition
    boolean
    Check if this symbol represents super
    boolean
    Check if this symbol represents this
    boolean
    Is this symbol used.
    boolean
    Is this symbol captured by an inner scope.
    boolean
    Check if this symbol is a variable
    boolean
     
    void
    Mark this symbol as captured by a closure.
    void
    Mark this symbol as a hoisted block function declaration.
    void
    Mark this symbol as used.
    void
    Mark this symbol as captured by an inner scope.
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • IS_LET

      public static final int IS_LET
      Is this a let binding
      See Also:
    • IS_CONST

      public static final int IS_CONST
      Is this a const binding
      See Also:
    • IS_VAR

      public static final int IS_VAR
      Is this a var binding
      See Also:
    • KINDMASK

      public static final int KINDMASK
      Mask for kind flags
      See Also:
    • IS_GLOBAL

      public static final int IS_GLOBAL
      Is this a global binding
      See Also:
    • IS_PARAM

      public static final int IS_PARAM
      Is this a parameter
      See Also:
    • IS_THIS

      public static final int IS_THIS
      Is this a this symbol
      See Also:
    • IS_INTERNAL

      public static final int IS_INTERNAL
      Is this an internal symbol, never represented explicitly in source code
      See Also:
    • IS_FUNCTION_SELF

      public static final int IS_FUNCTION_SELF
      Is this a function self-reference symbol
      See Also:
    • IS_HOISTABLE_DECLARATION

      public static final int IS_HOISTABLE_DECLARATION
      Is this a hoistable var declaration?
      See Also:
    • IS_PROGRAM_LEVEL

      public static final int IS_PROGRAM_LEVEL
      Is this a program level symbol?
      See Also:
    • HAS_BEEN_DECLARED

      public static final int HAS_BEEN_DECLARED
      Is this symbol already declared? Used for block scoped LET and CONST symbols only.
      See Also:
    • IS_HOISTED_BLOCK_FUNCTION

      public static final int IS_HOISTED_BLOCK_FUNCTION
      Is this symbol a block function declaration hoisted into the body scope.
      See Also:
    • IS_VAR_REDECLARED_HERE

      public static final int IS_VAR_REDECLARED_HERE
      Is this symbol a var declaration binding that needs to be initialized with the value of the parent's scope's binding with the same name? Used for parameter bindings that are replicated in the body's VariableEnvironment.
      See Also:
    • IS_DECLARED_IN_SWITCH_BLOCK

      public static final int IS_DECLARED_IN_SWITCH_BLOCK
      Is this symbol declared in an unprotected switch case context?
      See Also:
    • IS_IMPORT_BINDING

      public static final int IS_IMPORT_BINDING
      Is this symbol an indirect import binding of a module environment?
      See Also:
    • IS_CATCH_PARAMETER

      public static final int IS_CATCH_PARAMETER
      Is this symbol a catch parameter binding?
      See Also:
    • IS_BLOCK_FUNCTION_DECLARATION

      public static final int IS_BLOCK_FUNCTION_DECLARATION
      Is this symbol a block function declaration?
      See Also:
    • IS_PRIVATE_NAME

      public static final int IS_PRIVATE_NAME
      Is this symbol a private name?
      See Also:
    • IS_PRIVATE_NAME_STATIC

      public static final int IS_PRIVATE_NAME_STATIC
      Is this symbol a private name associated with a static member?
      See Also:
    • IS_PRIVATE_NAME_METHOD

      public static final int IS_PRIVATE_NAME_METHOD
      Is this symbol a private name associated with a method?
      See Also:
    • IS_PRIVATE_NAME_ACCESSOR

      public static final int IS_PRIVATE_NAME_ACCESSOR
      Is this symbol a private name associated with an accessor?
      See Also:
    • IS_ARGUMENTS

      public static final int IS_ARGUMENTS
      Is this symbol the function 'arguments' binding?
      See Also:
    • IS_USED

      public static final int IS_USED
      Is this symbol used?
      See Also:
    • IS_CLOSED_OVER

      public static final int IS_CLOSED_OVER
      Is this symbol closed over by an inner function closure?
      See Also:
    • IS_USED_IN_INNER_SCOPE

      public static final int IS_USED_IN_INNER_SCOPE
      Is this symbol used by an inner scope within the same function?
      See Also:
    • IS_SUPER

      public static final int IS_SUPER
      Is this the home object, used by super property accesses.
      See Also:
    • IS_NEW_TARGET

      public static final int IS_NEW_TARGET
      Is this the new.target.
      See Also:
  • Constructor Details

    • Symbol

      public Symbol(com.oracle.truffle.api.strings.TruffleString name, int flags)
      Constructor
      Parameters:
      name - name of symbol
      flags - symbol flags
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(Symbol other)
      Specified by:
      compareTo in interface Comparable<Symbol>
    • isHoistableDeclaration

      public boolean isHoistableDeclaration()
      Check if this symbol is a hoistable var declaration.
      Returns:
      true if a hoistable var declaration
      See Also:
    • isVar

      public boolean isVar()
      Check if this symbol is a variable
      Returns:
      true if variable
    • isGlobal

      public boolean isGlobal()
      Check if this symbol is a global (undeclared) variable
      Returns:
      true if global
    • isParam

      public boolean isParam()
      Check if this symbol is a function parameter
      Returns:
      true if parameter
    • isProgramLevel

      public boolean isProgramLevel()
      Check if this is a program (script) level definition
      Returns:
      true if program level
    • isConst

      public boolean isConst()
      Check if this symbol is a constant
      Returns:
      true if a constant
    • isInternal

      public boolean isInternal()
      Check if this is an internal symbol, without an explicit JavaScript source code equivalent
      Returns:
      true if internal
    • isThis

      public boolean isThis()
      Check if this symbol represents this
      Returns:
      true if this
    • isSuper

      public boolean isSuper()
      Check if this symbol represents super
      Returns:
      true if super
    • isNewTarget

      public boolean isNewTarget()
      Check if this symbol represents new.target
      Returns:
      true if new.target
    • isLet

      public boolean isLet()
      Check if this symbol is a let
      Returns:
      true if let
    • isFunctionSelf

      public boolean isFunctionSelf()
      Flag this symbol as a function's self-referencing symbol.
      Returns:
      true if this symbol as a function's self-referencing symbol.
    • isBlockScoped

      public boolean isBlockScoped()
      Is this a block scoped symbol
      Returns:
      true if block scoped
    • hasBeenDeclared

      public boolean hasBeenDeclared()
      Returns true if this symbol can be assumed to have already been declared and initialized in the declaring scope, i.e., it does not have or need a temporal dead zone. Only relevant for lexical (let, const) declarations.
      Returns:
      true if declared
    • getFlags

      public int getFlags()
      Get the symbol flags
      Returns:
      flags
    • getName

      public String getName()
      Get the name of this symbol
      Returns:
      symbol name
    • getNameTS

      public com.oracle.truffle.api.strings.TruffleString getNameTS()
    • isDeclaredInSwitchBlock

      public boolean isDeclaredInSwitchBlock()
      Has this symbol been declared
      Returns:
      true if declared
    • isImportBinding

      public boolean isImportBinding()
      Returns:
      true if this symbol is an indirect import binding
      See Also:
    • isCatchParameter

      public boolean isCatchParameter()
      Returns:
      true if this symbol is a catch parameter binding
      See Also:
    • isVarRedeclaredHere

      public boolean isVarRedeclaredHere()
    • isHoistedBlockFunctionDeclaration

      public boolean isHoistedBlockFunctionDeclaration()
      Is this symbol a hoisted block function declaration.
    • setHoistedBlockFunctionDeclaration

      public void setHoistedBlockFunctionDeclaration()
      Mark this symbol as a hoisted block function declaration.
    • isBlockFunctionDeclaration

      public boolean isBlockFunctionDeclaration()
      Is this symbol a block function declaration.
    • isPrivateName

      public boolean isPrivateName()
      Is this symbol a private name.
    • isPrivateNameStatic

      public boolean isPrivateNameStatic()
      Is this symbol a private name associated with a static member.
    • isPrivateField

      public boolean isPrivateField()
      Is this symbol a private name associated with a field.
    • isPrivateMethod

      public boolean isPrivateMethod()
      Is this symbol a private name associated with a method.
    • isPrivateAccessor

      public boolean isPrivateAccessor()
      Is this symbol a private name associated with an accessor.
    • isArguments

      public boolean isArguments()
      Is this symbol the function 'arguments' binding.
    • isUsed

      public boolean isUsed()
      Is this symbol used.
    • setUsed

      public void setUsed()
      Mark this symbol as used.
    • isClosedOver

      public boolean isClosedOver()
      Is this symbol captured by a closure.
    • setClosedOver

      public void setClosedOver()
      Mark this symbol as captured by a closure.
    • isUsedInInnerScope

      public boolean isUsedInInnerScope()
      Is this symbol captured by an inner scope.
    • setUsedInInnerScope

      public void setUsedInInnerScope()
      Mark this symbol as captured by an inner scope.