com.saxonica.bytecode

## Class ForExpressionCompiler

- java.lang.Object
- - com.saxonica.bytecode.ExpressionCompiler
  - - com.saxonica.bytecode.ToIteratorCompiler
    - - com.saxonica.bytecode.ForExpressionCompiler

-     public class ForExpressionCompiler
      extends ToIteratorCompiler

  Generate bytecode for a call to the ForExpression()

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ForExpressionCompiler()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `compileToIterator(CompilerService compiler, Expression expression)` Generate bytecode to evaluate the ForExpression as an iterator Precondition: none.
    `void` | `compileToLoop(CompilerService compiler, Expression expression, LoopBodyGenerator loopBody)` The compileToLoop method compiles this expression in such a way that the code generated by the supplied loopBody argument will be executed once for each item in the result of this expression.
    `void` | `compileToPush(CompilerService compiler, Expression expression)` Generate bytecode to evaluate the ForExpression in push mode Precondition: none.
    `static Class` | `generateSequenceMappingAction(CompilerService compiler, ForExpression expression, Expression action, int slotNumber)` Generate a mapping function with a map() method that returns an iterator over the results of one iteration of the loop

    - ### Methods inherited from class com.saxonica.bytecode.ToIteratorCompiler

      `compileToBoolean, compileToItem`

    - ### Methods inherited from class com.saxonica.bytecode.ExpressionCompiler

      `allocateStatic, compileItemFromInt, compileItemFromString, compileToPrimitive, generateMethod, handleEmptyStringResult, throwXPathException, throwXPathException, unboxItem, verify, visitAnnotation, visitLineNumber`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ForExpressionCompiler

          public ForExpressionCompiler()

  - ### Method Detail

    - #### compileToPush

          public void compileToPush(CompilerService compiler,
                           Expression expression)
                             throws CannotCompileException

      Generate bytecode to evaluate the ForExpression in push mode Precondition: none. Postcondition: the stack is empty
      Overrides:
        `compileToPush` in class `ToIteratorCompiler`
      Parameters:
        `compiler` - the compiler service
        `expression` - the expression to be compiled
      Throws:
        `CannotCompileException`

    - #### compileToLoop

          public void compileToLoop(CompilerService compiler,
                           Expression expression,
                           LoopBodyGenerator loopBody)
                             throws CannotCompileException

      The compileToLoop method compiles this expression in such a way that the code generated by the supplied loopBody argument will be executed once for each item in the result of this expression. The code generated by the loopBody expects to find this item on the top of the bytecode stack.
      Overrides:
        `compileToLoop` in class `ExpressionCompiler`
      Parameters:
        `compiler` - the compiler service
        `expression` - the expression to be compiled
        `loopBody` - a generator which produces code to be executed once for every item in the result of this expression, with that item being on the top of the bytecode stack.
      Throws:
        `CannotCompileException`

    - #### compileToIterator

          public void compileToIterator(CompilerService compiler,
                               Expression expression)
                                 throws CannotCompileException

      Generate bytecode to evaluate the ForExpression as an iterator Precondition: none. Postcondition: the stack contains an iterator representing the result of the expression
      Specified by:
        `compileToIterator` in class `ExpressionCompiler`
      Parameters:
        `compiler` - the compiler service
        `expression` - the expression to be compiled
      Throws:
        `CannotCompileException`

    - #### generateSequenceMappingAction

          public static Class generateSequenceMappingAction(CompilerService compiler,
                                            ForExpression expression,
                                            Expression action,
                                            int slotNumber)
                                                     throws CannotCompileException

      Generate a mapping function with a map() method that returns an iterator over the results of one iteration of the loop
      Parameters:
        `compiler` - the CompilerService
        `expression` - the "for" expression itself
        `action` - the body of the "for" loop, which represents the expression to be compiled
      Throws:
        `CannotCompileException`

Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.