net.sf.saxon.expr

Class UserFunctionCall

public class UserFunctionCall extends FunctionCall

This class represents a call to a user-defined function in the stylesheet or query.
Constructor Summary
UserFunctionCall()
Create a function call to a user-written function in a query or stylesheet
Method Summary
PathMap.PathMapNodeSetaddToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.
voidcheckArguments(ExpressionVisitor visitor)
Method called during the type checking phase
voidcheckFunctionCall(UserFunction compiledFunction, ExpressionVisitor visitor)
Check the function call against the declared function signature
voidcomputeArgumentEvaluationModes()
Compute the evaluation mode of each argument
intcomputeCardinality()
Determine the cardinality of the result
protected intcomputeSpecialProperties()
Compute the special properties of this expression.
Expressioncopy()
Copy an expression.
ValueRepresentationdynamicCall(ValueRepresentation[] suppliedArguments, XPathContext context)
Call the function dynamically.
ItemevaluateItem(XPathContext c)
Call the function, returning the value as an item.
voidevaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
Evaluate an updating expression, adding the results to a Pending Update List.
voidexplain(ExpressionPresenter out)
Diagnostic print of expression structure.
int[]getArgumentEvaluationModes()
Get the evaluation modes that have been determined for each of the arguments
Expression[]getArguments()
Get the arguments (the expressions supplied in the function call)
intgetConstructType()
UserFunctiongetFunction()
Get the function that is being called by this function call
StructuredQNamegetFunctionName()
Get the qualified of the function being called
intgetImplementationMethod()
intgetIntrinsicDependencies()
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the expression, if possible
intgetLineNumber(long locationId)
Get the line number within the document or module containing a particular location
StructuredQNamegetObjectName()
ObjectgetProperty(String name)
StringgetSystemId(long locationId)
Get the URI of the document or module containing a particular location
booleanisConfirmed()
Determine whether this function call is confirmed
booleanisRecursiveTailCall()
Determine whether this is a recursive tail call
booleanisTailCall()
Determine whether this is a tail call (not necessarily a recursive tail call)
booleanisUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification
SequenceIteratoriterate(XPathContext c)
Call the function, returning an iterator over the results.
EventIteratoriterateEvents(XPathContext context)
Process the function call in pull mode
intmarkTailFunctionCalls(StructuredQName qName, int arity)
Mark tail-recursive calls on stylesheet functions.
Expressionoptimize(ExpressionVisitor visitor, ItemType contextItemType)
ExpressionpreEvaluate(ExpressionVisitor visitor)
Pre-evaluate a function at compile time.
voidprocess(XPathContext context)
Process the function call in push mode
Expressionpromote(PromotionOffer offer, Expression parent)
Promote this expression if possible
voidsetConfirmed(boolean conf)
Set this function as confirmed (the function being called is known to exist) or not
voidsetFunction(UserFunction compiledFunction)
Create the reference to the function to be called
voidsetStaticType(SequenceType type)
Set the static type
ExpressiontypeCheck(ExpressionVisitor visitor, ItemType contextItemType)

Constructor Detail

UserFunctionCall

public UserFunctionCall()
Create a function call to a user-written function in a query or stylesheet

Method Detail

addToPathMap

public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
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.

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 pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter 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.

checkArguments

public void checkArguments(ExpressionVisitor visitor)
Method called during the type checking phase

checkFunctionCall

public void checkFunctionCall(UserFunction compiledFunction, ExpressionVisitor visitor)
Check the function call against the declared function signature

Parameters: compiledFunction the function being called visitor an expression visitor

computeArgumentEvaluationModes

public void computeArgumentEvaluationModes()
Compute the evaluation mode of each argument

computeCardinality

public int computeCardinality()
Determine the cardinality of the result

computeSpecialProperties

protected int computeSpecialProperties()
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.

Returns: the special properties, as a bit-significant integer

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Returns: the copy of the original expression

dynamicCall

public ValueRepresentation dynamicCall(ValueRepresentation[] suppliedArguments, XPathContext context)
Call the function dynamically. For this to be possible, the static arguments of the function call must have been set up as SuppliedParameterReference objects. The actual arguments are placed on the callee's stack, and the type conversion takes place "in situ".

