1 19 20 27 28 package soot.jimple.toolkits.annotation.purity; 29 import java.util.*; 30 import soot.*; 31 import soot.util.*; 32 import soot.jimple.*; 33 import soot.jimple.toolkits.callgraph.*; 34 import soot.toolkits.graph.*; 35 36 47 public class DirectedCallGraph implements DirectedGraph { 48 49 protected Set nodes; 50 protected Map succ; 51 protected Map pred; 52 protected List heads; 53 protected List tails; 54 protected int size; 55 56 67 public DirectedCallGraph(CallGraph cg, 68 SootMethodFilter filter, 69 Iterator heads, 70 boolean verbose) 71 { 72 List filteredHeads = new LinkedList(); 74 while (heads.hasNext()) { 75 SootMethod m = (SootMethod) heads.next(); 76 if (m.isConcrete() && filter.want(m)) filteredHeads.add(m); 77 } 78 79 this.nodes = new HashSet(filteredHeads); 80 81 MultiMap s = new HashMultiMap(); 82 MultiMap p = new HashMultiMap(); 83 84 Set remain = new HashSet(filteredHeads); 86 int nb = 0; 87 if (verbose) G.v().out.println("[AM] dumping method dependencies"); 88 while (!remain.isEmpty()) { 89 Set newRemain = new HashSet(); 90 Iterator it = remain.iterator(); 91 while (it.hasNext()) { 92 SootMethod m = (SootMethod)it.next(); 93 Iterator itt = cg.edgesOutOf(m); 94 if (verbose) 95 G.v().out.println(" |- "+m.toString()+" calls"); 96 while (itt.hasNext()) { 97 Edge edge = (Edge)itt.next(); 98 SootMethod mm = edge.tgt(); 99 boolean keep = mm.isConcrete() && filter.want(mm); 100 if (verbose) 101 G.v().out.println(" | |- "+mm.toString()+ 102 (keep?"":" (filtered out)")); 103 if (keep) { 104 if (this.nodes.add(mm)) newRemain.add(mm); 105 s.put(m,mm); 106 p.put(mm,m); 107 } 108 } 109 nb++; 110 } 111 remain = newRemain; 112 } 113 G.v().out.println("[AM] number of methods to be analysed: "+nb); 114 115 this.succ = new HashMap(); 117 this.pred = new HashMap(); 118 this.tails = new LinkedList(); 119 this.heads = new LinkedList(); 120 Iterator it = this.nodes.iterator(); 121 while (it.hasNext()) { 122 Object x = it.next(); 123 Set ss = s.get(x); 124 Set pp = p.get(x); 125 this.succ.put(x, new LinkedList(ss)); 126 this.pred.put(x, new LinkedList(pp)); 127 if (ss.isEmpty()) this.tails.add(x); 128 if (pp.isEmpty()) this.heads.add(x); 129 } 130 131 this.size = this.nodes.size(); 132 } 133 134 135 public List getHeads() { return heads; } 136 137 138 public List getTails() { return tails; } 139 140 141 public Iterator iterator() { return nodes.iterator(); } 142 143 public int size() { return size; } 144 145 146 public List getSuccsOf(Object s) { return (List)succ.get(s); } 147 148 149 public List getPredsOf(Object s) { return (List)pred.get(s); } 150 } 151 | Popular Tags |