public class Optimizer extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected Configuration |
config |
static int |
FULL_OPTIMIZATION |
static int |
NO_OPTIMIZATION |
Constructor and Description |
---|
Optimizer(Configuration config)
Create an Optimizer.
|
Modifier and Type | Method and Description |
---|---|
void |
checkStreamability(XSLTemplate sourceTemplate,
Template compiledTemplate)
Check the streamability of a template
|
Expression |
compileToByteCode(Expression expr,
String objectName,
int evaluationMethods)
Generate Java byte code for an expression
|
Expression |
convertPathExpressionToKey(SlashExpression pathExp,
ExpressionVisitor visitor)
Examine a path expression to see whether it can be replaced by a call on the key() function;
if so, generate an appropriate key definition and return the call on key().
|
FilterExpression |
convertToFilterExpression(SlashExpression pathExp,
TypeHierarchy th)
Convert a path expression such as a/b/c[predicate] into a filter expression
of the form (a/b/c)[predicate].
|
Expression |
extractGlobalVariables(Expression body,
ExpressionVisitor visitor,
PromotionOffer offer)
Extract subexpressions from the body of a function that can be evaluated
as global variables
|
Expression |
generateMultithreadedInstruction(Expression instruction)
Generate a multi-threaded version of an instruction.
|
Configuration |
getConfiguration()
Get the Saxon configuration object
|
int |
getOptimizationLevel()
Get the optimization level
|
int |
isIndexableFilter(Expression filter)
Test whether a filter predicate is indexable.
|
boolean |
isVariableReplaceableByDot(Expression exp,
Binding[] binding)
Determine whether it is possible to rearrange an expression so that all references to a given
variable are replaced by a reference to ".".
|
Expression |
makeCastableToList(Expression operand,
SchemaType targetType,
boolean allowsEmpty)
Make an expression castable check to a union type.
|
Expression |
makeCastableToUnion(Expression operand,
SchemaType targetType,
boolean allowsEmpty)
Make an expression castable check to a union type.
|
Expression |
makeCastToList(Expression operand,
SchemaType targetType,
boolean allowsEmpty)
Make an expression that casts to a list type.
|
Expression |
makeCastToUnion(Expression operand,
SchemaType targetType,
boolean allowsEmpty)
Make an expression that casts to a union type.
|
FunctionItem |
makeCastToUnion(UnionType type,
NamespaceResolver resolver) |
Expression |
makeConditionalDocumentSorter(DocumentSorter sorter,
SlashExpression path)
Make a conditional document sorter.
|
void |
makeCopyOperationsExplicit(Expression parent,
Expression child)
In streaming mode, make the copy operation applied to subexpressions of a complex-content
sequence constructor into explicit copy-of operations.
|
Sequence |
makeIndexedValue(SequenceIterator iter)
Create an indexed value
|
RuleTarget |
makeInversion(Pattern pattern,
Template template,
NodeTest nodeTest)
Generate the inversion of the expression comprising the body of a template rules.
|
Expression |
makeStreamingApplyTemplates(ApplyTemplates inst,
List<String> reasonsForFailure)
Make a streaming applyTemplates instruction.
|
Expression |
optimizeCopy(Expression select)
Attempt to optimize a copy operation.
|
Expression |
optimizeForExpressionForStreaming(ForExpression expr)
In streaming mode, optimizer a ForExpression for streaming
|
BinaryExpression |
optimizeGeneralComparison(GeneralComparison gc,
boolean backwardsCompatible)
Simplify a GeneralComparison expression
|
Expression |
optimizeQuantifiedExpressionForStreaming(QuantifiedExpression expr)
In streaming mode, optimizer a QuantifiedExpression for streaming
|
Expression |
promoteExpressionsToGlobal(Expression body,
ExpressionVisitor visitor)
Identify expressions within a function or template body that can be promoted to be
evaluated as global variables.
|
void |
setOptimizationLevel(int level)
Set the optimization level
|
void |
trace(String message)
Trace optimization actions
|
void |
trace(String message,
Expression exp)
Trace optimization actions
|
Expression |
tryIndexedFilter(FilterExpression f,
ExpressionVisitor visitor,
boolean indexFirstOperand,
boolean contextIsDoc)
Try converting a filter expression to a call on the key function.
|
Expression |
tryInlineFunctionCall(UserFunctionCall functionCall,
ExpressionVisitor visitor,
ExpressionVisitor.ContextItemType contextItemType)
Replace a function call by the body of the function, assuming all conditions for inlining
the function are satisfied
|
Expression |
trySwitch(Choose choose,
StaticContext env)
Try to convert a Choose expression into a switch
|
public static final int NO_OPTIMIZATION
public static final int FULL_OPTIMIZATION
protected Configuration config
public Optimizer(Configuration config)
config
- the Saxon configurationpublic Configuration getConfiguration()
public void setOptimizationLevel(int level)
level
- the optimization level, between 0 (no optimization) and 10 (full optimization).
Currently all values greater than zero have the same effect as full optimizationpublic int getOptimizationLevel()
public BinaryExpression optimizeGeneralComparison(GeneralComparison gc, boolean backwardsCompatible)
gc
- the GeneralComparison to be simplifiedbackwardsCompatible
- true if in 1.0 compatibility modepublic Expression optimizeCopy(Expression select) throws XPathException
select
- the expression that selects the items to be copiedXPathException
public Expression convertPathExpressionToKey(SlashExpression pathExp, ExpressionVisitor visitor) throws XPathException
pathExp
- The path expression to be converted.visitor
- The expression visitorXPathException
public Expression tryIndexedFilter(FilterExpression f, ExpressionVisitor visitor, boolean indexFirstOperand, boolean contextIsDoc)
f
- the filter expression to be convertedvisitor
- the expression visitor, which must be currently visiting the filter expression findexFirstOperand
- true if the first operand of the filter comparison is to be indexed;
false if it is the second operandcontextIsDoc
- true if the context item is known to be a document nodepublic FilterExpression convertToFilterExpression(SlashExpression pathExp, TypeHierarchy th) throws XPathException
pathExp
- the path expression to be convertedth
- the type hierarchy cacheXPathException
public int isIndexableFilter(Expression filter)
filter
- the predicate expressionpublic Sequence makeIndexedValue(SequenceIterator iter) throws XPathException
iter
- the iterator that delivers the sequence of values to be indexedUnsupportedOperationException:
- this method should not be called in Saxon-BXPathException
public boolean isVariableReplaceableByDot(Expression exp, Binding[] binding)
exp
- the expression in questionbinding
- an array of bindings defining range variables; the method tests that there are no
references to any of these variables within a predicate or on the rhs of "/"public Expression makeConditionalDocumentSorter(DocumentSorter sorter, SlashExpression path)
sorter
- the document sorterpath
- the path expressionpublic Expression tryInlineFunctionCall(UserFunctionCall functionCall, ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)
functionCall
- the functionCall expressionvisitor
- the expression visitorcontextItemType
- the context item typepublic Expression promoteExpressionsToGlobal(Expression body, ExpressionVisitor visitor) throws XPathException
body
- the body of the template or functionvisitor
- the expression visitorXPathException
public Expression trySwitch(Choose choose, StaticContext env)
choose
- the Choose expressionenv
- the static contextpublic Expression extractGlobalVariables(Expression body, ExpressionVisitor visitor, PromotionOffer offer) throws XPathException
body
- the body of the functionoffer
- The PromotionOffer. Will be marked to indicate whether any action was takenXPathException
public Expression makeStreamingApplyTemplates(ApplyTemplates inst, List<String> reasonsForFailure) throws XPathException
inst
- the unoptimized applyTemplates instructionreasonsForFailure
- a list to which diagnostic messages will be addedXPathException
- if an error is detectedpublic RuleTarget makeInversion(Pattern pattern, Template template, NodeTest nodeTest) throws XPathException
pattern
- the match pattern of this template ruletemplate
- the template to be invertednodeTest
- the static item type of the context node of the templateXPathException
public void makeCopyOperationsExplicit(Expression parent, Expression child) throws XPathException
XPathException
public void checkStreamability(XSLTemplate sourceTemplate, Template compiledTemplate) throws XPathException
sourceTemplate
- the source of the template in the stylesheet treecompiledTemplate
- the compiled templateXPathException
- if the template is declared streamable but does not satisfy the straming rulespublic Expression makeCastToUnion(Expression operand, SchemaType targetType, boolean allowsEmpty)
public Expression makeCastToList(Expression operand, SchemaType targetType, boolean allowsEmpty)
public Expression makeCastableToUnion(Expression operand, SchemaType targetType, boolean allowsEmpty)
public Expression makeCastableToList(Expression operand, SchemaType targetType, boolean allowsEmpty)
public Expression optimizeForExpressionForStreaming(ForExpression expr) throws XPathException
expr
- the expression to be optimizedXPathException
public Expression optimizeQuantifiedExpressionForStreaming(QuantifiedExpression expr) throws XPathException
expr
- the expression to be optimizedXPathException
public FunctionItem makeCastToUnion(UnionType type, NamespaceResolver resolver)
public Expression generateMultithreadedInstruction(Expression instruction)
instruction
- the instruction to be multi-threadedpublic Expression compileToByteCode(Expression expr, String objectName, int evaluationMethods)
expr
- the expression to be compiledobjectName
- the name of the object (e.g. function) being compiledevaluationMethods
- The evaluation modes for which code is generated. Currently a subset of
Expression.PROCESS_METHOD
, Expression.ITERATE_METHOD
. If no code is generated forpublic void trace(String message, Expression exp)
message
- the message to be displayedexp
- the expression after being rewrittenpublic void trace(String message)
message
- the message to be displayedCopyright (c) 2004-2013 Saxonica Limited. All rights reserved.