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.ObjectThis 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 theCompilerServiceworking 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 SummaryConstructors Constructor Description ExpressionCompiler()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static voidallocateStatic(CompilerService compiler, java.lang.Object value)Generate code to allocate static field in widget and to push field on stackprotected voidcompileItemFromInt(CompilerService compiler, Expression expression)Helper method to implement compileFromItem when the class implements compileToPrimitive returning an integerabstract voidcompileToBoolean(CompilerService compiler, Expression expression)Generate bytecode to evaluate the expression as a boolean Precondition: none.abstract voidcompileToItem(CompilerService compiler, Expression expression)Generate bytecode to evaluate the expression as an Item Precondition: none.abstract voidcompileToIterator(CompilerService compiler, Expression expression)Generate bytecode to evaluate the expression as aSequenceIteratorPrecondition: none.voidcompileToPrimitive(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 voidcompileToPush(CompilerService compiler, Expression expression)Generate bytecode to evaluate the expression in push mode Precondition: none.voidgenerateMethod(CompilerService compiler, Expression expression, org.objectweb.asm.ClassVisitor cv)static voidhandleEmptyStringResult(OnEmpty onEmpty, Generator ga, GeneratedMethodInfo methodInfo, LabelInfo exit)static voidprintStackTop(CompilerService compiler)Print the top entry on the bytecode value stack, for diagnostic purposesstatic voidverify(org.objectweb.asm.ClassWriter cw, java.lang.String objectName, boolean debug)Verify the generated bytecode, for diagnostic purposesstatic voidvisitAnnotation(CompilerService compiler, java.lang.String message)Generate annotations in the bytecode, for diagnostic purposesstatic voidvisitLineNumber(CompilerService compiler, Generator ga, Expression expr)Generate line number of expression in byte-code
 
- 
- 
- 
Method Detail- 
compileToItempublic 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 service
- expression- the expression to be compiled
- Throws:
- CannotCompileException- if the expression cannot be compiled to bytecode
 
 - 
compileToIteratorpublic abstract void compileToIterator(CompilerService compiler, Expression expression) throws CannotCompileException Generate bytecode to evaluate the expression as aSequenceIteratorPrecondition: none. Postcondition: at execution time, the stack contains a SequenceIterator representing the result of the expression- Parameters:
- compiler- the compiler service
- expression- the expression to be compiled
- Throws:
- CannotCompileException- if the expression cannot be compiled to bytecode
 
 - 
compileToBooleanpublic 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 service
- expression- the expression to be compiled
- Throws:
- CannotCompileException- if the expression cannot be compiled to bytecode
 
 - 
compileToPrimitivepublic 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 service
- expression- the expression to be compiled
- requiredClass- 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
- Throws:
- CannotCompileException- if the expression cannot be compiled to bytecode
 
 - 
handleEmptyStringResultpublic static void handleEmptyStringResult(OnEmpty onEmpty, Generator ga, GeneratedMethodInfo methodInfo, LabelInfo exit) 
 - 
compileToPushpublic 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 service
- expression- the expression to be compiled
- Throws:
- CannotCompileException- if the expression cannot be compiled to bytecode
 
 - 
compileItemFromIntprotected 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 service
- expression- the expression to be compiled
- Throws:
- CannotCompileException- if the expression cannot be compiled to bytecode
 
 - 
visitAnnotationpublic static void visitAnnotation(CompilerService compiler, java.lang.String message) Generate annotations in the bytecode, for diagnostic purposes- Parameters:
- compiler- the compiler service
- message- the message to be inserted in the bytecode
 
 - 
printStackToppublic 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
 
 - 
allocateStaticpublic 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 service
- value- the Object of the field
 
 - 
verifypublic static void verify(org.objectweb.asm.ClassWriter cw, java.lang.String objectName, boolean debug)Verify the generated bytecode, for diagnostic purposes- Parameters:
- cw- the ClassWriter
- objectName-
- debug- true if bytecode tracing is required
 
 - 
visitLineNumberpublic static void visitLineNumber(CompilerService compiler, Generator ga, Expression expr) Generate line number of expression in byte-code- Parameters:
- compiler- the compiler service
- ga- the generator adapter
- expr- Expression
 
 - 
generateMethodpublic void generateMethod(CompilerService compiler, Expression expression, org.objectweb.asm.ClassVisitor cv) 
 
- 
 
-