polyglot.visit
Class ExceptionChecker

java.lang.Object
  extended by polyglot.visit.NodeVisitor
      extended by polyglot.visit.HaltingVisitor
          extended by polyglot.visit.ErrorHandlingVisitor
              extended by polyglot.visit.ExceptionChecker
All Implemented Interfaces:
java.lang.Cloneable, Copy

public class ExceptionChecker
extends ErrorHandlingVisitor

Visitor which checks if exceptions are caught or declared properly.


Field Summary
protected  java.util.Map exceptionPositions
           
protected  ExceptionChecker outer
           
 
Fields inherited from class polyglot.visit.ErrorHandlingVisitor
error, job, nf, ts
 
Constructor Summary
ExceptionChecker(Job job, TypeSystem ts, NodeFactory nf)
           
 
Method Summary
protected  NodeVisitor enterCall(Node n)
          This method is called when we are to perform a "normal" traversal of a subtree rooted at n.
protected  NodeVisitor enterError(Node n)
          This method determines what should be returned by enter() should its call to enterCall() throw a SemanticException.
 Position exceptionPosition(Type t)
          Method to determine the position at which a particular exception is thrown
protected  Node leaveCall(Node old, Node n, NodeVisitor v)
          Here, we pop the stack frame that we pushed in enter and agregate the exceptions.
 ExceptionChecker pop()
           
 ExceptionChecker push()
           
 ExceptionChecker pushNew()
           
 void throwsException(Type t, Position pos)
          The ast nodes will use this callback to notify us that they throw an exception of type t.
 SubtypeSet throwsSet()
          Method to allow the throws clause and method body to inspect and modify the throwsSet.
 
Methods inherited from class polyglot.visit.ErrorHandlingVisitor
begin, catchErrors, enter, enterCall, errorQueue, job, leave, leaveCall, nodeFactory, typeSystem
 
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

outer

protected ExceptionChecker outer

exceptionPositions

protected java.util.Map exceptionPositions
Constructor Detail

ExceptionChecker

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

pushNew

public ExceptionChecker pushNew()

push

public ExceptionChecker push()

pop

public ExceptionChecker pop()

enterCall

protected NodeVisitor enterCall(Node n)
                         throws SemanticException
This method is called when we are to perform a "normal" traversal of a subtree rooted at n. At every node, we will push a stack frame. Each child node will add the exceptions that it throws to this stack frame. For most nodes ( excdeption for the try / catch) will just aggregate the stack frames.

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

enterError

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

Overrides:
enterError in class ErrorHandlingVisitor
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
Here, we pop the stack frame that we pushed in enter and agregate the exceptions.

Overrides:
leaveCall in class ErrorHandlingVisitor
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)

throwsException

public void throwsException(Type t,
                            Position pos)
The ast nodes will use this callback to notify us that they throw an exception of type t. This should only be called by MethodExpr node, and throw node, since they are the only node which can generate exceptions.

Parameters:
t - The type of exception that the node throws.

throwsSet

public SubtypeSet throwsSet()
Method to allow the throws clause and method body to inspect and modify the throwsSet.


exceptionPosition

public Position exceptionPosition(Type t)
Method to determine the position at which a particular exception is thrown