public class If extends Expression
A expression to perform a boolean test and return an expression depending on whether the test is true or false;
  • Field Details

    • test

      public final BooleanExpr test
      The boolean test to perform
    • trueExpr

      public final Expression trueExpr
      The expression to return if the test is true
    • falseExpr

      public final Expression falseExpr
      The expression to return if the test is false. This may be null
    • hasFalse

      public final boolean hasFalse
      True if this expression has a falseExpr
    • testSequence

      public List<BooleanExpr> testSequence
      The sequence of comparisons executed by this test (this is computed when the Java byte code is generated
    • trueResult

      public Result trueResult
      A placeholder used for generation to mark when the true expression is executed
    • falseResult

      public Result falseResult
      A placeholder used for generation to mark when the false expression is executed
  • Constructor Details

    • If

      public If(BooleanExpr test, Expression trueExpr, Expression falseExpr)
      Create an if expression
      Parameters:
      test - The test to perform
      trueExpr - The expression to return if the test is true
      falseExpr - The expression to return if the test is false
    • If

      public If(BooleanExpr test, Expression trueExpr, Expression falseExpr, String filename, int lineNumber)
      Create an if expression
      Parameters:
      test - The test to perform
      trueExpr - The expression to return if the test is true
      falseExpr - The expression to return if the test is false
      filename - The source filename this expression is associated with
      lineNumber - The source line number this expression is associated with
    • If

      public If(BooleanExpr test, Expression trueExpr)
      Create an if expression
      Parameters:
      test - The test to perform
      trueExpr - The expression to return if the test is true
    • If

      public If(BooleanExpr test, Expression trueExpr, String filename, int lineNumber)
      Create an if expression
      Parameters:
      test - The test to perform
      trueExpr - The expression to return if the test is true
      filename - The source filename this expression is associated with
      lineNumber - The source line number this expression is associated with
  • Method Details

    • getType

      public Type getType()
      Description copied from class: Expression
      Get the type returned by this expression
      Specified by:
      getType in class Expression
      Returns:
      The type of this expression
    • reset

      public void reset()
      Description copied from class: Expression
      Resets any labels in expressions so that the method can be regenerated
      Overrides:
      reset in class Expression
    • findCaptured

      public void findCaptured(Environment env)
      Description copied from class: Expression
      Search for local variables that would be captured by a lambda. Each expression has its own implementation of this, because each subexpression must be searched.
      Specified by:
      findCaptured in class Expression
      Parameters:
      env - The environment chain to search
    • convertToFullTailCalls

      public Expression convertToFullTailCalls(boolean inTailPosition)
      Description copied from class: Expression
      Converts this expression to one that is compatible with full tail call optimization
      Specified by:
      convertToFullTailCalls in class Expression
      Parameters:
      inTailPosition - True if this expression is called from the tail position
      Returns:
      A version of this expression whose types are compatible with full tail call optimization
    • generate

      public void generate(ClassGenerator generator, Environment env, boolean inTailPosition)
      Description copied from class: Expression
      Generate the bytecode for this expression
      Specified by:
      generate in class Expression
      Parameters:
      generator - The generator for generating instructions and additional declarations
      env - The environment containing the local variables currently visible to this expression
      inTailPosition - True if this expression is being generated from the tail position of the method