01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-1999 Raja Vallee-Rai
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: package soot.jbco.util;
21:
22: import java.util.*;
23:
24: import soot.Body;
25: import soot.Trap;
26: import soot.Unit;
27: import soot.toolkits.graph.TrapUnitGraph;
28:
29: /**
30: * @author Michael Batchelder
31: *
32: * Created on 15-Jun-2006
33: */
34: public class SimpleExceptionalGraph extends TrapUnitGraph {
35:
36: /**
37: * @param body
38: */
39: public SimpleExceptionalGraph(Body body) {
40: super (body);
41: int size = unitChain.size();
42:
43: unitToSuccs = new HashMap(size * 2 + 1, 0.7f);
44: unitToPreds = new HashMap(size * 2 + 1, 0.7f);
45: buildUnexceptionalEdges(unitToSuccs, unitToPreds);
46: buildSimpleExceptionalEdges(unitToSuccs, unitToPreds);
47:
48: makeMappedListsUnmodifiable(unitToSuccs);
49: makeMappedListsUnmodifiable(unitToPreds);
50: buildHeadsAndTails();
51: }
52:
53: protected void buildSimpleExceptionalEdges(Map unitToSuccs,
54: Map unitToPreds) {
55: for (Iterator trapIt = body.getTraps().iterator(); trapIt
56: .hasNext();) {
57: Trap trap = (Trap) trapIt.next();
58:
59: Unit handler = trap.getHandlerUnit();
60: for (Iterator predIt = ((List) unitToPreds.get(trap
61: .getBeginUnit())).iterator(); predIt.hasNext();) {
62: Unit pred = (Unit) predIt.next();
63: addEdge(unitToSuccs, unitToPreds, pred, handler);
64: }
65: }
66: }
67: }
|