net.sf.saxon.expr

Class UserFunctionCall

Implemented Interfaces:
EvaluableItem, InstructionInfoProvider, SequenceIterable, Serializable, SourceLocator

public class UserFunctionCall
extends FunctionCall
implements InstructionInfoProvider

This class represents a call to a user-defined function in the stylesheet or query.

Field Summary

Fields inherited from class net.sf.saxon.expr.FunctionCall

argument

Fields inherited from class net.sf.saxon.expr.Expression

EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD, locationId, staticProperties

Constructor Summary

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

Method Summary

PathMap.PathMapNodeSet
addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)
Add a representation of this expression to a PathMap.
void
checkArguments(ExpressionVisitor visitor)
Method called during the type checking phase
void
checkFunctionCall(UserFunction compiledFunction, ExpressionVisitor visitor)
Check the function call against the declared function signature
void
computeArgumentEvaluationModes()
Compute the evaluation mode of each argument
int
computeCardinality()
Determine the cardinality of the result
Expression
copy()
Copy an expression.
ValueRepresentation
dynamicCall(ValueRepresentation[] suppliedArguments, XPathContext context)
Call the function dynamically.
Item
evaluateItem(XPathContext c)
Call the function, returning the value as an item.
void
explain(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)
UserFunction
getFunction()
Get the function that is being called by this function call
StructuredQName
getFunctionName()
Get the qualified of the function being called
int
getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
InstructionInfo
getInstructionInfo()
Get diagnostic information about this expression
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
boolean
isConfirmed()
Determine whether this function call is confirmed
boolean
isRecursiveTailCall()
Determine whether this is a recursive tail call
boolean
isTailCall()
Determine whether this is a tail call (not necessarily a recursive tail call)
SequenceIterator
iterate(XPathContext c)
Call the function, returning an iterator over the results.
EventIterator
iterateEvents(XPathContext context)
Process the function call in pull mode
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.
Expression
preEvaluate(ExpressionVisitor visitor)
Pre-evaluate a function at compile time.
void
process(XPathContext context)
Process the function call in push mode
void
setConfirmed(boolean conf)
Set this function as confirmed (the function being called is known to exist) or not
void
setFunction(UserFunction compiledFunction)
Create the reference to the function to be called
void
setStaticType(SequenceType type)
Set the static type
Expression
typeCheck(ExpressionVisitor visitor, ItemType contextItemType)
Perform type checking of an expression and its subexpressions.

Methods inherited from class net.sf.saxon.expr.FunctionCall

addExternalFunctionCallToPathMap, checkArgumentCount, checkArguments, equals, explain, getArguments, getDisplayName, getFunctionName, getNumberOfArguments, hashCode, iterateSubExpressions, optimize, preEvaluate, promote, replaceSubExpression, setArguments, setFunctionName, simplify, simplifyArguments, toString, typeCheck

Methods inherited from class net.sf.saxon.expr.Expression

addToPathMap, adoptChildExpression, checkPermittedContents, computeCardinality, computeDependencies, computeSpecialProperties, computeStaticProperties, copy, display, doPromotion, dynamicError, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, explain, findParentOf, getCardinality, getColumnNumber, getConstructType, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getItemType, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, iterateSubExpressions, markTailFunctionCalls, optimize, process, promote, replaceSubExpression, resetLocalStaticProperties, setContainer, setFiltered, setFlattened, setLocationId, simplify, staticTypeCheck, suppressValidation, toString, typeCheck, typeError

Constructor Details

UserFunctionCall

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

Method Details

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.

Overrides:
addToPathMap in interface Expression
Parameters:
pathMap - the PathMap to which the expression should be added
pathMapNodeSet -
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)
            throws XPathException
Method called during the type checking phase
Overrides:
checkArguments in interface FunctionCall

checkFunctionCall

public void checkFunctionCall(UserFunction compiledFunction,
                              ExpressionVisitor visitor)
            throws XPathException
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
Overrides:
computeCardinality in interface Expression

copy

public Expression copy()
Copy an expression. This makes a deep copy.
Overrides:
copy in interface Expression
Returns:
the copy of the original expression

dynamicCall

public ValueRepresentation dynamicCall(ValueRepresentation[] suppliedArguments,
                                       XPathContext context)
            throws XPathException
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)
            throws XPathException
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
Specified by:
evaluateItem in interface EvaluableItem
Overrides:
evaluateItem in interface Expression

explain

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

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)
Overrides:
getArguments in interface FunctionCall
Returns:
the actual expressions used as arguments in the function call

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
Overrides:
getFunctionName in interface FunctionCall
Returns:
the qualified name

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.
Overrides:
getImplementationMethod in interface Expression
Returns:
the implementation method, for example Expression.ITERATE_METHOD or Expression.EVALUATE_METHOD or Expression.PROCESS_METHOD

getInstructionInfo

public InstructionInfo getInstructionInfo()
Get diagnostic information about this expression
Specified by:
getInstructionInfo in interface InstructionInfoProvider
Overrides:
getInstructionInfo in interface Expression

getIntrinsicDependencies

public int getIntrinsicDependencies()
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 interface Expression
Returns:
a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the expression, if possible
Overrides:
getItemType in interface Expression
Parameters:
th - the type hierarchy cache
Returns:
Type.ITEM (meaning not known in advance)

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

iterate

public SequenceIterator iterate(XPathContext c)
            throws XPathException
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)
Specified by:
iterate in interface SequenceIterable
Overrides:
iterate in interface Expression

iterateEvents

public EventIterator iterateEvents(XPathContext context)
            throws XPathException
Process the function call in pull mode
Overrides:
iterateEvents in interface Expression
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.
Overrides:
markTailFunctionCalls in interface Expression

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
            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 interface FunctionCall
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 Type.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)

preEvaluate

public Expression preEvaluate(ExpressionVisitor visitor)
Pre-evaluate a function at compile time. This version of the method suppresses early evaluation by doing nothing.
Overrides:
preEvaluate in interface FunctionCall
Parameters:
visitor - an expression visitor

process

public void process(XPathContext context)
            throws XPathException
Process the function call in push mode
Overrides:
process in interface Expression
Parameters:
context - the XPath dynamic context
Throws:
XPathException -

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

typeCheck

public Expression typeCheck(ExpressionVisitor visitor,
                            ItemType contextItemType)
            throws XPathException
Perform type checking of an expression and its subexpressions. This is the second phase of static optimization.

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 parent pointer and 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.

Overrides:
typeCheck in interface FunctionCall
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 Type.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)