1 19 20 package soot.jimple.toolkits.pointer; 21 import soot.*; 22 import java.util.*; 23 import soot.tagkit.*; 24 25 public class DependenceGraph implements Attribute 26 { 27 private final static String NAME = "DependenceGraph"; 28 HashSet edges = new HashSet(); 29 30 protected class Edge { 31 short from; 32 short to; 33 Edge( short from, short to ) { this.from = from; this.to = to; } 34 public int hashCode() { return ( (((int) from) << 16) + to ); } 35 public boolean equals( Object other ) { 36 Edge o = (Edge) other; 37 return from == o.from && to == o.to; 38 } 39 } 40 41 public boolean areAdjacent( short from, short to ) { 42 if( from > to ) return areAdjacent( to, from ); 43 if( from < 0 || to < 0 ) return false; 44 if( from == to ) return true; 45 return edges.contains( new Edge( from, to ) ); 46 } 47 public void addEdge( short from, short to ) { 48 if( from < 0 ) throw new RuntimeException ( "from < 0" ); 49 if( to < 0 ) throw new RuntimeException ( "to < 0" ); 50 if( from > to ) { 51 addEdge( to, from ); 52 return; 53 } 54 edges.add( new Edge( from, to ) ); 55 } 56 public String getName() 57 { 58 return NAME; 59 } 60 61 public void setValue(byte[] v) { 62 throw new RuntimeException ( "Not Supported" ); 63 } 64 65 public byte[] getValue() { 66 byte[] ret = new byte[4*edges.size()]; 67 int i = 0; 68 for( Iterator it = edges.iterator(); it.hasNext(); ) { 69 Edge e = (Edge) it.next(); 70 ret[i+0] = (byte) ( (e.from >> 8) & 0xff ); 71 ret[i+1] = (byte) ( e.from & 0xff ); 72 ret[i+2] = (byte) ( (e.to >> 8) & 0xff ); 73 ret[i+3] = (byte) ( e.to & 0xff ); 74 i += 4; 75 } 76 return ret; 77 } 78 79 public String toString() 80 { 81 StringBuffer buf = new StringBuffer ( "Dependences" ); 82 for( Iterator it = edges.iterator(); it.hasNext(); ) { 83 Edge e = (Edge) it.next(); 84 buf.append( "( "+e.from+", "+e.to+" ) " ); 85 } 86 return buf.toString(); 87 } 88 } 89 | Popular Tags |