com.saxonica.bytecode
Class CompiledExpression

java.lang.Object
  extended by net.sf.saxon.expr.Expression
      extended by com.saxonica.bytecode.CompiledExpression
All Implemented Interfaces:
Serializable, SourceLocator, LocationProvider, SaxonLocator, InstructionInfo, Locator

public class CompiledExpression
extends Expression

An expression that has been compiled to Java bytecode. The actual bytecode is contained in a separate object of type GeneratedCode, to which evaluation is delegated

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.expr.Expression
EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, EVENT_FEED_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, locationId, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, PUSH_SELECTION, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, WATCH_METHOD
 
Constructor Summary
CompiledExpression(Expression original, GeneratedCode byteCode)
           
 
Method Summary
 PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
          Add a representation of this expression to a PathMap.
 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  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.
 Expression copy()
          Copy an expression.
 void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
          Evaluate an updating expression, adding the results to a Pending Update List.
 void explain(ExpressionPresenter out)
          Diagnostic print of expression structure.
 int getCardinality()
          Determine the static cardinality of the expression.
 int getConstructType()
          Get the type of this expression for use in tracing and diagnostics
 int getDependencies()
          Determine which aspects of the context the expression depends on.
 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().
 int getIntrinsicDependencies()
          Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.
 ItemType getItemType(TypeHierarchy th)
          Determine the data type of the expression, if possible.
 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 getProperties()
          Get an iterator over all the properties available.
 Object getProperty(String name)
          Get the value of a particular property of the instruction.
 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.
 Iterator<Expression> iterateSubExpressions()
          Get the immediate sub-expressions of this expression.
 void process(XPathContext context)
          Process the instruction, without returning any tail calls
 boolean replaceSubExpression(Expression original, Expression replacement)
          Replace one subexpression by a replacement subexpression
 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.
 
Methods inherited from class net.sf.saxon.expr.Expression
adoptChildExpression, computeStaticProperties, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, getColumnNumber, getColumnNumber, getContainer, getEvaluationMethod, getExecutable, getIntegerBounds, getLineNumber, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, getSystemId, hasLoopingSubexpression, hasVariableBinding, implementsStaticTypeCheck, iterateEvents, iterateSameFocusSubExpressions, markTailFunctionCalls, optimize, promote, resetLocalStaticProperties, setContainer, setEvaluationMethod, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, typeCheck, typeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompiledExpression

public CompiledExpression(Expression original,
                          GeneratedCode byteCode)
Method Detail

getExpressionName

public String getExpressionName()
Description copied from class: Expression
Get a name identifying the kind of expression, in terms meaningful to a user.

Overrides:
getExpressionName in class Expression
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 explain() output displaying the expression.

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.

Overrides:
getImplementationMethod in class Expression
Returns:
the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD

getCardinality

public int getCardinality()
Description copied from class: Expression
Determine the static cardinality of the expression. This establishes how many items there will be in the result of the expression, at compile time (i.e., without actually evaluating the result.

Overrides:
getCardinality in class Expression
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).

getItemType

public ItemType getItemType(TypeHierarchy th)
Description copied from class: Expression
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 class Expression
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)

getDependencies

public int getDependencies()
Description copied from class: Expression
Determine which aspects of the context the expression depends on. The result is a bitwise-or'ed value composed from constants such as XPathContext.VARIABLES and XPathContext.CURRENT_NODE. The default implementation combines the intrinsic dependencies of this expression with the dependencies of the subexpressions, computed recursively. This is overridden for expressions such as FilterExpression where a subexpression's dependencies are not necessarily inherited by the parent expression.

Overrides:
getDependencies in class Expression
Returns:
a set of bit-significant flags identifying the dependencies of the expression

process

public void process(XPathContext context)
             throws XPathException
Description copied from class: Expression
Process the instruction, without returning any tail calls

Overrides:
process in class Expression
Parameters:
context - The dynamic context, giving access to the current node, the current variables, etc.
Throws:
XPathException - if a dynamic error occurs

evaluatePendingUpdates

public void evaluatePendingUpdates(XPathContext context,
                                   PendingUpdateList pul)
                            throws XPathException
Description copied from class: Expression
Evaluate an updating expression, adding the results to a Pending Update List. The default implementation of this method, which is used for non-updating expressions, throws an UnsupportedOperationException

Overrides:
evaluatePendingUpdates in class Expression
Parameters:
context - the XPath dynamic evaluation context
pul - the pending update list to which the results should be written
Throws:
XPathException - if evaluation fails

toString

public String toString()
Description copied from class: Expression
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. In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax

Overrides:
toString in class Expression
Returns:
a representation of the expression as a string

explain

public void explain(ExpressionPresenter out)
Description copied from class: Expression
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

Specified by:
explain in class Expression
Parameters:
out - the expression presenter used to display the structure

checkPermittedContents

public void checkPermittedContents(SchemaType parentType,
                                   StaticContext env,
                                   boolean whole)
                            throws XPathException
Description copied from class: Expression
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type. It's always OK to say yes, since the check will be repeated at run-time. The process of checking element and attribute constructors against the content model of a complex type also registers the type of content expected of those constructors, so the static validation can continue recursively.

