Package net.sf.saxon.expr
Class SlashExpression
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.BinaryExpression
-
- net.sf.saxon.expr.SlashExpression
-
- All Implemented Interfaces:
ContextOriginator
,ContextSwitchingExpression
,ExportAgent
,Locatable
,IdentityComparable
,Traceable
- Direct Known Subclasses:
SimpleStepExpression
public class SlashExpression extends BinaryExpression implements ContextSwitchingExpression
A slash expression is any expression using the binary slash operator "/". The parser initially generates a slash expression for all occurrences of the binary "/" operator, wrapped in a documentSort() function to do the sorting and de-duplication required by the semantics of path expressions. The documentSort() is subsequently stripped off by the optimizer if sorting and deduplication is found to be unnecessary. The slash expression itself, therefore, does not perform sorting or de-duplication.
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.BinaryExpression
operator
-
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 SlashExpression(Expression start, Expression step)
Constructor
-
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.protected int
computeCardinality()
Determine the static cardinality of the expressionprotected int
computeHashCode()
get HashCode for comparing two expressionsprotected int
computeSpecialProperties()
Get the static properties of this expression (other than its type).Expression
copy(RebindingMap rebindings)
Copy an expression.void
disableIndexing()
boolean
equals(java.lang.Object other)
Is this expression the same as another expression?void
export(ExpressionPresenter destination)
Diagnostic print of expression structure.Expression
getActionExpression()
Get the step expression (the right-hand operand)double
getCost()
Return the estimated cost of evaluating an expression.java.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.Expression
getFirstStep()
Get the first step in this expression.int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().IntegerValue[]
getIntegerBounds()
For an expression that returns an integer or a sequence of integers, get a lower and upper bound on the values of the integers that may be returned, from static analysis.ItemType
getItemType()
Determine the data type of the items returned by this exprssionExpression
getLastStep()
Get the last step of the path expressionExpression
getLeadingSteps()
Get a path expression consisting of all steps except the lastprotected OperandRole
getOperandRole(int arg)
Get the operand roleExpression
getRemainingSteps()
Get all steps after the first.Expression
getSelectExpression()
Get the start expression (the left-hand operand)Expression
getStart()
Get the left-hand operandUType
getStaticUType(UType contextItemType)
Get the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.Expression
getStep()
Get the right-hand operandjava.lang.String
getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expressionboolean
isAbsolute()
Test whether a path expression is an absolute path - that is, a path whose first step selects a document nodeboolean
isContextFree()
A SlashExpression is context free if the right-hand argument is an AxisExpression.SequenceIterator
iterate(XPathContext context)
Iterate the path-expression in a given contextExpression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Perform optimisation of an expression and its subexpressions.void
setContextFree(boolean free)
Mark this expression as being context free (or not).void
setStart(Expression start)
Set the left-hand operandvoid
setStep(Expression step)
Set the right-hand operandSlashExpression
simplifyDescendantPath(StaticContext env)
Pattern
toPattern(Configuration config)
Convert this expression to an equivalent XSLT patternjava.lang.String
toShortString()
Produce a short string identifying the expression for use in error messagesjava.lang.String
toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath.SlashExpression
tryToMakeAbsolute()
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node; if not, see if it can be converted to an absolute path.Expression
tryToMakeSorted(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Expression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Type-check the expressionExpression
unordered(boolean retainAllNodes, boolean forStreaming)
Replace this expression by a simpler expression that delivers the results without regard to order.-
Methods inherited from class net.sf.saxon.expr.BinaryExpression
displayOperator, explainExtraAttributes, getLhs, getLhsExpression, getOperator, getRhs, getRhsExpression, isAssociative, isCommutative, isInverse, operands, setFlattened, setLhsExpression, setRhsExpression, tag
-
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getDependencies, getEvaluationMethod, getExtraProperty, getInterpretedExpression, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, typeCheckChildren, typeError, 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
-
SlashExpression
public SlashExpression(Expression start, Expression step)
Constructor- Parameters:
start
- The left hand operand (which must always select a sequence of nodes).step
- The step to be followed from each node in the start expression to yield a new sequence; this may return either nodes or atomic values (but not a mixture of the two)
-
-
Method Detail
-
getOperandRole
protected OperandRole getOperandRole(int arg)
Description copied from class:BinaryExpression
Get the operand role- Overrides:
getOperandRole
in classBinaryExpression
- Parameters:
arg
- which argument: 0 for the lhs, 1 for the rhs- Returns:
- the operand role
-
getStart
public Expression getStart()
Get the left-hand operand- Returns:
- the left-hand operand
-
setStart
public void setStart(Expression start)
Set the left-hand operand- Parameters:
start
- the left-hand operand
-
getStep
public Expression getStep()
Get the right-hand operand- Returns:
- the right-hand operand
-
setStep
public void setStep(Expression step)
Set the right-hand operand- Parameters:
step
- the right-hand operand
-
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.
-
getSelectExpression
public Expression getSelectExpression()
Get the start expression (the left-hand operand)- Specified by:
getSelectExpression
in interfaceContextSwitchingExpression
- Returns:
- the first operand
-
getActionExpression
public Expression getActionExpression()
Get the step expression (the right-hand operand)- Specified by:
getActionExpression
in interfaceContextSwitchingExpression
- Returns:
- the second operand
-
disableIndexing
public void disableIndexing()
-
getItemType
public final ItemType getItemType()
Determine the data type of the items returned by this exprssion- Specified by:
getItemType
in classExpression
- Returns:
- the type of the step
-
getStaticUType
public UType getStaticUType(UType contextItemType)
Get the static type of the expression as a UType, following precisely the type inference rules defined in the XSLT 3.0 specification.- Overrides:
getStaticUType
in classExpression
- Parameters:
contextItemType
- the static type of the context item- Returns:
- the static item type of the expression according to the XSLT 3.0 defined rules
-
getIntegerBounds
public IntegerValue[] getIntegerBounds()
For an expression that returns an integer or a sequence of integers, get a lower and upper bound on the values of the integers that may be returned, from static analysis. The default implementation returns null, meaning "unknown" or "not applicable". Other implementations return an array of two IntegerValue objects, representing the lower and upper bounds respectively. The values UNBOUNDED_LOWER and UNBOUNDED_UPPER are used by convention to indicate that the value may be arbitrarily large. The values MAX_STRING_LENGTH and MAX_SEQUENCE_LENGTH are used to indicate values limited by the size of a string or the size of a sequence.- Overrides:
getIntegerBounds
in classExpression
- Returns:
- the lower and upper bounds of integer values in the result, or null to indicate unknown or not applicable.
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Type-check the expression- Overrides:
typeCheck
in classBinaryExpression
- Parameters:
visitor
- an expression visitorcontextInfo
- Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.- Returns:
- the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
simplifyDescendantPath
public SlashExpression simplifyDescendantPath(StaticContext env)
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Description copied from class:BinaryExpression
Perform optimisation of an expression and its subexpressions.This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
- Overrides:
optimize
in classBinaryExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
tryToMakeAbsolute
public SlashExpression tryToMakeAbsolute()
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node; if not, see if it can be converted to an absolute path. This is possible in cases where the path expression has the form a/b/c and it is known that the context item is a document node; in this case it is safe to change the path expression to /a/b/c- Returns:
- the path expression if it is absolute; the converted path expression if it can be made absolute; or null if neither condition applies.
-
getCost
public double getCost()
Return the estimated cost of evaluating an expression. This is a very crude measure based on the syntactic form of the expression (we have no knowledge of data values). We take the cost of evaluating a simple scalar comparison or arithmetic expression as 1 (one), and we assume that a sequence has length 5. The resulting estimates may be used, for example, to reorder the predicates in a filter expression so cheaper predicates are evaluated first.- Overrides:
getCost
in classExpression
- Returns:
- the cost estimate
-
tryToMakeSorted
public Expression tryToMakeSorted(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
- Throws:
XPathException
-
unordered
public Expression unordered(boolean retainAllNodes, boolean forStreaming) throws XPathException
Replace this expression by a simpler expression that delivers the results without regard to order.- Overrides:
unordered
in classExpression
- Parameters:
retainAllNodes
- set to true if the result must contain exactly the same nodes as the original; set to false if the result can eliminate (or introduce) duplicates.forStreaming
- set to true if optimizing for streaming- Returns:
- an expression that delivers the same nodes in a more convenient order
- Throws:
XPathException
- if the rewrite fails
-
addToPathMap
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
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.- 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 pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter expression
-
getImplementationMethod
public int getImplementationMethod()
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.- Overrides:
getImplementationMethod
in classBinaryExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- variables that need to be re-bound- Returns:
- the copy of the original expression
-
computeSpecialProperties
protected int computeSpecialProperties()
Get the static properties of this expression (other than its type). The result is bit-signficant. These properties are used for optimizations. In general, if property bit is set, it is true, but if it is unset, the value is unknown.- Overrides:
computeSpecialProperties
in classBinaryExpression
- Returns:
StaticProperty.NO_NODES_NEWLY_CREATED
. This is overridden for some subclasses.
-
computeCardinality
protected int computeCardinality()
Determine the static cardinality of the expression- Overrides:
computeCardinality
in classBinaryExpression
- 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.
-
toPattern
public Pattern toPattern(Configuration config) throws XPathException
Convert this expression to an equivalent XSLT pattern- Overrides:
toPattern
in classExpression
- Parameters:
config
- the Saxon configuration- Returns:
- the equivalent pattern
- Throws:
XPathException
- if conversion is not possible
-
isContextFree
public boolean isContextFree()
A SlashExpression is context free if the right-hand argument is an AxisExpression. This allows evaluation without creating a new XPathContext or FocusTrackingIterator; the expression can be evaluated as a simple flat-mapping function from nodes to nodes.- Returns:
- true if the expression has been assessed as context-free, that is, if the right-hand operand is an AxisExpression
-
setContextFree
public void setContextFree(boolean free)
Mark this expression as being context free (or not). This is done during reloading from a SEF file.- Parameters:
free
- true if the expression has been assessed as context-free, that is, if the right-hand operand is an AxisExpression
-
equals
public boolean equals(java.lang.Object other)
Is this expression the same as another expression?- Overrides:
equals
in classBinaryExpression
- Parameters:
other
- the other operand; the result is false if this is not an Expression- Returns:
- true if the other operand is an expression and if it can be determined that the two expressions are equivalent, in the sense that they will always return the same result.
-
computeHashCode
protected int computeHashCode()
get HashCode for comparing two expressions- Overrides:
computeHashCode
in classBinaryExpression
- Returns:
- a computed hash code
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
Iterate the path-expression in a given context- Overrides:
iterate
in classExpression
- Parameters:
context
- the evaluation context- 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
-
export
public void export(ExpressionPresenter destination) throws XPathException
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Overrides:
export
in classBinaryExpression
- Parameters:
destination
- the output destination for the displayed expression tree- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
toString
public java.lang.String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax- Overrides:
toString
in classBinaryExpression
- Returns:
- a representation of the expression as a string
-
toShortString
public java.lang.String toShortString()
Description copied from class:Expression
Produce a short string identifying the expression for use in error messages- Overrides:
toShortString
in classBinaryExpression
- Returns:
- a short string, sufficient to identify the expression
-
getFirstStep
public Expression getFirstStep()
Get the first step in this expression. A path expression A/B/C is represented as (A/B)/C, but the first step is A- Returns:
- the first step in the expression, after expanding any nested path expressions
-
getRemainingSteps
public Expression getRemainingSteps()
Get all steps after the first. This is complicated by the fact that A/B/C is represented as ((A/B)/C; we are required to return B/C- Returns:
- a path expression containing all steps in this path expression other than the first, after expanding any nested path expressions
-
getLastStep
public Expression getLastStep()
Get the last step of the path expression- Returns:
- the last step in the expression, after expanding any nested path expressions
-
getLeadingSteps
public Expression getLeadingSteps()
Get a path expression consisting of all steps except the last- Returns:
- a path expression containing all steps in this path expression other than the last, after expanding any nested path expressions
-
isAbsolute
public boolean isAbsolute()
Test whether a path expression is an absolute path - that is, a path whose first step selects a document node- Returns:
- true if the first step in this path expression selects a document node
-
getStreamerName
public java.lang.String getStreamerName()
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerName
in classExpression
- Returns:
- the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
-
-