public class ExpressionTool
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
ExpressionTool.ExpressionPredicate |
static interface |
ExpressionTool.ExpressionSelector
Callback for selecting expressions in the tree
|
Modifier and Type | Field and Description |
---|---|
static int |
CALL_EVALUATE_ITEM |
static int |
EVALUATE_AND_MATERIALIZE_VARIABLE |
static int |
EVALUATE_SUPPLIED_PARAMETER |
static int |
EVALUATE_VARIABLE |
static int |
ITERATE_AND_MATERIALIZE |
static int |
LAZY_TAIL_EXPRESSION |
static int |
MAKE_CLOSURE |
static int |
MAKE_INDEXED_VARIABLE |
static int |
MAKE_MEMO_CLOSURE |
static int |
MAKE_SINGLETON_CLOSURE |
static int |
NO_EVALUATION_NEEDED |
static int |
PROCESS |
static int |
RETURN_EMPTY_SEQUENCE |
static int |
SHARED_APPEND_EXPRESSION |
static int |
STREAMING_ARGUMENT |
static int |
UNDECIDED |
Modifier and Type | Method and Description |
---|---|
static int |
allocateSlots(Expression exp,
int nextFree,
SlotManager frame)
Allocate slot numbers to range variables
|
static boolean |
callsFunction(Expression exp,
StructuredQName qName,
boolean sameFocusOnly)
Determine whether an expression contains a call on the function with a given name
|
static boolean |
changesXsltContext(Expression exp)
Determine whether an expression possible calls (directly or indirectly) xsl:result-document, or
has other context dependencies that prevent function inlining,
which we assume is true if it contains a template call.
|
static void |
clearStreamabilityData(Expression exp)
Clear all computed streamability properties for an expression and its contained subtree
|
static void |
computeEvaluationModesForUserFunctionCalls(Expression exp)
Compute argument evaluation modes for all calls on user defined functions with
a specified expression
|
static boolean |
contains(Expression exp,
boolean sameFocusOnly,
ExpressionTool.ExpressionPredicate predicate)
Test whether a given expression is, or contains, at any depth, an expression that satisfies a supplied
condition
|
static boolean |
contains(Expression a,
Expression b)
Ask whether one expression is a subexpression of another
|
static boolean |
containsLocalParam(Expression exp)
Determine whether an expression contains a LocalParamSetter subexpression
|
static boolean |
containsLocalVariableReference(Expression exp)
Determine whether an expression contains a local variable reference,
other than a reference to a local variable whose binding occurs
within this expression
|
static boolean |
containsSubexpression(Expression exp,
java.lang.Class<? extends Expression> subClass)
Determine whether an expression has a subexpression of a given implementation class
|
static void |
copyLocationInfo(Expression from,
Expression to)
Copy location information (the line number and reference to the container) from one expression
to another
|
static boolean |
dependsOnFocus(Expression exp)
Ask whether an expression has a dependency on the focus
|
static boolean |
dependsOnVariable(Expression exp,
Binding[] bindingList)
Determine whether an expression depends on any one of a set of variables
|
static Sequence |
eagerEvaluate(Expression exp,
XPathContext context)
Evaluate an expression now; lazy evaluation is not permitted in this case
|
static int |
eagerEvaluationMode(Expression exp)
Determine the method of evaluation to be used when lazy evaluation of an expression is
preferred.
|
static void |
ebvError(java.lang.String reason)
Report an error in computing the effective boolean value of an expression
|
static boolean |
effectiveBooleanValue(Item item)
Determine the effective boolean value of a single item
|
static boolean |
effectiveBooleanValue(SequenceIterator iterator)
Determine the effective boolean value of a sequence, given an iterator over the sequence
|
static boolean |
equalOrNull(java.lang.Object x,
java.lang.Object y)
Return true if two objects are equal or if both are null
|
static Sequence |
evaluate(Expression exp,
int evaluationMode,
XPathContext context,
int ref)
Do lazy evaluation of an expression.
|
static int |
expressionSize(Expression exp)
Get the size of an expression tree (the number of subexpressions it contains)
|
static boolean |
factorOutDot(Expression exp,
Binding variable)
Replace references to the context item with references to a variable
|
static Operand |
findOperand(Expression parentExpression,
Expression childExpression)
Find the operand corresponding to a particular child expression
|
static void |
gatherCalledFunctionNames(Expression e,
java.util.List<SymbolicName> list)
Gather a list of the names of the user-defined functions which a given expression calls directly
|
static void |
gatherCalledFunctions(Expression e,
java.util.List<UserFunction> list)
Gather a list of all the user-defined functions which a given expression calls directly
|
static void |
gatherReferencedVariables(Expression e,
java.util.List<Binding> list)
Gather a list of all the variable bindings on which a given expression depends
|
static void |
gatherVariableReferences(Expression exp,
Binding binding,
java.util.List<VariableReference> list)
Get a list of all references to a particular variable within a subtree
|
static java.net.URI |
getBaseURI(StaticContext env,
javax.xml.transform.SourceLocator locator,
boolean fail)
Determine the base URI of an expression, so that it can be saved on the expression tree for use
when the expression is evaluated
|
static Expression |
getContextDocumentSettingContainer(Expression exp)
Get the context-document-setting container of an expression.
|
static java.lang.String |
getCurrentDirectory() |
static Expression |
getFocusSettingContainer(Expression exp)
Get the focus-setting container of an expression
*
|
static Item |
getItemFromProcessMethod(Expression exp,
XPathContext context)
Helper method to construct an item representing the results of the expression when all that
the expression itself offers is a process() method.
|
static SequenceIterator |
getIteratorFromProcessMethod(Expression exp,
XPathContext context)
Helper method to construct an iterator over the results of the expression when all that
the expression itself offers is a process() method.
|
static int |
getReferenceCount(Expression exp,
Binding binding,
boolean inLoop)
Determine how often a variable is referenced.
|
static boolean |
hasLoopingSubexpression(Expression parent,
Expression child) |
static java.lang.String |
indent(int level)
Construct indent string, for diagnostic output
|
static boolean |
inlineVariableReferences(Expression expr,
Binding binding,
Expression replacement)
Inline variable references.
|
static boolean |
inlineVariableReferencesInternal(Expression expr,
Binding binding,
Expression replacement) |
static boolean |
isAllowedInUpdatingContext(Expression exp)
Determine whether the expression is either an updating expression, or an expression that is permitted
in a context where updating expressions are allowed
|
static boolean |
isLocalConstructor(Expression child)
Ask whether a supplied expression is a nested node constructor.
|
static boolean |
isLoopingReference(VariableReference reference,
Binding binding) |
static boolean |
isLoopingSubexpression(Expression child,
Expression ancestor)
Return true if a given expression is evaluated repeatedly
when a given ancestor expression is evaluated once
|
static Sequence |
lazyEvaluate(Expression exp,
XPathContext context,
int ref)
Do lazy evaluation of an expression.
|
static int |
lazyEvaluationMode(Expression exp)
Determine the method of evaluation to be used when lazy evaluation of an expression is
preferred.
|
static Expression |
make(java.lang.String expression,
StaticContext env,
int start,
int terminator,
CodeInjector codeInjector)
Parse an XPath expression.
|
static Expression |
makePathExpression(Expression start,
Expression step,
boolean sortAndDeduplicate)
Make a mapping expression.
|
static Expression |
makeRawPathExpression(Expression start,
Expression step,
boolean sortAndDeduplicate) |
static int |
markTailFunctionCalls(Expression exp,
StructuredQName qName,
int arity)
Scan an expression to find and mark any recursive tail function calls
|
static Expression |
optimizeComponentBody(Expression body,
Compilation compilation,
ExpressionVisitor visitor,
ContextItemStaticInfo cit,
boolean extractGlobals)
Optimize the implementation of a component such as a function, template, or global variable
|
static java.lang.String |
parenthesize(Expression exp)
Display an expression adding parentheses if it is possible they are necessary
because the expression has sub-expressions
|
static java.lang.String |
parenthesizeShort(Expression exp) |
static boolean |
processExpressionTree(Expression root,
java.lang.Object result,
ExpressionAction action)
Process every node on a subtree of the expression tree using a supplied action.
|
static void |
rebindVariableReferences(Expression exp,
Binding oldBinding,
Binding newBinding)
Rebind all variable references to a binding
|
static boolean |
refersToVariableOrFunction(Expression exp)
Determine whether the expression contains any variable references or calls to user-written functions
|
static boolean |
replaceCallsToCurrent(Expression expr,
LocalBinding binding)
Replace calls to current() by a variable reference.
|
static boolean |
replaceSelectedSubexpressions(Expression exp,
ExpressionTool.ExpressionSelector selector,
Expression replacement,
boolean mustCopy)
Replace all selected subexpressions within a subtree
|
static boolean |
replaceTrivialCallsToCurrent(Expression expr)
Replace trivial calls to current() by a context item expression (
. ). |
static void |
replaceVariableReferences(Expression exp,
Binding binding,
Expression replacement,
boolean mustCopy)
Replace all references to a particular variable within a subtree
|
static void |
resetPropertiesWithinSubtree(Expression exp)
Reset cached static properties within a subtree, meaning that they have to be
recalulated next time they are required
|
static void |
resetStaticProperties(Expression exp)
Reset the static properties for the current expression and for all its containing expressions.
|
static Expression |
resolveCallsToCurrentFunction(Expression exp)
Resolve calls to the XSLT current() function within an expression
|
static void |
setDeepRetainedStaticContext(Expression exp,
RetainedStaticContext rsc)
Ensure that every node in the expression tree has a retained static context.
|
static Expression |
tryToFactorOutDot(Expression exp,
ItemType contextItemType)
Try to factor out dependencies on the context item, by rewriting an expression f(.) as
let $dot := .
|
static Expression |
unfilteredExpression(Expression exp,
boolean allowPositional)
Get the expression that remains after removing any filter predicates
|
static Expression |
unsortedIfHomogeneous(Expression exp,
boolean forStreaming)
Remove unwanted sorting from an expression, at compile time, if and only if it is known
that the result of the expression will be homogeneous (all nodes, or all atomic values).
|
static void |
validateTree(Expression exp) |
public static final int UNDECIDED
public static final int NO_EVALUATION_NEEDED
public static final int EVALUATE_VARIABLE
public static final int MAKE_CLOSURE
public static final int MAKE_MEMO_CLOSURE
public static final int RETURN_EMPTY_SEQUENCE
public static final int EVALUATE_AND_MATERIALIZE_VARIABLE
public static final int CALL_EVALUATE_ITEM
public static final int ITERATE_AND_MATERIALIZE
public static final int PROCESS
public static final int LAZY_TAIL_EXPRESSION
public static final int SHARED_APPEND_EXPRESSION
public static final int MAKE_INDEXED_VARIABLE
public static final int MAKE_SINGLETON_CLOSURE
public static final int EVALUATE_SUPPLIED_PARAMETER
public static final int STREAMING_ARGUMENT
public static Expression make(java.lang.String expression, StaticContext env, int start, int terminator, CodeInjector codeInjector) throws XPathException
expression
- The expression (as a character string)env
- An object giving information about the compile-time
context of the expressionstart
- position of the first significant character in the expressionterminator
- The token that marks the end of this expression; typically
Token.EOF, but may for example be a right curly bracecodeInjector
- true allows injection of tracing, debugging, or performance monitoring code; null if
not requiredXPathException
- if the expression contains a static errorpublic static void setDeepRetainedStaticContext(Expression exp, RetainedStaticContext rsc)
exp
- the root of the expression treersc
- the retained static context to be applied to nodes that do not already have one,
and that do not have an ancestor with an existing retained static context.public static void copyLocationInfo(Expression from, Expression to)
from
- the expression containing the location informationto
- the expression to which the information is to be copiedpublic static Expression unsortedIfHomogeneous(Expression exp, boolean forStreaming) throws XPathException
exp
- the expression to be optimizedforStreaming
- true if streamed evaluation of the expression is requiredXPathException
- if a static error is found while doing the rewritepublic static int lazyEvaluationMode(Expression exp)
exp
- the expression to be evaluatedpublic static int eagerEvaluationMode(Expression exp)
exp
- the expression to be evaluatedpublic static Sequence evaluate(Expression exp, int evaluationMode, XPathContext context, int ref) throws XPathException
exp
- the expression to be evaluatedevaluationMode
- the evaluation mode for this expressioncontext
- the run-time evaluation context for the expression. If
the expression is not evaluated immediately, then parts of the
context on which the expression depends need to be saved as part of
the Closureref
- an indication of how the value will be used. The value 1 indicates that the value
is only expected to be used once, so that there is no need to keep it in memory. A small value >1
indicates multiple references, so the value will be saved when first evaluated. The special value
FILTERED indicates a reference within a loop of the form $x[predicate], indicating that the value
should be saved in a way that permits indexing.XPathException
- if any error occurs in evaluating the
expressionpublic static Sequence lazyEvaluate(Expression exp, XPathContext context, int ref) throws XPathException
exp
- the expression to be evaluatedcontext
- the run-time evaluation context for the expression. If
the expression is not evaluated immediately, then parts of the
context on which the expression depends need to be saved as part of
the Closureref
- an indication of how the value will be used. The value 1 indicates that the value
is only expected to be used once, so that there is no need to keep it in memory. A small value >1
indicates multiple references, so the value will be saved when first evaluated. The special value
FILTERED indicates a reference within a loop of the form $x[predicate], indicating that the value
should be saved in a way that permits indexing.XPathException
- if any error occurs in evaluating the
expressionpublic static Sequence eagerEvaluate(Expression exp, XPathContext context) throws XPathException
exp
- the expression to be evaluatedcontext
- the run-time evaluation contextXPathException
- if any dynamic error occurs evaluating the
expressionpublic static int markTailFunctionCalls(Expression exp, StructuredQName qName, int arity)
exp
- the expression to be analyzedqName
- the name of the containing functionarity
- the arity of the containing functionpublic static java.lang.String indent(int level)
level
- the indentation level (the number of spaces to return)public static boolean contains(Expression a, Expression b)
a
- the containing expressionb
- the putative contained expressionpublic static boolean containsLocalParam(Expression exp)
exp
- the expression to be testedpublic static boolean containsLocalVariableReference(Expression exp)
exp
- the expression to be testedpublic static boolean contains(Expression exp, boolean sameFocusOnly, ExpressionTool.ExpressionPredicate predicate)
exp
- the given expressionsameFocusOnly
- if true, only subexpressions evaluated in the same focus are searched. If false,
all subexpressions are searchedpredicate
- the condition to be satisfiedpublic static boolean changesXsltContext(Expression exp)
exp
- the expression to be testedpublic static boolean isLoopingSubexpression(Expression child, Expression ancestor)
child
- the expression to be testedancestor
- the ancestor expression. May be null, in which case the search goes all the way
to the base of the stack.public static boolean isLoopingReference(VariableReference reference, Binding binding)
public static boolean hasLoopingSubexpression(Expression parent, Expression child)
public static Expression getFocusSettingContainer(Expression exp)
Note, this always returns an expression or null. Unlike the like-named concept in the spec, it can't return a component such as a template or an attribute set.
exp
- the expression whose focus-setting container is requiredpublic static Expression getContextDocumentSettingContainer(Expression exp)
exp
- the expression whose document-context-setting container is requiredpublic static void resetStaticProperties(Expression exp)
exp
- the expression whose properties are to be reset; the method also resets local
properties for all its ancestor expressions.public static boolean equalOrNull(java.lang.Object x, java.lang.Object y)
x
- the first objecty
- the second objectpublic static SequenceIterator getIteratorFromProcessMethod(Expression exp, XPathContext context) throws XPathException
context
- the dynamic evaluation contextXPathException
- if a dynamic error occurspublic static Item getItemFromProcessMethod(Expression exp, XPathContext context) throws XPathException
context
- the dynamic evaluation contextXPathException
- if a dynamic error occurspublic static int allocateSlots(Expression exp, int nextFree, SlotManager frame)
exp
- the expression whose range variables need to have slot numbers assignednextFree
- the next slot number that is available for allocationframe
- a SlotManager object that is used to track the mapping of slot numbers
to variable names for debugging purposes. May be null.public static boolean effectiveBooleanValue(SequenceIterator iterator) throws XPathException
iterator
- An iterator over the sequence whose effective boolean value is requiredXPathException
- if a dynamic error occurspublic static boolean effectiveBooleanValue(Item item) throws XPathException
item
- the item whose effective boolean value is requiredXPathException
- if a dynamic error occurspublic static void ebvError(java.lang.String reason) throws XPathException
reason
- the nature of the errorXPathException
- alwayspublic static boolean dependsOnFocus(Expression exp)
exp
- the expressionpublic static boolean dependsOnVariable(Expression exp, Binding[] bindingList)
exp
- the expression being testedbindingList
- the set of variables being testedpublic static void gatherReferencedVariables(Expression e, java.util.List<Binding> list)
e
- the expression being testedlist
- a list to which the bindings are to be added. The items in this list must
implement Binding
public static boolean refersToVariableOrFunction(Expression exp)
exp
- the expression being testedpublic static boolean callsFunction(Expression exp, StructuredQName qName, boolean sameFocusOnly)
exp
- The expression being testedqName
- The name of the functionsameFocusOnly
- If true, only expressions with the same (top-level) focus are searchedpublic static boolean containsSubexpression(Expression exp, java.lang.Class<? extends Expression> subClass)
exp
- The expression being testedsubClass
- The impementation class of the sought subexpressionpublic static void gatherCalledFunctions(Expression e, java.util.List<UserFunction> list)
e
- the expression being testedlist
- a list of the functions that are called. The items in this list must
be objects of class UserFunction
public static void gatherCalledFunctionNames(Expression e, java.util.List<SymbolicName> list)
e
- the expression being testedlist
- a list of the functions that are called. The items in this list are strings in the format
"{uri}local/arity"public static Expression optimizeComponentBody(Expression body, Compilation compilation, ExpressionVisitor visitor, ContextItemStaticInfo cit, boolean extractGlobals) throws XPathException
body
- the expression forming the body of the componentcompilation
- the current compilationvisitor
- the expression visitorcit
- information about the context item for evaluation of the component bodyextractGlobals
- true if constant expressions are to be extracted as global variablesXPathException
- if anything goes wrongpublic static void computeEvaluationModesForUserFunctionCalls(Expression exp) throws XPathException
XPathException
public static void clearStreamabilityData(Expression exp) throws XPathException
exp
- the expression whose streamability data is to be resetXPathException
- should not happenpublic static void resetPropertiesWithinSubtree(Expression exp)
exp
- the root of the subtree within which static properties should be resetpublic static Expression resolveCallsToCurrentFunction(Expression exp) throws XPathException
exp
- the expression within which calls to current() should be resolvedXPathException
- if a static error is detectedpublic static void gatherVariableReferences(Expression exp, Binding binding, java.util.List<VariableReference> list)
exp
- the expression at the root of the subtreebinding
- the variable binding whose references are soughtlist
- a list to be populated with the references to this variablepublic static boolean processExpressionTree(Expression root, java.lang.Object result, ExpressionAction action) throws XPathException
root
- the root of the subtree to be processedresult
- an arbitrary object that is passed to each action call and that can be
updated to gather results of the processingaction
- an action to be performed on each node of the expression tree. Processing
stops if any action returns the value trueXPathException
public static boolean replaceSelectedSubexpressions(Expression exp, ExpressionTool.ExpressionSelector selector, Expression replacement, boolean mustCopy)
exp
- the expression at the root of the subtreeselector
- callback to determine whether a subexpression is selectedreplacement
- the expression to be used in place of the variable referencemustCopy
- if true, the replacement expression must be copied before usepublic static void replaceVariableReferences(Expression exp, Binding binding, Expression replacement, boolean mustCopy)
exp
- the expression at the root of the subtreebinding
- the variable binding whose references are soughtreplacement
- the expression to be used in place of the variable referencemustCopy
- true if the replacement expression must be copied before usepublic static int getReferenceCount(Expression exp, Binding binding, boolean inLoop)
exp
- the expression within which variable references are to be countedbinding
- identifies the variable of interestinLoop
- true if the expression is within a loop, in which case a reference counts as many.
This should be set to false on the initial call, it may be set to true on an internal recursive
callpublic static int expressionSize(Expression exp)
exp
- the expression whose size is requiredpublic static void rebindVariableReferences(Expression exp, Binding oldBinding, Binding newBinding)
exp
- the expression whose contained variable references are to be reboundoldBinding
- the old binding for the variable referencesnewBinding
- the new binding to which the variables should be reboundpublic static Expression makePathExpression(Expression start, Expression step, boolean sortAndDeduplicate)
start
- the start expression (the first operand of "/")step
- the step expression (the second operand of "/")sortAndDeduplicate
- set to true if this is a path expression ("/") where the result needs to be
homogenous, and needs to be sorted and deduplicated if it consists of nodes. Set to false if the caller
knows that this is not necessary (typically because it has already been checked).public static Expression makeRawPathExpression(Expression start, Expression step, boolean sortAndDeduplicate)
public static Operand findOperand(Expression parentExpression, Expression childExpression)
parentExpression
- the parent expressionchildExpression
- the child expressionpublic static Expression unfilteredExpression(Expression exp, boolean allowPositional)
exp
- the expression to be examinedallowPositional
- true if positional predicates are allowedpublic static Expression tryToFactorOutDot(Expression exp, ItemType contextItemType)
exp
- the expression from which references to "." should be factored out if possiblecontextItemType
- the static type of the context itempublic static boolean factorOutDot(Expression exp, Binding variable)
exp
- the expression in which the replacement is to take placevariable
- the declaration of the variablepublic static boolean inlineVariableReferences(Expression expr, Binding binding, Expression replacement)
expr
- the expression containing the variable references to be inlinedbinding
- the variable binding to be inlinedreplacement
- the expression to be used as a replacement for the variable referencepublic static boolean inlineVariableReferencesInternal(Expression expr, Binding binding, Expression replacement)
public static boolean replaceTrivialCallsToCurrent(Expression expr)
.
).expr
- the expression potentially containing the calls to be replacedpublic static boolean replaceCallsToCurrent(Expression expr, LocalBinding binding)
expr
- the expression potentially containing the calls to be replacedbinding
- the variable binding to be referencedpublic static boolean isAllowedInUpdatingContext(Expression exp)
exp
- the expression under testpublic static java.lang.String getCurrentDirectory()
public static java.net.URI getBaseURI(StaticContext env, javax.xml.transform.SourceLocator locator, boolean fail) throws XPathException
env
- the static contextlocator
- location of the expression for error messagesfail
- if true, the method throws an exception when there is no absolute base URI; otherwise, the
method returns nullXPathException
- if an error occurspublic static java.lang.String parenthesize(Expression exp)
exp
- the expression to be displayedpublic static java.lang.String parenthesizeShort(Expression exp)
public static void validateTree(Expression exp)
public static boolean isLocalConstructor(Expression child)
child
- child expression to be testedCopyright (c) 2004-2018 Saxonica Limited. All rights reserved.