1 19 20 package soot.jimple.spark.sets; 21 import soot.jimple.spark.*; 22 import soot.jimple.spark.pag.*; 23 import soot.*; 24 import java.util.*; 25 26 29 public abstract class PointsToSetInternal implements PointsToSet { 30 32 public boolean addAll( PointsToSetInternal other, 33 final PointsToSetInternal exclude ) { 34 if( other instanceof DoublePointsToSet ) { 35 return addAll( other.getNewSet(), exclude ) 36 | addAll( other.getOldSet(), exclude ); 37 } else if( other instanceof EmptyPointsToSet ) { 38 return false; 39 } else if( exclude instanceof EmptyPointsToSet ) { 40 return addAll( other, null ); 41 } 42 if( !G.v().PointsToSetInternal_warnedAlready ) { 43 G.v().out.println( "Warning: using default implementation of addAll. You should implement a faster specialized implementation." ); 44 G.v().out.println( "this is of type "+getClass().getName() ); 45 G.v().out.println( "other is of type "+other.getClass().getName() ); 46 if( exclude == null ) { 47 G.v().out.println( "exclude is null" ); 48 } else { 49 G.v().out.println( "exclude is of type "+ 50 exclude.getClass().getName() ); 51 } 52 G.v().PointsToSetInternal_warnedAlready = true; 53 } 54 return other.forall( new P2SetVisitor() { 55 public final void visit( Node n ) { 56 if( exclude == null || !exclude.contains( n ) ) 57 returnValue = add( n ) | returnValue; 58 } 59 } ); 60 } 61 62 public abstract boolean forall( P2SetVisitor v ); 63 64 public abstract boolean add( Node n ); 65 66 public PointsToSetInternal getNewSet() { return this; } 67 68 public PointsToSetInternal getOldSet() { return EmptyPointsToSet.v(); } 69 70 public void flushNew() {} 71 72 public void unFlushNew() {} 73 74 public void mergeWith( PointsToSetInternal other ) 75 { addAll( other, null ); } 76 77 public abstract boolean contains( Node n ); 78 79 public PointsToSetInternal( Type type ) { this.type = type; } 80 81 public boolean hasNonEmptyIntersection( PointsToSet other ) { 82 final PointsToSetInternal o = (PointsToSetInternal) other; 83 return forall( new P2SetVisitor() { 84 public void visit( Node n ) { 85 if( o.contains( n ) ) returnValue = true; 86 } 87 } ); 88 } 89 public Set possibleTypes() { 90 final HashSet ret = new HashSet(); 91 forall( new P2SetVisitor() { 92 public void visit( Node n ) { 93 Type t = n.getType(); 94 if( t instanceof RefType ) { 95 RefType rt = (RefType) t; 96 if( rt.getSootClass().isAbstract() ) return; 97 } 98 ret.add( t ); 99 } 100 } ); 101 return ret; 102 } 103 public Type getType() { 104 return type; 105 } 106 public void setType( Type type ) { 107 this.type = type; 108 } 109 public int size() { 110 final int[] ret = new int[1]; 111 forall( new P2SetVisitor() { 112 public void visit( Node n ) { 113 ret[0]++; 114 } 115 } ); 116 return ret[0]; 117 } 118 public String toString() { 119 final StringBuffer ret = new StringBuffer (); 120 this.forall( new P2SetVisitor() { 121 public final void visit( Node n ) { 122 ret.append( ""+n+"," ); 123 }} ); 124 return ret.toString(); 125 } 126 127 public Set possibleStringConstants() { 128 final HashSet ret = new HashSet(); 129 return this.forall( new P2SetVisitor() { 130 public final void visit( Node n ) { 131 if( n instanceof StringConstantNode ) { 132 ret.add( ((StringConstantNode)n).getString() ); 133 } else { 134 returnValue = true; 135 } 136 }} ) ? null : ret; 137 } 138 public Set possibleClassConstants() { 139 final HashSet ret = new HashSet(); 140 return this.forall( new P2SetVisitor() { 141 public final void visit( Node n ) { 142 if( n instanceof ClassConstantNode ) { 143 ret.add( ((ClassConstantNode)n).getClassConstant() ); 144 } else { 145 returnValue = true; 146 } 147 }} ) ? null : ret; 148 } 149 150 151 152 153 protected Type type; 154 } 155 156 | Popular Tags |