| 1 19 20 package soot.jimple.spark.sets; 21 import soot.jimple.spark.*; 22 import soot.jimple.spark.pag.Node; 23 import soot.jimple.spark.pag.PAG; 24 import java.util.*; 25 import soot.*; 26 27 32 public class DoublePointsToSet extends PointsToSetInternal { 33 public DoublePointsToSet( Type type, PAG pag ) { 34 super( type ); 35 newSet = G.v().newSetFactory.newSet( type, pag ); 36 oldSet = G.v().oldSetFactory.newSet( type, pag ); 37 this.pag = pag; 38 } 39 40 public boolean isEmpty() { 41 return oldSet.isEmpty() && newSet.isEmpty(); 42 } 43 44 public boolean hasNonEmptyIntersection( PointsToSet other ) { 45 return oldSet.hasNonEmptyIntersection(other) 46 || newSet.hasNonEmptyIntersection(other); 47 } 48 49 public Set possibleTypes() { 50 Set ret = new HashSet(); 51 ret.addAll(oldSet.possibleTypes()); 52 ret.addAll(newSet.possibleTypes()); 53 return ret; 54 } 55 57 public boolean addAll( PointsToSetInternal other, 58 PointsToSetInternal exclude ) { 59 if( exclude != null ) { 60 throw new RuntimeException ( "NYI" ); 61 } 62 return newSet.addAll( other, oldSet ); 63 } 64 65 public boolean forall( P2SetVisitor v ) { 66 oldSet.forall( v ); 67 newSet.forall( v ); 68 return v.getReturnValue(); 69 } 70 71 public boolean add( Node n ) { 72 if( oldSet.contains( n ) ) return false; 73 return newSet.add( n ); 74 } 75 76 public PointsToSetInternal getOldSet() { return oldSet; } 77 78 public PointsToSetInternal getNewSet() { return newSet; } 79 80 public void flushNew() { 81 oldSet.addAll( newSet, null ); 82 newSet = G.v().newSetFactory.newSet( type, pag ); 83 } 84 85 public void unFlushNew() { 86 newSet.addAll( oldSet, null ); 87 oldSet = G.v().oldSetFactory.newSet( type, pag ); 88 } 89 90 public void mergeWith( PointsToSetInternal other ) { 91 if( !( other instanceof DoublePointsToSet ) ) { 92 throw new RuntimeException ( "NYI" ); 93 } 94 final DoublePointsToSet o = (DoublePointsToSet) other; 95 if( other.type != null && !( other.type.equals( type ) ) ) { 96 throw new RuntimeException ( "different types "+type+" and "+other.type ); 97 } 98 if( other.type == null && type != null ) { 99 throw new RuntimeException ( "different types "+type+" and "+other.type ); 100 } 101 final PointsToSetInternal newNewSet = G.v().newSetFactory.newSet( type, pag ); 102 final PointsToSetInternal newOldSet = G.v().oldSetFactory.newSet( type, pag ); 103 oldSet.forall( new P2SetVisitor() { 104 public final void visit( Node n ) { 105 if( o.oldSet.contains( n ) ) newOldSet.add( n ); 106 }} ); 107 newNewSet.addAll( this, newOldSet ); 108 newNewSet.addAll( o, newOldSet ); 109 newSet = newNewSet; 110 oldSet = newOldSet; 111 } 112 113 public boolean contains( Node n ) { 114 return oldSet.contains( n ) || newSet.contains( n ); 115 } 116 117 public static P2SetFactory getFactory( P2SetFactory newFactory, 118 P2SetFactory oldFactory ) { 119 G.v().newSetFactory = newFactory; 120 G.v().oldSetFactory = oldFactory; 121 return new P2SetFactory() { 122 public PointsToSetInternal newSet( Type type, PAG pag ) { 123 return new DoublePointsToSet( type, pag ); 124 } 125 }; 126 } 127 128 129 130 131 private PAG pag; 132 protected PointsToSetInternal newSet; 133 protected PointsToSetInternal oldSet; 134 } 135 136 | Popular Tags |