Class TernaryNode

All Implemented Interfaces:
Cloneable

public final class TernaryNode extends Expression
TernaryNode represent the ternary operator ?:. Note that for control-flow calculation reasons its branch expressions (but not its test expression) are always wrapped in instances of JoinPredecessorExpression.
  • Constructor Details

    • TernaryNode

      public TernaryNode(long token, Expression test, JoinPredecessorExpression trueExpr, JoinPredecessorExpression falseExpr)
      Constructor
      Parameters:
      token - token
      test - test expression
      trueExpr - expression evaluated when test evaluates to true
      falseExpr - expression evaluated when test evaluates to true
  • Method Details

    • accept

      public Node accept(NodeVisitor<? extends LexicalContext> visitor)
      Description copied from class: Node
      Provides a means to navigate the IR.
      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 class Node
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • 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?
    • getTest

      public Expression getTest()
      Get the test expression for this ternary expression, i.e. "x" in x ? y : z
      Returns:
      the test expression
    • getTrueExpression

      public JoinPredecessorExpression getTrueExpression()
      Get the true expression for this ternary expression, i.e. "y" in x ? y : z
      Returns:
      the true expression
    • getFalseExpression

      public JoinPredecessorExpression getFalseExpression()
      Get the false expression for this ternary expression, i.e. "z" in x ? y : z
      Returns:
      the false expression
    • setTest

      public TernaryNode setTest(Expression test)
      Set the test expression for this node
      Parameters:
      test - new test expression
      Returns:
      a node equivalent to this one except for the requested change.
    • setTrueExpression

      public TernaryNode setTrueExpression(JoinPredecessorExpression trueExpr)
      Set the true expression for this node
      Parameters:
      trueExpr - new true expression
      Returns:
      a node equivalent to this one except for the requested change.
    • setFalseExpression

      public TernaryNode setFalseExpression(JoinPredecessorExpression falseExpr)
      Set the false expression for this node
      Parameters:
      falseExpr - new false expression
      Returns:
      a node equivalent to this one except for the requested change.