Class Block

java.lang.Object
com.oracle.js.parser.ir.Node
com.oracle.js.parser.ir.Block
All Implemented Interfaces:
BreakableNode, Flags<Block>, LexicalContextNode, LexicalContextScope, Terminal, Cloneable

public class Block extends Node implements BreakableNode, Terminal, Flags<Block>, LexicalContextScope
IR representation for a list of statements.
  • Field Details

    • statements

      protected final List<Statement> statements
      List of statements
    • scope

      protected final Scope scope
    • flags

      protected final int flags
      Does the block/function need a new scope? Is this synthetic?
    • NEEDS_SCOPE

      public static final int NEEDS_SCOPE
      Flag indicating that this block needs scope
      See Also:
    • IS_TERMINAL

      public static final int IS_TERMINAL
      Is this block tagged as terminal based on its contents (usually the last statement)
      See Also:
    • IS_GLOBAL_SCOPE

      public static final int IS_GLOBAL_SCOPE
      Is this block the eager global scope - i.e. the original program. This isn't true for the outermost level of recompiles
      See Also:
    • IS_SYNTHETIC

      public static final int IS_SYNTHETIC
      Is this block a synthetic one introduced by Parser?
      See Also:
    • IS_BODY

      public static final int IS_BODY
      Is this the function body block? May not be the first, if parameter list contains expressions.
      See Also:
    • IS_PARAMETER_BLOCK

      public static final int IS_PARAMETER_BLOCK
      Is this the parameter initialization block? If present, must be the first block, immediately wrapping the function body block.
      See Also:
    • IS_SWITCH_BLOCK

      public static final int IS_SWITCH_BLOCK
      Marks the variable declaration block for case clauses of a switch statement.
      See Also:
    • IS_EXPRESSION_BLOCK

      public static final int IS_EXPRESSION_BLOCK
      Is this an expression block (class or do expression) that should return its completion value.
      See Also:
    • IS_MODULE_BODY

      public static final int IS_MODULE_BODY
      Marks the module body block.
      See Also:
  • Constructor Details

    • Block

      public Block(long token, int finish, int flags, Scope scope, List<Statement> statements)
      Constructor
      Parameters:
      token - The first token of the block
      finish - The index of the last character
      flags - The flags of the block
      statements - All statements in the block
  • Method Details

    • isGlobalScope

      public boolean isGlobalScope()
      Is this block the outermost eager global scope - i.e. the primordial program? Used for global anchor point for scope depth computation for recompilation code
      Returns:
      true if outermost eager global scope
    • accept

      public Node accept(LexicalContext lc, NodeVisitor<? extends LexicalContext> visitor)
      Assist in IR navigation.
      Specified by:
      accept in interface LexicalContextNode
      Parameters:
      lc - lexical context
      visitor - IR navigating visitor.
      Returns:
      new or same node
    • accept

      public <R> R accept(LexicalContext lc, TranslatorNodeVisitor<? extends LexicalContext, R> visitor)
      Specified by:
      accept in interface LexicalContextNode
    • 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.
    • isCatchBlock

      public boolean isCatchBlock()
      Test if this block represents a catch block in a try statement.
      Returns:
      true if this block represents a catch block in a try statement.
    • toString

      public void toString(StringBuilder sb, boolean printType)
      Description copied from class: Node
      Print logic that decides whether to show the optimistic type or not - for example it should not be printed after just parse, when it hasn't been computed, or has been set to a trivially provable value
      Specified by:
      toString in class Node
      Parameters:
      sb - string builder
      printType - print type?
    • getFlags

      public int getFlags()
      Description copied from interface: Flags
      Get all flags of a LexicalContextNode
      Specified by:
      getFlags in interface Flags<Block>
      Returns:
      flags
    • isTerminal

      public boolean isTerminal()
      Is this a terminal block, i.e. does it end control flow like ending with a throw or return?
      Specified by:
      isTerminal in interface Terminal
      Returns:
      true if this node statement is terminal
    • getStatements

      public List<Statement> getStatements()
      Get the list of statements in this block
      Returns:
      a list of statements
    • getStatementCount

      public int getStatementCount()
      Returns the number of statements in the block.
      Returns:
      the number of statements in the block.
    • getFirstStatementLineNumber

      public int getFirstStatementLineNumber()
      Returns the line number of the first statement in the block.
      Returns:
      the line number of the first statement in the block, or -1 if the block has no statements.
    • getFirstStatement

      public Statement getFirstStatement()
      Returns the first statement in the block.
      Returns:
      the first statement in the block, or null if the block has no statements.
    • getLastStatement

      public Statement getLastStatement()
      Returns the last statement in the block.
      Returns:
      the last statement in the block, or null if the block has no statements.
    • setStatements

      public Block setStatements(LexicalContext lc, List<Statement> statements)
      Reset the statement list for this block
      Parameters:
      lc - lexical context
      statements - new statement list
      Returns:
      new block if statements changed, identity of statements == block.statements
    • needsScope

      public boolean needsScope()
      Check whether scope is necessary for this Block
      Returns:
      true if this function needs a scope
    • isSynthetic

      public boolean isSynthetic()
      Check whether this block is synthetic or not.
      Returns:
      true if this is a synthetic block
    • setFlags

      public Block setFlags(LexicalContext lc, int flags)
      Description copied from interface: Flags
      Set all flags of a LexicalContextNode, overwriting previous flags
      Specified by:
      setFlags in interface Flags<Block>
      Parameters:
      lc - lexical context
      flags - new flags value
      Returns:
      the new LexicalContext node if flags were changed, same otherwise
    • setFlag

      public Block setFlag(LexicalContext lc, int flag)
      Description copied from interface: Flags
      Set a flag of a LexicalContextNode
      Specified by:
      setFlag in interface Flags<Block>
      Parameters:
      lc - lexical context
      flag - flag to set
      Returns:
      the new LexicalContext node if flags were changed, same otherwise
    • getFlag

      public boolean getFlag(int flag)
      Description copied from interface: Flags
      Check if a flag is set in a lexical context node
      Specified by:
      getFlag in interface Flags<Block>
      Parameters:
      flag - flag to check
      Returns:
      flags
    • isBreakableWithoutLabel

      public boolean isBreakableWithoutLabel()
      Description copied from interface: BreakableNode
      Check whether this can be broken out from without using a label, e.g. everything but Blocks, basically.
      Specified by:
      isBreakableWithoutLabel in interface BreakableNode
      Returns:
      true if breakable without label
    • accept

      public Node accept(NodeVisitor<? extends LexicalContext> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      Specified by:
      accept in interface LexicalContextNode
      Specified by:
      accept in class Node
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • accept

      public <R> R accept(TranslatorNodeVisitor<? extends LexicalContext, R> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      Specified by:
      accept in interface LexicalContextNode
      Specified by:
      accept in class Node
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • getScope

      public Scope getScope()
      Specified by:
      getScope in interface LexicalContextScope
    • isFunctionBody

      public boolean isFunctionBody()
    • isParameterBlock

      public boolean isParameterBlock()
    • isSwitchBlock

      public boolean isSwitchBlock()
    • isExpressionBlock

      public boolean isExpressionBlock()
    • isModuleBody

      public boolean isModuleBody()