com.saxonica.codegen
Class ExpressionCompiler

java.lang.Object
  extended by com.saxonica.codegen.ExpressionCompiler
Direct Known Subclasses:
ChooseCompiler, ContextItemCompiler, ErrorCompiler, ErrorExpressionCompiler, IntegratedFunctionCallCompiler, LiteralCompiler, ParentNodeExpressionCompiler, PushExpressionCompiler, RootExpressionCompiler, SequenceExpressionCompiler, SingletonExpressionCompiler, ToBooleanCompiler, TraceCompiler

public abstract class ExpressionCompiler
extends Object

This abstract class represents the compiler (that is, Java code generator) for a particular kind of expression on the expression tree. The expression compiler is called by the CompilerService working its way down the expression tree in a top down fashion: there is a one-to-one correspondence between the classes implementing the expression on the expression tree and the compiler object used to generate Java code fragments. Various methods are supplied to compile expressions; exactly one of them is called, depending on the context in which the expression appears.


Constructor Summary
ExpressionCompiler()
           
 
Method Summary
 void compileAsLoop(CompilerService compiler, Expression expression, LoopAction action)
          Compile an XPath expression in the form of a loop.
abstract  void compilePush(CompilerService compiler, Expression expression)
          Generate Java code to execute the expression in push mode, that is, code to write events to the current output Receiver
 String compileToCharSequence(CompilerService compiler, Expression expression)
          Generate Java code to evaluate the expression as a CharSequence
abstract  String compileToEffectiveBooleanValue(CompilerService compiler, Expression expression, ReturnAction options)
          Generate Java code to evaluate the effective boolean value of the expression
abstract  String compileToItem(CompilerService compiler, Expression expression)
          Generate Java code to evaluate the expression as an Item
abstract  String compileToIterator(CompilerService compiler, Expression expression)
          Generate Java code to evaluate the expression as a SequenceIterator
 String compileToValueRepresentation(CompilerService compiler, Expression expression)
          Generate Java code to evaluate the expression as a ValueRepresentation
 Configuration getConfiguration()
          Get the Saxon Configuration
static ExpressionCompiler makeExpressionCompiler(Expression exp, Configuration config)
          Make an expression compiler for a particular expression.
 void setConfiguration(Configuration config)
          Set the Saxon Configuration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionCompiler

public ExpressionCompiler()
Method Detail

setConfiguration

public void setConfiguration(Configuration config)
Set the Saxon Configuration


getConfiguration

public Configuration getConfiguration()
Get the Saxon Configuration


compilePush

public abstract void compilePush(CompilerService compiler,
                                 Expression expression)
Generate Java code to execute the expression in push mode, that is, code to write events to the current output Receiver

Parameters:
compiler - the compiler service
expression - the expression to be compiled

compileToItem

public abstract String compileToItem(CompilerService compiler,
                                     Expression expression)
Generate Java code to evaluate the expression as an Item

Parameters:
compiler - the compiler service
expression - the expression to be compiled
Returns:
a simple Java expression (usually the name of a variable that has been declared) which will be of class Item, and which will hold the value of the expression at run-time (or hold null, representing an empty sequence).

compileToIterator

public abstract String compileToIterator(CompilerService compiler,
                                         Expression expression)
Generate Java code to evaluate the expression as a SequenceIterator

Parameters:
compiler - the compiler service
expression - the XPath expression to be compiled
Returns:
a simple Java expression (usually the name of a variable that has been declared) which will be of class SequenceIterator, and which at run-time will hold an iterator over the the value of the XPath expression

compileToEffectiveBooleanValue

public abstract String compileToEffectiveBooleanValue(CompilerService compiler,
                                                      Expression expression,
                                                      ReturnAction options)
Generate Java code to evaluate the effective boolean value of the expression

Parameters:
compiler - the compiler service
expression - the XPath expression to be compiled
options - indicates how the boolean result is to be returned
Returns:
the result depends on the supplied value of the options argument. If options is a JavaDeclaration, the code must declare a Java variable and return the name of this variable. If options is a JavaAssignment, the code must assign the value to an existing Java variable. If options is a Return, the code must generate a return statement that returns the value of the boolean (in which case the result of this method is null).

compileToCharSequence

public String compileToCharSequence(CompilerService compiler,
                                    Expression expression)
Generate Java code to evaluate the expression as a CharSequence

Parameters:
compiler - the compiler service
expression - the XPath expression to be compiled
Returns:
a simple Java expression (usually the name of a variable that has been declared, or a string literal) which will be of class CharSequence, and which will hold the string value of the XPath expression at run-time

compileToValueRepresentation

public String compileToValueRepresentation(CompilerService compiler,
                                           Expression expression)
Generate Java code to evaluate the expression as a ValueRepresentation

Parameters:
compiler - the compiler service
expression - the expression to be compiled
Returns:
a simple Java expression (usually the name of a variable that has been declared) which will be of class ValueRepresentation, and which at run-time will hold the value of the expression

compileAsLoop

public void compileAsLoop(CompilerService compiler,
                          Expression expression,
                          LoopAction action)
Compile an XPath expression in the form of a loop. This generates Java code that loops over the items in the result of the expression; the body of the loop is constructed by a callback to the supplied LoopAction (which will handle nested expressions)

Parameters:
compiler - the CompilerService
expression - the XPath expression to be compiled
action - the action to be taken to compile code that processes each item in the sequence returned by the XPath expression

makeExpressionCompiler

public static ExpressionCompiler makeExpressionCompiler(Expression exp,
                                                        Configuration config)
Make an expression compiler for a particular expression.

This would normally be a method on the class Expression; the only reason it isn't is because this code is specific to commercial editions of Saxon.

Parameters:
exp - the expression to be compiled
config - the Saxon Configuration
Returns:
the compiler for this kind of expression


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