Package net.sf.saxon.expr
Class VariableReference
- java.lang.Object
-
- net.sf.saxon.expr.ComputedExpression
-
- net.sf.saxon.expr.VariableReference
-
- All Implemented Interfaces:
java.io.Serializable
,javax.xml.transform.SourceLocator
,BindingReference
,Container
,Expression
,InstructionInfoProvider
- Direct Known Subclasses:
LocalVariableReference
public class VariableReference extends ComputedExpression implements BindingReference
Variable reference: a reference to a variable. This may be an XSLT-defined variable, a range variable defined within the XPath expression, or a variable defined in some other static context.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Binding
binding
(package private) Value
constantValue
(package private) java.lang.String
displayName
(package private) SequenceType
staticType
-
Fields inherited from class net.sf.saxon.expr.ComputedExpression
locationId, staticProperties
-
Fields inherited from interface net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD
-
-
Constructor Summary
Constructors Constructor Description VariableReference()
VariableReference(VariableDeclaration declaration)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
computeCardinality()
Get the static cardinalityint
computeSpecialProperties()
Determine the special properties of this expressionVariableReference
copy()
Create a clone copy of this VariableReferencevoid
display(int level, java.io.PrintStream out, Configuration config)
Diagnostic print of expression structureboolean
equals(java.lang.Object other)
Test if this expression is the same as another expression.Item
evaluateItem(XPathContext c)
Evaluate an expression as a single item.ValueRepresentation
evaluateVariable(XPathContext c)
void
fixup(Binding binding)
Fix up this variable reference to a Binding object, which enables the value of the variable to be located at run-time.Binding
getBinding()
Get the object bound to the variableint
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().int
getIntrinsicDependencies()
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.ItemType
getItemType(TypeHierarchy th)
Determine the data type of the expression, if possibleint
hashCode()
get HashCode for comparing two expressionsSequenceIterator
iterate(XPathContext c)
Get the value of this variable in a given context.Expression
optimize(Optimizer opt, StaticContext env, ItemType contextItemType)
Type-check the expression.void
process(XPathContext c)
Process the instruction, without returning any tail callsExpression
promote(PromotionOffer offer)
Promote this expression if possiblevoid
refineVariableReference()
Replace this VariableReference where appropriate by a more efficient implementation.void
setStaticType(SequenceType type, Value value, int properties)
Set static type.Expression
typeCheck(StaticContext env, ItemType contextItemType)
Type-check the expression.-
Methods inherited from class net.sf.saxon.expr.ComputedExpression
adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, getCardinality, getColumnNumber, getConstructType, getDependencies, getExecutable, getHostLanguage, getInstructionInfo, getLineNumber, getLocationId, getLocationProvider, getParentExpression, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasBadParentPointer, iterateSubExpressions, markTailFunctionCalls, replaceSubExpression, resetStaticProperties, setLocationId, setParentExpression, setParentExpression, simplify, suppressValidation, typeError
-
-
-
-
Field Detail
-
binding
Binding binding
-
staticType
SequenceType staticType
-
constantValue
Value constantValue
-
displayName
transient java.lang.String displayName
-
-
Constructor Detail
-
VariableReference
public VariableReference()
-
VariableReference
public VariableReference(VariableDeclaration declaration)
Constructor- Parameters:
declaration
- the variable declaration to which this variable refers
-
-
Method Detail
-
copy
public VariableReference copy()
Create a clone copy of this VariableReference
-
setStaticType
public void setStaticType(SequenceType type, Value value, int properties)
Set static type. This is a callback from the variable declaration object. As well as supplying the static type, it may also supply a compile-time value for the variable. As well as the type information, other static properties of the value are supplied: for example, whether the value is an ordered node-set.- Specified by:
setStaticType
in interfaceBindingReference
-
typeCheck
public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException
Type-check the expression. At this stage details of the static type must be known. If the variable has a compile-time value, this is substituted for the variable reference- Specified by:
typeCheck
in interfaceExpression
- Parameters:
env
- the static context of the expressioncontextItemType
- 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:
StaticError
- if an error is discovered during this phase (typically a type error)XPathException
-
optimize
public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException
Type-check the expression. At this stage details of the static type must be known. If the variable has a compile-time value, this is substituted for the variable reference- Specified by:
optimize
in interfaceExpression
- 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 expressioncontextItemType
- 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:
StaticError
- if an error is discovered during this phase (typically a type error)XPathException
-
fixup
public void fixup(Binding binding)
Fix up this variable reference to a Binding object, which enables the value of the variable to be located at run-time.- Specified by:
fixup
in interfaceBindingReference
-
refineVariableReference
public void refineVariableReference()
Replace this VariableReference where appropriate by a more efficient implementation. This can only be done after all slot numbers are allocated. The efficiency is gained by binding the VariableReference directly to a local or global slot, rather than going via the Binding object
-
getItemType
public ItemType getItemType(TypeHierarchy th)
Determine the data type of the expression, if possible- Specified by:
getItemType
in interfaceExpression
- Parameters:
th
-- Returns:
- the type of the variable, if this can be determined statically; otherwise Type.ITEM (meaning not known in advance)
-
computeCardinality
public int computeCardinality()
Get the static cardinality- Specified by:
computeCardinality
in classComputedExpression
-
computeSpecialProperties
public int computeSpecialProperties()
Determine the special properties of this expression- Overrides:
computeSpecialProperties
in classComputedExpression
- Returns:
StaticProperty.NON_CREATIVE
(unless the variable is assignable using saxon:assign)
-
equals
public boolean equals(java.lang.Object other)
Test if this expression is the same as another expression. (Note, we only compare expressions that have the same static and dynamic context).- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
get HashCode for comparing two expressions- Overrides:
hashCode
in classjava.lang.Object
-
getIntrinsicDependencies
public int getIntrinsicDependencies()
Description copied from class:ComputedExpression
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".- Overrides:
getIntrinsicDependencies
in classComputedExpression
- Returns:
- a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
-
promote
public Expression promote(PromotionOffer offer) throws XPathException
Promote this expression if possible- Specified by:
promote
in interfaceExpression
- Overrides:
promote
in classComputedExpression
- 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 expression- 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
-
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 all three methods natively.- Specified by:
getImplementationMethod
in interfaceExpression
- Overrides:
getImplementationMethod
in classComputedExpression
-
iterate
public SequenceIterator iterate(XPathContext c) throws XPathException
Get the value of this variable in a given context.- Specified by:
iterate
in interfaceExpression
- Overrides:
iterate
in classComputedExpression
- Parameters:
c
- the XPathContext which contains the relevant variable bindings- Returns:
- the value of the variable, if it is defined
- Throws:
XPathException
- if the variable is undefined
-
evaluateItem
public Item evaluateItem(XPathContext c) throws XPathException
Description copied from class:ComputedExpression
Evaluate an expression as a single item. This always returns either a single Item or null (denoting the empty sequence). No conversion is done. This method should not be used unless the static type of the expression is a subtype of "item" or "item?": that is, it should not be called if the expression may return a sequence. There is no guarantee that this condition will be detected.- Specified by:
evaluateItem
in interfaceExpression
- Overrides:
evaluateItem
in classComputedExpression
- Parameters:
c
- The context in which the expression is to be evaluated- Returns:
- the node or atomic value that results from evaluating the expression; or null to indicate that the result is an empty sequence
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
process
public void process(XPathContext c) throws XPathException
Description copied from class:ComputedExpression
Process the instruction, without returning any tail calls- Specified by:
process
in interfaceExpression
- Overrides:
process
in classComputedExpression
- Parameters:
c
- The dynamic context, giving access to the current node, the current variables, etc.- Throws:
XPathException
-
evaluateVariable
public ValueRepresentation evaluateVariable(XPathContext c) throws XPathException
- Throws:
XPathException
-
getBinding
public Binding getBinding()
Get the object bound to the variable
-
display
public void display(int level, java.io.PrintStream out, Configuration config)
Diagnostic print of expression structure- Specified by:
display
in interfaceExpression
- Parameters:
level
- indentation level for this expressionout
- Output destination
-
-