## net.sf.saxon.instruct
Class Instruction

    java.lang.Object
      net.sf.saxon.expr.ComputedExpression
          net.sf.saxon.instruct.Instruction

All Implemented Interfaces:
  Container, Expression, InstructionInfoProvider, java.io.Serializable, javax.xml.transform.SourceLocator

Direct Known Subclasses:
  AnalyzeString, ApplyImports, ApplyTemplates, Block, CallTemplate, Choose, CopyOf, DeferredError, Doctype, DocumentInstr, ElementCreator, ForEach, ForEachGroup, GeneralVariable, Message, ResultDocument, SimpleNodeConstructor, TraceWrapper, While

public abstract class Instruction
extends ComputedExpression
implements javax.xml.transform.SourceLocator

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.

See Also:
  Serialized Form

Field Summary

Fields inherited from class net.sf.saxon.expr.ComputedExpression
`locationId, staticProperties`

Fields inherited from interface net.sf.saxon.expr.Expression
`EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD`

Constructor Summary
`Instruction()` Constructor

Method Summary
`abstract Expression` `analyze(StaticContext env, ItemType contextItemType)` Perform static analysis of an expression and its subexpressions.
`static void` `appendItem(Item it, SequenceReceiver out, int locationId)` Static method to append an item that results from evaluating an expression to the current result receiver.
`protected static ParameterSet` `assembleParams(XPathContext context, WithParam[] actualParams)` Assemble a ParameterSet.
`protected 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).
`boolean` `createsNewNodes()` Determine whether this instruction creates new nodes.
`protected static XPathException` `dynamicError(javax.xml.transform.SourceLocator loc, XPathException error, XPathContext context)` Construct an exception with diagnostic information.
`protected XPathException` `dynamicError(java.lang.String message, Controller controller)` Raise a dynamic error
`boolean` `effectiveBooleanValue(XPathContext context)` Get the effective boolean value of the expression.
`java.lang.String` `evaluateAsString(XPathContext context)` Evaluate an expression as a String.
`Item` `evaluateItem(XPathContext context)` Evaluate an expression as a single item.
`int` `getImplementationMethod()` An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
`InstructionInfo` `getInstructionInfo()` Get InstructionInfo for this expression
`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
`javax.xml.transform.SourceLocator` `getSourceLocator()` Get a SourceLocator identifying the location of this instruction
`boolean` `isXSLT(XPathContext context)` 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.
`void` `process(XPathContext context)` Process the instruction, without returning any tail calls
`abstract TailCall` `processLeavingTail(XPathContext context)` ProcessLeavingTail: called to do the real work of this instruction.
`Expression` `promote(PromotionOffer offer)` Offer promotion for this subexpression.
`protected void` `promoteInst(PromotionOffer offer)` Handle promotion offers, that is, non-local tree rewrites.
`abstract Expression` `simplify(StaticContext env)` Simplify an expression.

Methods inherited from class net.sf.saxon.expr.ComputedExpression

`adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, dynamicError, dynamicError, getCardinality, getColumnNumber, getConstructType, getDependencies, getExecutable, getIntrinsicDependencies, getLineNumber, getLocationId, getParentExpression, getPublicId, getSpecialProperties, getSystemId, iterateSubExpressions, markTailFunctionCalls, resetStaticProperties, setLocationId, setParentExpression, typeError, typeError`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface javax.xml.transform.SourceLocator
`getColumnNumber, getLineNumber, getPublicId, getSystemId`

Methods inherited from interface net.sf.saxon.expr.Expression
`display`

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 interface `Expression`
  Overrides:
    `getImplementationMethod` in class `ComputedExpression`

### getInstructionNameCode

    public int getInstructionNameCode()

  Get the namecode of the instruction for use in diagnostics

### getItemType

    public ItemType getItemType()

  Get the item type of the items returned by evaluating this instruction

  Specified by:
    `getItemType` in interface `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 `ComputedExpression`
  Returns:
    the static cardinality

### processLeavingTail

    public abstract TailCall processLeavingTail(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.

  Parameters:
    `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`

### process

    public void process(XPathContext context)
                 throws XPathException

  Process the instruction, without returning any tail calls

  Specified by:
    `process` in interface `Expression`
  Overrides:
    `process` in class `ComputedExpression`
  Parameters:
    `context` - The dynamic context, giving access to the current node, the current variables, etc.
  Throws:
    `XPathException`

### getSourceLocator

    public javax.xml.transform.SourceLocator getSourceLocator()

  Get a SourceLocator identifying the location of this instruction

### dynamicError

    protected static XPathException dynamicError(javax.xml.transform.SourceLocator 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:
    `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

