Class IntSwitch


public class IntSwitch extends Expression
A switch expression whose cases are all integers This class maps directly to either Java's tableswitch or lookupswitch instructions, meaning that the switch items must be integers. Other switches must currently be implemented with if statements, although switches on classes and enumerations will be supported by JFuncMachine eventually. A table switch is a simple jump table that is good when the case values are roughly consecutive. A lookup switch performs a binary search on a sorted array of case values to determine which case value to execute.
  • Field Details

    • expr

      public final Expression expr
      The expression generating the value to be switched on
    • cases

      public final IntSwitchCase[] cases
      A case containing a numeric value and an expression to be executed if the switch expression equals the case value
    • defaultCase

      public final Expression defaultCase
      The expression to be executed if none of the cases match the switch value
    • gapThreshold

      public final int gapThreshold
      The maximum number of empty spaces between switch values allowed before the switch is converted to a lookup switch.
  • Constructor Details

    • IntSwitch

      public IntSwitch(Expression expr, IntSwitchCase[] cases, Expression defaultCase)
      Create a Switch expression
      Parameters:
      expr - The expression generating the value to be switched on
      cases - A case containing a numeric value and an expression to be executed if the switch expression equals the case value
      defaultCase - The expression to be executed if none of the cases match the switch value
    • IntSwitch

      public IntSwitch(Expression expr, IntSwitchCase[] cases, Expression defaultCase, String filename, int lineNumber)
      Create a Switch expression
      Parameters:
      expr - The expression generating the value to be switched on
      cases - A case containing a numeric value and an expression to be executed if the switch expression equals the case value
      defaultCase - The expression to be executed if none of the cases match the switch value
      filename - The name of the source file where this switch is defined
      lineNumber - The line number in the source file where this switch starts
    • IntSwitch

      public IntSwitch(Expression expr, IntSwitchCase[] cases, Expression defaultCase, int gapThreshold)
      Create a Switch expression
      Parameters:
      expr - The expression generating the value to be switched on
      cases - A case containing a numeric value and an expression to be executed if the switch expression equals the case value
      defaultCase - The expression to be executed if none of the cases match the switch value
      gapThreshold - The maximum number of empty spaces between switch values allowed before the switch is converted to a lookup switch.
    • IntSwitch

      public IntSwitch(Expression expr, IntSwitchCase[] cases, Expression defaultCase, int gapThreshold, String filename, int lineNumber)
      Create a Switch expression
      Parameters:
      expr - The expression generating the value to be switched on
      cases - A case containing a numeric value and an expression to be executed if the switch expression equals the case value
      defaultCase - The expression to be executed if none of the cases match the switch value
      gapThreshold - The maximum number of empty spaces between switch values allowed before the switch is converted to a lookup switch.
      filename - The name of the source file where this switch is defined
      lineNumber - The line number in the source file where this switch starts
  • 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