Class CompiledExpression
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- com.saxonica.ee.bytecode.CompiledExpression
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
public class CompiledExpression extends Expression
An expression that has been compiled to Java bytecode. The actual bytecode is contained in a separate object of typeGeneratedCode
, to which evaluation is delegated
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description CompiledExpression(Expression original, GeneratedCode byteCode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PathMap.PathMapNodeSet
addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.void
checkForUpdatingSubexpressions()
Check to ensure that this expression does not contain any inappropriate updating subexpressions.void
checkPermittedContents(SchemaType parentType, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type.protected int
computeCardinality()
Compute the static cardinality of this expressionint
computeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions.protected int
computeHashCode()
Hashcode supporting equals()protected int
computeSpecialProperties()
Compute the special properties of this expression.Expression
copy(RebindingMap rebindings)
Copy an expression.boolean
effectiveBooleanValue(XPathContext context)
Get the effective boolean value of the expression.boolean
equals(java.lang.Object other)
Is this expression the same as another expression?Item
evaluateItem(XPathContext context)
Evaluate an expression as a single item.void
evaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.void
export(ExpressionPresenter out)
Diagnostic print of expression structure.int
getCardinality()
Determine the static cardinality of the expression.java.lang.String
getClassName()
int
getDependencies()
Determine which aspects of the context the expression depends on.java.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.GeneratedCode
getGeneratedCode()
int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().Expression
getInterpretedExpression()
Get the original (uncompiled) expression of which this is the compiled formint
getIntrinsicDependencies()
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.ItemType
getItemType()
Determine the static item type of the expression, as precisely possible.StructuredQName
getObjectName()
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc.java.util.Iterator<java.lang.String>
getProperties()
Get an iterator over all the properties available.java.lang.Object
getProperty(java.lang.String name)
boolean
isSubtreeExpression()
Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node.boolean
isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specificationboolean
isVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specificationSequenceIterator
iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.void
process(Outputter output, XPathContext context)
Process the instruction, without returning any tail callsvoid
setClassName(java.lang.String cname)
java.lang.String
toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.-
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, computeStaticProperties, dynamicError, evaluateAsString, explain, getConfiguration, getCost, getEvaluationMethod, getExtraProperty, getIntegerBounds, getLocalRetainedStaticContext, getLocation, getNetCost, getPackageData, getParentExpression, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, markTailFunctionCalls, operandList, operands, operandSparseList, optimize, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, toShortString, typeCheck, typeCheckChildren, typeError, unordered, verifyParentPointers
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Constructor Detail
-
CompiledExpression
public CompiledExpression(Expression original, GeneratedCode byteCode)
-
-
Method Detail
-
getInterpretedExpression
public Expression getInterpretedExpression()
Get the original (uncompiled) expression of which this is the compiled form- Overrides:
getInterpretedExpression
in classExpression
- Returns:
- the original expression
-
getGeneratedCode
public GeneratedCode getGeneratedCode()
-
setClassName
public void setClassName(java.lang.String cname)
-
getClassName
public java.lang.String getClassName()
-
getExpressionName
public java.lang.String getExpressionName()
Description copied from class:Expression
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionName
in classExpression
- Returns:
- a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in export() output displaying the expression.
-
getImplementationMethod
public int getImplementationMethod()
Description copied from class:Expression
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.- Specified by:
getImplementationMethod
in classExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
getCardinality
public int getCardinality()
Description copied from class:Expression
Determine the static cardinality of the expression. This establishes how many items there will be in the result of the expression, at compile time (i.e., without actually evaluating the result.- Overrides:
getCardinality
in classExpression
- Returns:
- one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).
-
getItemType
public ItemType getItemType()
Description copied from class:Expression
Determine the static item type of the expression, as precisely possible. All expression return sequences, in general; this method determines the type of the items within the sequence, assuming that (a) this is known in advance, and (b) it is the same for all items in the sequence.This method should always return a result, though it may be the best approximation that is available at the time.
- Specified by:
getItemType
in classExpression
- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
-
getDependencies
public int getDependencies()
Description copied from class:Expression
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and XPathContext.CURRENT_NODE. The default implementation combines the intrinsic dependencies of this expression with the dependencies of the subexpressions, computed recursively. This is overridden for expressions such as FilterExpression where a subexpression's dependencies are not necessarily inherited by the parent expression.- Overrides:
getDependencies
in classExpression
- Returns:
- a set of bit-significant flags identifying the dependencies of the expression
-
process
public void process(Outputter output, XPathContext context) throws XPathException
Description copied from class:Expression
Process the instruction, without returning any tail calls- Overrides:
process
in classExpression
- Parameters:
output
- the destination for the resultcontext
- The dynamic context, giving access to the current node, the current variables, etc.- Throws:
XPathException
- if a dynamic error occurs
-
evaluatePendingUpdates
public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException
Description copied from class:Expression
Evaluate an updating expression, adding the results to a Pending Update List. The default implementation of this method, which is used for non-updating expressions, throws an UnsupportedOperationException- Overrides:
evaluatePendingUpdates
in classExpression
- Parameters:
context
- the XPath dynamic evaluation contextpul
- the pending update list to which the results should be written- Throws:
XPathException
- if evaluation fails
-
toString
public java.lang.String toString()
Description copied from class:Expression
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.
For subclasses of Expression that represent XPath expressions, the result should always be a string that parses as an XPath 3.0 expression. The expression produced should be equivalent to the original making certain assumptions about the static context. In general the expansion will make no assumptions about namespace bindings, except that (a) the prefix "xs" is used to refer to the XML Schema namespace, and (b) the default function namespace is assumed to be the "fn" namespace.
In the case of XSLT instructions and XQuery expressions, the toString() method gives an abstracted view of the syntax that is not designed in general to be parseable.
- Overrides:
toString
in classExpression
- Returns:
- a representation of the expression as a string
-
export
public void export(ExpressionPresenter out) throws XPathException
Description copied from class:Expression
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classExpression
- Parameters:
out
- the expression presenter used to display the structure- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
checkPermittedContents
public void checkPermittedContents(SchemaType parentType, boolean whole) throws XPathException
Description copied from class:Expression
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type. It's always OK to say yes, since the check will be repeated at run-time. The process of checking element and attribute constructors against the content model of a complex type also registers the type of content expected of those constructors, so the static validation can continue recursively.- Overrides:
checkPermittedContents
in classExpression
- Parameters:
parentType
- the "given complex type": the method is checking that the nodes returned by this expression are acceptable members of the content model of this typewhole
- if true, we want to check that the value of this expression satisfies the content model as a whole; if false we want to check that the value of the expression is acceptable as one part of the content- Throws:
XPathException
- if the value delivered by this expression cannot be part of the content model of the given type
-
computeCardinality
protected int computeCardinality()
Description copied from class:Expression
Compute the static cardinality of this expression- Specified by:
computeCardinality
in classExpression
- Returns:
- the computed cardinality, as one of the values
StaticProperty.ALLOWS_ZERO_OR_ONE
,StaticProperty.EXACTLY_ONE
,StaticProperty.ALLOWS_ONE_OR_MORE
,StaticProperty.ALLOWS_ZERO_OR_MORE
. May also returnStaticProperty.ALLOWS_ZERO
if the result is known to be an empty sequence, orStaticProperty.ALLOWS_MANY
if if is known to return a sequence of length two or more.
-
computeSpecialProperties
protected int computeSpecialProperties()
Description copied from class:Expression
Compute the special properties of this expression. These properties are denoted by a bit-significant integer, possible values are in classStaticProperty
. The "special" properties are properties other than cardinality and dependencies, and most of them relate to properties of node sequences, for example whether the nodes are in document order.- Overrides:
computeSpecialProperties
in classExpression
- Returns:
- the special properties, as a bit-significant integer
-
computeDependencies
public int computeDependencies()
Description copied from class:Expression
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions. (This is overridden for path expressions and filter expressions, where the dependencies of a subexpression are not all propogated). This method should be called only once, to compute the dependencies; after that, getDependencies should be used.- Overrides:
computeDependencies
in classExpression
- Returns:
- the depencies, as a bit-mask
-
getIntrinsicDependencies
public int getIntrinsicDependencies()
Description copied from class:Expression
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".- Overrides:
getIntrinsicDependencies
in classExpression
- Returns:
- a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
-
checkForUpdatingSubexpressions
public void checkForUpdatingSubexpressions() throws XPathException
Description copied from class:Expression
Check to ensure that this expression does not contain any inappropriate updating subexpressions. This check is overridden for those expressions that permit updating subexpressions.- Overrides:
checkForUpdatingSubexpressions
in classExpression
- Throws:
XPathException
- if the expression has a non-permitted updating subexpression
-
isUpdatingExpression
public boolean isUpdatingExpression()
Description copied from class:Expression
Determine whether this is an updating expression as defined in the XQuery update specification- Overrides:
isUpdatingExpression
in classExpression
- Returns:
- true if this is an updating expression
-
isVacuousExpression
public boolean isVacuousExpression()
Description copied from class:Expression
Determine whether this is a vacuous expression as defined in the XQuery update specification- Overrides:
isVacuousExpression
in classExpression
- Returns:
- true if this expression is vacuous
-
copy
public Expression copy(RebindingMap rebindings)
Description copied from class:Expression
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- a mutable list of (old binding, new binding) pairs that is used to update the bindings held in any local variable references that are copied.- Returns:
- the copy of the original expression
-
getObjectName
public StructuredQName getObjectName()
Description copied from interface:Traceable
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc. This is used only where the name is known statically.- Specified by:
getObjectName
in interfaceTraceable
- Overrides:
getObjectName
in classExpression
- Returns:
- the QName of the object declared or manipulated by this instruction or expression
-
equals
public boolean equals(java.lang.Object other)
Is this expression the same as another expression?- Overrides:
equals
in classExpression
- Parameters:
other
- the expression to be compared with this one- Returns:
- true if the two expressions are statically equivalent
-
computeHashCode
protected int computeHashCode()
Hashcode supporting equals()- Overrides:
computeHashCode
in classExpression
- Returns:
- a computed hash code
-
getProperty
public java.lang.Object getProperty(java.lang.String name)
- Overrides:
getProperty
in classExpression
-
getProperties
public java.util.Iterator<java.lang.String> getProperties()
Description copied from class:Expression
Get an iterator over all the properties available. The values returned by the iterator will be of type String, and each string can be supplied as input to the getProperty() method to retrieve the value of the property. The iterator may return properties whose value is null.- Overrides:
getProperties
in classExpression
- Returns:
- an iterator over the properties
-
addToPathMap
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Description copied from class:Expression
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression.
- Overrides:
addToPathMap
in classExpression
- Parameters:
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the PathMapNodeSet to which the paths embodied in this expression should be added- Returns:
- the pathMapNodeSet representing the points in the source document that are both reachable by this expression, and that represent possible results of this expression. For an expression that does navigation, it represents the end of the arc in the path map that describes the navigation route. For other expressions, it is the same as the input pathMapNode.
-
isSubtreeExpression
public boolean isSubtreeExpression()
Description copied from class:Expression
Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node.- Overrides:
isSubtreeExpression
in classExpression
- Returns:
- true if the expression has no dependencies on the context node, or if the only dependencies on the context node are downward selections using the self, child, descendant, attribute, and namespace axes.
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
Description copied from class:Expression
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.- Overrides:
iterate
in classExpression
- Parameters:
context
- supplies the context for evaluation- Returns:
- a SequenceIterator that can be used to iterate over the result of the expression
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
evaluateItem
public Item evaluateItem(XPathContext context) throws XPathException
Description copied from class:Expression
Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.- Overrides:
evaluateItem
in classExpression
- Parameters:
context
- The context in which the expression is to be evaluated- Returns:
- the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
effectiveBooleanValue
public boolean effectiveBooleanValue(XPathContext context) throws XPathException
Description copied from class:Expression
Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.- Overrides:
effectiveBooleanValue
in classExpression
- Parameters:
context
- The context in which the expression is to be evaluated- Returns:
- the effective boolean value
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
-