1 19 20 23 24 31 32 package soot.dava.toolkits.base.AST.structuredAnalysis; 33 34 import soot.*; 35 import java.util.*; 36 import soot.jimple.*; 37 import soot.dava.internal.javaRep.*; 38 import soot.dava.internal.AST.*; 39 40 66 67 public class ReachingCopies extends StructuredAnalysis{ 68 69 70 71 public class LocalPair{ 72 private Local leftLocal; 73 private Local rightLocal; 74 75 public LocalPair(Local left, Local right){ 76 leftLocal=left; 77 rightLocal=right; 78 } 79 80 81 public Local getLeftLocal(){ 82 return leftLocal; 83 } 84 85 public Local getRightLocal(){ 86 return rightLocal; 87 } 88 89 public boolean equals(Object other){ 90 if(other instanceof LocalPair){ 91 if(this.leftLocal.toString().equals(((LocalPair)other).getLeftLocal().toString())){ 92 if(this.rightLocal.toString().equals(((LocalPair)other).getRightLocal().toString())){ 93 return true; 94 } 95 } 96 } 97 return false; 98 } 99 100 104 public boolean contains(Local local){ 105 if(leftLocal.toString().equals(local.toString()) || rightLocal.toString().equals(local.toString())){ 106 return true; 107 } 108 return false; 109 } 110 111 public String toString(){ 112 StringBuffer b = new StringBuffer (); 113 b.append("<"+leftLocal.toString()+","+rightLocal.toString()+">"); 114 return b.toString(); 115 } 116 117 } 118 119 120 121 122 123 124 125 126 public ReachingCopies(Object analyze){ 127 super(); 128 DavaFlowSet temp = (DavaFlowSet)process(analyze,new DavaFlowSet()); 130 } 131 132 133 public void setMergeType(){ 134 MERGETYPE=INTERSECTION; 135 } 136 137 public Object newInitialFlow(){ 138 return new DavaFlowSet(); 139 } 140 141 public Object cloneFlowSet(Object flowSet){ 142 if(flowSet instanceof DavaFlowSet){ 143 return ((DavaFlowSet)flowSet).clone(); 144 } 145 else 146 throw new RuntimeException ("cloneFlowSet not implemented for other flowSet types"); 147 } 148 149 150 151 152 156 public Object processUnaryBinaryCondition(ASTUnaryBinaryCondition cond, Object input){ 157 if(!(input instanceof DavaFlowSet)){ 158 throw new RuntimeException ("processCondition is not implemented for other flowSet types"); 159 } 160 return input; 161 } 162 163 164 168 public Object processSynchronizedLocal(Local local,Object input){ 169 if(!(input instanceof DavaFlowSet)){ 170 throw new RuntimeException ("processCondition is not implemented for other flowSet types"); 171 } 172 return input; 173 } 174 175 176 177 181 public Object processSwitchKey(Value key,Object input){ 182 if(!(input instanceof DavaFlowSet)){ 183 throw new RuntimeException ("processCondition is not implemented for other flowSet types"); 184 } 185 return input; 186 } 187 188 189 190 191 192 193 194 195 196 197 201 public Object processStatement(Stmt s, Object input){ 202 if(!(input instanceof DavaFlowSet)){ 203 throw new RuntimeException ("processStatement is not implemented for other flowSet types"); 204 } 205 DavaFlowSet inSet = (DavaFlowSet)input; 206 207 210 if(inSet == NOPATH){ 211 return inSet; 212 } 213 214 if(s instanceof DefinitionStmt){ 215 DavaFlowSet toReturn = (DavaFlowSet)cloneFlowSet(inSet); 216 Value leftOp = ((DefinitionStmt)s).getLeftOp(); 219 Value rightOp = ((DefinitionStmt)s).getRightOp(); 220 221 222 if(leftOp instanceof Local){ 223 kill(toReturn,(Local)leftOp); 225 } 227 228 if(leftOp instanceof Local && rightOp instanceof Local){ 229 gen(toReturn,(Local)leftOp,(Local)rightOp); 232 } 233 return toReturn; 234 } 235 else{ 236 239 return input; 240 } 241 } 242 243 244 public void gen(DavaFlowSet in, Local left, Local right){ 245 LocalPair localp = new LocalPair(left,right); 248 in.add(localp); 249 } 250 251 public void kill(DavaFlowSet in, Local redefined){ 252 List list = in.toList(); 254 Iterator listIt = list.iterator(); 255 while(listIt.hasNext()){ 256 LocalPair tempPair = (LocalPair)listIt.next(); 257 if(tempPair.contains(redefined)){ 258 in.remove(tempPair); 260 } 261 } 262 } 263 264 265 266 270 public DavaFlowSet getReachingCopies(Object node){ 271 Object beforeSet=getBeforeSet(node); 273 274 if(beforeSet == null){ 275 throw new RuntimeException ("Could not get reaching copies of node/stmt"); 276 } 277 if(!(beforeSet instanceof DavaFlowSet)){ 278 throw new RuntimeException ("Reaching def set is not a Dava FlowSet"); 279 } 280 281 DavaFlowSet beforeSetReaching = (DavaFlowSet)beforeSet; 282 284 288 289 return beforeSetReaching; 290 } 291 292 } | Popular Tags |