public abstract class Expression extends Object implements Serializable, SourceLocator, InstructionInfo
Two expressions are considered equal if they return the same result when evaluated in the same context.
Modifier and Type | Field and Description |
---|---|
static int |
EFFECTIVE_BOOLEAN_VALUE |
static int |
EVALUATE_METHOD |
static int |
EVENT_FEED_METHOD |
static int |
INHERITED_CONTEXT |
static int |
INSPECTION_CONTEXT |
static int |
ITEM_FEED_METHOD |
static int |
ITERATE_METHOD |
protected int |
locationId |
static IntegerValue |
MAX_SEQUENCE_LENGTH |
static IntegerValue |
MAX_STRING_LENGTH |
static int |
NAVIGATION_CONTEXT |
static int |
NODE_VALUE_CONTEXT |
static int |
PROCESS_METHOD |
static int |
PUSH_SELECTION |
protected int |
staticProperties |
static IntegerValue |
UNBOUNDED_LOWER |
static IntegerValue |
UNBOUNDED_UPPER |
static int |
W3C_CONSUMING |
static int |
W3C_FREE_RANGING |
static int |
W3C_GROUP_CONSUMING |
static int |
W3C_MOTIONLESS |
static int |
WATCH_METHOD |
Constructor and Description |
---|
Expression() |
Modifier and Type | Method and Description |
---|---|
PathMap.PathMapNodeSet |
addToPathMap(PathMap pathMap,
PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.
|
void |
adoptChildExpression(Expression child)
Set up a parent-child relationship between this expression and a given child expression.
|
void |
checkForUpdatingSubexpressions()
Check to ensure that this expression does not contain any inappropriate updating subexpressions.
|
void |
checkPermittedContents(SchemaType parentType,
StaticContext env,
boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable
in the content model of a given complex type.
|
protected abstract int |
computeCardinality()
Compute the static cardinality of this expression
|
int |
computeDependencies()
Compute the dependencies of an expression, as the union of the
dependencies of its subexpressions.
|
protected int |
computeSpecialProperties()
Compute the special properties of this expression.
|
void |
computeStaticProperties()
Compute the static properties.
|
abstract Expression |
copy()
Copy an expression.
|
Expression |
doPromotion(Expression subexpression,
PromotionOffer offer)
Promote a subexpression if possible, and if the expression was changed, carry out housekeeping
to reset the static properties and correct the parent pointers in the tree
|
protected void |
dynamicError(String message,
String code,
XPathContext context)
Method used in subclasses to signal a dynamic error
|
boolean |
effectiveBooleanValue(XPathContext context)
Get the effective boolean value of the expression.
|
CharSequence |
evaluateAsString(XPathContext context)
Evaluate an expression as a String.
|
Item |
evaluateItem(XPathContext context)
Evaluate an expression as a single item.
|
void |
evaluatePendingUpdates(XPathContext context,
PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.
|
abstract void |
explain(ExpressionPresenter out)
Diagnostic print of expression structure.
|
void |
explain(OutputStream out)
Diagnostic print of expression structure.
|
int |
getCardinality()
Determine the static cardinality of the expression.
|
int |
getColumnNumber()
Get the column number of the expression
|
int |
getColumnNumber(long locationId)
Get the column number within the document, entity, or module containing a particular location
|
int |
getConstructType()
Get the type of this expression for use in tracing and diagnostics
|
Container |
getContainer()
Get the container in which this expression is located.
|
int |
getDependencies()
Determine which aspects of the context the expression depends on.
|
int |
getEvaluationMethod() |
Executable |
getExecutable()
Get the executable containing this expression
|
ExpressionCompiler |
getExpressionCompiler()
Return the compiler relating to a particular expression
|
String |
getExpressionName()
Get a name identifying the kind of expression, in terms meaningful to a user.
|
int |
getHostLanguage()
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container
|
int |
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
|
IntegerValue[] |
getIntegerBounds()
For an expression that returns an integer or a sequence of integers, get
a lower and upper bound on the values of the integers that may be returned, from
static analysis.
|
int |
getIntrinsicDependencies()
Determine the intrinsic dependencies of an expression, that is, those which are not derived
from the dependencies of its subexpressions.
|
abstract ItemType |
getItemType(TypeHierarchy th)
Determine the data type of the expression, if possible.
|
int |
getLineNumber()
Get the line number of the expression
|
int |
getLineNumber(long locationId)
Get the line number within the document or module containing a particular location
|
int |
getLocationId()
Get the location ID of the expression
|
LocationProvider |
getLocationProvider()
Get the LocationProvider allowing location identifiers to be resolved.
|
StructuredQName |
getObjectName()
Get a name identifying the object of the expression, for example a function name, template name,
variable name, key name, element name, etc.
|
Iterator<String> |
getProperties()
Get an iterator over all the properties available.
|
Object |
getProperty(String name)
Get the value of a particular property of the instruction.
|
String |
getPublicId()
Get the publicId of the module containing the expression (to satisfy the SourceLocator interface)
|
int[] |
getSlotsUsed()
Get the local variables (identified by their slot numbers) on which this expression depends.
|
int |
getSpecialProperties()
Get the static properties of this expression (other than its type).
|
int |
getStreamability(int syntacticContext,
boolean allowExtensions,
List<String> reasons)
Get the "sweep" of this expression as defined in the W3C streamability specifications.
|
StreamingAdjunct |
getStreamingAdjunct()
Get a class that supports streamed evaluation of this expression
|
String |
getSystemId()
Get the systemId of the module containing the expression
|
String |
getSystemId(long locationId)
Get the URI of the document or module containing a particular location
|
boolean |
hasVariableBinding(Binding binding) |
boolean |
implementsStaticTypeCheck()
Determine whether this expression implements its own method for static type checking
|
boolean |
isSubtreeExpression()
Determine whether the expression can be evaluated without reference to the part of the context
document outside the subtree rooted at the context node.
|
boolean |
isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification
|
boolean |
isVacuousExpression()
Determine whether this is a vacuous expression as defined in the XQuery update specification
|
SequenceIterator<? extends Item> |
iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
|
EventIterator |
iterateEvents(XPathContext context)
Deliver the result of the expression as a sequence of events.
|
Iterator<SubExpressionInfo> |
iterateSubExpressionInfo()
Get the immediate sub-expressions of this expression, with information about the relationship
of each expression to its parent expression.
|
Iterator<Expression> |
iterateSubExpressions()
Get the immediate sub-expressions of this expression.
|
int |
markTailFunctionCalls(StructuredQName qName,
int arity)
Mark tail-recursive calls on stylesheet functions.
|
Expression |
optimize(ExpressionVisitor visitor,
ExpressionVisitor.ContextItemType contextItemType)
Perform optimisation of an expression and its subexpressions.
|
void |
process(XPathContext context)
Process the instruction, without returning any tail calls
|
Expression |
promote(PromotionOffer offer,
Expression parent)
Offer promotion for this subexpression.
|
boolean |
replaceSubExpression(Expression original,
Expression replacement)
Replace one subexpression by a replacement subexpression
|
void |
resetLocalStaticProperties()
Reset the static properties of the expression to -1, so that they have to be recomputed
next time they are used.
|
void |
setContainer(Container container)
Mark an expression as being in a given Container.
|
void |
setEvaluationMethod(int method) |
void |
setFiltered(boolean filtered)
Mark an expression as filtered: that is, it appears as the base expression in a filter expression.
|
void |
setFlattened(boolean flattened)
Mark an expression as being "flattened".
|
void |
setLocationId(int id)
Set the location ID on an expression.
|
Expression |
simplify(ExpressionVisitor visitor)
Simplify an expression.
|
Expression |
staticTypeCheck(SequenceType req,
boolean backwardsCompatible,
RoleLocator role,
TypeCheckerEnvironment visitor)
Static type checking of some expressions is delegated to the expression itself, by calling
this method.
|
void |
suppressValidation(int parentValidationMode)
Suppress validation on contained element constructors, on the grounds that the parent element
is already performing validation.
|
Pattern |
toPattern(Configuration config,
boolean is30)
Convert this expression to an equivalent XSLT pattern
|
Pattern |
toStreamingPattern(Configuration config,
List<String> reasonForFailure)
Convert this expression to a streaming pattern (a pattern used internally to match nodes during
push processing of an event stream)
|
String |
toString()
The toString() method for an expression attempts to give a representation of the expression
in an XPath-like form.
|
Expression |
typeCheck(ExpressionVisitor visitor,
ExpressionVisitor.ContextItemType contextItemType)
Perform type checking of an expression and its subexpressions.
|
protected void |
typeError(String message,
String errorCode,
XPathContext context)
Method used in subclasses to signal a runtime type error
|
public static final int EVALUATE_METHOD
public static final int ITERATE_METHOD
public static final int PROCESS_METHOD
public static final int WATCH_METHOD
public static final int ITEM_FEED_METHOD
public static final int EVENT_FEED_METHOD
public static final int PUSH_SELECTION
public static final int EFFECTIVE_BOOLEAN_VALUE
public static final int W3C_MOTIONLESS
public static final int W3C_GROUP_CONSUMING
public static final int W3C_CONSUMING
public static final int W3C_FREE_RANGING
public static final int NAVIGATION_CONTEXT
public static final int NODE_VALUE_CONTEXT
public static final int INHERITED_CONTEXT
public static final int INSPECTION_CONTEXT
protected int staticProperties
protected int locationId
public static final IntegerValue UNBOUNDED_LOWER
public static final IntegerValue UNBOUNDED_UPPER
public static final IntegerValue MAX_STRING_LENGTH
public static final IntegerValue MAX_SEQUENCE_LENGTH
public String getExpressionName()
public int getImplementationMethod()
ITERATE_METHOD
or EVALUATE_METHOD
or
PROCESS_METHOD
public boolean implementsStaticTypeCheck()
public boolean hasVariableBinding(Binding binding)
public Expression simplify(ExpressionVisitor visitor) throws XPathException
visitor
- an expression visitorXPathException
- if an error is discovered during expression
rewritingpublic Expression typeCheck(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) throws XPathException
This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.
This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.
If the implementation returns a value other than "this", then it is required to ensure that the location information in the returned expression have been set up correctly. It should not rely on the caller to do this, although for historical reasons many callers do so.
visitor
- an expression visitorcontextItemType
- 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 to
Type.ITEM_TYPE
XPathException
- if an error is discovered during this phase
(typically a type error)public Expression staticTypeCheck(SequenceType req, boolean backwardsCompatible, RoleLocator role, TypeCheckerEnvironment visitor) throws XPathException
req
- the required typebackwardsCompatible
- true if backwards compatibility mode appliesrole
- the role of the expression in relation to the required typevisitor
- an expression visitorXPathException
- if failures occur, for example if the static type of one branch of the conditional
is incompatible with the required typepublic Expression optimize(ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType) throws XPathException
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.
visitor
- an expression visitorcontextItemType
- 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 to
Type.ITEM_TYPE
XPathException
- if an error is discovered during this phase
(typically a type error)public Expression promote(PromotionOffer offer, Expression parent) throws XPathException
This method must be overridden for any Expression that has subexpressions.
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 expressionparent
- the containing expression in the expression treeXPathException
- if any error is detectedpublic final int getSpecialProperties()
public int getCardinality()
public abstract ItemType getItemType(TypeHierarchy th)
This method should always return a result, though it may be the best approximation that is available at the time.
th
- the type hierarchy cachepublic int getDependencies()
public IntegerValue[] getIntegerBounds()
public int getStreamability(int syntacticContext, boolean allowExtensions, List<String> reasons)
syntacticContext
- one of the values NAVIGATION_CONTEXT
,
NODE_VALUE_CONTEXT
, INHERITED_CONTEXT
, INSPECTION_CONTEXT
allowExtensions
- if false, the definition of "guaranteed streamability" in the
W3C specification is used. If true, Saxon extensions are permitted, which make somereasons
- the caller may supply a list, in which case the implementation may add to this
list a message explaining why the construct is not streamable, suitable for inclusion in an
error message.W3C_MOTIONLESS
, W3C_CONSUMING
,
W3C_GROUP_CONSUMING
, W3C_FREE_RANGING
public Iterator<Expression> iterateSubExpressions()
public Iterator<SubExpressionInfo> iterateSubExpressionInfo()
public void setFlattened(boolean flattened)
flattened
- set to true if the result of the expression is atomized or otherwise turned into
an atomic valuepublic void setFiltered(boolean filtered)
filtered
- if true, marks this expression as the base of a filter expressionpublic Item evaluateItem(XPathContext context) throws XPathException
context
- The context in which the expression is to be evaluatedXPathException
- if any dynamic error occurs evaluating the
expressionpublic SequenceIterator<? extends Item> iterate(XPathContext context) throws XPathException
context
- supplies the context for evaluationXPathException
- if any dynamic error occurs evaluating the
expressionpublic EventIterator iterateEvents(XPathContext context) throws XPathException
The events (of class PullEvent
) are either complete
items, or one of startElement, endElement, startDocument, or endDocument, known
as semi-nodes. The stream of events may also include a nested EventIterator.
If a start-end pair exists in the sequence, then the events between
this pair represent the content of the document or element. The content sequence will
have been processed to the extent that any attribute and namespace nodes in the
content sequence will have been merged into the startElement event. Namespace fixup
will have been performed: that is, unique prefixes will have been allocated to element
and attribute nodes, and all namespaces will be declared by means of a namespace node
in the startElement event or in an outer startElement forming part of the sequence.
However, duplicate namespaces may appear in the sequence.
The content of an element or document may include adjacent or zero-length text nodes, atomic values, and nodes represented as nodes rather than broken down into events.
context
- The dynamic evaluation contextXPathException
- if a dynamic error occurs during expression evaluationpublic boolean effectiveBooleanValue(XPathContext context) throws XPathException
context
- The context in which the expression is to be evaluatedXPathException
- if any dynamic error occurs evaluating the
expressionpublic CharSequence evaluateAsString(XPathContext context) throws XPathException
context
- The context in which the expression is to be evaluatedXPathException
- if any dynamic error occurs evaluating the
expressionClassCastException
- if the result type of the
expression is not xs:string?public void process(XPathContext context) throws XPathException
context
- The dynamic context, giving access to the current node,
the current variables, etc.XPathException
- if a dynamic error occurspublic void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException
context
- the XPath dynamic evaluation contextpul
- the pending update list to which the results should be writtenXPathException
- if evaluation failsUnsupportedOperationException
- if the expression is not an updating expressionpublic String toString()
The toString() method for an expression attempts to give a representation of the expression in an XPath-like form.
For subclasses of Expression that represent XPath expressions, the result should always be a string that parses as an XPath 3.0 expression. The expression produced should be equivalent to the original making certain assumptions about the static context. In general the expansion will make no assumptions about namespace bindings, except that (a) the prefix "xs" is used to refer to the XML Schema namespace, and (b) the default funcion namespace is assumed to be the "fn" namespace.
In the case of XSLT instructions and XQuery expressions, the toString() method gives an abstracted view of the syntax that is not designed in general to be parseable.
public abstract void explain(ExpressionPresenter out)
out
- the expression presenter used to display the structurepublic final void explain(OutputStream out)
out
- the expression presenter used to display the structurepublic void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException
parentType
- the "given complex type": the method is checking that the nodes returned by this
expression are acceptable members of the content model of this typeenv
- the static contextwhole
- if true, we want to check that the value of this expression satisfies the content model
as a whole; if false we want to check that the value of the expression is acceptable as one part
of the contentXPathException
- if the value delivered by this expression cannot be part of the content model
of the given typepublic void setContainer(Container container)
This affects the expression and all its subexpressions. Any subexpressions that are not in the same container are marked with the new container, and this proceeds recursively. However, any subexpression that is already in the correct container is not modified.
container
- The container of this expression.public Container getContainer()
public void adoptChildExpression(Expression child)
child
- the child expressionpublic void setLocationId(int id)
id
- the location idpublic final int getLocationId()
public int getLineNumber()
getLineNumber
in interface SourceLocator
getLineNumber
in interface InstructionInfo
getLineNumber
in interface Locator
public int getColumnNumber()
getColumnNumber
in interface SourceLocator
getColumnNumber
in interface Locator
public String getSystemId()
getSystemId
in interface SourceLocator
getSystemId
in interface InstructionInfo
getSystemId
in interface Locator
public final String getPublicId()
getPublicId
in interface SourceLocator
getPublicId
in interface Locator
public Executable getExecutable()
public LocationProvider getLocationProvider()
public final Expression doPromotion(Expression subexpression, PromotionOffer offer) throws XPathException
subexpression
- the subexpression that is a candidate for promotionoffer
- details of the promotion being considered @return the result of the promotion. This will be the current expression if no promotion
actions have taken placeXPathException
- if an error occurspublic final void computeStaticProperties()
public void resetLocalStaticProperties()
protected abstract int computeCardinality()
StaticProperty.ALLOWS_ZERO_OR_ONE
,
StaticProperty.EXACTLY_ONE
, StaticProperty.ALLOWS_ONE_OR_MORE
,
StaticProperty.ALLOWS_ZERO_OR_MORE
protected int computeSpecialProperties()
StaticProperty
. The "special" properties are properties
other than cardinality and dependencies, and most of them relate to properties of node sequences, for
example whether the nodes are in document order.public int computeDependencies()
public int getIntrinsicDependencies()
public void checkForUpdatingSubexpressions() throws XPathException
XPathException
- if the expression has a non-permitted updating subexpressionpublic boolean isUpdatingExpression()
public boolean isVacuousExpression()
public abstract Expression copy()
public boolean replaceSubExpression(Expression original, Expression replacement)
original
- the original subexpressionreplacement
- the replacement subexpressionpublic void suppressValidation(int parentValidationMode)
parentValidationMode
- the kind of validation being performed on the parent expressionpublic int markTailFunctionCalls(StructuredQName qName, int arity)
qName
- the name of the functionarity
- the arity (number of parameters) of the functionUserFunctionCall.NOT_TAIL_CALL
if no tail call was found;
UserFunctionCall.FOREIGN_TAIL_CALL
if a tail call on a different function was found;public Pattern toPattern(Configuration config, boolean is30) throws XPathException
config
- the Saxon configurationis30
- true if this is XSLT 3.0XPathException
- if conversion is not possiblepublic Pattern toStreamingPattern(Configuration config, List<String> reasonForFailure)
config
- the Saxon configurationreasonForFailure
- a list which will be populated with messages giving reasons why the
expression cannot be convertedpublic final int[] getSlotsUsed()
protected void dynamicError(String message, String code, XPathContext context) throws XPathException
message
- the error messagecode
- the error codecontext
- the XPath dynamic contextXPathException
- always thrown, to signal a dynamic errorprotected void typeError(String message, String errorCode, XPathContext context) throws XPathException
message
- the error messageerrorCode
- the error codecontext
- the XPath dynamic contextXPathException
- always thrown, to signal a dynamic errorpublic int getConstructType()
getConstructType
in interface InstructionInfo
Location
public StructuredQName getObjectName()
InstructionInfo
getObjectName
in interface InstructionInfo
public Object getProperty(String name)
InstructionInfo
getProperty
in interface InstructionInfo
name
- The name of the required propertypublic int getLineNumber(long locationId)
getLineNumber
in interface LocationProvider
locationId
- identifier of the location in question (as passed down the Receiver pipeline)public int getColumnNumber(long locationId)
LocationProvider
getColumnNumber
in interface LocationProvider
locationId
- identifier of the location in question (as passed down the Receiver pipeline)public String getSystemId(long locationId)
getSystemId
in interface LocationProvider
locationId
- identifier of the location in question (as passed down the Receiver pipeline)public Iterator<String> getProperties()
getProperties
in interface InstructionInfo
public int getHostLanguage()
Configuration.XSLT
or Configuration.XQUERY
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression.
pathMap
- the PathMap to which the expression should be addedpathMapNodeSet
- the PathMapNodeSet to which the paths embodied in this expression should be addedpublic boolean isSubtreeExpression()
public void setEvaluationMethod(int method)
public int getEvaluationMethod()
public ExpressionCompiler getExpressionCompiler() throws CannotCompileException
CannotCompileException
- if it is not possible to generate bytecode for this expressionpublic StreamingAdjunct getStreamingAdjunct()
Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.