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.


Nested Class Summary
static class ExceptionChecker.CodeTypeReporter
           
static class ExceptionChecker.UncaughtReporter
           
 
Field Summary
protected  java.util.Set catchable
          Set of exceptions that can be caught.
protected  boolean catchAllThrowable
          Should the propogation of eceptions upwards go past this point?
protected  ExceptionChecker outer
           
protected  ExceptionChecker.UncaughtReporter reporter
          Responsible for creating an appropriate exception.
protected  SubtypeSet throwsSet
          The throws set, calculated bottom up.
 
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)
           
protected  NodeVisitor enterError(Node n)
          This method determines what should be returned by enter() should its call to enterCall() throw a SemanticException.
protected  Node leaveCall(Node old, Node n, NodeVisitor v)
          Call exceptionCheck(ExceptionChecker) on the node.
 ExceptionChecker pop()
           
 ExceptionChecker push()
           
 ExceptionChecker push(java.util.Collection catchableTypes)
           
 ExceptionChecker push(ExceptionChecker.UncaughtReporter reporter)
           
 ExceptionChecker push(Type catchableType)
           
 ExceptionChecker pushCatchAllThrowable()
           
protected  void reportUncaughtException(Type t, Position pos)
           
 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()
           
 
Methods inherited from class polyglot.visit.ErrorHandlingVisitor
begin, catchErrors, enter, enterCall, errorQueue, hasErrors, job, leave, leaveCall, leaveCall, nodeFactory, typeSystem
 
Methods inherited from class polyglot.visit.HaltingVisitor
bypass, bypass, bypassChildren, override, visitChildren
 
Methods inherited from class polyglot.visit.NodeVisitor
copy, enter, 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 ExceptionChecker outer

catchable

protected java.util.Set catchable
Set of exceptions that can be caught. Combined with the outer field, these sets form a stack of exceptions, representing all and only the exceptions that may be thrown at this point in the code. Note: Consider the following code, where A,B,C,D are Exception subclasses. void m() throws A, B { try { ... } catch (C ex) { ... } catch (D ex) { ... } } Inside the try-block, the stack of catchable sets is: { C } { D } { A, B }


throwsSet

protected SubtypeSet throwsSet
The throws set, calculated bottom up.


reporter

protected ExceptionChecker.UncaughtReporter reporter
Responsible for creating an appropriate exception.


catchAllThrowable

protected boolean catchAllThrowable
Should the propogation of eceptions upwards go past this point?

Constructor Detail

ExceptionChecker

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

push

public ExceptionChecker push(ExceptionChecker.UncaughtReporter reporter)

push

public ExceptionChecker push(Type catchableType)

push

public ExceptionChecker push(java.util.Collection catchableTypes)

pushCatchAllThrowable

public ExceptionChecker pushCatchAllThrowable()

push

public ExceptionChecker push()

pop

public ExceptionChecker pop()

enterCall

protected NodeVisitor enterCall(Node n)
                         throws SemanticException
Overrides:
enterCall in class ErrorHandlingVisitor
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
Call exceptionCheck(ExceptionChecker) on the node.

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

throwsException

public void throwsException(Type t,
                            Position pos)
                     throws SemanticException
The ast nodes will use this callback to notify us that they throw an exception of type t. This method will throw a SemanticException if the type t is not allowed to be thrown at this point; the exception t will be added to the throwsSet of all exception checkers in the stack, up to (and not including) the exception checker that catches the exception.

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

throwsSet

public SubtypeSet throwsSet()

reportUncaughtException

protected void reportUncaughtException(Type t,
                                       Position pos)
                                throws SemanticException
Throws:
SemanticException