Package net.sf.saxon.expr.instruct

## 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`, `TailCallReturner`, `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

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Evaluator` | `evaluator` |
    `protected int` | `referenceCount` |
    `protected int` | `slotNumber` |
    `protected StructuredQName` | `variableQName` |

    - ### 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 expression
    `void` | `checkAgainstRequiredType​(ExpressionVisitor visitor)` | Check the select expression against the required type.
    `int` | `computeCardinality()` | Get the cardinality of the sequence returned by evaluating this instruction
    `void` | `computeEvaluationMode()` |
    `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 variable
    `void` | `export​(ExpressionPresenter out)` | Diagnostic print of expression structure.
    `int` | `getCardinality()` | Get the cardinality of the result of this instruction.
    `Expression` | `getConversion()` | Get the conversion expression
    `EvaluationMode` | `getConversionEvaluationMode()` |
    `java.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 purposes
    `IntegerValue[]` | `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 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
    `Sequence` | `getSelectValue​(XPathContext context)` | Evaluate the variable.
    `int` | `getSlotNumber()` | Get the slot number allocated to this variable
    `StructuredQName` | `getVariableQName()` | Get the name of this variable
    `boolean` | `hasVariableBinding​(Binding binding)` | Ask whether this expression is, or contains, the binding of a given variable
    `boolean` | `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 another
    `boolean` | `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 value
    `boolean` | `isIndexedVariable()` | Ask whether the binding is to be indexed
    `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
    `boolean` | `isRequiredParam()` | Ask whether this variable represents a required parameter
    `boolean` | `isTunnelParam()` | Ask whether this variable represents a tunnel parameter
    `boolean` | `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)
    `Expression` | `optimize​(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)` | Perform optimisation of an expression and its subexpressions.
    `TailCall` | `processLeavingTail​(Outputter output, XPathContext context)` | Process the local parameter declaration
    `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 indexed
    `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
    `java.lang.String` | `toShortString()` | Produce a short string identifying the expression for use in error messages
    `Expression` | `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, dynamicError, effectiveBooleanValue, equals, evaluatePendingUpdates, explain, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, 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, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, toString, typeCheckChildren, typeError, unordered, verifyParentPointers`

    - ### 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`

- - ### Field Detail

    - #### variableQName

          protected StructuredQName variableQName

    - #### slotNumber

          protected int slotNumber

    - #### referenceCount

          protected int referenceCount

    - #### evaluator

          protected Evaluator evaluator

  - ### Constructor Detail

    - #### LocalParam

          public LocalParam()

  - ### 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 interface `Binding`
      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 class `Expression`
      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 interface `Binding`
      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.
      Specified by:
        `isGlobal` in interface `Binding`
      Returns:
        true if the binding is global

    - #### 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 `LocalBinding`
      Returns:
        the slot number on the local stack frame

    - #### isRequiredParam

          public final boolean isRequiredParam()

      Ask whether this variable represents a required parameter
      Returns:
        true if this is a required parameter

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

    - #### isTunnelParam

          public final 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 class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextItemType` - 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)

    - #### optimize

          public Expression optimize​(ExpressionVisitor visitor,
                                     ContextItemStaticInfo contextItemType)
                              throws XPathException

      Description copied from class: `Expression`
      Perform 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.

      Overrides:
        `optimize` in class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextItemType` - 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 to `Type.ITEM_TYPE`
      Returns:
        the original expression, rewritten if appropriate to optimize execution
      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 class `Expression`
      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 interface `Binding`
      Parameters:
        `ref` - the variable reference
        `isLoopingReference` - - 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

    - #### getSelectValue

          public Sequence 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
      Throws:
        `XPathException` - if evaluation of the select expression fails with a dynamic error

    - #### 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 interface `Binding`
      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

    - #### getConversionEvaluationMode

          public EvaluationMode getConversionEvaluationMode()

    - #### getInstructionNameCode

          public int getInstructionNameCode()

      Get the name of this instruction for diagnostic and tracing purposes
      Overrides:
        `getInstructionNameCode` in class `Instruction`
      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 class `Instruction`
      Returns:
        an iterator over the subexpressions

    - #### processLeavingTail

          public TailCall processLeavingTail​(Outputter output,
                                             XPathContext context)
                                      throws XPathException

      Process the local parameter declaration
      Specified by:
        `processLeavingTail` in interface `TailCallReturner`
      Specified by:
        `processLeavingTail` in class `Instruction`
      Parameters:
        `output` - the destination for the result
        `context` - the dynamic context
      Returns:
        either null if processing is complete, or a tailcall if one is left outstanding
      Throws:
        `XPathException` - if a dynamic error occurs in the evaluation

    - #### 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 interface `Binding`
      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 interface `Binding`
      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 class `Expression`
      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 class `Expression`
      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 class `Instruction`
      Returns:
        the static item type of the instruction

    - #### computeCardinality

          public int computeCardinality()

      Get the cardinality of the sequence returned by evaluating this instruction
      Overrides:
        `computeCardinality` in class `Instruction`
      Returns:
        the static cardinality

    - #### computeSpecialProperties

          public 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 class `Instruction`
      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 class `Instruction`
      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 class `Instruction`
      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 class `Expression`
      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 interface `ExportAgent`
      Specified by:
        `export` in class `Expression`
      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 interface `LocalBinding`

    - #### isIndexedVariable

          public boolean isIndexedVariable()

      Ask whether the binding is to be indexed
      Specified by:
        `isIndexedVariable` in interface `LocalBinding`
      Returns:
        true if the variable value can be indexed