edu.cmu.cs.crystal.cfg
Class ExceptionMap<N,Node extends ICFGNode<N>>

java.lang.Object
  extended by edu.cmu.cs.crystal.cfg.ExceptionMap<N,Node>
Type Parameters:
Node -
All Implemented Interfaces:
Cloneable

public class ExceptionMap<N,Node extends ICFGNode<N>>
extends Object
implements Cloneable

This class maintains the exception information for the CFG algorithm while it is building the graph. It is notified of certain points in the cfg algorithm (such as finding a finally or catch), and it can be queried for information about the finallys at a given point or the nearest catch. The ExceptionMap maintains links to ASTNodes and CFGNodes. It should be deleted when the CFG is done with it.

Author:
ciera

Constructor Summary
ExceptionMap()
           
 
Method Summary
 Object clone()
           
 Node getCatchNode(ITypeBinding exception)
           
 Stack<Node> getFinallyToException(ITypeBinding exceptionToStopAt)
          Returns a stack of nodes that are the finally nodes up to the exception.
 Node popCatch()
          Finish a catch.
 Node popFinally()
          Finish a try.
 void pushCatch(Node catchNode, ITypeBinding exception)
          Notify the exception map that we have an exception, and it is catching a particular type of exception.
 void pushFinally(Node finallyNode)
          Notify the exception map that we've found a try node, and we have a finally for it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExceptionMap

public ExceptionMap()
Method Detail

pushFinally

public void pushFinally(Node finallyNode)
Notify the exception map that we've found a try node, and we have a finally for it. Finallys should be pushed before their corresponding catches. If a try has no finally, it should push on null.

Parameters:
finallyNode -

pushCatch

public void pushCatch(Node catchNode,
                      ITypeBinding exception)
Notify the exception map that we have an exception, and it is catching a particular type of exception. Catches should be pushed in the opposite order (bottom first).

Parameters:
catchNode -
exception -

popFinally

public Node popFinally()
Finish a try.

Returns:
the finally node

popCatch

public Node popCatch()
Finish a catch.

Returns:
The last catch to be put on the ExceptionMap

getCatchNode

public Node getCatchNode(ITypeBinding exception)
Parameters:
exception - An exception to find a catch node for, considering subtyping
Returns:
the catch node that will catch this exception, or null if one could not be found

getFinallyToException

public Stack<Node> getFinallyToException(ITypeBinding exceptionToStopAt)
Returns a stack of nodes that are the finally nodes up to the exception. This will not include the finally node at the exception catch. The returned stack will be that the nearest finally is at the top of the stack. If the exception is null, then this returns the entire stack of nodes.

Parameters:
exceptionToStopAt - The exception we should stop at. This might be a subtype of the actual exception that we stop at.
Returns:
The stack to the exception point, or the entire stack if the exception is null.

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException