001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2004 John Jorgensen
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: /*
021: * Modified by the Sable Research Group and others 1997-2004.
022: * See the 'credits' file distributed with Soot for the complete list of
023: * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
024: */
025:
026: package soot.toolkits.graph;
027:
028: import soot.toolkits.graph.DirectedGraph;
029: import soot.Body;
030: import soot.Trap;
031: import soot.Unit;
032:
033: import java.util.List;
034: import java.util.Collection;
035: import soot.toolkits.exceptions.ThrowableSet;
036:
037: /**
038: * <p>Defines the interface for navigating a control flow graph which
039: * distinguishes exceptional control flow.</p>
040: * @param N node type
041: */
042: public interface ExceptionalGraph<N extends Unit> extends
043: DirectedGraph<N> {
044: /**
045: * <p>Data structure to represent the fact that
046: * a given {@link Trap} will catch some subset of the exceptions
047: * which may be thrown by a given graph node.</p>
048: *
049: * <p>Note that these ``destinations'' are different from the
050: * edges in the CFG proper which are returned by
051: * <code>getSuccsOf()</code> and <code>getPredsOf()</code>. An
052: * edge from <code>a</code> to <code>b</code> in the CFG
053: * represents the fact that after node <code>a</code> executes
054: * (perhaps only partially, if it throws an exception after
055: * producing a side effect), execution may proceed to
056: * node <code>b</code>. An ExceptionDest from <code>a</code> to
057: * <code>b</code>, on the other hand, says that when
058: * <code>a</code> fails to execute, execution may proceed
059: * to <code>b</code> instead.</p>
060: */
061: public interface ExceptionDest<N> {
062:
063: /**
064: * Returns the trap corresponding to this destination.
065: *
066: * @return either a {@link Trap} representing the handler that
067: * catches the exceptions, if there is such a handler within
068: * the method, or <code>null</code> if there is no such
069: * handler and the exceptions cause the method to terminate
070: * abruptly.
071: */
072: public Trap getTrap();
073:
074: /**
075: * Returns the exceptions thrown to this destination.
076: *
077: * @return a {@link ThrowableSet} representing
078: * the exceptions which may be caught by this
079: * <code>ExceptionDest</code>'s trap.
080: */
081: public ThrowableSet getThrowables();
082:
083: /**
084: * Returns the CFG node corresponding to the beginning of
085: * the exception handler that catches the exceptions (that is,
086: * the node that includes {@link trap().getBeginUnit()}).
087: *
088: * @return the node in this graph which represents the
089: * beginning of the handler which catches these exceptions, or
090: * <code>null</code> if there is no such handler and the
091: * exceptions cause the method to terminate abruptly.
092: */
093: // Maybe we should define an interface for Unit and Block to
094: // implement, and return an instance of that, rather than
095: // an Object. We chose Object because that's what DirectedGraph
096: // deals in.
097: public N getHandlerNode();
098: }
099:
100: /**
101: * Returns the {@link Body} from which this graph was built.
102: *
103: * @return the <code>Body</code> from which this graph was built.
104: */
105: public Body getBody();
106:
107: /**
108: * Returns a list of nodes which are predecessors of a given
109: * node when only unexceptional control flow is considered.
110: *
111: * @param n The node whose predecessors are to be returned.
112: *
113: * @return a {@link List} of the nodes in this graph from which
114: * there is an unexceptional edge to <code>n</code>.
115: */
116: public List<N> getUnexceptionalPredsOf(N n);
117:
118: /**
119: * Returns a list of nodes which are successors of a given
120: * node when only unexceptional control flow is considered.
121: *
122: * @param n The node whose successors are to be returned.
123: *
124: * @return a {@link List} of nodes in this graph to which
125: * there is an unexceptional edge from <code>n</code>.
126: */
127: public List<N> getUnexceptionalSuccsOf(N n);
128:
129: /**
130: * Returns a list of nodes which are predecessors of a given
131: * node when only exceptional control flow is considered.
132: *
133: * @param n The node whose predecessors are to be returned.
134: *
135: * @return a {@link List} of nodes in this graph from which
136: * there is an exceptional edge to <code>n</code>.
137: */
138: public List<N> getExceptionalPredsOf(N n);
139:
140: /**
141: * Returns a list of nodes which are successors of a given
142: * node when only exceptional control flow is considered.
143: *
144: * @param n The node whose successors are to be returned.
145: *
146: * @return a {@link List} of nodes in this graph to which
147: * there is an exceptional edge from <code>n</code>.
148: */
149: public List<N> getExceptionalSuccsOf(N n);
150:
151: /**
152: * Returns a collection of
153: * {@link ExceptionalGraph.ExceptionDest ExceptionDest}
154: * objects which represent how exceptions thrown by a specified
155: * node will be handled.
156: *
157: * @param n The node for which to provide exception information.
158: *
159: * @return a collection of <code>ExceptionDest</code> objects describing
160: * the traps and handlers, if any, which catch the exceptions
161: * which may be thrown by <code>n</code>.
162: */
163: public Collection<N> getExceptionDests(N n);
164: }
|