Package net.sf.saxon.expr.instruct

## Class Instruction

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.instruct.Instruction

- All Implemented Interfaces:
    `ExportAgent`, `TailCallReturner`, `Locatable`, `IdentityComparable`, `Traceable`
  Direct Known Subclasses:
    `AnalyzeString`, `ApplyNextMatchingTemplate`, `ApplyTemplates`, `Assign`, `Block`, `BreakInstr`, `CallTemplate`, `Choose`, `ComponentTracer`, `ConditionalBlock`, `CopyOf`, `DeepUpdate`, `Doctype`, `DoInstr`, `ForEach`, `ForEachGroup`, `Fork`, `IterateInstr`, `LocalParam`, `LocalParamBlock`, `MergeInstr`, `Message`, `NextIteration`, `ParentNodeConstructor`, `ResultDocument`, `SimpleNodeConstructor`, `SourceDocument`, `TabulateMaps`, `TraceExpression`, `UseAttributeSet`, `While`

      public abstract class Instruction
      extends Expression
      implements TailCallReturner

  Abstract superclass for all instructions in the compiled stylesheet. This represents a compiled instruction, and as such, the minimum information is retained from the original stylesheet.
  Note: this class implements SourceLocator: that is, it can identify where in the stylesheet the source instruction was located.

- - ### 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
    --- | ---
    `Instruction()` | Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `alwaysCreatesNewNodes()` | Ask whether it is guaranteed that every item in the result of this instruction is a newly created node.
    `static ParameterSet` | `assembleParams​(XPathContext context, WithParam[] actualParams)` | Assemble a ParameterSet.
    `static ParameterSet` | `assembleTunnelParams​(XPathContext context, WithParam[] actualParams)` | Assemble a ParameterSet.
    `int` | `computeCardinality()` | Get the cardinality of the sequence returned by evaluating this instruction
    `int` | `computeSpecialProperties()` | Get the static properties of this expression (other than its type).
    `protected static XPathException` | `dynamicError​(Location loc, XPathException error, XPathContext context)` | Construct an exception with diagnostic information.
    `java.lang.CharSequence` | `evaluateAsString​(XPathContext context)` | Evaluate an expression as a String.
    `Item` | `evaluateItem​(XPathContext context)` | Evaluate an expression as a single item.
    `java.lang.String` | `getExpressionName()` | Get a name identifying the kind of expression, in terms meaningful to a user.
    `int` | `getImplementationMethod()` | An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
    `int` | `getInstructionNameCode()` | Get the namecode of the instruction for use in diagnostics
    `ItemType` | `getItemType()` | Get the item type of the items returned by evaluating this instruction
    `int` | `getNetCost()` | Return the estimated cost of evaluating an expression.
    `javax.xml.transform.SourceLocator` | `getSourceLocator()` | Get a SourceLocator identifying the location of this instruction
    `boolean` | `isInstruction()` | Ask whether this expression is an instruction.
    `boolean` | `isXSLT()` | Establish whether this is an XSLT instruction or an XQuery instruction (used to produce appropriate diagnostics)
    `SequenceIterator` | `iterate​(XPathContext context)` | Return an Iterator to iterate over the values of a sequence.
    `boolean` | `mayCreateNewNodes()` | Ask whether this instruction potentially creates and returns new nodes.
    `abstract java.lang.Iterable<Operand>` | `operands()` | Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.
    `void` | `process​(Outputter output, XPathContext context)` | Process the instruction, without returning any tail calls
    `abstract TailCall` | `processLeavingTail​(Outputter output, XPathContext context)` | ProcessLeavingTail: called to do the real work of this instruction.
    `protected boolean` | `someOperandCreatesNewNodes()` | Helper method for `mayCreateNewNodes()` - returns true if any operand creates new nodes

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, copy, dynamicError, effectiveBooleanValue, equals, evaluatePendingUpdates, explain, export, getCardinality, 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, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimize, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, toShortString, toString, typeCheck, 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`

- - ### Constructor Detail

    - #### Instruction

          public Instruction()

      Constructor

  - ### Method Detail

    - #### getImplementationMethod

          public int getImplementationMethod()

      An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is prefered. For instructions this is the process() method.
      Specified by:
        `getImplementationMethod` in class `Expression`
      Returns:
        the implementation method, for example `Expression.ITERATE_METHOD` or `Expression.EVALUATE_METHOD` or `Expression.PROCESS_METHOD`

    - #### isInstruction

          public boolean isInstruction()

      Description copied from class: `Expression`
      Ask whether this expression is an instruction. In XSLT streamability analysis this is used to distinguish constructs corresponding to XSLT instructions from other constructs, typically XPath expressions (but also things like attribute constructors on a literal result element, references to attribute sets, etc. However, an XPath expression within a text value template in a text node of an XSLT stylesheet is treated as an instruction. In a non-XSLT environment (such as XQuery) this property has no meaning and its setting is undefined.
      Overrides:
        `isInstruction` in class `Expression`
      Returns:
        true if this construct originates as an XSLT instruction

    - #### getInstructionNameCode

          public int getInstructionNameCode()

      Get the namecode of the instruction for use in diagnostics
      Returns:
        a code identifying the instruction: typically but not always the fingerprint of a name in the XSLT namespace

    - #### getExpressionName

          public java.lang.String getExpressionName()

      Get a name identifying the kind of expression, in terms meaningful to a user.
      Overrides:
        `getExpressionName` in class `Expression`
      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.

    - #### getItemType

          public ItemType getItemType()

      Get the item type of the items returned by evaluating this instruction
      Specified by:
        `getItemType` in class `Expression`
      Returns:
        the static item type of the instruction

    - #### computeCardinality

          public int computeCardinality()

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

    - #### operands

          public abstract java.lang.Iterable<Operand> operands()

      Description copied from class: `Expression`
      Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation works off the results of iterateSubExpressions()

      If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.

      Overrides:
        `operands` in class `Expression`
      Returns:
        an iterator containing the sub-expressions of this expression

    - #### processLeavingTail

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

      ProcessLeavingTail: called to do the real work of this instruction. This method must be implemented in each subclass. The results of the instruction are written to the current Receiver, which can be obtained via the Controller.
      Specified by:
        `processLeavingTail` in interface `TailCallReturner`
      Parameters:
        `output` - the destination for the result
        `context` - The dynamic context of the transformation, giving access to the current node, the current variables, etc.
      Returns:
        null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.
      Throws:
        `XPathException` - if a dynamic error occurs during the evaluation of the instruction

    - #### process

          public void process​(Outputter output,
                              XPathContext context)
                       throws XPathException

      Process the instruction, without returning any tail calls
      Overrides:
        `process` in class `Expression`
      Parameters:
        `output` - the destination for the result
        `context` - The dynamic context, giving access to the current node,
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### getSourceLocator

          public javax.xml.transform.SourceLocator getSourceLocator()

      Get a SourceLocator identifying the location of this instruction
      Returns:
        the location of this instruction in the source stylesheet or query

    - #### dynamicError

          protected static XPathException dynamicError​(Location loc,
                                                       XPathException error,
                                                       XPathContext context)

      Construct an exception with diagnostic information. Note that this method returns the exception, it does not throw it: that is up to the caller.
      Parameters:
        `loc` - the location of the error
        `error` - The exception containing information about the error
        `context` - The controller of the transformation
      Returns:
        an exception based on the supplied exception, but with location information added relating to this instruction

    - #### assembleParams

          public static ParameterSet assembleParams​(XPathContext context,
                                                    WithParam[] actualParams)
                                             throws XPathException

      Assemble a ParameterSet. Method used by instructions that have xsl:with-param children. This method is used for the non-tunnel parameters.
      Parameters:
        `context` - the XPath dynamic context
        `actualParams` - the set of with-param parameters that specify tunnel="no"
      Returns:
        a ParameterSet
      Throws:
        `XPathException` - if an error occurs evaluating one of the parameters

    - #### assembleTunnelParams

          public static ParameterSet assembleTunnelParams​(XPathContext context,
                                                          WithParam[] actualParams)
                                                   throws XPathException

      Assemble a ParameterSet. Method used by instructions that have xsl:with-param children. This method is used for the tunnel parameters.
      Parameters:
        `context` - the XPath dynamic context
        `actualParams` - the set of with-param parameters that specify tunnel="yes"
      Returns:
        a ParameterSet
      Throws:
        `XPathException` - if an error occurs evaluating one of the tunnel parameters

    - #### 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 `Expression`
      Returns:
        a set of flags indicating static properties of this expression

    - #### getNetCost

          public int getNetCost()

      Return the estimated cost of evaluating an expression. This is a very crude measure based on the syntactic form of the expression (we have no knowledge of data values). We take the cost of evaluating a simple scalar comparison or arithmetic expression as 1 (one), and we assume that a sequence has length 5. The resulting estimates may be used, for example, to reorder the predicates in a filter expression so cheaper predicates are evaluated first.
      Overrides:
        `getNetCost` in class `Expression`
      Returns:
        the intrinsic cost of this operation, excluding the costs of evaluating the operands

    - #### mayCreateNewNodes

          public boolean mayCreateNewNodes()

      Ask whether this instruction potentially creates and returns new nodes. Returns true if some branches or dynamic conditions result in new nodes being created. This implementation returns a default value of false
      Returns:
        true if the instruction creates new nodes under some input conditions (or if it can't be proved that it doesn't)

    - #### alwaysCreatesNewNodes

          public boolean alwaysCreatesNewNodes()

      Ask whether it is guaranteed that every item in the result of this instruction is a newly created node.
      Returns:
        true if result of the instruction is always either an empty sequence or a sequence consisting entirely of newly created nodes

    - #### someOperandCreatesNewNodes

          protected final boolean someOperandCreatesNewNodes()

      Helper method for `mayCreateNewNodes()` - returns true if any operand creates new nodes
      Returns:
        true if any operand creates new nodes

    - #### 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.
      Overrides:
        `evaluateItem` in class `Expression`
      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 handles iteration for expressions that return singleton values: for non-singleton expressions, the subclass must provide its own implementation.
      Overrides:
        `iterate` in class `Expression`
      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

    - #### evaluateAsString

          public final java.lang.CharSequence evaluateAsString​(XPathContext context)
                                                        throws XPathException

      Evaluate an expression as a String. This function must only be called in contexts where it is known that the expression will return a single string (or where an empty sequence is to be treated as a zero-length string). Implementations should not attempt to convert the result to a string, other than converting () to "". This method is used mainly to evaluate expressions produced by compiling an attribute value template.
      Overrides:
        `evaluateAsString` in class `Expression`
      Parameters:
        `context` - The context in which the expression is to be evaluated
      Returns:
        the value of the expression, evaluated in the current context. The expression must return a string or (); if the value of the expression is (), this method returns "".
      Throws:
        `XPathException` - if any dynamic error occurs evaluating the expression
        `java.lang.ClassCastException` - if the result type of the expression is not xs:string?

    - #### isXSLT

          public boolean isXSLT()

      Establish whether this is an XSLT instruction or an XQuery instruction (used to produce appropriate diagnostics)
      Returns:
        true for XSLT, false for XQuery