net.sf.saxon.instruct

Class TraceWrapper

public class TraceWrapper extends Instruction

This class is a tracing wrapper around any expression: it delivers the same result as the wrapped expression, but traces its evaluation to a TraceListener
Field Summary
Expressionchild
Method Summary
intcomputeDependencies()
Get the static properties of this expression (other than its type).
Expressioncopy()
Copy an expression.
booleancreatesNewNodes()
Determine whether this instruction creates new nodes.
ItemevaluateItem(XPathContext context)
Evaluate an expression as a single item.
voidevaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
intgetCardinality()
Determine the static cardinality of the expression.
intgetDependencies()
Determine which aspects of the context the expression depends on.
intgetImplementationMethod()
InstructionInfogetInstructionInfo()
Get the instruction details
intgetInstructionNameCode()
ItemTypegetItemType(TypeHierarchy th)
Get the item type of the items returned by evaluating this instruction
SequenceIteratoriterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
Iterator<Expression>iterateSubExpressions()
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
TailCallprocessLeavingTail(XPathContext context)
Execute this instruction, with the possibility of returning tail calls if there are any.
Expressionpromote(PromotionOffer offer, Expression parent)
Offer promotion for this subexpression.
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression.
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Field Detail

child

Expression child

Method Detail

computeDependencies

public int computeDependencies()
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.

Returns: a set of flags indicating static properties of this expression

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

createsNewNodes

public final boolean createsNewNodes()
Determine whether this instruction creates new nodes.

evaluateItem

public Item evaluateItem(XPathContext context)
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.

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: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression

evaluatePendingUpdates

public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List. The default implementation of this method, which is used for non-updating expressions, throws an UnsupportedOperationException

Parameters: context the XPath dynamic evaluation context pul the pending update list to which the results should be written

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

getCardinality

public int getCardinality()
Determine the static cardinality of the expression. This establishes how many items there will be in the result of the expression, at compile time (i.e., without actually evaluating the result.

Returns: one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).

getDependencies

public int getDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as DEPENDS_ON_CONTEXT_ITEM and DEPENDS_ON_CURRENT_ITEM. The default implementation combines the intrinsic dependencies of this expression with the dependencies of the subexpressions, computed recursively. This is overridden for expressions such as FilterExpression where a subexpression's dependencies are not necessarily inherited by the parent expression.

Returns: a set of bit-significant flags identifying the dependencies of the expression

getImplementationMethod

public int getImplementationMethod()

getInstructionInfo

public InstructionInfo getInstructionInfo()
Get the instruction details

Returns: the details of the child instruction (the instruction being traced)

getInstructionNameCode

public int getInstructionNameCode()

getItemType

public ItemType getItemType(TypeHierarchy th)
Get the item type of the items returned by evaluating this instruction

Parameters: th the type hierarchy cache

Returns: the static item type of the instruction

iterate

public SequenceIterator iterate(XPathContext context)
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.

Parameters: context supplies the context for evaluation

Returns: a SequenceIterator that can be used to iterate over the result of the expression

Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

processLeavingTail

public TailCall processLeavingTail(XPathContext context)
Execute this instruction, with the possibility of returning tail calls if there are any. This outputs the trace information via the registered TraceListener, and invokes the instruction being traced.

Parameters: context the dynamic execution context

Returns: either null, or a tail call that the caller must invoke on return

Throws: net.sf.saxon.trans.XPathException

promote

public Expression promote(PromotionOffer offer, Expression parent)
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.

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 parent

Returns: if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression

Throws: net.sf.saxon.trans.XPathException if any error is detected

replaceSubExpression

public boolean replaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression

Parameters: original the original subexpression replacement the replacement subexpression

Returns: true if the original subexpression is found

simplify

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

Parameters: visitor an expression visitor

Returns: the simplified expression

Throws: net.sf.saxon.trans.XPathException if an error is discovered during expression rewriting

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)