public class CompilerService extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CompilerService.GeneratedClassInfo |
class |
CompilerService.GeneratedExpression
sub-class GeneratedExpression - used to keep track of ExpressionCompiler classes that need to generate a method
|
static class |
CompilerService.StaticSubClasses |
static class |
CompilerService.StaticVariableInfo |
Modifier and Type | Field and Description |
---|---|
HashMap<com.saxonica.ee.bytecode.util.CompilerService.ObjectIdentityWrapper,CompilerService.StaticSubClasses> |
cClassMap |
int |
mostRecentLineNumber |
static int |
tracePoint |
Constructor and Description |
---|
CompilerService(Configuration config) |
Modifier and Type | Method and Description |
---|---|
void |
addNewMethod(ExpressionCompiler ec,
Expression e)
The methods adds the
|
CompilerService.StaticVariableInfo |
allocateStaticVariableInfo(Object value)
Create a StaticVariableInfo containing the information needed to allow a static reference
to a given object to be added as a static field in the currently-being-compiled class
|
boolean |
canCompileToLoop(Expression expr)
Ask if an expression can be compiled using the compileToLoop() method
|
void |
compileToBoolean(Expression expr)
Generate bytecode to evaluate an expression leaving a boolean on the stack.
|
CompiledExpression |
compileToByteCode(Expression expr,
String objectName,
int evaluationModes)
Compile a top-level expression to bytecode, and return the resulting expression
|
void |
compileToItem(Expression expr)
Generate bytecode to evaluate an expression leaving either an Item or null on the stack
(null indicating that the expression evaluated to an empty sequence).
|
void |
compileToIterator(Expression expr)
Generate bytecode to evaluate an expression leaving a SequenceIterator on the stack
|
void |
compileToLoop(Expression expr,
LoopBodyGenerator bodyGen) |
void |
compileToPrimitive(Expression expr,
Class requiredClass,
OnEmpty onEmpty)
Compile an expression that returns a singleton (or empty) result of type xs:double, xs:float, xs:string,
xs:untypedAtomic.
|
void |
compileToPush(Expression expr)
Generate bytecode to evaluate an expression by writing events to the current
SequenceReceiver (leaving nothing on the stack at execution time)
|
void |
compileToSequence(Expression expression)
Compile code to evaluate a variable reference, or any other expresssion,
leaving a Sequence on the stack
|
PrintWriter |
createPrintWriter(String filename) |
void |
generateDynamicError(String message,
String errorCode,
SourceLocator locator,
boolean isTypeError)
Generate code to throw an XPathException.
|
void |
generateGetContext()
Generate code to load the current XPathContext, leaving it on the top of the stack
|
void |
generateGetReceiver()
Generate code to load the current Receiver, leaving it on the top of the stack
|
void |
generateParameterizedDynamicError(MessageBuilder builder,
String errorCode,
SourceLocator locator,
boolean isTypeError)
Generate code to throw an XPath Exception.
|
Class |
getCompiledClass(Object expr) |
Configuration |
getConfiguration()
Get the Configuration used by this CompilerService
|
CompilerService.GeneratedClassInfo |
getCurrentClass() |
Generator |
getCurrentGenerator() |
GeneratedMethodInfo |
getCurrentMethod() |
Stack<GeneratedMethodInfo> |
getCurrentMethods() |
int |
getFlags()
Get the flag options used by the ClassWriter
|
int |
getUniqueNumber()
Get a unique number which is different from any other number allocated by a call on this method,
for the same CompilerService instance
|
void |
initNewMethod(Generator ga,
boolean holdReceiverAsLocal)
Initialize context information for a new method.
|
boolean |
isDebugByteCode() |
boolean |
isDisplayByteCode() |
boolean |
isInRangeForInt(Expression exp) |
boolean |
isInRangeForLong(Expression exp) |
static boolean |
isLanguagePrimitiveType(AtomicType targetType) |
org.objectweb.asm.ClassVisitor |
makeAnnotatedTraceClassVisitor(org.objectweb.asm.ClassVisitor cv,
String className)
Make a class visitor for displaying bytecode
|
Class |
makeClass(org.objectweb.asm.ClassWriter writer,
String className)
Having written the bytecode for all the methods for a class, create the Class itself so it can be used
|
String |
makeValidJavaName(String name)
Given a candidate Java name, make it into a valid Java name by removing surplus white spaces
and truncating it to a maximum of 256 characters if length is greater than 256 characters.
|
void |
popCurrentMethodInfo() |
void |
popReceiverInfo()
Generate code to reinstate the previous current receiver by popping it from the
receiver stack.
|
void |
pushNewClassInfo(String className,
Class superclass,
org.objectweb.asm.ClassWriter cw) |
void |
pushNewMethodInfo(Generator ga,
boolean contextIsArgument,
int contextVariablePosition) |
void |
pushNewReceiverInfo(Generator ga)
Generate code to set a new current receiver on the top of the receiver stack.
|
void |
setCompiledClass(Object expr,
Class clss) |
public static int tracePoint
public int mostRecentLineNumber
public HashMap<com.saxonica.ee.bytecode.util.CompilerService.ObjectIdentityWrapper,CompilerService.StaticSubClasses> cClassMap
public CompilerService(Configuration config)
public static boolean isLanguagePrimitiveType(AtomicType targetType)
public boolean isDisplayByteCode()
public boolean isDebugByteCode()
public PrintWriter createPrintWriter(String filename)
public void addNewMethod(ExpressionCompiler ec, Expression e)
ec
- - The ExpressionCompiler that needs to generate a methode
- - The expression represented by the Expressioncompilerpublic void compileToSequence(Expression expression) throws CannotCompileException
expression
- the expression to be compiledCannotCompileException
- if the expression cannot be compiledpublic int getUniqueNumber()
public void pushNewReceiverInfo(Generator ga)
Runtime precondition: the new receiver is on the top of the bytecode stack
Runtime postcondition: the new receiver is now the current receiver; the previous current receiver has been added to the receiver stack. The top entry from the bytecode stack has been consumed.
ga
- the code generatorpublic void popReceiverInfo()
Runtime precondition: there is a non-empty receiver stack
Runtime postcondition: the top entry in the receiver stack has been removed from the receiver stack and is now the current receiver.
public void pushNewMethodInfo(Generator ga, boolean contextIsArgument, int contextVariablePosition)
public void initNewMethod(Generator ga, boolean holdReceiverAsLocal)
ga
- the code generatorholdReceiverAsLocal
- true if a local variable on the bytecode stack is to be
allocated to hold the current receiver; if false, the receiver is obtained via the context when requiredpublic void pushNewClassInfo(String className, Class superclass, org.objectweb.asm.ClassWriter cw)
public Stack<GeneratedMethodInfo> getCurrentMethods()
public GeneratedMethodInfo getCurrentMethod()
public CompilerService.GeneratedClassInfo getCurrentClass()
public Configuration getConfiguration()
public int getFlags()
public CompiledExpression compileToByteCode(Expression expr, String objectName, int evaluationModes)
expr
- The expression to be compiledobjectName
- The name of the object (e.g. function) being compiledevaluationModes
- The evaluation modes for which code is generated. Currently a subset of
Expression.PROCESS_METHOD
,
Expression.ITERATE_METHOD
,
Expression.EVALUATE_METHOD
. If no code is generated for
a given evaluation method, the fallback implementation from the superclass is used.public void compileToIterator(Expression expr) throws CannotCompileException
expr
- the expression to be evaluatedCannotCompileException
- if the expression cannot be compiledpublic void compileToPush(Expression expr) throws CannotCompileException
expr
- the expression to be evaluatedCannotCompileException
- if the expression cannot be compiledpublic void compileToItem(Expression expr) throws CannotCompileException
expr
- the expression to be evaluatedCannotCompileException
- if the expression cannot be compiledpublic void compileToBoolean(Expression expr) throws CannotCompileException
expr
- the expression to be evaluatedCannotCompileException
- if the expression cannot be compiledpublic boolean isInRangeForInt(Expression exp)
public boolean isInRangeForLong(Expression exp)
public void compileToPrimitive(Expression expr, Class requiredClass, OnEmpty onEmpty) throws CannotCompileException
expr
- the expression to be compiledrequiredClass
- the required class. For an expression with static type xs:double, this will be
Double.TYPE; for xs:float it will be Float.TYPE; for xs:string and xs:untypedAtomic it may be either
String.class or CharSequence.class. The expression compiler MUST generate code that leaves this class
of value on the top of the bytecode stack.
For an expression whose static type is xs:integer, the requiredClass may be Integer.TYPE or Long.TYPE,
provided that either (a) the expression is known always to deliver a value in the range of an int or long
respectively, or (b) that any other value would exceed system limits in the context where it is used (for
example, if it is used as an index into a sequence then it cannot exceed a 32-bit integer). All expressions
that have a static type of xs:integer must therefore implement this method.onEmpty
- action to be taken when the expression returns an empty result.CannotCompileException
- if the expression cannot be compiledpublic boolean canCompileToLoop(Expression expr)
expr
- the expression in questionpublic void compileToLoop(Expression expr, LoopBodyGenerator bodyGen) throws CannotCompileException
CannotCompileException
public Generator getCurrentGenerator()
public void popCurrentMethodInfo()
public void generateGetContext()
public void generateGetReceiver()
public void generateDynamicError(String message, String errorCode, SourceLocator locator, boolean isTypeError)
message
- the error messageerrorCode
- the (local part of the) error code to be generatedlocator
- the location in the source code where the error occursisTypeError
- true if this is a type errorpublic void generateParameterizedDynamicError(MessageBuilder builder, String errorCode, SourceLocator locator, boolean isTypeError)
builder
- the error message builder. This generates code to build the error message at run-time and leave
it on the stackerrorCode
- the (local part of the) error code to be generatedlocator
- the location in the source code where the error occursisTypeError
- true if this is a type errorpublic Class makeClass(org.objectweb.asm.ClassWriter writer, String className)
writer
- the writer that was used to create the classclassName
- the name of the classpublic CompilerService.StaticVariableInfo allocateStaticVariableInfo(Object value)
value
- the object to be referencedpublic String makeValidJavaName(String name)
name
- a candidate Java namepublic org.objectweb.asm.ClassVisitor makeAnnotatedTraceClassVisitor(org.objectweb.asm.ClassVisitor cv, String className)
cv
- the classvisitorCopyright (c) 2004-2014 Saxonica Limited. All rights reserved.