Package com.saxonica.ee.optim
Class SwitchExpression
java.lang.Object
net.sf.saxon.expr.Expression
com.saxonica.ee.optim.SwitchExpression
- All Implemented Interfaces:
ExportAgent
,ConditionalInstruction
,Locatable
,IdentityComparable
,Traceable
An optimized Choose expression in which all the branches are tests of the same expression for equality
with some value. Note this is not quite the same as the XQuery 3.1 switch expression; this switch expression
is usually generated as the result of optimizing an xsl:choose or extended if/then/else expression.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Data structure used for holding details of a switch expressionstatic class
Elaborator for a "Switch" expression (typically anxsl:choose
that tests one expression against a list of constants: not exactly equivalent to an XQuery 3.1 switch expression). -
Field Summary
FieldsFields 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
ConstructorsConstructorDescriptionSwitchExpression
(SwitchExpression.SwitchCaseInfo switchCaseInfo) Create a switch expression -
Method Summary
Modifier and TypeMethodDescriptionboolean
Ask whether common subexpressions found in the operands of this expression can be extracted and evaluated outside the expression itself.protected int
Compute the static cardinality of this expressioncopy
(RebindingMap rebindings) Copy an expression.evaluateItem
(XPathContext context) Evaluate an expression as a single item.void
Diagnostic print of expression structure.getAction
(int index) Get the map from XPathComparable objects representing the values to the expressions to be executed for each of these valuesGet the collation usedMake an elaborator for this expressionGet a name identifying the kind of expression, in terms meaningful to a user.int
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().int
getIndex
(AtomicMatchKey key) Determine the data type of the expression, if possible.Get the default ("otherwise") expressionGet the (partial) name of a class that supports streaming of this kind of expressionGet the subject expression (the expression that computes the switch value)boolean
Ask whether this expression is an instruction.iterate
(XPathContext context) Return an Iterator to iterate over the values of a sequence.operands()
Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.void
process
(Outputter output, XPathContext context) Process the instruction, without returning any tail callsvoid
setInstruction
(boolean inst) Say whether this switch expression originates as an XSLT instructionunordered
(boolean retainAllNodes, boolean forStreaming) Replace this expression by a simpler expression that delivers the results without regard to order.Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeSpecialProperties, computeStaticProperties, dispatchTailCall, dynamicError, effectiveBooleanValue, equals, evaluateAsString, 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, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, makeElaborator, markTailFunctionCalls, operandList, operandSparseList, optimize, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, supportsLazyEvaluation, suppressValidation, toPattern, toShortString, toString, typeCheck, typeCheckChildren, typeError, 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 Details
-
SUBJECT
-
-
Constructor Details
-
SwitchExpression
Create a switch expression- Parameters:
switchCaseInfo
- details of the expression to be constructed
-
-
Method Details
-
setInstruction
public void setInstruction(boolean inst) Say whether this switch expression originates as an XSLT instruction- Parameters:
inst
- true if this started life as an xsl:choose instruction
-
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.- Overrides:
isInstruction
in classExpression
- Returns:
- true if this construct originates as an XSLT instruction
-
getSubjectExpression
Get the subject expression (the expression that computes the switch value)- Returns:
- the expression that computes the switch value
-
getCaseMap
Get the map from XPathComparable objects representing the values to the expressions to be executed for each of these values- Returns:
- the map of case clauses
-
getOtherwiseExpression
Get the default ("otherwise") expression- Returns:
- the "otherwise" expression giving the value to be returned if none of the cases match
-
getAction
-
getActions
-
getOtherwiseOperand
-
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
-
getCollation
Get the collation used- Returns:
- the collation
-
computeCardinality
protected int computeCardinality()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
-
allowExtractingCommonSubexpressions
public boolean allowExtractingCommonSubexpressions()Ask whether common subexpressions found in the operands of this expression can be extracted and evaluated outside the expression itself. The result is irrelevant in the case of operands evaluated with a different focus, which will never be extracted in this way, even if they have no focus dependency.- Overrides:
allowExtractingCommonSubexpressions
in classExpression
- Returns:
- false for this kind of expression
-
copy
Copy an expression. This makes a deep copy.- Specified by:
copy
in classExpression
- Parameters:
rebindings
- variables that need to be re-bound- Returns:
- the copy of the original expression
-
export
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.
-
getItemType
Determine the data type of the expression, if 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)
-
unordered
Replace this expression by a simpler expression that delivers the results without regard to order.- Overrides:
unordered
in classExpression
- Parameters:
retainAllNodes
- set to true if the result must contain exactly the same nodes as the original; set to false if the result can eliminate (or introduce) duplicates.forStreaming
- set to true if optimizing for streaming- Returns:
- an expression that delivers the same nodes in a more convenient order
- Throws:
XPathException
- if the rewrite fails
-
evaluateItem
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.- Overrides:
evaluateItem
in classExpression
- 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:
XPathException
- if any dynamic error occurs evaluating the expression
-
getIndex
-
iterate
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.- Overrides:
iterate
in classExpression
- Parameters:
context
- supplies the context for evaluation- Returns:
- a SequenceIterator that can be used to iterate over the result of the expression
- Throws:
XPathException
- if any dynamic error occurs evaluating the expression
-
process
Process the instruction, without returning any tail calls- Overrides:
process
in classExpression
- Parameters:
output
- the destination for the resultcontext
- The dynamic context, giving access to the current node,- Throws:
XPathException
- if a dynamic error occurs
-
getImplementationMethod
public int getImplementationMethod()Description copied from class:Expression
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
-
getExpressionName
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.
-
getStreamerName
Description copied from class:Expression
Get the (partial) name of a class that supports streaming of this kind of expression- Overrides:
getStreamerName
in classExpression
- Returns:
- the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class
-
getElaborator
Make an elaborator for this expression- Overrides:
getElaborator
in classExpression
- Returns:
- a suitable elaborator
-