net.sf.saxon.expr

Class LetExpression

public class LetExpression extends Assignation implements TailCallReturner

A LetExpression is modelled on the XQuery syntax let $x := expr return expr. This syntax is not available in the surface XPath language, but it is used internally in an optimized expression tree.
Field Summary
intrefCount
Constructor Summary
LetExpression()
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
intcomputeSpecialProperties()
Get the static properties of this expression (other than its type).
voiddisplay(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure
protected ValueRepresentationeval(XPathContext context)
Evaluate the variable.
ItemevaluateItem(XPathContext context)
Evaluate the expression as a singleton
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible
SequenceIteratoriterate(XPathContext context)
Iterate over the sequence of values
booleanmarkTailFunctionCalls()
Mark tail function calls
Expressionoptimize(Optimizer opt, StaticContext env, ItemType contextItemType)
Perform optimisation of an expression and its subexpressions.
voidprocess(XPathContext context)
Process this expression as an instruction, writing results to the current outputter
TailCallprocessLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction.
Expressionpromote(PromotionOffer offer)
Promote this expression if possible
ExpressiontypeCheck(StaticContext env, ItemType contextItemType)
Type-check the expression

Field Detail

refCount

int refCount

Constructor Detail

LetExpression

public LetExpression()

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

computeSpecialProperties

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

display

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

eval

protected ValueRepresentation eval(XPathContext context)
Evaluate the variable. (This is overridden in a subclass).

evaluateItem

public Item evaluateItem(XPathContext context)
Evaluate the expression as a singleton

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)

iterate

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

markTailFunctionCalls

public boolean markTailFunctionCalls()
Mark tail function calls

optimize

public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType)
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.

Parameters: opt the optimizer in use. This provides access to supporting functions; it also allows different optimization strategies to be used in different circumstances. env the static context of the expression contextItemType 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 to ITEM_TYPE

Returns: the original expression, rewritten if appropriate to optimize execution

Throws: net.sf.saxon.trans.StaticError if an error is discovered during this phase (typically a type error)

process

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

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
ProcessLeavingTail: called to do the real work of this instruction. The results of the instruction are written to the current Receiver, which can be obtained via the Controller.

Parameters: context The dynamic context of the transformation, giving access to the current node, the current variables, etc.

Returns: null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.

promote

public Expression promote(PromotionOffer offer)
Promote this expression if possible

typeCheck

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