Class ForNode

All Implemented Interfaces:
BreakableNode, LexicalContextNode, Terminal, Cloneable

public final class ForNode extends LoopNode
IR representing a FOR statement.
  • Field Details

    • IS_FOR_IN

      public static final int IS_FOR_IN
      Is this a normal for in loop?
      See Also:
    • IS_FOR_EACH

      public static final int IS_FOR_EACH
      Is this a normal for each in loop?
      See Also:
    • PER_ITERATION_SCOPE

      public static final int PER_ITERATION_SCOPE
      Does this loop need a per-iteration scope because its init contain a LET declaration?
      See Also:
    • IS_FOR_OF

      public static final int IS_FOR_OF
      Is this a for of loop?
      See Also:
    • IS_FOR_AWAIT_OF

      public static final int IS_FOR_AWAIT_OF
      Is this a for await of loop?
      See Also:
  • Constructor Details

    • ForNode

      public ForNode(int lineNumber, long token, int finish, Block body, int flags, Expression init, JoinPredecessorExpression test, JoinPredecessorExpression modify)
      Constructor
      Parameters:
      lineNumber - The line number of header
      token - The for token
      finish - The last character of the for node
      body - The body of the for node
      flags - The flags
      init - The initial expression
      test - The test expression
      modify - The modify expression
  • Method Details

    • accept

      public Node accept(LexicalContext lc, NodeVisitor<? extends LexicalContext> visitor)
      Description copied from interface: LexicalContextNode
      Accept function for the node given a lexical context. It must be prepared to replace itself if present in the lexical context
      Parameters:
      lc - lexical context
      visitor - node visitor
      Returns:
      new node or same node depending on state change
    • accept

      public <R> R accept(LexicalContext lc, TranslatorNodeVisitor<? extends LexicalContext, R> visitor)
    • toString

      public void toString(StringBuilder sb, boolean printTypes)
      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
      printTypes - print type?
    • hasGoto

      public boolean hasGoto()
      Description copied from class: Statement
      Check if this statement repositions control flow with goto like semantics, for example BreakNode or a ForNode with no test
      Overrides:
      hasGoto in class Statement
      Returns:
      true if statement has goto semantics
    • mustEnter

      public boolean mustEnter()
      Description copied from class: LoopNode
      Conservative check: does this loop have to be entered?
      Specified by:
      mustEnter in class LoopNode
      Returns:
      true if body will execute at least once
    • getInit

      public Expression getInit()
      Get the initialization expression for this for loop
      Returns:
      the initialization expression
    • setInit

      public ForNode setInit(LexicalContext lc, Expression init)
      Reset the initialization expression for this for loop
      Parameters:
      lc - lexical context
      init - new initialization expression
      Returns:
      new for node if changed or existing if not
    • isForIn

      public boolean isForIn()
      Is this a for in construct rather than a standard init;condition;modification one
      Returns:
      true if this is a for in construct
    • isForEach

      public boolean isForEach()
      Is this a (non-standard) for each construct, known from e.g. Rhino.
      Returns:
      true if this is a for each construct
    • isForOf

      public boolean isForOf()
      Is this an ECMAScript 6 for of construct.
      Returns:
      true if this is a for of construct
    • isForAwaitOf

      public boolean isForAwaitOf()
      Is this an ECMAScript 8 for-await-of construct.
      Returns:
      true if this is a for-await-of construct
    • isForInOrOf

      public boolean isForInOrOf()
      Is this a for-in or for-of statement?
      Returns:
      true if this is a for-in or for-of loop
    • getIterator

      public Symbol getIterator()
      If this is a for in or for each construct, there is an iterator symbol
      Returns:
      the symbol for the iterator to be used, or null if none exists
    • setIterator

      public void setIterator(Symbol iterator)
      Assign an iterator symbol to this ForNode. Used for for in and for each constructs
      Parameters:
      iterator - the iterator symbol
    • getModify

      public JoinPredecessorExpression getModify()
      Get the modification expression for this ForNode
      Returns:
      the modification expression
    • setModify

      public ForNode setModify(LexicalContext lc, JoinPredecessorExpression modify)
      Reset the modification expression for this ForNode
      Parameters:
      lc - lexical context
      modify - new modification expression
      Returns:
      new for node if changed or existing if not
    • setTest

      public ForNode setTest(LexicalContext lc, JoinPredecessorExpression test)
      Description copied from class: LoopNode
      Set the test for this for node
      Specified by:
      setTest in class LoopNode
      Parameters:
      lc - lexical context
      test - new test
      Returns:
      same or new node depending on if test was changed
    • getBody

      public Block getBody()
      Description copied from class: LoopNode
      Get the body for this for node
      Specified by:
      getBody in class LoopNode
      Returns:
      the body
    • setBody

      public ForNode setBody(LexicalContext lc, Block body)
      Specified by:
      setBody in class LoopNode
      Parameters:
      lc - lexical context
      body - new body
      Returns:
      new for node if changed or existing if not
    • setControlFlowEscapes

      public ForNode setControlFlowEscapes(LexicalContext lc, boolean controlFlowEscapes)
      Description copied from class: LoopNode
      Set the control flow escapes flag for this node.
      Specified by:
      setControlFlowEscapes in class LoopNode
      Parameters:
      lc - lexical context
      controlFlowEscapes - control flow escapes value
      Returns:
      new loop node if changed otherwise the same
    • hasPerIterationScope

      public boolean hasPerIterationScope()
      Description copied from class: LoopNode
      Does this loop have a LET declaration and hence require a per-iteration scope?
      Specified by:
      hasPerIterationScope in class LoopNode
      Returns:
      true if a per-iteration scope is required.
    • isBreakableWithoutLabel

      public boolean isBreakableWithoutLabel()
      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 final 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 final <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