net.sf.saxon.instruct

Class GeneralVariable

Implemented Interfaces:
Binding, Serializable, SourceLocator, EvaluableItem, InstructionInfoProvider, SequenceIterable, TailCallReturner
Known Direct Subclasses:
Assign, GlobalVariable, LocalParam, LocalVariable, SQLColumn.ColumnInstruction, WithParam

public abstract class GeneralVariable
extends Instruction
implements Binding

This class defines common behaviour across xsl:variable, xsl:param, and xsl:with-param; also saxon:assign

Field Summary

protected int
evaluationMode
protected int
referenceCount
protected int
slotNumber
protected StructuredQName
variableQName

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

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

GeneralVariable()
Create a general variable

Method Summary

Expression
copy()
Copy an expression.
Item
evaluateItem(XPathContext context)
Evaluate an expression as a single item.
void
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
int
getCardinality()
Get the cardinality of the result of this instruction.
int
getEvaluationMode()
Get the evaluation mode of the variable
int
getInstructionNameCode()
Get the name of this instruction (that is xsl:variable, xsl:param etc) for diagnostics
ItemType
getItemType(TypeHierarchy th)
Get the type of the result of this instruction.
int
getLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number.
SequenceType
getRequiredType()
Get the required type of this variable
Expression
getSelectExpression()
Get the expression to which this variable is bound
ValueRepresentation
getSelectValue(XPathContext context)
Evaluate the variable.
int
getSlotNumber()
Get the slot number allocated to this variable
StructuredQName
getVariableQName()
Get the name of this variable
void
init(Expression select, StructuredQName qName)
Initialize the properties of the variable
boolean
isAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element.
boolean
isGlobal()
boolean
isImplicitlyRequiredParam()
Ask whether this variable represents a parameter that is implicitly required, because there is no usable default value
boolean
isRequiredParam()
Ask whether this variable represents a required parameter
boolean
isTunnelParam()
Ask whether this variable represents a tunnel parameter
SequenceIterator
iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
Iterator
iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Expression
optimize(ExpressionVisitor visitor, ItemType contextItemType)
protected void
promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
boolean
replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
void
setAssignable(boolean assignable)
Indicate whether this variable is assignable using saxon:assign
void
setImplicitlyRequiredParam(boolean requiredParam)
Indicate that this variable represents a parameter that is implicitly required (because there is no usable default value)
void
setReferenceCount(int refCount)
Set the nominal number of references to this variable
void
setRequiredParam(boolean requiredParam)
Indicate that this variable represents a required parameter
void
setRequiredType(SequenceType required)
Set the required type of this variable
void
setSelectExpression(Expression select)
Set the expression to which this variable is bound
void
setSlotNumber(int s)
Set the slot number of this variable
void
setTunnel(boolean tunnel)
Indicate whether this variable represents a tunnel parameter
void
setVariableQName(StructuredQName s)
Set the name of the variable
Expression
simplify(ExpressionVisitor visitor)
Simplify this expression
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Methods inherited from class net.sf.saxon.instruct.Instruction

assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, createsNewNodes, dynamicError, evaluateAsString, evaluateItem, getImplementationMethod, getInstructionInfo, getInstructionNameCode, getItemType, getSourceLocator, isXSLT, iterate, process, processLeavingTail, promote, promoteInst, simplify

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

Field Details

evaluationMode

protected int evaluationMode

referenceCount

protected int referenceCount

slotNumber

protected int slotNumber

variableQName

protected StructuredQName variableQName

Constructor Details

GeneralVariable

public GeneralVariable()
Create a general variable

Method Details

copy

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

evaluateItem

public Item evaluateItem(XPathContext context)
            throws XPathException
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 interface EvaluableItem
Overrides:
evaluateItem in interface Instruction
Parameters:
context - 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

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

getCardinality

public int getCardinality()
Get the cardinality of the result of this instruction. An xsl:variable instruction returns nothing, so the type is empty.
Overrides:
getCardinality in interface Expression
Returns:
the empty cardinality.

getEvaluationMode

public int getEvaluationMode()
Get the evaluation mode of the variable

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction (that is xsl:variable, xsl:param etc) for diagnostics
Overrides:
getInstructionNameCode in interface Instruction
Returns:
the name of this instruction, as a name pool name code

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the type of the result of this instruction. An xsl:variable instruction returns nothing, so the type is empty.
Overrides:
getItemType in interface Instruction
Parameters:
th - the type hierarchy cache
Returns:
the empty type.

getLocalSlotNumber

public int getLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number. In other cases, return -1.
Specified by:
getLocalSlotNumber in interface Binding

getRequiredType

