Class FLWORExpression
- All Implemented Interfaces:
Serializable
,SourceLocator
,LocationProvider
,SaxonLocator
,InstructionInfo
,Locator
- See Also:
-
Field Summary
FieldsFields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, WATCH_METHOD
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Check to ensure that this expression does not contain any inappropriate updating subexpressions.protected int
Compute the static cardinality of this expressioncopy()
Copy an expression.void
evaluatePendingUpdates
(XPathContext context, PendingUpdateList pul) Evaluate an updating expression, adding the results to a Pending Update List.void
Diagnostic print of expression structure.Get the list of clauses of the FLWOR expression, in the order they are written.int
Determine the data type of the items returned by the expression.Get the return clause of the FLWOR expressionboolean
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedlyboolean
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
Determine whether this expression implements its own method for static type checkingboolean
Determine whether this is an updating expression as defined in the XQuery update specificationSequenceIterator
<? extends Item> iterate
(XPathContext context) Return an Iterator to iterate over the values of a sequence.Get the immediate sub-expressions of this expression.optimize
(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) Perform optimisation of an expression and its subexpressions.void
process
(XPathContext context) Process the instruction, without returning any tail callspromote
(PromotionOffer offer, Expression parent) Promote this expression if possibleboolean
replaceSubExpression
(Expression original, Expression replacement) Replace one subexpression by a replacement subexpressionsimplify
(ExpressionVisitor visitor) Simplify an expression.staticTypeCheck
(SequenceType req, boolean backwardsCompatible, RoleLocator role, TypeCheckerEnvironment 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 conditionaltoString()
Display the expression as a stringtypeCheck
(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) Perform type checking of an expression and its subexpressions.Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkPermittedContents, computeDependencies, computeSpecialProperties, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, getCardinality, getColumnNumber, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getExpressionName, getHostLanguage, getImplementationMethod, getIntegerBounds, getIntrinsicDependencies, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getObjectName, getProperties, getProperty, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, isSubtreeExpression, isVacuousExpression, iterateEvents, iterateSameFocusSubExpressions, markTailFunctionCalls, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, suppressValidation, typeError
-
Field Details
-
clauses
-
returnClause
-
-
Constructor Details
-
FLWORExpression
-
-
Method Details
-
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
-
hasLoopingSubexpression
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly- Overrides:
hasLoopingSubexpression
in classExpression
- Parameters:
child
- the immediate subexpression- Returns:
- true if the child expression is evaluated repeatedly
-
getReturnClause
Get the return clause of the FLWOR expression- Returns:
- the expression contained in the return clause
-
hasVariableBinding
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
-
simplify
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
- Parameters:
visitor
- an expression visitor- Returns:
- the simplified expression
- Throws:
XPathException
- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) 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.
- Overrides:
typeCheck
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 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, RoleLocator role, TypeCheckerEnvironment 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 appliesrole
- 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
Determine the data type of the items returned by the expression.- Specified by:
getItemType
in classExpression
- Parameters:
th
- the type hierarchy cache- 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
-
iterateSubExpressions
Get the immediate sub-expressions of this expression.- Overrides:
iterateSubExpressions
in classExpression
- Returns:
- an iterator containing the sub-expressions of this expression
-
checkForUpdatingSubexpressions
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
-
replaceSubExpression
Replace one subexpression by a replacement subexpression- Overrides:
replaceSubExpression
in classExpression
- Parameters:
original
- the original subexpressionreplacement
- the replacement subexpression- Returns:
- true if the original subexpression is found
-
explain
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
explain
in classExpression
- Parameters:
out
- the expression presenter used to display the structure
-
copy
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Returns:
- the copy of the original expression
-
promote
Promote this expression if possible- Overrides:
promote
in classExpression
- Parameters:
offer
- details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expressionparent
- the containing expression in the expression tree- Returns:
- if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
- Throws:
XPathException
- if any error is detected
-
getEvaluationMethod
public int getEvaluationMethod()- Overrides:
getEvaluationMethod
in classExpression
-
optimize
public Expression optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType 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
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
Process the instruction, without returning any tail calls- Overrides:
process
in classExpression
- Parameters:
context
- 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 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 failsUnsupportedOperationException
- if the expression is not an updating expression
-
toString
Display the expression as a string- Overrides:
toString
in classExpression
- Returns:
- a representation of the expression as a string
-
hasLoopingVariableReference
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.
-