01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2003 John Jorgensen
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.toolkits.graph;
21:
22: import java.util.*;
23: import soot.*;
24:
25: /**
26: * <p>Represents a CFG where the nodes are {@link Block}s and the
27: * edges are derived from control flow. Control flow associated with
28: * exceptions is taken into account: when a <tt>Unit</tt> may throw
29: * an exception that is caught by a {@link Trap} within the
30: * <tt>Body</tt>, the excepting <tt>Unit</tt> starts a new basic
31: * block.</p>
32: *
33: * <p> <tt>ClassicCompleteBlockGraph</tt> approximates the results
34: * that would have been produced by Soot's {@link CompleteBlockGraph}
35: * in releases up to Soot 2.1.0. It is included solely for testing
36: * purposes, and should not be used in actual analyses. The approximation
37: * works not by duplicating the old {@link CompleteBlockGraph}'s logic,
38: * but by using {@link ClassicCompleteUnitGraph} as the basis for
39: * dividing {@link Unit}s into {@link Block}s.</p>
40: *
41: */
42:
43: public class ClassicCompleteBlockGraph extends BlockGraph {
44: /**
45: * <p> Constructs a <tt>ClassicCompleteBlockGraph</tt> for the blocks
46: * found by partitioning the the units of the provided
47: * {@link Body} instance into basic blocks.</p>
48: *
49: * <p> Note that this constructor builds a {@link
50: * ClassicCompleteUnitGraph} internally when splitting <tt>body</tt>'s
51: * {@link Unit}s into {@link Block}s. Callers who already have
52: * a {@link ClassicCompleteUnitGraph} to hand can use the constructor
53: * taking a <tt>ClassicCompleteUnitGraph</tt> as a parameter, as a
54: * minor optimization.
55: *
56: * @param body The underlying body we want to make a graph for.
57: */
58: public ClassicCompleteBlockGraph(Body body) {
59: super (new ClassicCompleteUnitGraph(body));
60: }
61:
62: /**
63: * Constructs a graph for the blocks found by partitioning the
64: * the units in a {@link ClassicCompleteUnitGraph}.
65: *
66: * @param unitGraph A {@link ClassicCompleteUnitGraph} built from
67: * <tt>body</tt>. The <tt>CompleteBlockGraph</tt> constructor uses
68: * the passed <tt>graph</tt> to split the body into
69: * blocks.
70: */
71: public ClassicCompleteBlockGraph(ClassicCompleteUnitGraph unitGraph) {
72: super (unitGraph);
73: // Adjust the heads and tails to match the old CompleteBlockGraph.
74: Unit entryPoint = (Unit) (getBody().getUnits().getFirst());
75: List newHeads = new ArrayList(1);
76: for (Iterator blockIt = getBlocks().iterator(); blockIt
77: .hasNext();) {
78: Block b = (Block) blockIt.next();
79: if (b.getHead() == entryPoint) {
80: newHeads.add(b);
81: break;
82: }
83: }
84: mHeads = Collections.unmodifiableList(newHeads);
85: mTails = Collections.EMPTY_LIST;
86:
87: soot.util.PhaseDumper.v().dumpGraph(this, mBody);
88: }
89: }
|