01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2004 Jennifer Lhotak
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.jimple.toolkits.annotation.defs;
21:
22: import soot.*;
23: import soot.toolkits.scalar.*;
24: import soot.toolkits.graph.*;
25: import soot.tagkit.*;
26: import java.util.*;
27: import soot.jimple.*;
28:
29: public class ReachingDefsTagger extends BodyTransformer {
30:
31: public ReachingDefsTagger(Singletons.Global g) {
32: }
33:
34: public static ReachingDefsTagger v() {
35: return G
36: .v()
37: .soot_jimple_toolkits_annotation_defs_ReachingDefsTagger();
38: }
39:
40: protected void internalTransform(Body b, String phaseName,
41: Map options) {
42:
43: UnitGraph g = new ExceptionalUnitGraph(b);
44: LocalDefs sld = new SmartLocalDefs(g, new SimpleLiveLocals(g));
45:
46: Iterator it = b.getUnits().iterator();
47: while (it.hasNext()) {
48: Stmt s = (Stmt) it.next();
49: //System.out.println("stmt: "+s);
50: Iterator usesIt = s.getUseBoxes().iterator();
51: while (usesIt.hasNext()) {
52: ValueBox vbox = (ValueBox) usesIt.next();
53: if (vbox.getValue() instanceof Local) {
54: Local l = (Local) vbox.getValue();
55: //System.out.println("local: "+l);
56: Iterator<Unit> rDefsIt = sld.getDefsOfAt(l, s)
57: .iterator();
58: while (rDefsIt.hasNext()) {
59: Stmt next = (Stmt) rDefsIt.next();
60: String info = l + " has reaching def: "
61: + next.toString();
62: s.addTag(new LinkTag(info, next, b.getMethod()
63: .getDeclaringClass().getName(),
64: "Reaching Defs"));
65: }
66: }
67: }
68: }
69: }
70: }
|