Parameters: suppliedArguments the values to be used for the arguments of the function context the dynamic evaluation context

Returns: the result of evaluating the function

evaluateItem

public Item evaluateItem(XPathContext c)
Call the function, returning the value as an item. This method will be used only when the cardinality is zero or one. If the function is tail recursive, it returns an Object representing the arguments to the next (recursive) call

evaluatePendingUpdates

public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul)
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

Parameters: context the XPath dynamic evaluation context pul the pending update list to which the results should be written

explain

public void explain(ExpressionPresenter out)
Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.

getArgumentEvaluationModes

public int[] getArgumentEvaluationModes()
Get the evaluation modes that have been determined for each of the arguments

Returns: an array of integers representing the evaluation modes, one for each argument

getArguments

public Expression[] getArguments()
Get the arguments (the expressions supplied in the function call)

Returns: the actual expressions used as arguments in the function call

getConstructType

public int getConstructType()

getFunction

public UserFunction getFunction()
Get the function that is being called by this function call

Returns: the function being called

getFunctionName

public final StructuredQName getFunctionName()
Get the qualified of the function being called

Returns: the qualified name

getImplementationMethod

public int getImplementationMethod()

getIntrinsicDependencies

public int getIntrinsicDependencies()

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the expression, if possible

Parameters: th the type hierarchy cache

Returns: Type.ITEM (meaning not known in advance)

getLineNumber

public int getLineNumber(long locationId)
Get the line number within the document or module containing a particular location

Parameters: locationId identifier of the location in question (as passed down the Receiver pipeline)

Returns: the line number within the document or module.

getObjectName

public StructuredQName getObjectName()

getProperty

public Object getProperty(String name)

getSystemId

public String getSystemId(long locationId)
Get the URI of the document or module containing a particular location

Parameters: locationId identifier of the location in question (as passed down the Receiver pipeline)

Returns: the URI of the document or module.

isConfirmed

public boolean isConfirmed()
Determine whether this function call is confirmed

Returns: true if the function being called is known to exist

isRecursiveTailCall

public boolean isRecursiveTailCall()
Determine whether this is a recursive tail call

Returns: true if this function call is a recursive tail call

isTailCall

public boolean isTailCall()
Determine whether this is a tail call (not necessarily a recursive tail call)

Returns: true if this function call is a tail call

isUpdatingExpression

public boolean isUpdatingExpression()
Determine whether this is an updating expression as defined in the XQuery update specification

Returns: true if this is an updating expression

iterate

public SequenceIterator iterate(XPathContext c)
Call the function, returning an iterator over the results. (But if the function is tail recursive, it returns an iterator over the arguments of the recursive call)

iterateEvents

public EventIterator iterateEvents(XPathContext context)
Process the function call in pull mode

Parameters: context the XPath dynamic context

Throws: XPathException

markTailFunctionCalls

public int markTailFunctionCalls(StructuredQName qName, int arity)
Mark tail-recursive calls on stylesheet functions. This marks the function call as tailRecursive if if is a call to the containing function, and in this case it also returns "true" to the caller to indicate that a tail call was found.

optimize

public Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)

preEvaluate

public Expression preEvaluate(ExpressionVisitor visitor)
Pre-evaluate a function at compile time. This version of the method suppresses early evaluation by doing nothing.

Parameters: visitor an expression visitor

process

public void process(XPathContext context)
Process the function call in push mode

Parameters: context the XPath dynamic context

Throws: XPathException

promote

public Expression promote(PromotionOffer offer, Expression parent)
Promote this expression if possible

setConfirmed

public void setConfirmed(boolean conf)
Set this function as confirmed (the function being called is known to exist) or not

Parameters: conf true if the function being called is known to exist

setFunction

public void setFunction(UserFunction compiledFunction)
Create the reference to the function to be called

Parameters: compiledFunction the function being called

setStaticType

public void setStaticType(SequenceType type)
Set the static type

Parameters: type the static type of the result of the function call

typeCheck

public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType)