polyglot.visit
Class ErrorHandlingVisitor

java.lang.Object
  extended by polyglot.visit.NodeVisitor
      extended by polyglot.visit.HaltingVisitor
          extended by polyglot.visit.ErrorHandlingVisitor
All Implemented Interfaces:
java.lang.Cloneable, Copy
Direct Known Subclasses:
ContextVisitor, DataFlow, ExceptionChecker

public class ErrorHandlingVisitor
extends HaltingVisitor


Field Summary
protected  boolean error
           
protected  Job job
           
protected  NodeFactory nf
           
protected  TypeSystem ts
           
 
Constructor Summary
ErrorHandlingVisitor(Job job, TypeSystem ts, NodeFactory nf)
           
 
Method Summary
 NodeVisitor begin()
          Part of the initialization done by begin() in an ErrorHandlingVisitor method is initializing the error-handling state.
protected  boolean catchErrors(Node n)
          Return true if we should catch errors thrown when visiting the node.
 NodeVisitor enter(Node parent, Node n)
          Begin normal traversal of a subtree rooted at n.
protected  NodeVisitor enterCall(Node n)
           
protected  NodeVisitor enterCall(Node parent, Node n)
          Replaces the functionality of the enter() method; all sub-classes should over-ride this method instead of enter() if there is any chance of exceptions being generated.
protected  NodeVisitor enterError(Node n)
          This method determines what should be returned by enter() should its call to enterCall() throw a SemanticException.
 ErrorQueue errorQueue()
          Returns the ErrorQueue for the current Job.
 Job job()
          Returns the Job that this Visitor is part of.
 Node leave(Node parent, Node old, Node n, NodeVisitor v)
          This method is called after all of the children of n have been visited.
protected  Node leaveCall(Node n)
           
protected  Node leaveCall(Node old, Node n, NodeVisitor v)
          Contains all of the functionality that can be done in the leave method, but allows SemanticExceptions to be thrown.
 NodeFactory nodeFactory()
          Returns the NodeFactory that this Visitor is using.
 TypeSystem typeSystem()
          Returns the TypeSystem that this Visitor is using.
 
Methods inherited from class polyglot.visit.HaltingVisitor
bypass, bypass, bypassChildren, copy, override, visitChildren
 
Methods inherited from class polyglot.visit.NodeVisitor
enter, finish, finish, leave, override, toString, visitEdge
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

error

protected boolean error

job

protected Job job

ts

protected TypeSystem ts

nf

protected NodeFactory nf
Constructor Detail

ErrorHandlingVisitor

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

job

public Job job()
Returns the Job that this Visitor is part of.

See Also:
Job

begin

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

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

errorQueue

public ErrorQueue errorQueue()
Returns the ErrorQueue for the current Job.

See Also:
ErrorQueue

nodeFactory

public NodeFactory nodeFactory()
Returns the NodeFactory that this Visitor is using.

See Also:
NodeFactory

typeSystem

public TypeSystem typeSystem()
Returns the TypeSystem that this Visitor is using.

See Also:
TypeSystem

enterCall

protected NodeVisitor enterCall(Node parent,
                                Node n)
                         throws SemanticException
Replaces the functionality of the enter() method; all sub-classes should over-ride this method instead of enter() if there is any chance of exceptions being generated. This method is the replacement for the enter() method, so that all of its subclasses gain the error handling capabilities of this visitor without having to rewrite it for the enter() for each sub-class. This method allows for a SemanticException to be thrown in the body, while enter() does not.

Parameters:
n - The root of the subtree to be traversed.
Returns:
The ErrorHandlingVisitor which should be used to visit the children of n.
Throws:
SemanticException
See Also:
NodeVisitor.enter(Node, Node)

enterCall

protected NodeVisitor enterCall(Node n)
                         throws SemanticException
Throws:
SemanticException

enterError

protected NodeVisitor enterError(Node n)
This method determines what should be returned by enter() should its call to enterCall() throw a SemanticException.

Parameters:
n - The root of the subtree that was traversed.
Returns:
The ErrorHandlingVisitor which should be used to visit the childre of n.

leaveCall

protected Node leaveCall(Node old,
                         Node n,
                         NodeVisitor v)
                  throws SemanticException
Contains all of the functionality that can be done in the leave method, but allows SemanticExceptions to be thrown. This method is in addition to the leave method, and allows the compiler writer to write code that can throw errors and let the polyglot infrastructure handle the exceptions.

Parameters:
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.
Throws:
SemanticException
See Also:
NodeVisitor.leave(Node, Node, NodeVisitor)

leaveCall

protected Node leaveCall(Node n)
                  throws SemanticException
Throws:
SemanticException

catchErrors

protected boolean catchErrors(Node n)
Return true if we should catch errors thrown when visiting the node.


enter

public NodeVisitor enter(Node parent,
                         Node n)
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 NodeVisitor
Parameters:
n - The root of the subtree to be traversed.
parent - The parent of n, null if n has no parent.
Returns:
The NodeVisitor which should be used to visit the children of n.

leave

public Node leave(Node parent,
                  Node old,
                  Node n,
                  NodeVisitor v)
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 NodeVisitor
Parameters:
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.
parent - The parent of old, null if old has no parent.
Returns:
The final result of the traversal of the tree rooted at n.