net.sf.saxon.expr.parser
Class ExpressionVisitor

java.lang.Object
  extended by net.sf.saxon.expr.parser.ExpressionVisitor
All Implemented Interfaces:
TypeCheckerEnvironment

public class ExpressionVisitor
extends Object
implements TypeCheckerEnvironment

The ExpressionVisitor supports the various phases of processing of an expression tree which require a recursive walk of the tree structure visiting each node in turn. In maintains a stack holding the ancestor nodes of the node currently being visited.


Nested Class Summary
static class ExpressionVisitor.ContextItemType
          A data structure that represents the required type of the context item, together with information about whether it is known to be present or absent or whether it is not known statically whether it is present or absent.
 
Constructor Summary
ExpressionVisitor()
          Create an ExpressionVisitor
 
Method Summary
 CollationMap getCollationMap()
           
 Configuration getConfiguration()
          Get the Saxon configuration
 Expression getCurrentExpression()
          Get the current expression, the one being visited
 Executable getExecutable()
          Get the Executable containing the expressions being visited
 Stack<Expression> getExpressionStack()
          Get the stack containing all the expressions currently being visited
 Expression getParentExpression()
          Get the parent expression of the current expression in the expression tree
 StaticContext getStaticContext()
          Get the static context for the expressions being visited.
 boolean isLoopingReference(Binding binding, VariableReference ref)
           
 boolean isLoopingSubexpression(Expression ancestor)
          Return true if the current expression at the top of the visitor's stack is evaluated repeatedly when a given ancestor expression is evaluated once
 boolean isOptimizeForStreaming()
          Ask whether the visitor is to optimize expressions for evaluation in a streaming environment
 void issueWarning(String message, SourceLocator locator)
          Issue a warning message
static ExpressionVisitor make(StaticContext env, Executable exec)
          Factory method: make an expression visitor
 XPathContext makeDynamicContext()
          Create a dynamic context suitable for early evaluation of constant subexpressions
 Expression optimize(Expression exp, ExpressionVisitor.ContextItemType contextItemType)
          Optimize an expression, via the ExpressionVisitor
 void resetStaticProperties()
          Reset the static properties for the current expression and for all its containing expressions.
 void setConfiguration(Configuration configuration)
          Set the Saxon configuration
 void setExecutable(Executable executable)
          Set the Executable containing the expressions being visited
 void setExpressionStack(Stack<Expression> expressionStack)
          Set the stack used to hold the expressions being visited
 void setOptimizeForStreaming(boolean option)
          Tell the visitor to optimize expressions for evaluation in a streaming environment
 void setStaticContext(StaticContext staticContext)
          Set the static context for the expressions being visited.
 Expression simplify(Expression exp)
          Simplify an expression, via the ExpressionVisitor
 Expression typeCheck(Expression exp, ExpressionVisitor.ContextItemType contextItemType)
          Type check an expression, via the ExpressionVisitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionVisitor

public ExpressionVisitor()
Create an ExpressionVisitor

Method Detail

getConfiguration

public Configuration getConfiguration()
Get the Saxon configuration

Specified by:
getConfiguration in interface TypeCheckerEnvironment
Returns:
the Saxon configuration

setConfiguration

public void setConfiguration(Configuration configuration)
Set the Saxon configuration

Parameters:
configuration - the Saxon configuration

getExecutable

public Executable getExecutable()
Get the Executable containing the expressions being visited

Returns:
the Executable

setExecutable

public void setExecutable(Executable executable)
Set the Executable containing the expressions being visited

Parameters:
executable - the Executable

getCollationMap

public CollationMap getCollationMap()
Specified by:
getCollationMap in interface TypeCheckerEnvironment

getExpressionStack

public Stack<Expression> getExpressionStack()
Get the stack containing all the expressions currently being visited

Returns:
the expression stack holding all the containing expressions of the current expression; the objects on this Stack are instances of Expression

setExpressionStack

