1 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 public static CallGraphTagger v() { return G.v().soot_jimple_toolkits_annotation_callgraph_CallGraphTagger(); } 32 33 private MethodToContexts methodToContexts; 34 protected void internalTransform( 35 Body b, String phaseName, Map options) 36 { 37 38 CallGraph cg = Scene.v().getCallGraph(); 39 if( methodToContexts == null ) { 40 methodToContexts = new MethodToContexts( Scene.v().getReachableMethods().listener() ); 41 } 42 43 Iterator stmtIt = b.getUnits().iterator(); 44 45 while (stmtIt.hasNext()){ 46 47 Stmt s = (Stmt) stmtIt.next(); 48 49 Iterator edges = cg.edgesOutOf(s); 50 51 while (edges.hasNext()){ 52 Edge e = (Edge)edges.next(); 53 SootMethod m = e.tgt(); 54 s.addTag(new LinkTag("CallGraph: Type: "+e.kind()+" Target Method/Context: "+e.getTgt().toString(), m, m.getDeclaringClass().getName(), "Call Graph")); 55 56 } 57 } 58 59 SootMethod m = b.getMethod(); 60 for( Iterator momcIt = methodToContexts.get(m).iterator(); momcIt.hasNext(); ) { 61 final MethodOrMethodContext momc = (MethodOrMethodContext) momcIt.next(); 62 Iterator callerEdges = cg.edgesInto(momc); 63 while (callerEdges.hasNext()){ 64 Edge callEdge = (Edge)callerEdges.next(); 65 SootMethod methodCaller = callEdge.src(); 66 Host src = methodCaller; 67 if( callEdge.srcUnit() != null ) { 68 src = callEdge.srcUnit(); 69 } 70 m.addTag( 71 new LinkTag( 72 "CallGraph: Source Type: "+callEdge.kind()+" Source Method/Context: "+callEdge.getSrc().toString(), 73 src, 74 methodCaller.getDeclaringClass().getName(), 75 "Call Graph")); 76 } 77 } 78 } 79 80 } 81 82 | Popular Tags |