Class GeneralVariable
- java.lang.Object
-
- net.sf.saxon.expr.ComputedExpression
-
- net.sf.saxon.instruct.Instruction
-
- net.sf.saxon.instruct.GeneralVariable
-
- All Implemented Interfaces:
java.io.Serializable,javax.xml.transform.SourceLocator,Binding,Container,Expression,TailCallReturner,InstructionInfoProvider
- Direct Known 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- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intevaluationModeprotected intnameCodeprotected intreferenceCount(package private) SequenceTyperequiredType(package private) Expressionselectprotected intslotNumber-
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 GeneralVariable()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisplay(int level, java.io.PrintStream out, Configuration config)Diagnostic print of expression structure.ItemevaluateItem(XPathContext context)Evaluate an expression as a single item.intgetCardinality()Get the cardinality of the result of this instruction.intgetInstructionNameCode()Get the namecode of the instruction for use in diagnosticsItemTypegetItemType(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.intgetNameCode()SequenceTypegetRequiredType()ExpressiongetSelectExpression()ValueRepresentationgetSelectValue(XPathContext context)Evaluate the variable.intgetSlotNumber()intgetVariableFingerprint()Get the name of the variable (as a NamePool fingerprint)java.lang.StringgetVariableName()voidinit(Expression select, int nameCode)booleanisAssignable()Test whether it is permitted to assign to the variable using the saxon:assign extension element.booleanisGlobal()Indicate whether the binding is local or global.booleanisImplicitlyRequiredParam()booleanisRequiredParam()booleanisTunnelParam()SequenceIteratoriterate(XPathContext context)Return an Iterator to iterate over the values of a sequence.java.util.IteratoriterateSubExpressions()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(Optimizer opt, StaticContext env, ItemType contextItemType)Perform optimisation of an expression and its subexpressions.protected voidpromoteInst(PromotionOffer offer)Handle promotion offers, that is, non-local tree rewrites.booleanreplaceSubExpression(Expression original, Expression replacement)Replace one subexpression by a replacement subexpressionvoidsetAssignable(boolean assignable)voidsetImplicitlyRequiredParam(boolean requiredParam)voidsetNameCode(int nameCode)voidsetReferenceCount(int refCount)voidsetRequiredParam(boolean requiredParam)voidsetRequiredType(SequenceType required)voidsetSelectExpression(Expression select)voidsetSlotNumber(int s)voidsetTunnel(boolean tunnel)voidsetVariableName(java.lang.String s)Expressionsimplify(StaticContext env)Simplify an expression.ExpressiontypeCheck(StaticContext env, ItemType contextItemType)Perform type checking of an expression and its subexpressions.-
Methods inherited from class net.sf.saxon.instruct.Instruction
appendItem, assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, createsNewNodes, dynamicError, evaluateAsString, getImplementationMethod, getInstructionInfo, getSourceLocator, isXSLT, process, processLeavingTail, promote
-
Methods inherited from class net.sf.saxon.expr.ComputedExpression
adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, getColumnNumber, getConstructType, getDependencies, getExecutable, getHostLanguage, getIntrinsicDependencies, getLineNumber, getLocationId, getLocationProvider, getParentExpression, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasBadParentPointer, markTailFunctionCalls, resetStaticProperties, setLocationId, setParentExpression, setParentExpression, suppressValidation, typeError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.expr.Binding
evaluateVariable
-
-
-
-
Field Detail
-
select
Expression select
-
nameCode
protected int nameCode
-
requiredType
SequenceType requiredType
-
slotNumber
protected int slotNumber
-
referenceCount
protected int referenceCount
-
evaluationMode
protected int evaluationMode
-
-
Method Detail
-
init
public void init(Expression select, int nameCode)
-
setSelectExpression
public void setSelectExpression(Expression select)
-
getSelectExpression
public Expression getSelectExpression()
-
setRequiredType
public void setRequiredType(SequenceType required)
-
getRequiredType
public SequenceType getRequiredType()
-
setNameCode
public void setNameCode(int nameCode)
-
getNameCode
public int getNameCode()
-
setAssignable
public void setAssignable(boolean assignable)
-
setRequiredParam
public void setRequiredParam(boolean requiredParam)
-
setImplicitlyRequiredParam
public void setImplicitlyRequiredParam(boolean requiredParam)
-
setTunnel
public void setTunnel(boolean tunnel)
-
setReferenceCount
public void setReferenceCount(int refCount)
-
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:
isAssignablein interfaceBinding
-
getVariableFingerprint
public int getVariableFingerprint()
Get the name of the variable (as a NamePool fingerprint)- Returns:
- the NamePool fingerprint of the variable's expanded name.
-
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.- Specified by:
getItemTypein interfaceExpression- Overrides:
getItemTypein classInstruction- Parameters:
th-- Returns:
- the empty type.
-
getCardinality
public int getCardinality()
Get the cardinality of the result of this instruction. An xsl:variable instruction returns nothing, so the type is empty.- Specified by:
getCardinalityin interfaceExpression- Overrides:
getCardinalityin classComputedExpression- Returns:
- the empty cardinality.
-
isGlobal
public boolean isGlobal()
Description copied from interface:BindingIndicate whether the binding is local or global. A global binding is one that has a fixed value for the life of a query or transformation; any other binding is local.
-
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:
getLocalSlotNumberin interfaceBinding
-
isRequiredParam
public final boolean isRequiredParam()
-
isImplicitlyRequiredParam
public final boolean isImplicitlyRequiredParam()
-
isTunnelParam
public final boolean isTunnelParam()
-
getInstructionNameCode
public int getInstructionNameCode()
Description copied from class:InstructionGet the namecode of the instruction for use in diagnostics- Overrides:
getInstructionNameCodein classInstruction
-
simplify
public Expression simplify(StaticContext env) throws XPathException
Description copied from class:InstructionSimplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.- Specified by:
simplifyin interfaceExpression- Specified by:
simplifyin classInstruction- Parameters:
env- the static context- Returns:
- the simplified expression
- Throws:
XPathException- if an error is discovered during expression rewriting
-
typeCheck
public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException
Description copied from interface:ExpressionPerform type checking of an expression and its subexpressions. This is the second phase of static optimization.This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.
If the implementation returns a value other than "this", then it is required to ensure that the parent pointer and location information in the returned expression have been set up correctly. It should not rely on the caller to do this, although for historical reasons many callers do so.
- Specified by:
typeCheckin 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
Description copied from interface:ExpressionPerform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.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.
- Specified by:
optimizein 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
-
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:
evaluateItemin interfaceExpression- Overrides:
evaluateItemin classInstruction- 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
-
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:
iteratein interfaceExpression- Overrides:
iteratein classInstruction- 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
-
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- Throws:
XPathException
-
promoteInst
protected void promoteInst(PromotionOffer offer) throws XPathException
Handle promotion offers, that is, non-local tree rewrites.- Overrides:
promoteInstin classInstruction- Parameters:
offer- The type of rewrite being offered- Throws:
XPathException
-
iterateSubExpressions
public java.util.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)- Specified by:
iterateSubExpressionsin interfaceExpression- Overrides:
iterateSubExpressionsin classComputedExpression- Returns:
- an iterator containing the sub-expressions of this expression
-
replaceSubExpression
public boolean replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression- Specified by:
replaceSubExpressionin interfaceContainer- Overrides:
replaceSubExpressionin classComputedExpression- Parameters:
original- the original subexpressionreplacement- the replacement subexpression- Returns:
- true if the original subexpression is found
-
display
public void display(int level, java.io.PrintStream out, Configuration config)Diagnostic print of expression structure. The expression is written to the System.err output stream- Specified by:
displayin interfaceExpression- Parameters:
level- indentation level for this expressionout-config-
-
getSlotNumber
public int getSlotNumber()
-
setSlotNumber
public void setSlotNumber(int s)
-
setVariableName
public void setVariableName(java.lang.String s)
-
getVariableName
public java.lang.String getVariableName()
-
-