1 19 20 package soot.jimple.toolkits.pointer; 21 import java.util.*; 22 import soot.*; 23 24 25 public class SiteRWSet extends RWSet { 26 protected HashSet sets = new HashSet(); 27 protected boolean callsNative = false; 28 29 public String toString() { 30 boolean empty = true; 31 final StringBuffer ret = new StringBuffer (); 32 ret.append("SiteRWSet: "); 33 for( Iterator keyIt = sets.iterator(); keyIt.hasNext(); ) { 34 final Object key = (Object ) keyIt.next(); 35 ret.append( key.toString() ); 36 empty = false; 37 } 38 if(empty) ret.append("empty"); 39 return ret.toString(); 40 } 41 42 public boolean getCallsNative() { 43 return callsNative; 44 } 45 46 public boolean setCallsNative() { 47 boolean ret = !callsNative; 48 callsNative = true; 49 return ret; 50 } 51 52 53 public Set getGlobals() { 54 HashSet ret = new HashSet(); 55 for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) { 56 final RWSet s = (RWSet) sIt.next(); 57 ret.addAll( s.getGlobals() ); 58 } 59 return ret; 60 } 61 62 63 public Set getFields() { 64 HashSet ret = new HashSet(); 65 for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) { 66 final RWSet s = (RWSet) sIt.next(); 67 ret.addAll( s.getFields() ); 68 } 69 return ret; 70 } 71 72 73 public PointsToSet getBaseForField( Object f ) { 74 Union ret = null; 75 for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) { 76 final RWSet s = (RWSet) sIt.next(); 77 PointsToSet os = s.getBaseForField( f ); 78 if( os == null ) continue; 79 if( os.isEmpty() ) continue; 80 if( ret == null ) ret = G.v().Union_factory.newUnion(); 81 ret.addAll( os ); 82 } 83 return ret; 84 } 85 86 public boolean hasNonEmptyIntersection( RWSet oth ) { 87 if( sets.contains( oth ) ) return true; 88 for( Iterator sIt = sets.iterator(); sIt.hasNext(); ) { 89 final RWSet s = (RWSet) sIt.next(); 90 if( oth.hasNonEmptyIntersection( s ) ) return true; 91 } 92 return false; 93 } 94 95 96 public boolean union( RWSet other ) { 97 if( other == null ) return false; 98 boolean ret = false; 99 if( other.getCallsNative() ) ret = setCallsNative(); 100 if( other.getFields().isEmpty() && other.getGlobals().isEmpty() ) return ret; 101 return sets.add( other ) | ret; 102 } 103 104 public boolean addGlobal( SootField global ) { 105 throw new RuntimeException ( "Not implemented; try MethodRWSet" ); 106 } 107 public boolean addFieldRef( PointsToSet otherBase, Object field ) { 108 throw new RuntimeException ( "Not implemented; try MethodRWSet" ); 109 } 110 public boolean isEquivTo( RWSet other ) { 111 if( !( other instanceof SiteRWSet ) ) return false; 112 SiteRWSet o = (SiteRWSet) other; 113 if( o.callsNative != callsNative ) return false; 114 return o.sets.equals( sets ); 115 } 116 } 117 | Popular Tags |