Class 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

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

        protected int computeCardinality()
        Get the cardinality of the sequence returned by evaluating this instruction
        Overrides:
        computeCardinality in class Instruction
        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 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