1 19 20 package soot.jimple.toolkits.pointer; 21 import java.util.*; 22 import soot.*; 23 24 25 public class StmtRWSet extends RWSet { 26 protected Object field; 27 protected PointsToSet base; 28 protected boolean callsNative = false; 29 30 public String toString() { 31 return "[Field: "+field+base+"]\n"; 32 } 33 34 public boolean getCallsNative() { 35 return callsNative; 36 } 37 38 public boolean setCallsNative() { 39 boolean ret = !callsNative; 40 callsNative = true; 41 return ret; 42 } 43 44 45 public Set getGlobals() { 46 if( base == null ) { 47 HashSet ret = new HashSet(); 48 ret.add( field ); 49 return ret; 50 } 51 return Collections.EMPTY_SET; 52 } 53 54 55 public Set getFields() { 56 if( base != null ) { 57 HashSet ret = new HashSet(); 58 ret.add( field ); 59 return ret; 60 } 61 return Collections.EMPTY_SET; 62 } 63 64 65 public PointsToSet getBaseForField( Object f ) { 66 if( field.equals( f ) ) return base; 67 return null; 68 } 69 70 public boolean hasNonEmptyIntersection( RWSet other ) { 71 if( field == null ) return false; 72 if( other instanceof StmtRWSet ) { 73 StmtRWSet o = (StmtRWSet) other; 74 if( !field.equals( o.field ) ) return false; 75 if( base == null ) return o.base == null; 76 return Union.hasNonEmptyIntersection( base, o.base ); 77 } else if( other instanceof MethodRWSet ) { 78 MethodRWSet o = (MethodRWSet) other; 79 if( base == null ) return other.getGlobals().contains( field ); 80 return Union.hasNonEmptyIntersection( base, 81 other.getBaseForField( field ) ); 82 } else { 83 return other.hasNonEmptyIntersection( this ); 84 } 85 } 86 87 88 public boolean union( RWSet other ) { 89 throw new RuntimeException ( "Can't do that" ); 90 } 91 92 public boolean addGlobal( SootField global ) { 93 if( field != null || base != null ) 94 throw new RuntimeException ( "Can't do that" ); 95 field = global; 96 return true; 97 } 98 public boolean addFieldRef( PointsToSet otherBase, Object field ) { 99 if( this.field != null || base != null ) 100 throw new RuntimeException ( "Can't do that" ); 101 this.field = field; 102 base = otherBase; 103 return true; 104 } 105 public boolean isEquivTo( RWSet other ) { 106 if( !( other instanceof StmtRWSet ) ) return false; 107 StmtRWSet o = (StmtRWSet) other; 108 if( callsNative != o.callsNative ) return false; 109 if( !field.equals( o.field ) ) return false; 110 if( base instanceof FullObjectSet && o.base instanceof FullObjectSet ) return true; 111 if( base != o.base ) return false; 112 return true; 113 } 114 } 115 | Popular Tags |