public class CompilerService extends java.lang.Object implements ICompilerService
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 |
---|---|
java.util.HashMap<com.saxonica.ee.bytecode.util.CompilerService.ObjectIdentityWrapper,CompilerService.StaticSubClasses> |
cClassMap |
int |
mostRecentLineNumber |
static int |
tracePoint |
Constructor and Description |
---|
CompilerService(Configuration config,
int hostLanguage) |
Modifier and Type | Method and Description |
---|---|
void |
addNewMethod(ExpressionCompiler ec,
Expression e)
The methods adds the
|
CompilerService.StaticVariableInfo |
allocateStaticVariableInfo(java.lang.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
|
void |
checkMaxClassesLimit() |
AtomicTypeValidator |
compileAtomicValidator(UserAtomicType type,
ConversionRules rules)
Make a validator for user-defined atomic types
|
void |
compileToBoolean(Expression expr)
Generate bytecode to evaluate an expression leaving a boolean on the stack.
|
CompiledExpression |
compileToByteCode(Expression expr,
java.lang.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,
java.lang.Class c)
Generate bytecode to evaluate an expression leaving a primitive on the stack.
|
void |
compileToPrimitive(Expression expr,
java.lang.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
|
java.io.PrintWriter |
createPrintWriter(java.lang.String filename) |
void |
generateDynamicError(java.lang.String message,
java.lang.String errorCode,
javax.xml.transform.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,
java.lang.String errorCode,
javax.xml.transform.SourceLocator locator,
boolean isTypeError)
Generate code to throw an XPath Exception.
|
java.lang.Class |
getCompiledClass(Expression expr) |
Configuration |
getConfiguration()
Get the Configuration used by this CompilerService
|
CompilerService.GeneratedClassInfo |
getCurrentClass() |
Generator |
getCurrentGenerator() |
GeneratedMethodInfo |
getCurrentMethod() |
java.util.Stack<GeneratedMethodInfo> |
getCurrentMethods() |
int |
getFlags()
Get the flag options used by the ClassWriter
|
int |
getHostLanguage() |
ExpressionCompiler |
getNamedExpressionCompiler(java.lang.String name) |
static 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,
java.lang.String className)
Make a class visitor for displaying bytecode
|
java.lang.Class |
makeClass(org.objectweb.asm.ClassWriter writer,
java.lang.String className)
Having written the bytecode for all the methods for a class, create the Class itself so it can be used
|
java.lang.String |
makeValidJavaName(java.lang.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(java.lang.String className,
java.lang.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(Expression expr,
java.lang.Class clss) |
public static int tracePoint
public int mostRecentLineNumber
public java.util.HashMap<com.saxonica.ee.bytecode.util.CompilerService.ObjectIdentityWrapper,CompilerService.StaticSubClasses> cClassMap
public CompilerService(Configuration config, int hostLanguage)
public static boolean isLanguagePrimitiveType(AtomicType targetType)
public boolean isDisplayByteCode()
public boolean isDebugByteCode()
public int getHostLanguage()
public java.io.PrintWriter createPrintWriter(java.lang.String filename)
public ExpressionCompiler getNamedExpressionCompiler(java.lang.String name)
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 java.lang.Class getCompiledClass(Expression expr)
public void setCompiledClass(Expression expr, java.lang.Class clss)
public static 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(java.lang.String className, java.lang.Class superclass, org.objectweb.asm.ClassWriter cw)
public java.util.Stack<GeneratedMethodInfo> getCurrentMethods()
public GeneratedMethodInfo getCurrentMethod()
public CompilerService.GeneratedClassInfo getCurrentClass()
public Configuration getConfiguration()
public int getFlags()
public CompiledExpression compileToByteCode(Expression expr, java.lang.String objectName, int evaluationModes) throws CannotCompileException
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.CannotCompileException
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 void compileToPrimitive(Expression expr, java.lang.Class c) 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, java.lang.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 void compileToLoop(Expression expr, LoopBodyGenerator bodyGen) throws CannotCompileException
CannotCompileException
public Generator getCurrentGenerator()
public void popCurrentMethodInfo()
public void generateGetContext()
public void generateGetReceiver()
public void generateDynamicError(java.lang.String message, java.lang.String errorCode, javax.xml.transform.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, java.lang.String errorCode, javax.xml.transform.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 java.lang.Class makeClass(org.objectweb.asm.ClassWriter writer, java.lang.String className)
writer
- the writer that was used to create the classclassName
- the name of the classpublic CompilerService.StaticVariableInfo allocateStaticVariableInfo(java.lang.Object value)
value
- the object to be referencedpublic java.lang.String makeValidJavaName(java.lang.String name)
name
- a candidate Java namepublic org.objectweb.asm.ClassVisitor makeAnnotatedTraceClassVisitor(org.objectweb.asm.ClassVisitor cv, java.lang.String className)
cv
- the classvisitorpublic AtomicTypeValidator compileAtomicValidator(UserAtomicType type, ConversionRules rules) throws CannotCompileException
type
- the user-defined atomic type for which a validator is requiredrules
- the conversion rules to be used by the validatorAtomicTypeValidator
specialised to this atomic typeCannotCompileException
- if bytecode generation for this type is not possible for any reasonpublic void checkMaxClassesLimit() throws CannotCompileException
CannotCompileException
Copyright (c) 2004-2018 Saxonica Limited. All rights reserved.