Package net.sf.saxon.expr.instruct
Class NumberInstruction
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.instruct.NumberInstruction
-
- All Implemented Interfaces:
ExportAgent
,Locatable
,IdentityComparable
,Traceable
public class NumberInstruction extends Expression
This instruction performs the node-counting function of the xsl:number instruction. It delivers as its result a sequence of integers. The parent expression is typically aNumberSequenceFormatter
which takes this sequence of integers and performs the necessary formatting.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ANY
static java.lang.String[]
LEVEL_NAMES
static int
MULTI
static int
SIMPLE
static int
SINGLE
-
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD
-
-
Constructor Summary
Constructors Constructor Description NumberInstruction(Expression select, int level, Pattern count, Pattern from)
Construct a NumberInstruction
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
computeCardinality()
Compute the static cardinality of this expressionExpression
copy(RebindingMap rebindings)
Copy an expression.void
export(ExpressionPresenter out)
Diagnostic print of expression structure.Pattern
getCount()
Get the count pattern, if specifiedElaborator
getElaborator()
Make an elaborator for this expressionjava.lang.String
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.Pattern
getFrom()
Get the from pattern, if specifiedint
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().ItemType
getItemType()
Determine the static item type of the expression, as precisely possible.int
getLevel()
Get the level attributeExpression
getSelect()
Get the select expressionboolean
isInstruction()
Ask whether this expression is an instruction.SequenceIterator
iterate(XPathContext context)
Compute the required node number as a sequence of integersjava.lang.Iterable<Operand>
operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.Expression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform optimisation of an expression and its subexpressions.-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeSpecialProperties, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, evaluateAsString, evaluateItem, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getIntrinsicDependencies, getLocalRetainedStaticContext, getLocation, getNetCost, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getStreamerName, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, toShortString, toString, typeCheck, typeCheckChildren, typeError, unordered, verifyParentPointers, withLocation
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Field Detail
-
SINGLE
public static final int SINGLE
- See Also:
- Constant Field Values
-
MULTI
public static final int MULTI
- See Also:
- Constant Field Values
-
ANY
public static final int ANY
- See Also:
- Constant Field Values
-
SIMPLE
public static final int SIMPLE
- See Also:
- Constant Field Values
-
LEVEL_NAMES
public static final java.lang.String[] LEVEL_NAMES
-
-
Constructor Detail
-
NumberInstruction
public NumberInstruction(Expression select, int level, Pattern count, Pattern from)
Construct a NumberInstruction- Parameters:
select
- the expression supplied in the select attributelevel
- one of "single", "level", "multi"count
- the pattern supplied in the count attributefrom
- the pattern supplied in the from attribute
-
-
Method Detail
-
isInstruction
public boolean isInstruction()
Ask whether this expression is an instruction. In XSLT streamability analysis this is used to distinguish constructs corresponding to XSLT instructions from other constructs, typically XPath expressions.- Overrides:
isInstruction
in classExpression
- Returns:
- true -- this construct originates as an XSLT instruction
-
operands
public java.lang.Iterable<Operand> operands()
Description copied from class:Expression
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.
- Overrides:
operands
in classExpression
- Returns:
- an iterator containing the sub-expressions of this expression
-
getLevel
public int getLevel()
Get the level attribute- Returns:
- the coded value of the level attribute
-
getCount
public Pattern getCount()
Get the count pattern, if specified- Returns:
- the count pattern if there is one, otherwise null
-
getFrom
public Pattern getFrom()
Get the from pattern, if specified- Returns:
- the from pattern if there is one, otherwise null
-
getSelect
public Expression getSelect()
Get the select expression- Returns:
- the select expression (which defaults to a ContextItemExpression)
-
copy
public Expression copy(RebindingMap rebindings)
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- a mutable list of (old binding, new binding) pairs * that is used to update the bindings held in any * local variable references that are copied.- Returns:
- the copy of the original expression
-
getItemType
public ItemType getItemType()
Description copied from class:Expression
Determine the static item type of the expression, as precisely possible. All expression return sequences, in general; this method determines the type of the items within the sequence, assuming that (a) this is known in advance, and (b) it is the same for all items in the sequence.This method should always return a result, though it may be the best approximation that is available at the time.
- Specified by:
getItemType
in classExpression
- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
-
computeCardinality
protected int computeCardinality()
Description copied from class:Expression
Compute the static cardinality of this expression- Specified by:
computeCardinality
in classExpression
- Returns:
- the computed cardinality, as one of the values
StaticProperty.ALLOWS_ZERO_OR_ONE
,StaticProperty.EXACTLY_ONE
,StaticProperty.ALLOWS_ONE_OR_MORE
,StaticProperty.ALLOWS_ZERO_OR_MORE
. May also returnStaticProperty.ALLOWS_ZERO
if the result is known to be an empty sequence, orStaticProperty.ALLOWS_MANY
if if is known to return a sequence of length two or more.
-
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 provided directly. The other methods will always be available indirectly, using an implementation that relies on one of the other methods.- Specified by:
getImplementationMethod
in classExpression
- Returns:
- the implementation method, for example
Expression.ITERATE_METHOD
orExpression.EVALUATE_METHOD
orExpression.PROCESS_METHOD
-
optimize
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException
Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.
- Overrides:
optimize
in classExpression
- Parameters:
visitor
- an expression visitorcontextInfo
- 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 toType.ITEM_TYPE
- Returns:
- the original expression, rewritten if appropriate to optimize execution
- Throws:
XPathException
- if an error is discovered during this phase (typically a type error)
-
iterate
public SequenceIterator iterate(XPathContext context) throws XPathException
Compute the required node number as a sequence of integers- Overrides:
iterate
in classExpression
- Parameters:
context
- supplies the context for evaluation- Returns:
- a SequenceIterator of
IntegerValue
values - Throws:
XPathException
- if a failure occurs
-
getExpressionName
public java.lang.String getExpressionName()
Description copied from class:Expression
Get a name identifying the kind of expression, in terms meaningful to a user.- Overrides:
getExpressionName
in classExpression
- Returns:
- a name identifying the kind of expression, in terms meaningful to a user. The name will always be in the form of a lexical XML QName, and should match the name used in export() output displaying the expression.
-
export
public void export(ExpressionPresenter out) throws XPathException
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.- Specified by:
export
in interfaceExportAgent
- Specified by:
export
in classExpression
- Parameters:
out
- the expression presenter used to display the structure- Throws:
XPathException
- if the export fails, for example if an expression is found that won't work in the target environment.
-
getElaborator
public Elaborator getElaborator()
Make an elaborator for this expression- Overrides:
getElaborator
in classExpression
- Returns:
- an appropriate
Elaborator
-
-