Package com.saxonica.ee.bytecode
Class ExpressionCompiler
- java.lang.Object
-
- com.saxonica.ee.bytecode.ExpressionCompiler
-
- Direct Known Subclasses:
CompiledExpressionCompiler
,ErrorExpressionCompiler
,LiteralCompiler
,ToBooleanCompiler
,ToItemCompiler
,ToIteratorCompiler
public abstract class ExpressionCompiler extends java.lang.Object
This abstract class represents the compiler (that is, Java bytecode generator) for a particular kind of expression on the expression tree. The expression compiler is called by theCompilerService
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
Constructors Constructor Description ExpressionCompiler()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static void
allocateStatic(CompilerService compiler, java.lang.Object value)
Generate code to allocate static field in widget and to push field on stackprotected void
compileItemFromInt(CompilerService compiler, Expression expression)
Helper method to implement compileFromItem when the class implements compileToPrimitive returning an integerabstract 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 aSequenceIterator
Precondition: none.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 purposesstatic void
verify(org.objectweb.asm.ClassWriter cw, java.lang.String objectName, boolean debug)
Verify the generated bytecode, for diagnostic purposesstatic void
visitAnnotation(CompilerService compiler, java.lang.String message)
Generate annotations in the bytecode, for diagnostic purposesstatic void
visitLineNumber(CompilerService compiler, Generator ga, Expression expr)
Generate line number of expression in byte-code
-
-
-
Method Detail
-
compileToItem
public abstract void compileToItem(CompilerService compiler, Expression expression) throws CannotCompileException
Generate bytecode to evaluate the expression as an Item Precondition: none. Postcondition: at execution time, the stack contains either an item (the result of the expression), or null (representing an empty sequence).- Parameters:
compiler
- the compiler serviceexpression
- the expression to be compiled- Throws:
CannotCompileException
- if the expression cannot be compiled to bytecode
-
compileToIterator
public abstract void compileToIterator(CompilerService compiler, Expression expression) throws CannotCompileException
Generate bytecode to evaluate the expression as aSequenceIterator
Precondition: none. Postcondition: at execution time, the stack contains a SequenceIterator representing the result of the expression- Parameters:
compiler
- the compiler serviceexpression
- the expression to be compiled- Throws:
CannotCompileException
- if the expression cannot be compiled to bytecode
-
compileToBoolean
public abstract void compileToBoolean(CompilerService compiler, Expression expression) throws CannotCompileException
Generate bytecode to evaluate the expression as a boolean Precondition: none. Postcondition: at execution time, the stack contains an integer (0=false, 1=true) representing the result of the expression- Parameters:
compiler
- the compiler serviceexpression
- the expression to be compiled- Throws:
CannotCompileException
- if the expression cannot be compiled to bytecode
-
compileToPrimitive
public void compileToPrimitive(CompilerService compiler, Expression expression, java.lang.Class<?> requiredClass, OnEmpty onEmpty) throws CannotCompileException
Generate bytecode to evaluate the expression leaving a plain Java value on the stack. This method must only be called if the static type of the expressionis such that the value is known to be representable by a value of the specified class; the cardinality must be either exactly-one or zero-or-one.- Parameters:
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, String.class, UnicodeString.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 ofOnEmpty.UnwindAndJump
- Throws:
CannotCompileException
- if the expression cannot be compiled to bytecode
-
handleEmptyStringResult
public static void handleEmptyStringResult(OnEmpty onEmpty, Generator ga, GeneratedMethodInfo methodInfo, LabelInfo exit)
-
compileToPush
public abstract void compileToPush(CompilerService compiler, Expression expression) throws CannotCompileException
Generate bytecode to evaluate the expression in push mode Precondition: none. Postcondition: at execution time, the stack is unchanged, and the value of the expression has been written to the current receiver- Parameters:
compiler
- the compiler serviceexpression
- the expression to be compiled- Throws:
CannotCompileException
- if the expression cannot be compiled to bytecode
-
compileItemFromInt
protected final void compileItemFromInt(CompilerService compiler, Expression expression) throws CannotCompileException
Helper method to implement compileFromItem when the class implements compileToPrimitive returning an integer- Parameters:
compiler
- the compiler serviceexpression
- the expression to be compiled- Throws:
CannotCompileException
- if the expression cannot be compiled to bytecode
-
visitAnnotation
public static void visitAnnotation(CompilerService compiler, java.lang.String message)
Generate annotations in the bytecode, for diagnostic purposes- Parameters:
compiler
- the compiler servicemessage
- the message to be inserted in the bytecode
-
printStackTop
public static void printStackTop(CompilerService compiler)
Print the top entry on the bytecode value stack, for diagnostic purposes- Parameters:
compiler
- the bytecode compiler service to use
-
allocateStatic
public static void allocateStatic(CompilerService compiler, java.lang.Object value)
Generate code to allocate static field in widget and to push field on stack- Parameters:
compiler
- the compiler servicevalue
- the Object of the field
-
verify
public static void verify(org.objectweb.asm.ClassWriter cw, java.lang.String objectName, boolean debug)
Verify the generated bytecode, for diagnostic purposes- Parameters:
cw
- the ClassWriterobjectName
- name of the object being compiled, for diagnosticsdebug
- true if bytecode tracing is required
-
visitLineNumber
public static void visitLineNumber(CompilerService compiler, Generator ga, Expression expr)
Generate line number of expression in byte-code- Parameters:
compiler
- the compiler servicega
- the generator adapterexpr
- Expression
-
generateMethod
public void generateMethod(CompilerService compiler, Expression expression, org.objectweb.asm.ClassVisitor cv)
-
-