net.sf.saxon.expr

Class ForExpression

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
Constructor Summary
ForExpression()
Method Summary
voidcheckPermittedContents(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.
intcomputeCardinality()
Determine the static cardinality of the expression
ExpressionconvertWhereToPredicate(Optimizer opt, StaticContext env, ItemType contextItemType)
Convert where clause, if possible, to a predicate.
voiddisplay(int level, NamePool pool, PrintStream 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 intgetConstructType()
Get the type of this expression for use in tracing and diagnostics
intgetImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible
intgetPositionVariableNameCode()
intgetRequiredSlots()
Get the number of slots required.
SequenceIteratoriterate(XPathContext context)
Iterate over the sequence of values
booleanmarkTailFunctionCalls()
Mark tail function calls: only possible if the for expression iterates zero or one times.
Expressionoptimize(Optimizer opt, StaticContext env, ItemType contextItemType)
Optimize the expression
voidprocess(XPathContext context)
Process this expression as an instruction, writing results to the current outputter
voidsetAction(Expression action)
voidsetPositionVariable(RangeVariableDeclaration decl)
Set the reference to the position variable (XQuery only)
voidsetSlotNumber(int nr)
Set the slot number for the range variable
ExpressiontypeCheck(StaticContext env, ItemType contextItemType)
Type-check the expression

Constructor Detail

ForExpression

public ForExpression()

Method Detail

checkPermittedContents

public 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. 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.

computeCardinality

public int computeCardinality()
Determine the static cardinality of the expression

convertWhereToPredicate

public Expression convertWhereToPredicate(Optimizer opt, StaticContext env, ItemType contextItemType)
Convert where clause, if possible, to a predicate. Returns the converted expression if modified, or null otherwise

display

public void display(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure

extendBindingList

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

getConstructType

protected int getConstructType()
Get the type of this expression for use in tracing and diagnostics

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.

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible

Parameters: th

Returns: one of the values Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known in advance)

getPositionVariableNameCode

public int getPositionVariableNameCode()

getRequiredSlots

public int getRequiredSlots()
Get the number of slots required. Normally 1, except for a FOR expression with an AT clause, where it is 2.

iterate

public SequenceIterator iterate(XPathContext context)
Iterate over the sequence of values

markTailFunctionCalls

public boolean markTailFunctionCalls()
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)

optimize

public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType)
Optimize the expression

process

public void process(XPathContext context)
Process this expression as an instruction, writing results to the current outputter

setAction

public void setAction(Expression action)

setPositionVariable

public void setPositionVariable(RangeVariableDeclaration decl)
Set the reference to the position variable (XQuery only)

setSlotNumber

public void setSlotNumber(int nr)
Set the slot number for the range variable

typeCheck

public Expression typeCheck(StaticContext env, ItemType contextItemType)
Type-check the expression