Class FLWORExpression
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.flwor.FLWORExpression
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
public class FLWORExpression extends Expression
This class represents a FLWOR expression, evaluated using tuple streams
-
-
Field Summary
Fields Modifier and Type Field Description java.util.List<Clause>
clauses
Operand
returnClauseOp
PushEvaluator
returnPushEvaluator
-
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 FLWORExpression()
-
Method Summary
All Methods Static 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.boolean
allowExtractingCommonSubexpressions()
Ask whether common subexpressions found in the operands of this expression can be extracted and evaluated outside the expression itself.void
checkForUpdatingSubexpressions()
Check to ensure that this expression does not contain any inappropriate updating subexpressions.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.Expression
copy(RebindingMap rebindings)
Copy an expression.void
export(ExpressionPresenter out)
Diagnostic print of expression structure.java.util.List<Clause>
getClauseList()
Get the list of clauses of the FLWOR expression, in the order they are written.Elaborator
getElaborator()
Make an elaborator for this expressionint
getEvaluationMethod()
java.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().ItemType
getItemType()
Determine the data type of the items returned by the expression.Expression
getReturnClause()
Get the return clause of the FLWOR expressionPushEvaluator
getReturnPushEvaluator()
Get a push-evaluator for the return clause (used from bytecode)boolean
hasLoopingVariableReference(Binding binding)
Determine whether a variable reference found within a clause of a FLWOR expression is a looping reference, that is, whether the variable is used more than onceboolean
hasVariableBinding(Binding binding)
Determine whether a given variable binding belongs to this FLWOR expressionboolean
implementsStaticTypeCheck()
Determine whether this expression implements its own method for static type checkingvoid
init(java.util.List<Clause> clauses, Expression returnClause)
void
injectCode(CodeInjector injector)
Inject tracing (or other monitoring) code for each clausestatic boolean
isLoopingClause(Clause c)
boolean
isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specificationSequenceIterator
iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.java.lang.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.Expression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Perform optimisation of an expression and its subexpressions.void
process(Outputter output, XPathContext context)
Process the instruction, without returning any tail callsExpression
simplify()
Simplify an expression.Expression
staticTypeCheck(SequenceType req, boolean backwardsCompatible, java.util.function.Supplier<RoleDiagnostic> roleSupplier, ExpressionVisitor visitor)
Static type checking for let expressions is delegated to the expression itself, and is performed on the "return" expression, to allow further delegation to the branches of a conditionaljava.lang.String
toShortString()
Produce a short string identifying the expression for use in error messagesjava.lang.String
toString()
Display the expression as a stringExpression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform type checking of an expression and its subexpressions.Expression
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.Expression
adoptChildExpression, checkedOperands, checkPermittedContents, computeHashCode, computeSpecialProperties, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, evaluateAsString, evaluateItem, explain, getCardinality, getConfiguration, getCost, getDependencies, getExtraProperty, getIntegerBounds, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, identityHashCode, isCallOn, isEqual, isIdentical, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplifyChildren, supportsLazyEvaluation, suppressValidation, toPattern, typeCheckChildren, typeError, verifyParentPointers, withLocation
-
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
-
-
-
-
Field Detail
-
clauses
public java.util.List<Clause> clauses
-
returnClauseOp
public Operand returnClauseOp
-
returnPushEvaluator
public PushEvaluator returnPushEvaluator
-
-
Method Detail
-
init
public void init(java.util.List<Clause> clauses, Expression returnClause)
-
getClauseList
public java.util.List<Clause> getClauseList()
Get the list of clauses of the FLWOR expression, in the order they are written. This excludes the return clause- Returns:
- the list of clauses
-
isLoopingClause
public static boolean isLoopingClause(Clause c)
-
getReturnClause
public Expression getReturnClause()
Get the return clause of the FLWOR expression- Returns:
- the expression contained in the return clause
-
getReturnPushEvaluator
public PushEvaluator getReturnPushEvaluator()
Get a push-evaluator for the return clause (used from bytecode)
-
hasVariableBinding
public boolean hasVariableBinding(Binding binding)
Determine whether a given variable binding belongs to this FLWOR expression- Overrides:
hasVariableBinding
in classExpression
- Parameters:
binding
- the binding being sought- Returns:
- true if this binding belongs to one of the clauses of this FLWOR expression
-
allowExtractingCommonSubexpressions
public boolean allowExtractingCommonSubexpressions()
Ask whether common subexpressions found in the operands of this expression can be extracted and evaluated outside the expression itself. The result is irrelevant in the case of operands evaluated with a different focus, which will never be extracted in this way, even if they have no focus dependency.- Overrides:
allowExtractingCommonSubexpressions
in classExpression
- Returns:
- false for this kind of expression
-
simplify
public Expression simplify() throws XPathException
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.- Overrides:
simplify
in classExpression
- Returns:
- the simplified expression (or the original if unchanged, or if modified in-situ)
- Throws:
XPathException
- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Perform type checking of an expression and its subexpressions. This is the second phase of static optimization.This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.
If the implementation returns a value other than "this", then it is required to ensure that the location information in the returned expression have been set up correctly. It should not rely on the caller to do this, although for historical reasons many callers do so.
param visitor an expression visitor- Overrides:
typeCheck
in classExpression
- Parameters:
contextInfo
- static information about the dynamic contextvisitor
- an expression visitor- 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)
-
implementsStaticTypeCheck
public boolean implementsStaticTypeCheck()
Determine whether this expression implements its own method for static type checking- Overrides:
implementsStaticTypeCheck
in classExpression
- Returns:
- true - this expression has a non-trivial implementation of the staticTypeCheck() method
-
staticTypeCheck
public Expression staticTypeCheck(SequenceType req, boolean backwardsCompatible, java.util.function.Supplier<RoleDiagnostic> roleSupplier, ExpressionVisitor visitor) throws XPathException
Static type checking for let expressions is delegated to the expression itself, and is performed on the "return" expression, to allow further delegation to the branches of a conditional- Overrides:
staticTypeCheck
in classExpression
- Parameters:
req
- the required typebackwardsCompatible
- true if backwards compatibility mode appliesroleSupplier
- the role of the expression in relation to the required typevisitor
- an expression visitor- Returns:
- the expression after type checking (perhaps augmented with dynamic type checking code)
- Throws:
XPathException
- if failures occur, for example if the static type of one branch of the conditional is incompatible with the required type
-
getItemType
public ItemType getItemType()
Determine the data type of the items returned by the expression.- 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)
-
computeCardinality
protected int computeCardinality()
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
-
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
-
operands
public java.lang.Iterable<Operand> operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation returns a zero-length array, appropriate for an expression that has no sub-expressions.- Overrides:
operands
in classExpression
- Returns:
- an iterator containing the sub-expressions of this expression
-
checkForUpdatingSubexpressions
public void checkForUpdatingSubexpressions() throws XPathException
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 updateing subexpression
-
isUpdatingExpression
public boolean isUpdatingExpression()
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
-
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.- Specified by:
getImplementationMethod
in classExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
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.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.
-
injectCode
public void injectCode(CodeInjector injector)
Inject tracing (or other monitoring) code for each clause- Parameters:
injector
- the code injector responsible for processing each clause of the FLWOR expression
-
export
public void export(ExpressionPresenter out) throws XPathException
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.
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- variable bindings to be replaced- Returns:
- the copy of the original expression
-
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
-
getEvaluationMethod
public int getEvaluationMethod()
- Overrides:
getEvaluationMethod
in classExpression
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Description copied from class:Expression
Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.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 classExpression
- 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)
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
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
-
process
public void process(Outputter output, XPathContext context) throws XPathException
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
-
getExpressionName
public java.lang.String getExpressionName()
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.
-
toShortString
public java.lang.String toShortString()
Produce a short string identifying the expression for use in error messages- Overrides:
toShortString
in classExpression
- Returns:
- a short string, sufficient to identify the expression
-
toString
public java.lang.String toString()
Display the expression as a string- Overrides:
toString
in classExpression
- Returns:
- a representation of the expression as a string
-
hasLoopingVariableReference
public boolean hasLoopingVariableReference(Binding binding)
Determine whether a variable reference found within a clause of a FLWOR expression is a looping reference, that is, whether the variable is used more than once- Parameters:
binding
- the variable binding, which may be bound in a clause of the same FLWOR expression, or in some containing expression- Returns:
- true if a reference to the variable occurs within a loop relative to the binding, that is, if the variable's value is used more than once. Note that this method only detects a loop that is due to the clauses of this FLWOR expression itself. A loop in an inner expression or outer expression of the FLWOR expression must be detected by the caller.
-
getElaborator
public Elaborator getElaborator()
Make an elaborator for this expression- Overrides:
getElaborator
in classExpression
- Returns:
- an appropriate
Elaborator
-
-