Class LocalParam
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.instruct.Instruction
-
- net.sf.saxon.expr.instruct.LocalParam
-
- All Implemented Interfaces:
Binding
,ExportAgent
,LocalBinding
,Locatable
,IdentityComparable
,Traceable
public final class LocalParam extends Instruction implements LocalBinding
The compiled form of an xsl:param element within a template in an XSLT stylesheet.The xsl:param element in XSLT has mandatory attribute name and optional attribute select. It can also be specified as required="yes" or required="no".
This is used only for parameters to XSLT templates. For function calls, the caller of the function places supplied arguments onto the callee's stackframe and the callee does not need to do anything. Global parameters (XQuery external variables) are handled using
GlobalParam
.The LocalParam class is also used to represent parameters with the saxon:iterate instruction
Changed in Saxon 9.8 to combine the previously-separate LocalParamSetter and LocalParam classes into one
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LocalParam.LocalParamElaborator
The Elaborator for this kind of expression
-
Field Summary
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description LocalParam()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addReference(VariableReference ref, boolean isLoopingReference)
Register a variable reference that refers to the variable bound in this expressionvoid
checkAgainstRequiredType(ExpressionVisitor visitor)
Check the select expression against the required type.protected int
computeCardinality()
Get the cardinality of the sequence returned by evaluating this instructionvoid
computeEvaluationMode()
protected int
computeSpecialProperties()
Get the static properties of this expression (other than its type).LocalParam
copy(RebindingMap rebindings)
Copy an expression.Sequence
evaluateVariable(XPathContext c)
Evaluate the variablevoid
export(ExpressionPresenter out)
Diagnostic print of expression structure.int
getCardinality()
Get the cardinality of the result of this instruction.Expression
getConversion()
Get the conversion expressionElaborator
getElaborator()
Make an elaborator for this expressionjava.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.int
getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposesIntegerValue[]
getIntegerBoundsForVariable()
If the variable is bound to an integer, get the minimum and maximum possible values.ItemType
getItemType()
Get the item type of the items returned by evaluating this instructionint
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 variableExpression
getSelectExpression()
Get the expression to which this variable is boundint
getSlotNumber()
Get the slot number allocated to this variableStructuredQName
getVariableQName()
Get the name of this variableboolean
hasVariableBinding(Binding binding)
Ask whether this expression is, or contains, the binding of a given variableboolean
isAssignable()
Test whether it is permitted to assign to the variable using the saxon:assign extension element.boolean
isCompatible(LocalParam other)
Check if parameter is compatible with anotherboolean
isGlobal()
Indicate whether the binding is local or global.boolean
isImplicitlyRequiredParam()
Ask whether this variable represents a parameter that is implicitly required, because there is no usable default valueboolean
isIndexedVariable()
Ask whether the binding is to be indexedboolean
isLiftable(boolean forStreaming)
Ask whether the expression can be lifted out of a loop, assuming it has no dependencies on the controlling variable/focus of the loopboolean
isRequiredParam()
Ask whether this variable represents a required parameterboolean
isTunnelParam()
Ask whether this variable represents a tunnel parameterboolean
mayCreateNewNodes()
Determine whether this instruction creates new nodes.java.lang.Iterable<Operand>
operands()
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)void
setConversion(Expression convertor)
Define a conversion that is to be applied to the supplied parameter value.void
setImplicitlyRequiredParam(boolean requiredParam)
Indicate that this variable represents a parameter that is implicitly required (because there is no usable default value)void
setIndexedVariable()
Say that the bound value has the potential to be indexedvoid
setReferenceCount(int refCount)
Set the nominal number of references to this variablevoid
setRequiredParam(boolean requiredParam)
Indicate that this variable represents a required parametervoid
setRequiredType(SequenceType required)
Set the required type of this variablevoid
setSelectExpression(Expression select)
Set the expression to which this variable is boundvoid
setSlotNumber(int s)
Set the slot number of this variablevoid
setTunnel(boolean tunnel)
Indicate whether this variable represents a tunnel parametervoid
setVariableQName(StructuredQName s)
Set the name of the variablejava.lang.String
toShortString()
Produce a short string identifying the expression for use in error messagesExpression
typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
Perform type checking of an expression and its subexpressions.-
Methods inherited from class net.sf.saxon.expr.instruct.Instruction
alwaysCreatesNewNodes, assembleParams, assembleTunnelParams, dynamicError, evaluateAsString, evaluateItem, getImplementationMethod, getNetCost, getSourceLocator, isInstruction, isXSLT, iterate, process, someOperandCreatesNewNodes
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, explain, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimize, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, toString, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocation
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Method Detail
-
setSelectExpression
public void setSelectExpression(Expression select)
Set the expression to which this variable is bound- Parameters:
select
- the initializing expression
-
getSelectExpression
public Expression getSelectExpression()
Get the expression to which this variable is bound- Returns:
- the initializing expression
-
setRequiredType
public void setRequiredType(SequenceType required)
Set the required type of this variable- Parameters:
required
- the required type
-
getRequiredType
public SequenceType getRequiredType()
Get the required type of this variable- Specified by:
getRequiredType
in interfaceBinding
- Returns:
- the required type
-
setRequiredParam
public void setRequiredParam(boolean requiredParam)
Indicate that this variable represents a required parameter- Parameters:
requiredParam
- true if this is a required parameter
-
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
-
setTunnel
public void setTunnel(boolean tunnel)
Indicate whether this variable represents a tunnel parameter- Parameters:
tunnel
- true if this is a tunnel parameter
-
setReferenceCount
public void setReferenceCount(int refCount)
Set the nominal number of references to this variable- Parameters:
refCount
- the nominal number of references
-
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 classExpression
- Returns:
- the empty cardinality.
-
isAssignable
public boolean isAssignable()
Description copied from interface:Binding
Test whether it is permitted to assign to the variable using the saxon:assign extension element. This will only be for an XSLT global variable where the extra attribute saxon:assignable="yes" is present.- Specified by:
isAssignable
in interfaceBinding
- Returns:
- true if the binding is assignable
-
isGlobal
public boolean isGlobal()
Description copied from interface:Binding
Indicate 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:
getLocalSlotNumber
in interfaceLocalBinding
- Returns:
- the slot number on the local stack frame
-
isRequiredParam
public boolean isRequiredParam()
Ask whether this variable represents a required parameter- Returns:
- true if this is a required parameter
-
isImplicitlyRequiredParam
public 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
-
isTunnelParam
public boolean isTunnelParam()
Ask whether this variable represents a tunnel parameter- Returns:
- true if this is a tunnel parameter
-
typeCheck
public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException
Description copied from class:Expression
Perform 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.
- Overrides:
typeCheck
in classExpression
- Parameters:
visitor
- an expression visitorcontextItemType
- Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.- Returns:
- the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
computeEvaluationMode
public void computeEvaluationMode()
-
copy
public LocalParam copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- a mutable list of (old binding, new binding) pairs that is used to update the bindings held in any local variable references that are copied.- Returns:
- the copy of the original expression
-
addReference
public void addReference(VariableReference ref, boolean isLoopingReference)
Description copied from interface:Binding
Register a variable reference that refers to the variable bound in this expression- Specified by:
addReference
in interfaceBinding
- Parameters:
ref
- the variable referenceisLoopingReference
- - true if the reference occurs within a loop, such as the predicate of a filter expression
-
checkAgainstRequiredType
public void checkAgainstRequiredType(ExpressionVisitor visitor) throws XPathException
Check the select expression against the required type.- Parameters:
visitor
- an expression visitor- Throws:
XPathException
- if the check fails
-
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
-
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
-
setVariableQName
public void setVariableQName(StructuredQName s)
Set the name of the variable- Parameters:
s
- the name of the variable (a QName)
-
getVariableQName
public StructuredQName getVariableQName()
Get the name of this variable- Specified by:
getVariableQName
in interfaceBinding
- Returns:
- the name of this variable (a QName)
-
setConversion
public void setConversion(Expression convertor)
Define a conversion that is to be applied to the supplied parameter value.- Parameters:
convertor
- The expression to be applied. This performs type checking, and the basic conversions implied by function calling rules, for example numeric promotion, atomization, and conversion of untyped atomic values to a required type. The conversion uses the actual parameter value as input, referencing it using a VariableReference. The argument can be null to indicate that no conversion is required.
-
getConversion
public Expression getConversion()
Get the conversion expression- Returns:
- the expression used to convert the value to the required type, or null if there is none
-
getInstructionNameCode
public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes- Overrides:
getInstructionNameCode
in classInstruction
- Returns:
- the integer name code
-
operands
public java.lang.Iterable<Operand> operands()
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:
operands
in classInstruction
- Returns:
- an iterator over the subexpressions
-
getIntegerBoundsForVariable
public IntegerValue[] getIntegerBoundsForVariable()
If the variable is bound to an integer, get the minimum and maximum possible values. Return null if unknown or not applicable- Specified by:
getIntegerBoundsForVariable
in interfaceBinding
- Returns:
- a pair of integers containing the minimum and maximum values for the integer value; or null if the value is not an integer or the range is unknown
-
evaluateVariable
public Sequence evaluateVariable(XPathContext c)
Evaluate the variable- Specified by:
evaluateVariable
in interfaceBinding
- Parameters:
c
- the XPath dynamic evaluation context- Returns:
- the result of evaluating the variable
-
isCompatible
public boolean isCompatible(LocalParam other)
Check if parameter is compatible with another- Parameters:
other
- - the LocalParam object to compare- Returns:
- result of the compatibility check
-
isLiftable
public boolean isLiftable(boolean forStreaming)
Ask whether the expression can be lifted out of a loop, assuming it has no dependencies on the controlling variable/focus of the loop- Overrides:
isLiftable
in classExpression
- Parameters:
forStreaming
- true if compiling streamable code- Returns:
- true if the expression can be loop lifted
-
hasVariableBinding
public boolean hasVariableBinding(Binding binding)
Ask whether this expression is, or contains, the binding of a given variable- Overrides:
hasVariableBinding
in classExpression
- Parameters:
binding
- the variable binding- Returns:
- true if this expression is the variable binding (for example a ForExpression or LetExpression) or if it is a FLWOR expression that binds the variable in one of its clauses.
-
getItemType
public ItemType getItemType()
Get the item type of the items returned by evaluating this instruction- Overrides:
getItemType
in classInstruction
- Returns:
- the static item type of the instruction
-
computeCardinality
protected int computeCardinality()
Get the cardinality of the sequence returned by evaluating this instruction- Overrides:
computeCardinality
in classInstruction
- Returns:
- the static cardinality
-
computeSpecialProperties
protected 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.- Overrides:
computeSpecialProperties
in classInstruction
- Returns:
- a set of flags indicating static properties of this expression
-
mayCreateNewNodes
public boolean mayCreateNewNodes()
Determine whether this instruction creates new nodes. This implementation returns a default value of false- Overrides:
mayCreateNewNodes
in classInstruction
- Returns:
- true if the instruction creates new nodes (or if it can't be proved that it doesn't)
-
getExpressionName
public java.lang.String getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionName
in classInstruction
- Returns:
- a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in explain() output displaying the expression.
-
toShortString
public java.lang.String toShortString()
Produce a short string identifying the expression for use in error messages- Overrides:
toShortString
in classExpression
- Returns:
- a short string, sufficient to identify the expression
-
export
public void export(ExpressionPresenter out) throws XPathException
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classExpression
- Parameters:
out
- the expression presenter used to display the structure- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
setIndexedVariable
public void setIndexedVariable()
Say that the bound value has the potential to be indexed- Specified by:
setIndexedVariable
in interfaceLocalBinding
-
isIndexedVariable
public boolean isIndexedVariable()
Ask whether the binding is to be indexed- Specified by:
isIndexedVariable
in interfaceLocalBinding
- Returns:
- true if the variable value can be indexed
-
getElaborator
public Elaborator getElaborator()
Make an elaborator for this expression- Overrides:
getElaborator
in classExpression
- Returns:
- an appropriate
Elaborator
-
-