1 19 20 25 26 27 package soot.jimple.toolkits.scalar; 28 29 import soot.*; 30 import soot.util.*; 31 import soot.toolkits.scalar.*; 32 import java.util.*; 33 34 39 public class ToppedSet extends AbstractFlowSet 40 { 41 FlowSet underlyingSet; 42 boolean isTop; 43 44 public void setTop(boolean top) { isTop = top; } 45 public boolean isTop() { return isTop; } 46 47 public ToppedSet(FlowSet under) 48 { 49 underlyingSet = under; 50 } 51 52 public Object clone() 53 { 54 ToppedSet newSet = new ToppedSet((FlowSet)underlyingSet.clone()); 55 newSet.setTop(isTop()); 56 return newSet; 57 } 58 59 public void copy(FlowSet d) 60 { 61 ToppedSet dest = (ToppedSet)d; 62 if (!isTop()) 63 { 64 underlyingSet.copy(dest.underlyingSet); 65 dest.setTop(false); 66 return; 67 } 68 69 dest.setTop(true); 70 } 71 72 public Object emptySet() 73 { 74 return new ToppedSet((FlowSet)underlyingSet.emptySet()); 75 } 76 77 public void clear() 78 { 79 isTop = false; 80 underlyingSet.clear(); 81 } 82 83 public void union(FlowSet o, FlowSet d) 84 { 85 if (o instanceof ToppedSet && 86 d instanceof ToppedSet) { 87 ToppedSet other = (ToppedSet)o; 88 ToppedSet dest = (ToppedSet)d; 89 90 if (isTop()) 91 { 92 copy(dest); 93 return; 94 } 95 96 if (other.isTop()) 97 other.copy(dest); 98 else 99 { 100 underlyingSet.union(other.underlyingSet, 101 dest.underlyingSet); 102 dest.setTop(false); 103 } 104 } else 105 super.union(o, d); 106 } 107 108 public void intersection(FlowSet o, FlowSet d) 109 { 110 if (isTop()) 111 { 112 o.copy(d); 113 return; 114 } 115 116 ToppedSet other = (ToppedSet)o, dest = (ToppedSet)d; 117 118 if (other.isTop()) 119 { 120 copy(dest); 121 return; 122 } 123 else 124 { 125 underlyingSet.intersection(other.underlyingSet, 126 dest.underlyingSet); 127 dest.setTop(false); 128 } 129 } 130 131 public void difference(FlowSet o, FlowSet d) 132 { 133 ToppedSet other = (ToppedSet)o, dest = (ToppedSet)d; 134 135 if (isTop()) { 136 if (other.isTop()) 137 dest.clear(); 138 else if (other.underlyingSet instanceof BoundedFlowSet) 139 ((BoundedFlowSet)other.underlyingSet).complement(dest); 140 else 141 throw new RuntimeException ("can't take difference!"); 142 } else { 143 if (other.isTop()) 144 dest.clear(); 145 else 146 underlyingSet.difference(other.underlyingSet, dest.underlyingSet); 147 } 148 163 } 164 165 public boolean isEmpty() 166 { 167 if (isTop()) return false; 168 return underlyingSet.isEmpty(); 169 } 170 171 public int size() 172 { 173 if (isTop()) throw new UnsupportedOperationException (); 174 return underlyingSet.size(); 175 } 176 177 public void add(Object obj) 178 { 179 if (isTop()) return; 180 underlyingSet.add(obj); 181 } 182 183 public void remove(Object obj) 184 { 185 if (isTop()) return; 186 underlyingSet.remove(obj); 187 } 188 189 public boolean contains(Object obj) 190 { 191 if (isTop()) return true; 192 return underlyingSet.contains(obj); 193 } 194 195 public List toList() 196 { 197 if (isTop()) throw new UnsupportedOperationException (); 198 return underlyingSet.toList(); 199 } 200 201 public boolean equals(Object o) 202 { 203 if (!(o instanceof ToppedSet)) 204 return false; 205 206 ToppedSet other = (ToppedSet)o; 207 if (other.isTop() != isTop()) 208 return false; 209 return underlyingSet.equals(other.underlyingSet); 210 } 211 212 public String toString() 213 { 214 if (isTop()) return "{TOP}"; else return underlyingSet.toString(); 215 } 216 } 217 218 | Popular Tags |