net.sf.saxon.expr

Class ForExpression

Implemented Interfaces:
Binding, EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator

public class ForExpression
extends Assignation

A ForExpression maps an expression over a sequence. This version works with range variables, it doesn't change the context information

Field Summary

Fields inherited from class net.sf.saxon.expr.Assignation

action, requiredType, sequence, slotNumber, variableName

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

ForExpression()
Create a "for" expression (for $x at $p in SEQUENCE return ACTION)

Method Summary

void
checkPermittedContents(SchemaType parentType, StaticContext env, 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.
int
computeCardinality()
Determine the static cardinality of the expression
Expression
convertWhereToPredicate(ExpressionVisitor visitor, ItemType contextItemType)
Convert where clause, if possible, to a predicate.
Expression
copy()
Copy an expression.
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
protected Binding[]
extendBindingList(Binding[] in)
Extend an array of variable bindings to include the binding(s) defined in this expression
protected int
getConstructType()
Get the type of this expression for use in tracing and diagnostics
int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
ItemType
getItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible
StructuredQName
getPositionVariableName()
Get the name of the position variable
int
getRequiredSlots()
Get the number of slots required.
boolean
hasLoopingSubexpression(Expression child)
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
SequenceIterator
iterate(XPathContext context)
Iterate over the sequence of values
EventIterator
iterateEvents(XPathContext context)
Deliver the result of the expression as a sequence of events.
int
markTailFunctionCalls(StructuredQName qName, int arity)
Mark tail function calls: only possible if the for expression iterates zero or one times.
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
Optimize the expression
void
process(XPathContext context)
Process this expression as an instruction, writing results to the current outputter
void
setPositionVariable(PositionVariable decl)
Set the reference to the position variable (XQuery only)
void
setSlotNumber(int nr)
Set the slot number for the range variable
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

Methods inherited from class net.sf.saxon.expr.Assignation

addToPathMap, evaluateVariable, extendBindingList, getAction, getLocalSlotNumber, getRequiredSlots, getRequiredType, getSequence, getVariableName, getVariableQName, isAssignable, isGlobal, iterateSubExpressions, promote, promoteWhereClause, refineTypeInformation, replaceSubExpression, setAction, setRequiredType, setSequence, setSlotNumber, setVariableQName, simplify, suppressValidation

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Constructor Details

ForExpression

public ForExpression()
Create a "for" expression (for $x at $p in SEQUENCE return ACTION)

Method Details

checkPermittedContents

public void checkPermittedContents(SchemaType parentType,
                                   StaticContext env,
                                   boolean whole)
            throws XPathException
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 interface Expression

computeCardinality

public int computeCardinality()
Determine the static cardinality of the expression
Overrides:
computeCardinality in interface Expression

convertWhereToPredicate

public Expression convertWhereToPredicate(ExpressionVisitor visitor,
                                          ItemType contextItemType)
            throws XPathException
Convert where clause, if possible, to a predicate.
Parameters:
visitor - the expression visitor
contextItemType - the item type of the context item
Returns:
the converted expression if modified, or null otherwise

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
Returns:
the copy of the original expression

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
Overrides:
explain in interface Expression

extendBindingList

protected Binding[] extendBindingList(Binding[] in)
Extend an array of variable bindings to include the binding(s) defined in this expression
Overrides:
extendBindingList in interface Assignation

getConstructType

protected int getConstructType()
Get the type of this expression for use in tracing and diagnostics
Overrides:
getConstructType in interface Expression
Returns:
the type of expression, as enumerated in class Location

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. This implementation provides both iterate() and process() methods natively.
Overrides:
getImplementationMethod in interface Expression

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible
Overrides:
getItemType in interface Expression
Parameters:
th - the type hierarchy cache
Returns:
one of the values Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known in advance)

getPositionVariableName

public StructuredQName getPositionVariableName()
Get the name of the position variable
Returns:
the name of the position variable ("at $p") if there is one, or null if not

getRequiredSlots

public int getRequiredSlots()
Get the number of slots required.
Overrides:
getRequiredSlots in interface Assignation
Returns:
normally 1, except for a FOR expression with an AT clause, where it is 2.

hasLoopingSubexpression

public boolean hasLoopingSubexpression(Expression child)
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 interface Expression
Parameters:
child - the immediate subexpression
Returns:
true if the child expression is evaluated repeatedly

iterate

public SequenceIterator iterate(XPathContext context)
            throws XPathException
Iterate over the sequence of values
Specified by:
iterate in interface SequenceIterable
Overrides:
iterate in interface Expression

iterateEvents

public EventIterator iterateEvents(XPathContext context)
            throws XPathException
Deliver the result of the expression as a sequence of events.
Overrides:
iterateEvents in interface Expression
Parameters:
context - The dynamic evaluation context
Returns:
the result of the expression as an iterator over a sequence of PullEvent objects
Throws:
XPathException - if a dynamic error occurs during expression evaluation

markTailFunctionCalls

public int markTailFunctionCalls(StructuredQName qName,
                                 int arity)
Mark tail function calls: only possible if the for expression iterates zero or one times. (This arises in XSLT/XPath, which does not have a LET expression, so FOR gets used instead)
Overrides:
markTailFunctionCalls in interface Expression

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
            throws XPathException
Optimize the expression
Overrides:
optimize in interface Expression

process

public void process(XPathContext context)
            throws XPathException
Process this expression as an instruction, writing results to the current outputter
Overrides:
process in interface Expression

setPositionVariable

public void setPositionVariable(PositionVariable decl)
Set the reference to the position variable (XQuery only)
Parameters:
decl - the range variable declaration for the position variable

setSlotNumber

public void setSlotNumber(int nr)
Set the slot number for the range variable
Overrides:
setSlotNumber in interface Assignation
Parameters:
nr - the slot number allocated to the range variable on the local stack frame. This implicitly allocates the next slot number to the position variable if there is one.

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Type-check the expression
Overrides:
typeCheck in interface Expression