public abstract class ExpressionCompiler
extends java.lang.Object
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 and Description |
---|
ExpressionCompiler() |
Modifier and Type | Method and Description |
---|---|
static void |
allocateStatic(CompilerService compiler,
java.lang.Object value)
Generate code to allocate static field in widget and to push field on stack
|
protected void |
compileItemFromInt(CompilerService compiler,
Expression expression)
Helper method to implement compileFromItem when the class implements compileToPrimitive returning an integer
|
abstract void |
compileToBoolean(CompilerService compiler,
Expression expression)
Generate bytecode to evaluate the expression as a boolean
Precondition: none.
|
abstract void |
compileToItem(CompilerService compiler,
Expression expression)
Generate bytecode to evaluate the expression as an Item
Precondition: none.
|
abstract void |
compileToIterator(CompilerService compiler,
Expression expression)
Generate bytecode to evaluate the expression as a
SequenceIterator
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 |
compileToPrimitive(CompilerService compiler,
Expression expression,
java.lang.Class requiredClass,
OnEmpty onEmpty)
Generate bytecode to evaluate the expression leaving a plain Java value on the stack.
|
abstract void |
compileToPush(CompilerService compiler,
Expression expression)
Generate bytecode to evaluate the expression in push mode
Precondition: none.
|
void |
generateMethod(CompilerService compiler,
Expression expression,
org.objectweb.asm.ClassVisitor cv) |
static void |
handleEmptyStringResult(OnEmpty onEmpty,
Generator ga,
GeneratedMethodInfo methodInfo,
LabelInfo exit) |
static void |
printStackTop(CompilerService compiler)
Print the top entry on the bytecode value stack, for diagnostic purposes
|
void |
unboxItem(Generator ga,
java.lang.Class requiredClass)
Generate code to extract a primitive value from an Item (actually an Atomic value)
given knowledge of the primitive type of the item
|
static void |
verify(org.objectweb.asm.ClassWriter cw,
java.lang.String objectName,
boolean debug)
Verify the generated bytecode, for diagnostic purposes
|
static void |
visitAnnotation(CompilerService compiler,
java.lang.String message)
Generate annotations in the bytecode, for diagnostic purposes
|
static void |
visitLineNumber(CompilerService compiler,
Generator ga,
Expression expr)
Generate line number of expression in byte-code
|
public abstract void compileToItem(CompilerService compiler, Expression expression) throws CannotCompileException
compiler
- the compiler serviceexpression
- the expression to be compiledCannotCompileException
public abstract void compileToIterator(CompilerService compiler, Expression expression) throws CannotCompileException
SequenceIterator
Precondition: none.
Postcondition: at execution time, the stack contains a SequenceIterator representing the result of the expressioncompiler
- the compiler serviceexpression
- the expression to be compiledCannotCompileException
public abstract void compileToBoolean(CompilerService compiler, Expression expression) throws CannotCompileException
compiler
- the compiler serviceexpression
- the expression to be compiledCannotCompileException
public void compileToPrimitive(CompilerService compiler, Expression expression, java.lang.Class requiredClass, OnEmpty onEmpty) throws CannotCompileException
compiler
- the compiler serviceexpression
- the expression to be compiledrequiredClass
- the class of the Java value that is to be left on the stack if the generated code
exits normally. This must be one of Integer.TYPE, Double.TYPE, Float.TYPE, BigDecimal.class, CharSequence.class.onEmpty
- defines the action to be taken if the expression evaluates to the empty sequence.
May be null if the expression is known statically not to evaluate to an empty sequence. If the return
class is a primitive type (double, float, etc) this must be an instance of OnEmpty.UnwindAndJump
CannotCompileException
public static void handleEmptyStringResult(OnEmpty onEmpty, Generator ga, GeneratedMethodInfo methodInfo, LabelInfo exit)
public abstract void compileToPush(CompilerService compiler, Expression expression) throws CannotCompileException
compiler
- the compiler serviceexpression
- the expression to be compiledCannotCompileException
public void compileToLoop(CompilerService compiler, Expression expression, LoopBodyGenerator loopBody) throws CannotCompileException
Note that the compileToLoop() method must not be used where there is a need to maintain the value of position() or size(), or equivalents such as updating range variables. It is therefore generally used only for compiling aggregate functions such as count() and sum().
This has proved something of an obstacle. Attempts to compile path expressions as nested loops have failed in the case where there is a dependency on position() or last(): the current dependency mechanism doesn't always allow these cases to be detected (it only tells us when an expression uses position() or last(), not when it needs to maintain position() and last()). Hence this mode of compilation is not widely implemented (other than by the default implementation) and is currently used only when compiling sum() and count().
compiler
- the compiler serviceexpression
- the expression to be compiledloopBody
- 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.CannotCompileException
public void unboxItem(Generator ga, java.lang.Class requiredClass)
ga
- the generator adapterrequiredClass
- the type of value requiredprotected final void compileItemFromInt(CompilerService compiler, Expression expression) throws CannotCompileException
compiler
- expression
- CannotCompileException
public static void visitAnnotation(CompilerService compiler, java.lang.String message)
compiler
- message
- the message to be inserted in the bytecodepublic static void printStackTop(CompilerService compiler)
compiler
- the bytecode compiler service to usepublic static void allocateStatic(CompilerService compiler, java.lang.Object value)
compiler
- the CompilerServicevalue
- the Object of the fieldpublic static void verify(org.objectweb.asm.ClassWriter cw, java.lang.String objectName, boolean debug)
cw
- the ClassWriterobjectName
- public static void visitLineNumber(CompilerService compiler, Generator ga, Expression expr)
compiler
- ga
- the generator adapterexpr
- Expressionpublic void generateMethod(CompilerService compiler, Expression expression, org.objectweb.asm.ClassVisitor cv)
Copyright (c) 2004-2018 Saxonica Limited. All rights reserved.