Package: org.codehaus.groovy.classgen.asm

## [Java] Class OptimizingStatementWriter

- org.codehaus.groovy.classgen.asm.OptimizingStatementWriter

-     public class OptimizingStatementWriter
      extends StatementWriter

  A StatementWriter that emits optimized fast-path bytecode for statements involving integer (and other primitive) operations. When type guards confirm that the operands have their original (unboxed) types, the fast path is taken; otherwise execution falls back to the standard dynamic-dispatch slow path.

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `OptimizingStatementWriter.ClassNodeSkip` | Marker metadata used to skip optimization analysis for a class node.
    `static class` | `OptimizingStatementWriter.StatementMeta` | Stores optimization metadata collected for a statement or expression.

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class StatementWriter` | `controller`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `OptimizingStatementWriter(WriterController controller)` Creates an optimizing statement writer backed by the given controller.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static void` | `setNodeMeta(TypeChooser chooser, ClassNode classNode)` Populates optimization metadata for the supplied class.
    `` | `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. * * Parameters: `block` - the block statement to compile
    `` | `public void` | `writeDoWhileLoop(DoWhileStatement statement)` * Generates bytecode for a do-while loop. * * Parameters: `statement` - the do-while statement to compile
    `` | `public void` | `writeExpressionStatement(ExpressionStatement statement)` * Generates bytecode for an expression statement. * Evaluates the expression and discards any value left on the operand stack. * Marks method-call and binary expressions so that unused return values * are elided rather than boxed. * * Parameters: `statement` - the expression statement to compile
    `` | `protected void` | `writeForInLoop(ForStatement statement)` * Generates bytecode for a for-in loop by calling `iterator()` on the * collection expression and delegating loop control to * writeForInLoopControlAndBlock. * * Parameters: `statement` - the for-in statement to compile
    `` | `protected void` | `writeForLoopWithClosureList(ForStatement statement)` * Generates bytecode for a C-style `for(init; cond; incr)` loop. * The collection expression is a ClosureListExpression whose middle * element is the boolean condition, lower elements are initializers, and * upper elements are incrementors. * * Parameters: `statement` - the for statement with a ClosureListExpression collection
    `` | `public void` | `writeIfElse(IfStatement statement)` * Generates bytecode for an if/else statement. * * Parameters: `statement` - the if statement to compile
    `` | `protected void` | `writeIteratorHasNext(org.objectweb.asm.MethodVisitor mv)` * Emits the Iterator.hasNext call via the given visitor. * Overrideable so subclasses can substitute a specialized or inlined variant. * * Parameters: `mv` - the method visitor to write to
    `` | `protected void` | `writeIteratorNext(org.objectweb.asm.MethodVisitor mv)` * Emits the Iterator.next call via the given visitor. * Overrideable so subclasses can substitute a specialized or inlined variant. * * Parameters: `mv` - the method visitor to write to
    `` | `public void` | `writeReturn(ReturnStatement statement)` * Generates bytecode for a return statement. * For void methods emits `RETURN` after applying any finally blocks. * For value-returning methods evaluates the expression, casts it to the * declared return type, and emits the appropriate typed return instruction. * * Parameters: `statement` - the return statement to compile
    `` | `public void` | `writeWhileLoop(WhileStatement statement)` * Generates bytecode for a while loop. * * Parameters: `statement` - the while statement to compile

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class StatementWriter` | `defineLoopIndexVariable, incrementForLoopIndexVariable, storeForLoopVariable, writeAssert, writeBlockStatement, writeBreak, writeContinue, writeDoWhileLoop, writeExpressionStatement, writeForInLoop, writeForInLoopControlAndBlock, writeForLoopWithClosureList, writeForStatement, writeIfElse, writeIteratorHasNext, writeIteratorNext, writeLoopBackEdge, writeReturn, writeStatementLabel, writeSwitch, writeSynchronized, writeThrow, writeTryCatchFinally, writeWhileLoop`

- - ### Constructor Detail

    - #### public OptimizingStatementWriter(WriterController controller)

      Creates an optimizing statement writer backed by the given controller.

      Parameters:
        `controller` - the writer controller for the current compilation

  - ### Method Detail

    - #### public static void setNodeMeta(TypeChooser chooser, ClassNode classNode)

      Populates optimization metadata for the supplied class.

      Parameters:
        `chooser` - the type chooser used during analysis
        `classNode` - the class to annotate

    - #### 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. * *

      Parameters:
        `block` - the block statement to compile

    - #### public void writeDoWhileLoop(DoWhileStatement statement)

      * Generates bytecode for a do-while loop. * *

      Parameters:
        `statement` - the do-while statement to compile

    - #### public void writeExpressionStatement(ExpressionStatement statement)

      * Generates bytecode for an expression statement. * Evaluates the expression and discards any value left on the operand stack. * Marks method-call and binary expressions so that unused return values * are elided rather than boxed. * *

      Parameters:
        `statement` - the expression statement to compile

    - #### protected void writeForInLoop(ForStatement statement)

      * Generates bytecode for a for-in loop by calling `iterator()` on the * collection expression and delegating loop control to * writeForInLoopControlAndBlock. * *

      Parameters:
        `statement` - the for-in statement to compile

    - #### protected void writeForLoopWithClosureList(ForStatement statement)

      * Generates bytecode for a C-style `for(init; cond; incr)` loop. * The collection expression is a ClosureListExpression whose middle * element is the boolean condition, lower elements are initializers, and * upper elements are incrementors. * *

      Parameters:
        `statement` - the for statement with a ClosureListExpression collection

    - #### public void writeIfElse(IfStatement statement)

      * Generates bytecode for an if/else statement. * *

      Parameters:
        `statement` - the if statement to compile

    - #### protected void writeIteratorHasNext(org.objectweb.asm.MethodVisitor mv)

      * Emits the Iterator.hasNext call via the given visitor. * Overrideable so subclasses can substitute a specialized or inlined variant. * *

      Parameters:
        `mv` - the method visitor to write to

    - #### protected void writeIteratorNext(org.objectweb.asm.MethodVisitor mv)

      * Emits the Iterator.next call via the given visitor. * Overrideable so subclasses can substitute a specialized or inlined variant. * *

      Parameters:
        `mv` - the method visitor to write to

    - #### public void writeReturn(ReturnStatement statement)

      * Generates bytecode for a return statement. * For void methods emits `RETURN` after applying any finally blocks. * For value-returning methods evaluates the expression, casts it to the * declared return type, and emits the appropriate typed return instruction. * *

      Parameters:
        `statement` - the return statement to compile

    - #### public void writeWhileLoop(WhileStatement statement)

      * Generates bytecode for a while loop. * *

      Parameters:
        `statement` - the while statement to compile