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.
addReference
public void addReference(VariableReference v)
Register a variable reference that refers to the variable bound in this let expression
v
- the variable reference
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.
- checkPermittedContents in interface Expression
computeCardinality
public int computeCardinality()
Determine the static cardinality of the expression
- computeCardinality in interface 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.
- computeSpecialProperties in interface Expression
copy
public Expression copy()
Copy an expression. This makes a deep copy.
- copy in interface Expression
- 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.
- explain in interface Expression
getItemType
public ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by the expression, if possible
- getItemType in interface Expression
th
- the type hierarchy cache
- one of the values Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE,
or Type.ITEM (meaning not known in advance)
getNominalReferenceCount
public int getNominalReferenceCount()
Get the (nominal) count of the number of references to this variable
- zero if there are no references, one if there is a single reference that is not in
a loop, some higher number if there are multiple references (or a single reference in a loop),
or the special value @link RangeVariable#FILTERED} if there are any references
in filter expressions that require searching.
implementsStaticTypeCheck
public boolean implementsStaticTypeCheck()
Determine whether this expression implements its own method for static type checking
- implementsStaticTypeCheck in interface Expression
- true - this expression has a non-trivial implementation of the staticTypeCheck()
method
isIndexedVariable
public boolean isIndexedVariable()
Test whether the variable bound by this let expression should be indexable
- true if the variable should be indexable
optimize
public Expression optimize(ExpressionVisitor visitor,
ItemType contextItemType)
throws XPathException
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.
- optimize in interface Expression
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 to
Type.ITEM_TYPE
- the original expression, rewritten if appropriate to optimize execution
XPathException
- if an error is discovered during this phase
(typically a type error)
processLeavingTail
public TailCall processLeavingTail(XPathContext context)
throws XPathException
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.
- processLeavingTail in interface TailCallReturner
context
- The dynamic context of the transformation, giving access to the current node,
the current variables, etc.
- 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.
setIndexedVariable
public void setIndexedVariable()
Indicate that the variable bound by this let expression should be indexable
(because it is used in an appropriate filter expression)
staticTypeCheck
public Expression staticTypeCheck(SequenceType req,
boolean backwardsCompatible,
RoleLocator role,
ExpressionVisitor visitor)
throws XPathException
Static type checking for let expressions is delegated to the expression itself,
and is performed on the "action" expression, to allow further delegation to the branches
of a conditional
- staticTypeCheck in interface Expression
req
- the required typebackwardsCompatible
- true if backwards compatibility mode appliesrole
- the role of the expression in relation to the required typevisitor
- an expression visitor
- the expression after type checking (perhaps augmented with dynamic type checking code)
XPathException
- if failures occur, for example if the static type of one branch of the conditional
is incompatible with the required type