Class GlobalVariable

    • Constructor Detail

      • GlobalVariable

        public GlobalVariable()
        Create a global variable
    • Method Detail

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

        public SymbolicName getSymbolicName()
        Get the symbolic name of the component
        Specified by:
        getSymbolicName in class Actor
        Returns:
        the symbolic name
      • getTracingTag

        public java.lang.String getTracingTag()
        Description copied from class: Actor
        Get a string used to identify this kind of component when used in tracing output
        Specified by:
        getTracingTag in interface TraceableComponent
        Overrides:
        getTracingTag in class Actor
        Returns:
        a diagnostic string used to identify the component when tracing
      • gatherProperties

        public void gatherProperties​(java.util.function.BiConsumer<java.lang.String,​java.lang.Object> consumer)
        Get the properties of this object to be included in trace messages, by supplying the property values to a supplied consumer function
        Specified by:
        gatherProperties in interface Traceable
        Parameters:
        consumer - the function to which the properties should be supplied, as (property name, value) pairs.
      • setStatic

        public void setStatic​(boolean declaredStatic)
        Say whether this variable is declared to be static
        Parameters:
        declaredStatic - true if the variable is declared with static="yes"
      • isStatic

        public boolean isStatic()
        Ask whether this variable is declared to be static
        Returns:
        true if the variable is declared with static="yes"
      • 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
      • setOriginalVariable

        public void setOriginalVariable​(GlobalVariable var)
        Say that this (XQuery) variable is a copy of some originally declared variable. It's a separate variable when imported into another module, but it retains the link to the original.
        Parameters:
        var - the variable in the imported module from which this variable is derived
      • getOriginalVariable

        public GlobalVariable getOriginalVariable()
        Get the original declaration of this variable
        Returns:
        the variable in the imported module from which this variable is derived
      • getUltimateOriginalVariable

        public GlobalVariable getUltimateOriginalVariable()
        Get the original declaration of this variable, or its original declaration, transitively
        Returns:
        the real variable declaration in some transitively imported module from which this variable is ultimately derived
      • setUnused

        public void setUnused​(boolean unused)
        Say whether this variable is unused. Normally, unused variables are not compiled. However, in XSLT with debugging enabled (that is, with compileWithTracing set), dummy unused variables are created in respect of global variables that are declared but never referenced. These variables are included in the list of variables known to the Executable, but they are never evaluated, and do not have slot numbers allocated in the bindery.
        Parameters:
        unused - set to true if this global variable is to be marked as unused.
      • isUnused

        public boolean isUnused()
        Ask whether this variable is unused. Normally, unused variables are not compiled. However, in XSLT with debugging enabled (that is, with compileWithTracing set), dummy unused variables are created in respect of global variables that are declared but never referenced. These variables are included in the list of variables known to the Executable, but they are never evaluated, and do not have slot numbers allocated in the bindery.
        Returns:
        true if this global variable is marked as unused.
      • isPrivate

        public boolean isPrivate()
        Ask whether this global variable is private
        Returns:
        true if this variable is private
      • setPrivate

        public void setPrivate​(boolean b)
        Say whether this global variable is private
        Parameters:
        b - true if this variable is external
      • setAssignable

        public void setAssignable​(boolean assignable)
        Indicate whether this variable is assignable using saxon:assign
        Parameters:
        assignable - true if this variable is assignable
      • 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:
        isAssignable in interface Binding
        Returns:
        true if the binding is assignable
      • getObjectName

        public StructuredQName getObjectName()
        Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc. This is used only where the name is known statically.
        Specified by:
        getObjectName in interface Traceable
        Returns:
        the QName of the object declared or manipulated by this instruction or expression
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
        Get the value of a particular property of the instruction. Properties of XSLT instructions are generally known by the name of the stylesheet attribute that defines them.
        Overrides:
        getProperty in class Actor
        Parameters:
        name - The name of the required property
        Returns:
        The value of the requested property, or null if the property is not available
      • setIndexedVariable

        public void setIndexedVariable()
        Mark this as an indexed variable, to allow fast searching
      • isIndexedVariable

        public boolean isIndexedVariable()
        Ask whether this is an indexed variable
        Returns:
        true if this variable is indexed
      • setContainsLocals

        public void setContainsLocals​(SlotManager map)
        The expression that initializes a global variable may itself use local variables. In this case a stack frame needs to be allocated while evaluating the global variable
        Parameters:
        map - The stack frame map for local variables used while evaluating this global variable.
      • isGlobal

        public boolean isGlobal()
        Is this a global variable?
        Specified by:
        isGlobal in interface Binding
        Returns:
        true (yes, it is a global variable)
      • registerReference

        public void registerReference​(BindingReference ref)
        Register a variable reference that refers to this global variable
        Parameters:
        ref - the variable reference
      • iterateReferences

        public java.util.Iterator<BindingReference> iterateReferences()
        Iterate over the references to this variable
        Returns:
        an iterator over the references: returns objects of class VariableReference
      • getBinderySlotNumber

        public int getBinderySlotNumber()
        Get the slot number allocated to this variable in the Bindery
        Returns:
        the slot number, that is the position allocated to the variable within the Bindery
      • setBinderySlotNumber

        public void setBinderySlotNumber​(int s)
        Set the slot number of this variable in the Bindery
        Parameters:
        s - the slot number, that is, the position allocated to this variable within the Bindery
      • setRequiredParam

        public void setRequiredParam​(boolean requiredParam)
        Indicate that this variable represents a required parameter
        Parameters:
        requiredParam - true if this is a required parameter
      • isRequiredParam

        public boolean isRequiredParam()
        Ask whether this variable represents a required parameter
        Returns:
        true if this variable represents a required parameter
      • compile

        public void compile​(Executable exec,
                            int slot)
                     throws XPathException
        Create a compiled representation of this global variable. Used in XQuery only.
        Parameters:
        exec - the executable
        slot - the slot number allocated to this variable
        Throws:
        XPathException - if compile-time errors are found.
      • typeCheck

        public void typeCheck​(ExpressionVisitor visitor)
                       throws XPathException
        Type check the compiled representation of this global variable
        Parameters:
        visitor - an expression visitor
        Throws:
        XPathException - if compile-time errors are found.
      • lookForCycles

        public void lookForCycles​(IndexedStack<java.lang.Object> referees,
                                  XQueryFunctionLibrary globalFunctionLibrary)
                           throws XPathException
        Check for cycles in this variable definition
        Parameters:
        referees - the calls leading up to this one; it's an error if this variable is on the stack, because that means it calls itself directly or indirectly. The stack may contain variable definitions (GlobalVariable objects) and user-defined functions (UserFunction objects). It will never contain the same object more than once.
        globalFunctionLibrary - the library containing all global functions
        Throws:
        XPathException - if cycles are found
      • getSelectValue

        public GroundedValue getSelectValue​(XPathContext context,
                                            Component target)
                                     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 dynamic evaluation context
        target - the component representing the variable to be evaluated
        Returns:
        the value of the variable
        Throws:
        XPathException - if a dynamic error occurs during evaluation
      • evaluateVariable

        public GroundedValue evaluateVariable​(XPathContext context,
                                              Component target)
                                       throws XPathException
        Evaluate the variable
        Parameters:
        context - the XPath dynamic context
        target - the component representing this variable (in the context of a package where it is used)
        Returns:
        the value of the variable
        Throws:
        XPathException - if evaluation of the variable fails with a dynamic error
      • actuallyEvaluate

        protected GroundedValue actuallyEvaluate​(XPathContext context,
                                                 Component target)
                                          throws XPathException
        Evaluate the global variable, and save its value for use in subsequent references.
        Parameters:
        context - the XPath dynamic context
        target - the component representing this variable (in the context of a package where it is used)
        Returns:
        the value of the variable
        Throws:
        XPathException - if evaluation fails
      • setDependencies

        protected static void setDependencies​(GlobalVariable var,
                                              XPathContext context)
                                       throws XPathException
        Get the variable that is immediately dependent on this one, and register the dependency, so that circularities can be detected across threads. This relies on the fact that when the initialiser for variable X contains a reference to variable Y, then when Y is evaluated, a stack frame will be found on the context stack representing the evaluation of X. We don't set a dependency from X to Y if the value of Y was already available in the Bindery; it's not needed, because in this case we know that evaluation of Y is unproblematic, and can't lead to any circularities.
        Parameters:
        var - the global variable or parameter being evaluated
        context - the dynamic evaluation context
        Throws:
        XPathException - if a cycle of dependencies is found
      • 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
      • 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.
        Returns:
        the slot number on the local 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 the variable
        Specified by:
        getVariableQName in interface Binding
        Returns:
        the name of the variable, as a structured QName
      • getDescription

        public java.lang.String getDescription()
        Get a description of the variable for use in diagnostics
        Returns:
        a suitable description
      • addReference

        public void addReference​(VariableReference ref,
                                 boolean isLoopingReference)
        Register a variable reference that refers to the variable bound in this expression
        Specified by:
        addReference in interface Binding
        Parameters:
        ref - the variable reference to be registered
        isLoopingReference - - true if the reference occurs within a loop, such as the predicate of a filter expression
      • export

        public void export​(ExpressionPresenter presenter)
                    throws XPathException
        Diagnostic print of expression structure. The abstract expression tree is written to the supplied outputstream.
        Specified by:
        export in class Actor
        Parameters:
        presenter - the expression presenter used to display the structure
        Throws:
        XPathException - if things go wrong, for example an I/O failure
      • getFlags

        protected java.lang.String getFlags()