net.sf.saxon.expr

Class SlashExpression

public class SlashExpression extends Expression implements ContextMappingFunction, ContextSwitchingExpression

A slash expression is any expression using the binary slash operator "/". The parser initially generates a slash expression for all occurrences of the binary "/" operator. Subsequently, as a result of type inferencing, the majority of slash expressions will be rewritten as instances of PathExpression (returning nodes) or AtomicMappingExpressions (returning atomic values). However, in the rare case where it is not possible to determine statically whether the rh operand returns nodes or atomic values, instances of this class may need to be interpreted directly at run time.
Field Summary
Expressionstart
Expressionstep
Constructor Summary
SlashExpression(Expression start, Expression step)
Constructor
Method Summary
intcomputeCardinality()
Determine the static cardinality of the expression
intcomputeDependencies()
Determine which aspects of the context the expression depends on.
intcomputeSpecialProperties()
Get the static properties of this expression (other than its type).
Expressioncopy()
Copy an expression.
booleanequals(Object other)
Is this expression the same as another expression?
voidexplain(ExpressionPresenter destination)
Diagnostic print of expression structure.
ExpressiongetControlledExpression()
Get the step expression (the right-hand operand)
ExpressiongetControllingExpression()
Get the start expression (the left-hand operand)
ExpressiongetFirstStep()
Get the first step in this expression.
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the items returned by this exprssion
ExpressiongetLastStep()
Get the last step of the path expression
ExpressiongetLeadingSteps()
Get a path expression consisting of all steps except the last
ExpressiongetRemainingSteps()
Get all steps after the first.
inthashCode()
get HashCode for comparing two expressions
booleanhasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly
booleanisHybrid()
Determine whether this expression is capable (as far as static analysis is concerned) of returning a mixture of nodes and atomic values.
SequenceIteratoriterate(XPathContext context)
Iterate the path-expression in a given context
Iterator<Expression>iterateSameFocusSubExpressions()
Get the immediate sub-expressions of this expression that are evaluated with the same focus (context item, position, and size) as the parent expression.
Iterator<Expression>iterateSubExpressions()
Get the immediate subexpressions of this expression
static SlashExpressionmakeSlashExpression(Expression start, Expression step, TypeHierarchy th)
Static factory method, allowing early instantiation of a subclass if the type of the step expression is already known
SequenceIteratormap(XPathContext context)
Mapping function, from a node returned by the start iteration, to a sequence returned by the child.
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
Expressionpromote(PromotionOffer offer, Expression parent)
Promote this expression if possible
protected ExpressionpromoteFocusIndependentSubexpressions(ExpressionVisitor visitor, ItemType contextItemType)
If any subexpressions within the step are not dependent on the focus, and if they are not "creative" expressions (expressions that can create new nodes), then promote them: this causes them to be evaluated once, outside the path expression
booleanreplaceSubExpression(Expression original, Expression replacement)
Replace one subexpression by a replacement subexpression
protected voidsetStartExpression(Expression start2)
protected voidsetStepExpression(Expression step2)
Expressionsimplify(ExpressionVisitor visitor)
Simplify an expression
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression

Field Detail

start

Expression start

step

Expression step

Constructor Detail

SlashExpression

public SlashExpression(Expression start, Expression step)
Constructor

Parameters: start The left hand operand (which must always select a sequence of nodes). step The step to be followed from each node in the start expression to yield a new sequence; this may return either nodes or atomic values (but not a mixture of the two)

Method Detail

computeCardinality

public int computeCardinality()
Determine the static cardinality of the expression

computeDependencies

public int computeDependencies()
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and XPathContext.CURRENT_NODE

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.

copy

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

Returns: the copy of the original expression

equals

public boolean equals(Object other)
Is this expression the same as another expression?

explain

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

getControlledExpression

public Expression getControlledExpression()
Get the step expression (the right-hand operand)

Returns: the second operand

getControllingExpression

public Expression getControllingExpression()
Get the start expression (the left-hand operand)

Returns: the first operand

getFirstStep

public Expression getFirstStep()
Get the first step in this expression. A path expression A/B/C is represented as (A/B)/C, but the first step is A

Returns: the first step in the expression, after expanding any nested path expressions

getItemType

public final ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by this exprssion

Parameters: th the type hierarchy cache

Returns: the type of the step

getLastStep

public Expression getLastStep()
Get the last step of the path expression

Returns: the last step in the expression, after expanding any nested path expressions

getLeadingSteps

public Expression getLeadingSteps()
Get a path expression consisting of all steps except the last

Returns: a path expression containing all steps in this path expression other than the last, after expanding any nested path expressions

getRemainingSteps

public Expression getRemainingSteps()
Get all steps after the first. This is complicated by the fact that A/B/C is represented as ((A/B)/C; we are required to return B/C

Returns: a path expression containing all steps in this path expression other than the first, after expanding any nested path expressions

hashCode

public int hashCode()
get HashCode for comparing two expressions

hasLoopingSubexpression

public boolean hasLoopingSubexpression(Expression child)
Given an expression that is an immediate child of this expression, test whether the evaluation of the parent expression causes the child expression to be evaluated repeatedly

Parameters: child the immediate subexpression

Returns: true if the child expression is evaluated repeatedly

isHybrid

public boolean isHybrid()
Determine whether this expression is capable (as far as static analysis is concerned) of returning a mixture of nodes and atomic values. If so, this needs to be prevented at run time

Returns: true if the static type allows both nodes and atomic values

iterate

public SequenceIterator iterate(XPathContext context)
Iterate the path-expression in a given context

Parameters: context the evaluation context

iterateSameFocusSubExpressions

public Iterator<Expression> iterateSameFocusSubExpressions()
Get the immediate sub-expressions of this expression that are evaluated with the same focus (context item, position, and size) as the parent expression.

Returns: an iterator containing those sub-expressions of this expression that are evaluated with the same focus as the parent expression

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()
Get the immediate subexpressions of this expression

makeSlashExpression

public static SlashExpression makeSlashExpression(Expression start, Expression step, TypeHierarchy th)
Static factory method, allowing early instantiation of a subclass if the type of the step expression is already known

map

public final SequenceIterator map(XPathContext context)
Mapping function, from a node returned by the start iteration, to a sequence returned by the child.

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

promote

public Expression promote(PromotionOffer offer, Expression parent)
Promote this expression if possible

promoteFocusIndependentSubexpressions

protected Expression promoteFocusIndependentSubexpressions(ExpressionVisitor visitor, ItemType contextItemType)
If any subexpressions within the step are not dependent on the focus, and if they are not "creative" expressions (expressions that can create new nodes), then promote them: this causes them to be evaluated once, outside the path expression

Parameters: visitor the expression visitor contextItemType the type of the context item for evaluating the start expression

Returns: the rewritten expression, or the original expression if no rewrite was possible

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

setStartExpression

protected void setStartExpression(Expression start2)

setStepExpression

protected void setStepExpression(Expression step2)

simplify

public Expression simplify(ExpressionVisitor visitor)
Simplify an expression

Parameters: visitor the expression visitor

Returns: the simplified expression

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Type-check the expression