public SequenceType getRequiredType()
Get the required type of this variable
Specified by:
getRequiredType in interface Binding
Returns:
the required type

getSelectExpression

public Expression getSelectExpression()
Get the expression to which this variable is bound
Returns:
the initializing expression

getSelectValue

public ValueRepresentation getSelectValue(XPathContext context)
            throws XPathException
Evaluate the variable. That is, get the value of the select expression if present or the content of the element otherwise, either as a tree or as a sequence
Parameters:
context - the XPath dynamic context
Returns:
the result of evaluating the variable

getSlotNumber

public int getSlotNumber()
Get the slot number allocated to this variable
Returns:
the slot number, that is the position allocated to the variable on its stack frame

getVariableQName

public StructuredQName getVariableQName()
Get the name of this variable
Specified by:
getVariableQName in interface Binding
Returns:
the name of this variable (a QName)

init

public void init(Expression select,
                 StructuredQName qName)
Initialize the properties of the variable
Parameters:
select - the expression to which the variable is bound
qName - the name of the variable

isAssignable

public final boolean isAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element. This will only be true if the extra attribute saxon:assignable="yes" is present.
Specified by:
isAssignable in interface Binding

isGlobal

public boolean isGlobal()
Specified by:
isGlobal in interface Binding

isImplicitlyRequiredParam

public final boolean isImplicitlyRequiredParam()
Ask whether this variable represents a parameter that is implicitly required, because there is no usable default value
Returns:
true if this variable is an implicitly required parameter

isRequiredParam

public final boolean isRequiredParam()
Ask whether this variable represents a required parameter
Returns:
true if this is a required parameter

isTunnelParam

public final boolean isTunnelParam()
Ask whether this variable represents a tunnel parameter
Returns:
true if this is a tunnel parameter

iterate

public SequenceIterator iterate(XPathContext context)
            throws XPathException
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation relies on the process() method: it "pushes" the results of the instruction to a sequence in memory, and then iterates over this in-memory sequence. In principle instructions should implement a pipelined iterate() method that avoids the overhead of intermediate storage.
Specified by:
iterate in interface SequenceIterable
Overrides:
iterate in interface Instruction
Parameters:
context - supplies the context for evaluation
Returns:
a SequenceIterator that can be used to iterate over the result of the expression
Throws:
XPathException - if any dynamic error occurs evaluating the expression

iterateSubExpressions

public Iterator iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Overrides:
iterateSubExpressions in interface Expression

optimize

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

promoteInst

protected void promoteInst(PromotionOffer offer)
            throws XPathException
Handle promotion offers, that is, non-local tree rewrites.
Overrides:
promoteInst in interface Instruction
Parameters:
offer - The type of rewrite being offered
Throws:
XPathException -

replaceSubExpression

public boolean replaceSubExpression(Expression original,
                                    Expression replacement)
Replace one subexpression by a replacement subexpression
Overrides:
replaceSubExpression in interface Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

setAssignable

public void setAssignable(boolean assignable)
Indicate whether this variable is assignable using saxon:assign
Parameters:
assignable - true if this variable is assignable

setImplicitlyRequiredParam

public void setImplicitlyRequiredParam(boolean requiredParam)
Indicate that this variable represents a parameter that is implicitly required (because there is no usable default value)
Parameters:
requiredParam - true if this is an implicitly required parameter

setReferenceCount

public void setReferenceCount(int refCount)
Set the nominal number of references to this variable
Parameters:
refCount - the nominal number of references

setRequiredParam

public void setRequiredParam(boolean requiredParam)
Indicate that this variable represents a required parameter
Parameters:
requiredParam - true if this is a required parameter

setRequiredType

public void setRequiredType(SequenceType required)
Set the required type of this variable
Parameters:
required - the required type

setSelectExpression

public void setSelectExpression(Expression select)
Set the expression to which this variable is bound
Parameters:
select - the initializing expression

setSlotNumber

public void setSlotNumber(int s)
Set the slot number of this variable
Parameters:
s - the slot number, that is, the position allocated to this variable on its stack frame

setTunnel

public void setTunnel(boolean tunnel)
Indicate whether this variable represents a tunnel parameter
Parameters:
tunnel - true if this is a tunnel parameter

setVariableQName

public void setVariableQName(StructuredQName s)
Set the name of the variable
Parameters:
s - the name of the variable (a QName)

simplify

public Expression simplify(ExpressionVisitor visitor)
            throws XPathException
Simplify this expression
Overrides:
simplify in interface Instruction
Parameters:
visitor - an expression
Returns:
the simplified expression
Throws:
XPathException -

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Overrides:
typeCheck in interface Expression