1 19 20 package soot.jimple.toolkits.callgraph; 21 import soot.*; 22 import soot.util.*; 23 import soot.util.queue.*; 24 import java.util.*; 25 26 31 public class SlowCallGraph extends CallGraph 32 { 33 private Set edges = new HashSet(); 34 private MultiMap srcMap = new HashMultiMap(); 35 private MultiMap unitMap = new HashMultiMap(); 36 private MultiMap tgtMap = new HashMultiMap(); 37 private ChunkedQueue stream = new ChunkedQueue(); 38 private QueueReader reader = stream.reader(); 39 private Edge dummy = new Edge( null, null, null, Kind.INVALID ); 40 41 43 public boolean addEdge( Edge e ) { 44 if( !edges.add( e ) ) return false; 45 stream.add( e ); 46 47 srcMap.put( e.getSrc(), e ); 48 tgtMap.put( e.getTgt(), e ); 49 unitMap.put( e.srcUnit(), e ); 50 51 return true; 52 } 53 55 public boolean removeEdge( Edge e ) { 56 if( !edges.remove( e ) ) return false; 57 58 srcMap.remove(e.getSrc(), e); 59 tgtMap.remove(e.getTgt(), e); 60 unitMap.remove(e.srcUnit(), e); 61 62 return true; 63 } 64 65 67 public Iterator sourceMethods() { 68 return new ArrayList(srcMap.keySet()).iterator(); 69 } 70 71 public Iterator edgesOutOf( Unit u ) { 72 return new ArrayList(unitMap.get(u)).iterator(); 73 } 74 75 public Iterator edgesOutOf( MethodOrMethodContext m ) { 76 return new ArrayList(srcMap.get(m)).iterator(); 77 } 78 79 public Iterator edgesInto( MethodOrMethodContext m ) { 80 return new ArrayList(tgtMap.get(m)).iterator(); 81 } 82 85 public QueueReader listener() { 86 return (QueueReader) reader.clone(); 87 } 88 91 public QueueReader newListener() { 92 return stream.reader(); 93 } 94 public String toString() { 95 QueueReader reader = listener(); 96 StringBuffer out = new StringBuffer (); 97 while(reader.hasNext()) { 98 Edge e = (Edge) reader.next(); 99 out.append( e.toString() + "\n" ); 100 } 101 return out.toString(); 102 } 103 104 public int size() { 105 return edges.size(); 106 } 107 } 108 109 | Popular Tags |