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).
booleancreatesNewNodes()
Determine whether this instruction creates new nodes.
voiddisplay(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure.
ItemevaluateItem(XPathContext context)
Evaluate an expression as a single item.
intgetCardinality()
Determine the static cardinality of the expression.
intgetDependencies()
Determine which aspects of the context the expression depends on.
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.
IteratoriterateSubExpressions()
Expressionoptimize(Optimizer opt, StaticContext env, ItemType contextItemType)
TailCallprocessLeavingTail(XPathContext context)
Execute this instruction, with the possibility of returning tail calls if there are any.
Expressionpromote(PromotionOffer offer)
Offer promotion for this subexpression.
Expressionsimplify(StaticContext env)
Simplify an expression.
ExpressiontypeCheck(StaticContext env, 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

createsNewNodes

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

display

public void display(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure. The expression is written to the System.err output stream

Parameters: level indentation level for this expression out

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

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

getInstructionNameCode

public int getInstructionNameCode()

getItemType

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

Parameters: th

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 iterateSubExpressions()

optimize

public Expression optimize(Optimizer opt, StaticContext env, 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)
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

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

simplify

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

Returns: the simplified expression

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

typeCheck

public Expression typeCheck(StaticContext env, ItemType contextItemType)