Overrides:
checkPermittedContents in class Expression
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

computeCardinality

protected int computeCardinality()
Description copied from class: Expression
Compute the static cardinality of this expression

Specified by:
computeCardinality in class Expression
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

computeSpecialProperties

protected int computeSpecialProperties()
Description copied from class: Expression
Compute the special properties of this expression. These properties are denoted by a bit-significant integer, possible values are in class 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.

Overrides:
computeSpecialProperties in class Expression
Returns:
the special properties, as a bit-significant integer

computeDependencies

public int computeDependencies()
Description copied from class: Expression
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions. (This is overridden for path expressions and filter expressions, where the dependencies of a subexpression are not all propogated). This method should be called only once, to compute the dependencies; after that, getDependencies should be used.

Overrides:
computeDependencies in class Expression
Returns:
the depencies, as a bit-mask

getIntrinsicDependencies

public int getIntrinsicDependencies()
Description copied from class: Expression
Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".

Overrides:
getIntrinsicDependencies in class Expression
Returns:
a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty

checkForUpdatingSubexpressions

public void checkForUpdatingSubexpressions()
                                    throws XPathException
Description copied from class: Expression
Check to ensure that this expression does not contain any inappropriate updating subexpressions. This check is overridden for those expressions that permit updating subexpressions.

Overrides:
checkForUpdatingSubexpressions in class Expression
Throws:
XPathException - if the expression has a non-permitted updating subexpression

isUpdatingExpression

public boolean isUpdatingExpression()
Description copied from class: Expression
Determine whether this is an updating expression as defined in the XQuery update specification

Overrides:
isUpdatingExpression in class Expression
Returns:
true if this is an updating expression

isVacuousExpression

public boolean isVacuousExpression()
Description copied from class: Expression
Determine whether this is a vacuous expression as defined in the XQuery update specification

Overrides:
isVacuousExpression in class Expression
Returns:
true if this expression is vacuous

copy

public Expression copy()
Description copied from class: Expression
Copy an expression. This makes a deep copy.

Specified by:
copy in class Expression
Returns:
the copy of the original expression

replaceSubExpression

public boolean replaceSubExpression(Expression original,
                                    Expression replacement)
Description copied from class: Expression
Replace one subexpression by a replacement subexpression

Overrides:
replaceSubExpression in class Expression
Parameters:
original - the original subexpression
replacement - the replacement subexpression
Returns:
true if the original subexpression is found

getConstructType

public int getConstructType()
Description copied from class: Expression
Get the type of this expression for use in tracing and diagnostics

Specified by:
getConstructType in interface InstructionInfo
Overrides:
getConstructType in class Expression
Returns:
the type of expression, as enumerated in class Location

getObjectName

public StructuredQName getObjectName()
Description copied from interface: InstructionInfo
Get a name identifying the object of the expression, for example a function name, template name, variable name, key name, element name, etc. This is used only where the name is known statically.

Specified by:
getObjectName in interface InstructionInfo
Overrides:
getObjectName in class Expression
Returns:
the QName of the object declared or manipulated by this instruction or expression

getProperty

public Object getProperty(String name)
Description copied from interface: InstructionInfo
Get the value of a particular property of the instruction. Properties of XSLT instructions are generally known by the name of the stylesheet attribute that defines them.

Specified by:
getProperty in interface InstructionInfo
Overrides:
getProperty in class Expression
Parameters:
name - The name of the required property
Returns:
The value of the requested property, or null if the property is not available

getProperties

public Iterator getProperties()
Description copied from class: Expression
Get an iterator over all the properties available. The values returned by the iterator will be of type String, and each string can be supplied as input to the getProperty() method to retrieve the value of the property. The iterator may return properties whose value is null.

Specified by:
getProperties in interface InstructionInfo
Overrides:
getProperties in class Expression
Returns:
an iterator over the properties.

getHostLanguage

public int getHostLanguage()
Description copied from class: Expression
Get the host language (XSLT, XQuery, XPath) used to implement the code in this container

Overrides:
getHostLanguage in class Expression
Returns:
typically Configuration.XSLT or Configuration.XQUERY

addToPathMap

public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap,
                                           PathMap.PathMapNodeSet pathMapNodeSet)
Description copied from class: Expression
Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.

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.

Overrides:
addToPathMap in class 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.

isSubtreeExpression

public boolean isSubtreeExpression()
Description copied from class: Expression
Determine whether the expression can be evaluated without reference to the part of the context document outside the subtree rooted at the context node.

Overrides:
isSubtreeExpression in class Expression
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.

iterate

public SequenceIterator iterate(XPathContext context)
                         throws XPathException
Description copied from class: Expression
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 class Expression
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

iterateSubExpressions

public Iterator<Expression> iterateSubExpressions()
Description copied from class: Expression
Get the immediate sub-expressions of this expression. Default implementation returns a zero-length array, appropriate for an expression that has no sub-expressions.

Overrides:
iterateSubExpressions in class Expression
Returns:
an iterator containing the sub-expressions of this expression


Copyright (c) 2004-2011 Saxonica Limited. All rights reserved.