polyglot.visit
Class ContextVisitor

java.lang.Object
  extended by polyglot.visit.NodeVisitor
      extended by polyglot.visit.HaltingVisitor
          extended by polyglot.visit.ErrorHandlingVisitor
              extended by polyglot.visit.ContextVisitor
All Implemented Interfaces:
java.lang.Cloneable, Copy
Direct Known Subclasses:
AscriptionVisitor, ConstantChecker, ConstructorCallChecker, DisambiguationDriver, FwdReferenceChecker, InnerClassAbstractRemover, InnerClassRemover, InnerClassRemoverOld, LocalClassRemover, LocalClassRemoverOld

public class ContextVisitor
extends ErrorHandlingVisitor

A visitor which maintains a context throughout the visitor's pass. This is the base class of the disambiguation and type checking visitors. TODO: update this documentation. For a node n methods are called in this order:

 v.enter(n)
   v.enterScope(n);
     c' = n.enterScope(c)
   v' = copy(v) with c' for c
 n' = n.visitChildren(v')
 v.leave(n, n', v')
   v.addDecls(n')
     n.addDecls(c)
 


Field Summary
protected  Context context
          The current context of this visitor.
protected  ContextVisitor outer
           
protected  boolean prune
           
protected  boolean rethrowMissingDependencies
          Should MissingDependencyExceptions be rethrown? If not, then the dependency is added to the scheduler, and the visitor continues.
 
Fields inherited from class polyglot.visit.ErrorHandlingVisitor
error, job, nf, ts
 
Fields inherited from class polyglot.visit.HaltingVisitor
bypass, bypassParent
 
Constructor Summary
ContextVisitor(Job job, TypeSystem ts, NodeFactory nf)
           
 
Method Summary
protected  void addDecls(Node n)
          Imperatively update the context with declarations to be added after visiting the node.
 NodeVisitor begin()
          Part of the initialization done by begin() in an ErrorHandlingVisitor method is initializing the error-handling state.
 Context context()
          Returns the context for this visitor.
 ContextVisitor context(Context c)
          Returns a new ContextVisitor that is a copy of the current visitor, except with an updated context.
 NodeVisitor enter(Node n)
          Begin normal traversal of a subtree rooted at n.
 NodeVisitor enter(Node parent, Node n)
          Begin normal traversal of a subtree rooted at n.
protected  Context enterScope(Node parent, Node n)
          Returns a new context based on the current context, the Node current being visited (parent), and the Node that is being entered (n).
 Node leave(Node parent, Node old, Node n, NodeVisitor v)
          This method is called after all of the children of n have been visited.
 ContextVisitor rethrowMissingDependencies(boolean rethrow)
           
 NodeVisitor superEnter(Node parent, Node n)
           
 
Methods inherited from class polyglot.visit.ErrorHandlingVisitor
catchErrors, enterCall, enterCall, enterError, errorQueue, hasErrors, job, leaveCall, leaveCall, leaveCall, nodeFactory, typeSystem
 
Methods inherited from class polyglot.visit.HaltingVisitor
bypass, bypass, bypassChildren, override, visitChildren
 
Methods inherited from class polyglot.visit.NodeVisitor
copy, finish, finish, leave, override, toString, visitEdge, visitEdgeNoOverride
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

outer

protected ContextVisitor outer

rethrowMissingDependencies

protected boolean rethrowMissingDependencies
Should MissingDependencyExceptions be rethrown? If not, then the dependency is added to the scheduler, and the visitor continues.


context

protected Context context
The current context of this visitor.


prune

protected boolean prune
Constructor Detail

ContextVisitor

public ContextVisitor(Job job,
                      TypeSystem ts,
                      NodeFactory nf)
Method Detail

rethrowMissingDependencies

public ContextVisitor rethrowMissingDependencies(boolean rethrow)

begin

public NodeVisitor begin()
Description copied from class: ErrorHandlingVisitor
Part of the initialization done by begin() in an ErrorHandlingVisitor method is initializing the error-handling state.

Overrides:
begin in class ErrorHandlingVisitor
Returns:
the NodeVisitor to traverse the ast with. If null is returned, the ast is not traversed.

context

public Context context()
Returns the context for this visitor.

Returns:
Returns the context that is currently in use by this visitor.
See Also:
Context

context

public ContextVisitor context(Context c)
Returns a new ContextVisitor that is a copy of the current visitor, except with an updated context.

Parameters:
c - The new context that is to be used.
Returns:
Returns a copy of this visitor with the new context c.

enterScope

protected Context enterScope(Node parent,
                             Node n)
Returns a new context based on the current context, the Node current being visited (parent), and the Node that is being entered (n). This new context is to be used for visiting n.

Returns:
The new context after entering Node n.

addDecls

protected void addDecls(Node n)
Imperatively update the context with declarations to be added after visiting the node.


enter

public final NodeVisitor enter(Node n)
Description copied from class: NodeVisitor
Begin normal traversal of a subtree rooted at n. This gives the visitor the option of changing internal state or returning a new visitor which will be used to visit the children of n.

This method is typically called by the method enter(parent, n). If a subclass overrides the method enter(parent, n) then this method may not be called.

Overrides:
enter in class NodeVisitor
Parameters:
n - The root of the subtree to be traversed.
Returns:
The NodeVisitor which should be used to visit the children of n.

enter

public final NodeVisitor enter(Node parent,
                               Node n)
Description copied from class: ErrorHandlingVisitor
Begin normal traversal of a subtree rooted at n. This gives the visitor the option of changing internal state or returning a new visitor which will be used to visit the children of n. This method delegates all responsibility of functionality to the enterCall method, and handles and reports any exceptions generated by enterCall. In overriding this method, unless the class explicitly does not want to maintain any of the error handling aspects of this class, a call super.enter should be embedded within the method at the end.

Overrides:
enter in class ErrorHandlingVisitor
Parameters:
parent - The parent of n, null if n has no parent.
n - The root of the subtree to be traversed.
Returns:
The NodeVisitor which should be used to visit the children of n.

superEnter

public NodeVisitor superEnter(Node parent,
                              Node n)

leave

public final Node leave(Node parent,
                        Node old,
                        Node n,
                        NodeVisitor v)
Description copied from class: ErrorHandlingVisitor
This method is called after all of the children of n have been visited. In this case, these children were visited by the visitor v. This is the last chance for the visitor to modify the tree rooted at n. This method will be called exactly the same number of times as entry is called. That is, for each node that is not overriden, enter and leave are each called exactly once.

Note that if old == n then the vistior should make a copy of n before modifying it. It should then return the modified copy. This method delegates all responsibility of functionality to the leaveCall method, and handles and reports any exceptions generated by leaveCall. In overriding this method, unless the class explicitly does not want to maintain any of the error handling aspects of this class, a call super.leave should be embedded within the method at the end.

Overrides:
leave in class ErrorHandlingVisitor
Parameters:
parent - The parent of old, null if old has no parent.
old - The original state of root of the current subtree.
n - The current state of the root of the current subtree.
v - The NodeVisitor object used to visit the children.
Returns:
The final result of the traversal of the tree rooted at n.