public void setExpressionStack(Stack<Expression> expressionStack)
Set the stack used to hold the expressions being visited

Parameters:
expressionStack - the expression stack

getStaticContext

public StaticContext getStaticContext()
Get the static context for the expressions being visited. Note: this may not reflect all changes in static context (e.g. namespace context, base URI) applying to nested expressions

Returns:
the static context

setStaticContext

public void setStaticContext(StaticContext staticContext)
Set the static context for the expressions being visited. Note: this may not reflect all changes in static context (e.g. namespace context, base URI) applying to nested expressions

Parameters:
staticContext - the static context

getCurrentExpression

public Expression getCurrentExpression()
Get the current expression, the one being visited

Returns:
the current expression

make

public static ExpressionVisitor make(StaticContext env,
                                     Executable exec)
Factory method: make an expression visitor

Parameters:
env - the static context
exec - the executable
Returns:
the new expression visitor

issueWarning

public void issueWarning(String message,
                         SourceLocator locator)
Issue a warning message

Specified by:
issueWarning in interface TypeCheckerEnvironment
Parameters:
message - the message

makeDynamicContext

public XPathContext makeDynamicContext()
Create a dynamic context suitable for early evaluation of constant subexpressions

Specified by:
makeDynamicContext in interface TypeCheckerEnvironment

simplify

public Expression simplify(Expression exp)
                    throws XPathException
Simplify an expression, via the ExpressionVisitor

Specified by:
simplify in interface TypeCheckerEnvironment
Parameters:
exp - the expression to be simplified. Possibly null.
Returns:
the simplified expression. Returns null if and only if the supplied expression is null.
Throws:
XPathException - if any error occurs

typeCheck

public Expression typeCheck(Expression exp,
                            ExpressionVisitor.ContextItemType contextItemType)
                     throws XPathException
Type check an expression, via the ExpressionVisitor

Specified by:
typeCheck in interface TypeCheckerEnvironment
Parameters:
exp - the expression to be typechecked
contextItemType - the static type of the context item for this expression. The argument can be set to null to indicate that it is known that the context item will be absent.
Returns:
the expression that results from type checking (this may be wrapped in expressions that perform dynamic checking of the item type or cardinality, or that perform atomization or numeric promotion)
Throws:
XPathException - if static type checking fails, that is, if the expression cannot possibly deliver a value of the required type

setOptimizeForStreaming

public void setOptimizeForStreaming(boolean option)
Tell the visitor to optimize expressions for evaluation in a streaming environment

Parameters:
option - true if optimizing for streaming

isOptimizeForStreaming

public boolean isOptimizeForStreaming()
Ask whether the visitor is to optimize expressions for evaluation in a streaming environment

Returns:
true if optimizing for streaming

optimize

public Expression optimize(Expression exp,
                           ExpressionVisitor.ContextItemType contextItemType)
                    throws XPathException
Optimize an expression, via the ExpressionVisitor

Parameters:
exp - the expression to be typechecked
contextItemType - the static type of the context item for this expression. Passing null indicates that the context item will always be absent
Returns:
the rewritten expression
Throws:
XPathException - if a static error is found

getParentExpression

public Expression getParentExpression()
Get the parent expression of the current expression in the expression tree

Returns:
the parent of the current expression (or null if this is the root)

isLoopingSubexpression

public boolean isLoopingSubexpression(Expression ancestor)
Return true if the current expression at the top of the visitor's stack is evaluated repeatedly when a given ancestor expression is evaluated once

Parameters:
ancestor - the ancestor expression. May be null, in which case the search goes all the way to the base of the stack.
Returns:
true if the current expression is evaluated repeatedly

isLoopingReference

public boolean isLoopingReference(Binding binding,
                                  VariableReference ref)

resetStaticProperties

public final void resetStaticProperties()
Reset the static properties for the current expression and for all its containing expressions. This should be done whenever the expression is changed in a way that might affect the properties. It causes the properties to be recomputed next time they are needed.



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