net.sf.saxon.instruct

Class GeneralVariable

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 intevaluationMode
protected intreferenceCount
SequenceTyperequiredType
Expressionselect
protected intslotNumber
protected StructuredQNamevariableQName
Constructor Summary
GeneralVariable()
Create a general variable
Method Summary
Expressioncopy()
Copy an expression.
ItemevaluateItem(XPathContext context)
Evaluate an expression as a single item.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
intgetCardinality()
Get the cardinality of the result of this instruction.
intgetEvaluationMode()
Get the evaluation mode of the variable
intgetInstructionNameCode()
Get the name of this instruction (that is xsl:variable, xsl:param etc) for diagnostics
ItemTypegetItemType(TypeHierarchy th)
Get the type of the result of this instruction.
intgetLocalSlotNumber()
If this is a local variable held on the local stack frame, return the corresponding slot number.
SequenceTypegetRequiredType()
Get the required type of this variable
ExpressiongetSelectExpression()
Get the expression to which this variable is bound
ValueRepresentationgetSelectValue(XPathContext context)
Evaluate the variable.
intgetSlotNumber()
Get the slot number allocated to this variable
StructuredQNamegetVariableQName()
Get the name of this variable
voidinit(Expression select, StructuredQName qName)
Initialize the properties of the variable
booleanisAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element.
booleanisGlobal()
booleanisImplicitlyRequiredParam()
Ask whether this variable represents a parameter that is implicitly required, because there is no usable default value
booleanisRequiredParam()
Ask whether this variable represents a required parameter
booleanisTunnelParam()
Ask whether this variable represents a tunnel parameter
SequenceIteratoriterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
Iterator<Expression>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)
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
protected voidpromoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
voidsetAssignable(boolean assignable)
Indicate whether this variable is assignable using saxon:assign
voidsetImplicitlyRequiredParam(boolean requiredParam)
Indicate that this variable represents a parameter that is implicitly required (because there is no usable default value)
voidsetReferenceCount(int refCount)
Set the nominal number of references to this variable
voidsetRequiredParam(boolean requiredParam)
Indicate that this variable represents a required parameter
voidsetRequiredType(SequenceType required)
Set the required type of this variable
voidsetSelectExpression(Expression select)
Set the expression to which this variable is bound
voidsetSlotNumber(int s)
Set the slot number of this variable
voidsetTunnel(boolean tunnel)
Indicate whether this variable represents a tunnel parameter
voidsetVariableQName(StructuredQName s)
Set the name of the variable
Expressionsimplify(ExpressionVisitor visitor)
Simplify this expression
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Field Detail

evaluationMode

protected int evaluationMode

referenceCount

protected int referenceCount

requiredType

SequenceType requiredType

select

Expression select

slotNumber

protected int slotNumber

variableQName

protected StructuredQName variableQName

Constructor Detail

GeneralVariable

public GeneralVariable()
Create a general variable

Method Detail

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

evaluateItem

public Item evaluateItem(XPathContext context)
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.

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.

getCardinality

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

Returns: the empty cardinality.

getEvaluationMode

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

Returns: the evaluation mode (a constant in ExpressionTool

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction (that is xsl:variable, xsl:param etc) for diagnostics

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.

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.

getRequiredType

public SequenceType getRequiredType()
Get the required type of this variable

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)
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

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.

isGlobal

public boolean isGlobal()

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

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<Expression> 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)

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

promoteInst

protected void promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.

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

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)
Simplify this expression

Parameters: visitor an expression

Returns: the simplified expression

Throws: XPathException

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)