Class SwitchNode

All Implemented Interfaces:
BreakableNode, LexicalContextNode, Terminal, Cloneable

public final class SwitchNode extends Statement
IR representation of a SWITCH statement.
  • Constructor Details

    • SwitchNode

      public SwitchNode(int lineNumber, long token, int finish, Expression expression, List<CaseNode> cases, int defaultCaseIndex)
      Constructor
      Parameters:
      lineNumber - lineNumber
      token - token
      finish - finish
      expression - switch expression
      cases - cases
      defaultCaseIndex - the default case index; -1 if none, otherwise has to be present in cases list
  • Method Details

    • isTerminal

      public boolean isTerminal()
      Description copied from class: Statement
      Is this a terminal statement, i.e. does it end control flow like a throw or return?
      Specified by:
      isTerminal in interface Terminal
      Overrides:
      isTerminal in class Statement
      Returns:
      true if this node statement is terminal
    • 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 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?
    • getDefaultCase

      public CaseNode getDefaultCase()
      Return the case node that is default case
      Returns:
      default case or null if none
    • getCases

      public List<CaseNode> getCases()
      Get the cases in this switch
      Returns:
      a list of case nodes
    • getExpression

      public Expression getExpression()
      Return the expression to switch on
      Returns:
      switch expression
    • setExpression

      public SwitchNode setExpression(LexicalContext lc, Expression expression)
      Set or reset the expression to switch on
      Parameters:
      lc - lexical context
      expression - switch expression
      Returns:
      new switch node or same if no state was changed
    • getTag

      public Symbol getTag()
      Get the tag symbol for this switch. The tag symbol is where the switch expression result is stored
      Returns:
      tag symbol
    • setTag

      public void setTag(Symbol tag)
      Set the tag symbol for this switch. The tag symbol is where the switch expression result is stored
      Parameters:
      tag - a symbol
    • hasDefaultCase

      public boolean hasDefaultCase()
      Returns:
      true if this switch has a default case.
    • isCompletionValueNeverEmpty

      public boolean isCompletionValueNeverEmpty()
      Overrides:
      isCompletionValueNeverEmpty in class Statement
      Returns:
      true if the completion value of this statement is never the value empty
    • 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