Class PromotionOffer

java.lang.Object
net.sf.saxon.expr.parser.PromotionOffer

public class PromotionOffer extends Object
PromotionOffer is an object used transiently during compilation of an expression. It contains information passed by a containing expression to its subexpressions, when looking for subexpressions that can be promoted to a higher level because they are not dependent on the context established by the containing expression. The object is also used to pass back return information when the promotion actually takes place.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    Flag that is set if the offer has been accepted, that is, if the expression has changed
    int
    action is one of the possible promotion actions, FOCUS_INDEPENDENT, RANGE_INDEPENDENT, INLINE_VARIABLE_REFERENCES, UNORDERED, EXTRACT_GLOBAL_VARIABLES
    In the case of RANGE_INDEPENDENT, "binding" identifies the range variables whose dependencies we are looking for.
    When a promotion offer is made, containingExpression identifies the level to which the promotion should occur.
    static final int
    EXTRACT_GLOBAL_VARIABLES identifies subexpressions that are not constant, but have no dependencies other than on global variables or parameters (they must also be non-creative).
    static final int
    FOCUS_INDEPENDENT requests promotion of all non-trivial subexpressions that don't depend on the focus.
    static final int
    Inline variable references causes all references to a variable V to be replaced by the expression E.
    boolean
    In the case of FOCUS_INDEPENDENT, "promoteDocumentDependent" is a boolean that, when set to true, indicates that it is safe to promote a subexpression that depends on the context document but not on other aspects of the focus.
    boolean
    In the case of FOCUS_INDEPENDENT, "promoteXSLTFunctions" is a boolean that, when set to true, indicates that it is safe to promote XSLT functions such as current().
    static final int
    RANGE_INDEPENDENT requests promotion of all non-trivial subexpressions that don't depend on a specified range variable.
    static final int
    REPLACE_CURRENT causes calls to the XSLT current() function to be replaced by reference to a variable.
    boolean
    In the case of UNORDERED, "retainAllNodes" is a boolean that is set to true if the nodes can be delivered in any order so long as the right number of nodes are delivered.
    static final int
    UNORDERED indicates that the containing expression does not require the results to be delivered in any particular order.
    The expression visitor in use
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a PromotionOffer for use with a particular Optimizer
  • Method Summary

    Modifier and Type
    Method
    Description
    accept(Expression parent, Expression child)
    Method to test whether a subexpression qualifies for promotion, and if so, to accept the promotion.
    Get the optimizer in use

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FOCUS_INDEPENDENT

      public static final int FOCUS_INDEPENDENT
      FOCUS_INDEPENDENT requests promotion of all non-trivial subexpressions that don't depend on the focus. This is typically used to extract subexpressions from a filter predicate. The offer is optional - each subexpression can decide whether it's worth the trouble of promoting itself. The offer is normally passed on to subexpressions, except subexpressions that are evaluated with a different focus
      See Also:
    • RANGE_INDEPENDENT

      public static final int RANGE_INDEPENDENT
      RANGE_INDEPENDENT requests promotion of all non-trivial subexpressions that don't depend on a specified range variable. This is typically used to extract subexpressions from the action of a for expression or the condition of a some/every quantified expression. The offer is optional - each subexpression can decide whether it's worth the trouble of promoting itself. The offer is normally passed on to subexpressions, except subexpressions that are evaluated with a different focus or a different range variable, because these may have other dependencies that prevent their promotion.
      See Also:
    • INLINE_VARIABLE_REFERENCES

      public static final int INLINE_VARIABLE_REFERENCES
      Inline variable references causes all references to a variable V to be replaced by the expression E. The variable is supplied in the "binding" property; the replacement expression in the containingExpression property. A special case is where the replacement expression is a ContextItemExpression; in this case the offer is not passed on to subexpressions where the context is different.
      See Also:
    • UNORDERED

      public static final int UNORDERED
      UNORDERED indicates that the containing expression does not require the results to be delivered in any particular order. The boolean mustEliminateDuplicates is set if duplicate items in the result are not allowed.
      See Also:
    • REPLACE_CURRENT

      public static final int REPLACE_CURRENT
      REPLACE_CURRENT causes calls to the XSLT current() function to be replaced by reference to a variable. The variable binding is the single member of the array bindingList
      See Also:
    • EXTRACT_GLOBAL_VARIABLES

      public static final int EXTRACT_GLOBAL_VARIABLES
      EXTRACT_GLOBAL_VARIABLES identifies subexpressions that are not constant, but have no dependencies other than on global variables or parameters (they must also be non-creative). Such expressions can be extracted from a function or template and converted into global variables. This optimization is done in Saxon-EE only.
      See Also:
    • visitor

      public ExpressionVisitor visitor
      The expression visitor in use
    • action

      public int action
      action is one of the possible promotion actions, FOCUS_INDEPENDENT, RANGE_INDEPENDENT, INLINE_VARIABLE_REFERENCES, UNORDERED, EXTRACT_GLOBAL_VARIABLES
    • promoteDocumentDependent

      public boolean promoteDocumentDependent
      In the case of FOCUS_INDEPENDENT, "promoteDocumentDependent" is a boolean that, when set to true, indicates that it is safe to promote a subexpression that depends on the context document but not on other aspects of the focus. This is the case, for example, in a filter expression when it is known that all the nodes selected by the expression will be in the same document - as happens when the filter is applied to a path expression. This allows subexpressions such as key() to be promoted
    • promoteXSLTFunctions

      public boolean promoteXSLTFunctions
      In the case of FOCUS_INDEPENDENT, "promoteXSLTFunctions" is a boolean that, when set to true, indicates that it is safe to promote XSLT functions such as current(). This flag is set when rewriting XPath expressions and is unset when rewriting XSLT templates.
    • retainAllNodes

      public boolean retainAllNodes
      In the case of UNORDERED, "retainAllNodes" is a boolean that is set to true if the nodes can be delivered in any order so long as the right number of nodes are delivered. If this boolean is false, the caller doesn't care whether duplicate nodes are retained or whether they are eliminated.
    • bindingList

      public Binding[] bindingList
      In the case of RANGE_INDEPENDENT, "binding" identifies the range variables whose dependencies we are looking for. For INLINE_VARIABLE_REFERENCES it is a single Binding that we are aiming to inline
    • containingExpression

      public Expression containingExpression
      When a promotion offer is made, containingExpression identifies the level to which the promotion should occur. When a subexpression is promoted, an expression of the form let $VAR := SUB return ORIG is created, and this replaces the original containingExpression within the PromotionOffer.
    • accepted

      public boolean accepted
      Flag that is set if the offer has been accepted, that is, if the expression has changed
  • Constructor Details

    • PromotionOffer

      public PromotionOffer(Optimizer optimizer)
      Create a PromotionOffer for use with a particular Optimizer
      Parameters:
      optimizer - the optimizer
  • Method Details

    • getOptimizer

      public Optimizer getOptimizer()
      Get the optimizer in use
      Returns:
      the optimizer
    • accept

      public Expression accept(Expression parent, Expression child) throws XPathException
      Method to test whether a subexpression qualifies for promotion, and if so, to accept the promotion.
      Parameters:
      parent -
      child - the subexpression in question
      Returns:
      if promotion was done, returns the expression that should be used in place of the child expression. If no promotion was done, returns null. If promotion is determined not to be necessary for this subtree, returns the supplied child expression unchanged
      Throws:
      XPathException