net.sf.saxon.expr
public abstract class Expression extends Object implements SequenceIterable, EvaluableItem, Serializable, SourceLocator, InstructionInfo
Two expressions are considered equal if they return the same result when evaluated in the same context.
Field Summary | |
---|---|
static int | EVALUATE_METHOD |
static int | ITERATE_METHOD |
protected int | locationId |
static int | PROCESS_METHOD |
protected int | staticProperties |
Method Summary | |
---|---|
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 parentExpression, 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) |
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. |
Executable | getExecutable()
Get the executable containing this expression |
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().
|
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() |
Iterator | getProperties()
Get an iterator over all the properties available. |
Object | getProperty(String name) |
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). |
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 | 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 |
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 | 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<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 sub-expressions of this expression. |
int | markTailFunctionCalls(StructuredQName qName, int arity)
Mark tail-recursive calls on stylesheet functions. |
Expression | optimize(ExpressionVisitor visitor, ItemType 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 |
protected 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 | 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, ExpressionVisitor visitor)
Static type checking of some expressions is delegated to the expression itself, by calling
this method. |
void | suppressValidation(int validationMode)
Suppress validation on contained element constructors, on the grounds that the parent element
is already performing validation. |
String | toString()
The toString() method for an expression attempts to give a representation of the expression
in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath.
|
Expression | typeCheck(ExpressionVisitor visitor, ItemType 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 |
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.
Parameters: pathMap the PathMap to which the expression should be added pathMapNodeSet the PathMapNodeSet to which the paths embodied in this expression should be added
Returns: the pathMapNodeSet representing the points in the source document that are both reachable by this expression, and that represent possible results of this expression. For an expression that does navigation, it represents the end of the arc in the path map that describes the navigation route. For other expressions, it is the same as the input pathMapNode.
Note: many calls on this method are now redundant, but are kept in place for "belt-and-braces" reasons. The rule is that an implementation of simplify(), typeCheck(), or optimize() that returns a value other than "this" is required to set the location information and parent pointer in the new child expression. However, in the past this was often left to the caller, which did it by calling this method, either unconditionally on return from one of these methods, or after testing that the returned object was not the same as the original.
Parameters: child the child expression
Throws: XPathException if the expression has a non-permitted updating subexpression
Parameters: 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 type env the static context whole 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 content
Throws: XPathException if the value delivered by this expression cannot be part of the content model of the given type
Returns: the computed cardinality, as one of the values ALLOWS_ZERO_OR_ONE, EXACTLY_ONE, ALLOWS_ONE_OR_MORE, ALLOWS_ZERO_OR_MORE
Returns: the depencies, as a bit-mask
Returns: the special properties, as a bit-significant integer
Returns: the copy of the original expression
Parameters: parentExpression subexpression the subexpression that is a candidate for promotion offer details of the promotion being considered @return the result of the promotion. This will be the current expression if no promotion actions have taken place
Parameters: message the error message code the error code context the XPath dynamic context
Parameters: context The context in which the expression is to be evaluated
Returns: the effective boolean value
Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression
Parameters: context The context in which the expression is to be evaluated
Returns: the value of the expression, evaluated in the current context. The expression must return a string or (); if the value of the expression is (), this method returns "".
Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression ClassCastException if the result type of the expression is not xs:string?
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: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression
Parameters: context the XPath dynamic evaluation context pul the pending update list to which the results should be written
Parameters: out the expression presenter used to display the structure
Parameters: out the expression presenter used to display the structure
Returns: one of the values Cardinality.ONE_OR_MORE, Cardinality.ZERO_OR_MORE, Cardinality.EXACTLY_ONE, Cardinality.ZERO_OR_ONE, Cardinality.EMPTY. This default implementation returns ZERO_OR_MORE (which effectively gives no information).
Returns: the type of expression, as enumerated in class Location
Returns: the expression's container
Returns: a set of bit-significant flags identifying the dependencies of the expression
Returns: the containing Executable
Returns: the implementation method, for example ITERATE_METHOD or EVALUATE_METHOD or PROCESS_METHOD
Returns: a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty
This method should always return a result, though it may be the best approximation that is available at the time.
Parameters: th the type hierarchy cache
Returns: a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)
Parameters: locationId identifier of the location in question (as passed down the Receiver pipeline)
Returns: the line number within the document or module.
Returns: a location identifier, which can be turned into real location information by reference to a location provider
Returns: the LocationProvider used to turn the location id into real location information
Returns: an array of integers giving the slot numbers of the local variables referenced in this expression.
Returns: a set of flags indicating static properties of this expression
Parameters: locationId identifier of the location in question (as passed down the Receiver pipeline)
Returns: the URI of the document or module.
Parameters: child the immediate subexpression
Returns: true if the child expression is evaluated repeatedly
Returns: true if this expression has a non-trivial implementation of the staticTypeCheck() method
Returns: true if the expression has no dependencies on the context node, or if the only dependencies on the context node are downward selections using the self, child, descendant, attribute, and namespace axes.
Returns: true if this is an updating expression
Returns: true if this expression is vacuous
Parameters: context supplies the context for evaluation
Returns: a SequenceIterator that can be used to iterate over the result of the expression
Throws: net.sf.saxon.trans.XPathException if any dynamic error occurs evaluating the expression
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.
Parameters: context The dynamic evaluation context
Returns: the result of the expression as an iterator over a sequence of PullEvent objects
Throws: XPathException if a dynamic error occurs during expression evaluation
Returns: an iterator containing those sub-expressions of this expression that are evaluated with the same focus as the parent expression
Returns: an iterator containing the sub-expressions of this expression
Parameters: qName the name of the function arity the arity (number of parameters) of the function
Returns: 0 if no tail call was found; 1 if a tail call on a different function was found; 2 if a tail recursive call was found and if this call accounts for the whole of the value.
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.
Parameters: visitor an expression visitor contextItemType 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 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)
Parameters: context The dynamic context, giving access to the current node, the current variables, etc.
This method must be overridden for any Expression that has subexpressions.
Parameters: 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 expression parent
Returns: if the offer is not accepted, return this expression unchanged. Otherwise return the result of rewriting the expression to promote this subexpression
Throws: net.sf.saxon.trans.XPathException if any error is detected
Parameters: original the original subexpression replacement the replacement subexpression
Returns: true if the original subexpression is found
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.
Parameters: container The container of this expression.
Parameters: filtered if true, marks this expression as the base of a filter expression
Parameters: flattened set to true if the result of the expression is atomized or otherwise turned into an atomic value
Parameters: id the location id
Parameters: visitor an expression visitor
Returns: the simplified expression
Throws: net.sf.saxon.trans.XPathException if an error is discovered during expression rewriting
Parameters: req the required type backwardsCompatible true if backwards compatibility mode applies role the role of the expression in relation to the required type visitor an expression visitor
Returns: the expression after type checking (perhaps augmented with dynamic type checking code)
Throws: XPathException if failures occur, for example if the static type of one branch of the conditional is incompatible with the required type
Parameters: validationMode the kind of validation being performed on the parent expression
Returns: a representation of the expression as a string
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.
Parameters: visitor an expression visitor contextItemType 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 ITEM_TYPE
Returns: the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
Throws: XPathException if an error is discovered during this phase (typically a type error)
Parameters: message the error message errorCode the error code context the XPath dynamic context