Class StaticTypesStatementWriter

java.lang.Object
org.codehaus.groovy.classgen.asm.StatementWriter
org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter

public class StaticTypesStatementWriter extends StatementWriter
A class to write out the optimized statements.
  • Constructor Details

    • StaticTypesStatementWriter

      public StaticTypesStatementWriter(StaticTypesWriterController controller)
      Creates a statement writer that favors statically typed loop and block generation.
  • Method Details

    • writeBlockStatement

      public void writeBlockStatement(BlockStatement statement)
      Generates bytecode for a block statement by visiting each contained statement. Pushes the block's variable scope, emits the statements, and pops afterward. Named labels on the block create a breakable region so that break label within the block jumps to the end of it.
      Overrides:
      writeBlockStatement in class StatementWriter
      Parameters:
      statement - the block statement to compile
    • writeSwitch

      public void writeSwitch(SwitchStatement statement)
      Emits a jump table when the selector and labels are constants of a type javac would switch on, matching what a statically compiled switch expression already gets (GROOVY-12405). Anything else, including repeated labels, falls back to the sequential isCase chain.
      Overrides:
      writeSwitch in class StatementWriter
      Parameters:
      statement - the switch statement to compile
    • writeIsCaseComparison

      protected void writeIsCaseComparison(CaseStatement caseStatement, int selectorIndex, ClassNode selectorType)
      Emits the isCase call the type checker selected, so a label in statement position resolves the same method it would in a switch expression (GROOVY-12407). Arms with no selected target, including case null and anything under TypeCheckingMode.SKIP, keep the dynamic comparison.
      Overrides:
      writeIsCaseComparison in class StatementWriter
      Parameters:
      caseStatement - the arm whose label is being tested
      selectorIndex - local variable slot holding the switch selector
      selectorType - type of that slot
    • writeForInLoop

      protected void writeForInLoop(ForStatement loop)
      Generates bytecode for a for-in loop by calling iterator() on the collection expression and delegating loop control to StatementWriter.writeForInLoopControlAndBlock(org.codehaus.groovy.ast.stmt.ForStatement).
      Overrides:
      writeForInLoop in class StatementWriter
      Parameters:
      loop - the for-in statement to compile