Package net.sf.saxon.expr
Class CompareToConstant
- java.lang.Object
-
- net.sf.saxon.expr.Expression
-
- net.sf.saxon.expr.UnaryExpression
-
- net.sf.saxon.expr.CompareToConstant
-
- All Implemented Interfaces:
ComparisonExpression
,ExportAgent
,Locatable
,IdentityComparable
,Traceable
- Direct Known Subclasses:
CompareToIntegerConstant
,CompareToStringConstant
public abstract class CompareToConstant extends UnaryExpression implements ComparisonExpression
This class implements a comparison of a computed value to a literal constant using one of the operators eq, ne, lt, gt, le, ge. The semantics are identical to ValueComparison, but this is a fast path for an important common case. Different subclasses handle different types of constant.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
operator
-
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 CompareToConstant(Expression p0)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected int
computeSpecialProperties()
Get the static properties of this expression (other than its type).boolean
convertsUntypedToOther()
Determine whether untyped atomic values should be converted to the type of the other operandBooleanValue
evaluateItem(XPathContext context)
Evaluate an expression as a single item.int
getComparisonOperator()
Get the comparison operatorint
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().ItemType
getItemType()
Determine the data type of the expression, if possible.Operand
getLhs()
Get the left-hand operand of the comparisonExpression
getLhsExpression()
Get the left-hand expressionprotected OperandRole
getOperandRole()
Get the usage (in terms of streamability analysis) of the single operandOperand
getRhs()
Get the right-hand operand of the comparisonabstract Expression
getRhsExpression()
Get the right-hand expressionint
getSingletonOperator()
Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGEExpression
optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)
Perform optimisation of an expression and its subexpressions.-
Methods inherited from class net.sf.saxon.expr.UnaryExpression
computeCardinality, computeHashCode, displayOperator, emitExtraAttributes, equals, export, getBaseExpression, getOperand, operands, setBaseExpression, toShortString, toString, typeCheck
-
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeStaticProperties, copy, dynamicError, effectiveBooleanValue, evaluateAsString, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExpressionName, getExtraProperty, getIntegerBounds, getInterpretedExpression, 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, isInstruction, isLiftable, isMultiThreaded, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, iterate, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, process, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, typeCheckChildren, typeError, unordered, verifyParentPointers
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.expr.ComparisonExpression
getAtomicComparer
-
Methods inherited from interface net.sf.saxon.trace.Traceable
gatherProperties
-
-
-
-
Constructor Detail
-
CompareToConstant
public CompareToConstant(Expression p0)
-
-
Method Detail
-
getOperandRole
protected OperandRole getOperandRole()
Description copied from class:UnaryExpression
Get the usage (in terms of streamability analysis) of the single operand- Specified by:
getOperandRole
in classUnaryExpression
- Returns:
- the operand usage
-
getLhsExpression
public Expression getLhsExpression()
Description copied from interface:ComparisonExpression
Get the left-hand expression- Specified by:
getLhsExpression
in interfaceComparisonExpression
- Returns:
- the first operand expression
-
getLhs
public Operand getLhs()
Description copied from interface:ComparisonExpression
Get the left-hand operand of the comparison- Specified by:
getLhs
in interfaceComparisonExpression
- Returns:
- the first operand
-
getRhsExpression
public abstract Expression getRhsExpression()
Description copied from interface:ComparisonExpression
Get the right-hand expression- Specified by:
getRhsExpression
in interfaceComparisonExpression
- Returns:
- the second operand expression
-
getRhs
public Operand getRhs()
Description copied from interface:ComparisonExpression
Get the right-hand operand of the comparison- Specified by:
getRhs
in interfaceComparisonExpression
- Returns:
- the second operand
-
getComparisonOperator
public int getComparisonOperator()
Get the comparison operator
-
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 value
Expression.EVALUATE_METHOD
-
computeSpecialProperties
protected int computeSpecialProperties()
Description copied from class:UnaryExpression
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.- Overrides:
computeSpecialProperties
in classUnaryExpression
- Returns:
- the special properties, as a bit-significant integer
-
evaluateItem
public BooleanValue evaluateItem(XPathContext context) throws XPathException
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
-
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 classUnaryExpression
- Parameters:
visitor
- the 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)
-
getItemType
public ItemType 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.
- Overrides:
getItemType
in classUnaryExpression
- Returns:
- a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
-
getSingletonOperator
public int getSingletonOperator()
Get the primitive (singleton) operator used: one of Token.FEQ, Token.FNE, Token.FLT, Token.FGT, Token.FLE, Token.FGE- Specified by:
getSingletonOperator
in interfaceComparisonExpression
- Returns:
- the operator, as defined in class
Token
-
convertsUntypedToOther
public boolean convertsUntypedToOther()
Determine whether untyped atomic values should be converted to the type of the other operand- Specified by:
convertsUntypedToOther
in interfaceComparisonExpression
- Returns:
- true if untyped values should be converted to the type of the other operand, false if they should be converted to strings.
-
-