01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2003 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.callgraph;
21:
22: import soot.*;
23: import soot.jimple.toolkits.callgraph.*;
24: import soot.tagkit.*;
25: import java.util.*;
26: import soot.jimple.*;
27:
28: public class CallGraphTagger extends BodyTransformer {
29:
30: public CallGraphTagger(Singletons.Global g) {
31: }
32:
33: public static CallGraphTagger v() {
34: return G
35: .v()
36: .soot_jimple_toolkits_annotation_callgraph_CallGraphTagger();
37: }
38:
39: private MethodToContexts methodToContexts;
40:
41: protected void internalTransform(Body b, String phaseName,
42: Map options) {
43:
44: CallGraph cg = Scene.v().getCallGraph();
45: if (methodToContexts == null) {
46: methodToContexts = new MethodToContexts(Scene.v()
47: .getReachableMethods().listener());
48: }
49:
50: Iterator stmtIt = b.getUnits().iterator();
51:
52: while (stmtIt.hasNext()) {
53:
54: Stmt s = (Stmt) stmtIt.next();
55:
56: Iterator edges = cg.edgesOutOf(s);
57:
58: while (edges.hasNext()) {
59: Edge e = (Edge) edges.next();
60: SootMethod m = e.tgt();
61: s.addTag(new LinkTag("CallGraph: Type: " + e.kind()
62: + " Target Method/Context: "
63: + e.getTgt().toString(), m, m
64: .getDeclaringClass().getName(), "Call Graph"));
65:
66: }
67: }
68:
69: SootMethod m = b.getMethod();
70: for (Iterator momcIt = methodToContexts.get(m).iterator(); momcIt
71: .hasNext();) {
72: final MethodOrMethodContext momc = (MethodOrMethodContext) momcIt
73: .next();
74: Iterator callerEdges = cg.edgesInto(momc);
75: while (callerEdges.hasNext()) {
76: Edge callEdge = (Edge) callerEdges.next();
77: SootMethod methodCaller = callEdge.src();
78: Host src = methodCaller;
79: if (callEdge.srcUnit() != null) {
80: src = callEdge.srcUnit();
81: }
82: m.addTag(new LinkTag("CallGraph: Source Type: "
83: + callEdge.kind() + " Source Method/Context: "
84: + callEdge.getSrc().toString(), src,
85: methodCaller.getDeclaringClass().getName(),
86: "Call Graph"));
87: }
88: }
89: }
90:
91: }
|