### dynamicError

    protected XPathException dynamicError(java.lang.String message,
                                          Controller controller)

  Raise a dynamic error

  Parameters:
    `message` - An English text error message
    `controller` - The controller of the transformation
  Returns:
    an exception containing details of the dynamic error

### assembleParams

    protected 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.

  Throws:
    `XPathException`

### assembleTunnelParams

    protected 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.

  Throws:
    `XPathException`

### simplify

    public abstract Expression simplify(StaticContext env)
                                 throws XPathException

  Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression). The default implementation does nothing.

  Specified by:
    `simplify` in interface `Expression`
  Overrides:
    `simplify` in class `ComputedExpression`
  Returns:
    the simplified expression
  Throws:
    `XPathException` - if an error is discovered during expression rewriting

### analyze

    public abstract Expression analyze(StaticContext env,
                                       ItemType contextItemType)
                                throws XPathException

  Perform static analysis of an expression and its subexpressions.

  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 will only be accurately known if they have been explicitly declared.

  Specified by:
    `analyze` in interface `Expression`
  Parameters:
    `env` - the static context of the expression
    `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 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)

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

### createsNewNodes

    public boolean createsNewNodes()

  Determine whether this instruction creates new nodes. This implementation returns a default value of false

### promoteInst

    protected void promoteInst(PromotionOffer offer)
                        throws XPathException

  Handle promotion offers, that is, non-local tree rewrites.

  Parameters:
    `offer` - The type of rewrite being offered
  Throws:
    `XPathException`

### promote

    public Expression promote(PromotionOffer offer)
                       throws XPathException

  Offer promotion for this subexpression. The offer will be accepted if the subexpression is not dependent on the factors (e.g. the context item) identified in the PromotionOffer. This method is always called at compile time.

  Specified by:
    `promote` in interface `Expression`
  Overrides:
    `promote` in class `ComputedExpression`
  Parameters:
    `offer` - details of the offer, for example the offer to move expressions that don't depend on the context to an outer level in the containing expression
  Returns:
    if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
  Throws:
    `XPathException` - if any error is detected

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

  Specified by:
    `evaluateItem` in interface `Expression`
  Overrides:
    `evaluateItem` in class `ComputedExpression`
  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.

  Specified by:
    `iterate` in interface `Expression`
  Overrides:
    `iterate` in class `ComputedExpression`
  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.String 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.

  Specified by:
    `evaluateAsString` in interface `Expression`
  Overrides:
    `evaluateAsString` in class `ComputedExpression`
  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?

### effectiveBooleanValue

    public final boolean effectiveBooleanValue(XPathContext context)
                                        throws XPathException

  Get the effective boolean value of the expression. This returns false if the value is the empty sequence, a zero-length string, a number equal to zero, or the boolean false. Otherwise it returns true.

  Specified by:
    `effectiveBooleanValue` in interface `Expression`
  Overrides:
    `effectiveBooleanValue` in class `ComputedExpression`
  Parameters:
    `context` - The context in which the expression is to be evaluated
  Returns:
    the effective boolean value
  Throws:
    `XPathException` - if any dynamic error occurs evaluating the expression

### getInstructionInfo

    public InstructionInfo getInstructionInfo()

  Description copied from class: `ComputedExpression`
  Get InstructionInfo for this expression

  Specified by:
    `getInstructionInfo` in interface `InstructionInfoProvider`
  Overrides:
    `getInstructionInfo` in class `ComputedExpression`

### appendItem

    public static void appendItem(Item it,
                                  SequenceReceiver out,
                                  int locationId)
                           throws XPathException

  Static method to append an item that results from evaluating an expression to the current result receiver. The method checks to see whether the item returned from the expression is actually a function-call-package representing the result of a tail call optimization; if so, the tail function calls are complete and the final result is passed on.

  Parameters:
    `it` - the item: possibly a FunctionCallPackage
    `out` - the Receiver
  Throws:
    `XPathException`

### isXSLT

    public boolean isXSLT(XPathContext context)

  Establish whether this is an XSLT instruction or an XQuery instruction (used to produce appropriate diagnostics)

  Parameters:
    `context` -
  Returns:
    true for XSLT, false for XQuery