1 19 20 package soot.dava.toolkits.base.AST.transformations; 21 22 import soot.*; 23 import java.util.*; 24 import soot.dava.internal.SET.*; 25 import soot.dava.internal.AST.*; 26 import soot.dava.toolkits.base.AST.analysis.*; 27 28 29 45 46 public class ASTCleanerTwo extends DepthFirstAdapter{ 47 48 public ASTCleanerTwo(){ 49 } 50 51 public ASTCleanerTwo(boolean verbose){ 52 super(verbose); 53 } 54 55 56 public void caseASTStatementSequenceNode(ASTStatementSequenceNode node){ 57 } 58 59 66 public void normalRetrieving(ASTNode node){ 67 if(node instanceof ASTSwitchNode){ 68 dealWithSwitchNode((ASTSwitchNode)node); 69 return; 70 } 71 72 Iterator sbit = node.get_SubBodies().iterator(); 74 75 int subBodyNumber=0; 77 while (sbit.hasNext()) { 78 List subBody = (List)sbit.next(); 79 Iterator it = subBody.iterator(); 80 81 int nodeNumber=0; 82 while (it.hasNext()){ 84 ASTNode temp = (ASTNode) it.next(); 85 if(temp instanceof ASTIfElseNode){ 86 IfElseBreaker breaker = new IfElseBreaker(); 87 boolean success=false; 88 if(breaker.isIfElseBreakingPossiblePatternOne((ASTIfElseNode)temp)){ 89 success=true; 90 } 91 else if(breaker.isIfElseBreakingPossiblePatternTwo((ASTIfElseNode)temp)){ 92 success=true; 93 } 94 if(G.v().ASTTransformations_modified) 95 return; 96 if(!success){ 97 } 99 if(success){ 100 List newBody = breaker.createNewBody(subBody,nodeNumber); 101 102 if(newBody!= null){ 103 if(node instanceof ASTIfElseNode){ 104 if(subBodyNumber==0){ 105 List subBodies = node.get_SubBodies(); 107 List ifElseBody = (List)subBodies.get(1); 108 ((ASTIfElseNode)node).replaceBody(newBody,ifElseBody); 109 G.v().ASTTransformations_modified = true; 110 return; 112 } 113 else if(subBodyNumber==1){ 114 List subBodies = node.get_SubBodies(); 116 List ifBody = (List)subBodies.get(0); 117 ((ASTIfElseNode)node).replaceBody(ifBody,newBody); 118 G.v().ASTTransformations_modified = true; 119 return; 121 } 122 else{ 123 throw new RuntimeException ("Please report benchmark to programmer"); 124 } 125 } 126 else{ 127 if(node instanceof ASTMethodNode){ 128 ((ASTMethodNode)node).replaceBody(newBody); 129 G.v().ASTTransformations_modified = true; 130 return; 132 } 133 else if(node instanceof ASTSynchronizedBlockNode){ 134 ((ASTSynchronizedBlockNode)node).replaceBody(newBody); 135 G.v().ASTTransformations_modified = true; 136 return; 138 } 139 else if(node instanceof ASTLabeledBlockNode){ 140 ((ASTLabeledBlockNode)node).replaceBody(newBody); 141 G.v().ASTTransformations_modified = true; 142 return; 144 } 145 else if(node instanceof ASTUnconditionalLoopNode){ 146 ((ASTUnconditionalLoopNode)node).replaceBody(newBody); 147 G.v().ASTTransformations_modified = true; 148 return; 150 } 151 else if(node instanceof ASTIfNode){ 152 ((ASTIfNode)node).replaceBody(newBody); 153 G.v().ASTTransformations_modified = true; 154 return; 156 } 157 else if(node instanceof ASTWhileNode){ 158 ((ASTWhileNode)node).replaceBody(newBody); 159 G.v().ASTTransformations_modified = true; 160 return; 162 } 163 else if(node instanceof ASTDoWhileNode){ 164 ((ASTDoWhileNode)node).replaceBody(newBody); 165 G.v().ASTTransformations_modified = true; 166 return; 168 } 169 else if(node instanceof ASTForLoopNode){ 170 ((ASTForLoopNode)node).replaceBody(newBody); 171 G.v().ASTTransformations_modified = true; 172 return; 174 } 175 else { 176 throw new RuntimeException ("Please report benchmark to programmer"); 177 } 178 } 179 } } 181 } 182 temp.apply(this); 183 nodeNumber++; 184 } 185 subBodyNumber++; 186 } } 188 189 public void caseASTTryNode(ASTTryNode node){ 190 inASTTryNode(node); 191 192 List tryBody = node.get_TryBody(); 194 Iterator it = tryBody.iterator(); 195 196 int nodeNumber=0; 197 while (it.hasNext()){ 199 ASTNode temp = (ASTNode) it.next(); 200 if(temp instanceof ASTIfElseNode){ 201 202 IfElseBreaker breaker = new IfElseBreaker(); 203 boolean success=false; 204 if(breaker.isIfElseBreakingPossiblePatternOne((ASTIfElseNode)temp)){ 205 success=true; 206 } 207 else if(breaker.isIfElseBreakingPossiblePatternTwo((ASTIfElseNode)temp)){ 208 success=true; 209 } 210 if(G.v().ASTTransformations_modified) 211 return; 212 if(success){ 213 List newBody = breaker.createNewBody(tryBody,nodeNumber); 214 215 if(newBody!= null){ 216 node.replaceTryBody(newBody); 218 G.v().ASTTransformations_modified = true; 219 return; 221 } } 223 } 224 temp.apply(this); 225 nodeNumber++; 226 } 227 228 229 230 231 Map exceptionMap = node.get_ExceptionMap(); 232 Map paramMap = node.get_ParamMap(); 233 List catchList = node.get_CatchList(); 238 Iterator itBody=null; 239 it = catchList.iterator(); 240 while (it.hasNext()) { 241 ASTTryNode.container catchBody = (ASTTryNode.container)it.next(); 242 243 SootClass sootClass = ((SootClass)exceptionMap.get(catchBody)); 244 Type type = sootClass.getType(); 245 246 caseType(type); 248 249 Local local = (Local)paramMap.get(catchBody); 251 decideCaseExprOrRef(local); 252 253 List body = (List)catchBody.o; 255 itBody = body.iterator(); 256 257 nodeNumber=0; 258 while (itBody.hasNext()){ 260 ASTNode temp = (ASTNode) itBody.next(); 261 if(temp instanceof ASTIfElseNode){ 262 IfElseBreaker breaker = new IfElseBreaker(); 263 boolean success=false; 264 if(breaker.isIfElseBreakingPossiblePatternOne((ASTIfElseNode)temp)){ 265 success=true; 266 } 267 else if(breaker.isIfElseBreakingPossiblePatternTwo((ASTIfElseNode)temp)){ 268 success=true; 269 } 270 if(G.v().ASTTransformations_modified) 271 return; 272 if(success){ 273 List newBody = breaker.createNewBody(body,nodeNumber); 274 275 if(newBody!= null){ 276 catchBody.replaceBody(newBody); 278 G.v().ASTTransformations_modified = true; 279 return; 281 } } 283 } 284 temp.apply(this); 285 nodeNumber++; 286 } 287 } 288 289 outASTTryNode(node); 290 } 291 292 293 private void dealWithSwitchNode(ASTSwitchNode node){ 294 296 List indexList = node.getIndexList(); 297 Map index2BodyList = node.getIndex2BodyList(); 298 299 Iterator it = indexList.iterator(); 300 while (it.hasNext()) { Object currentIndex = it.next(); 302 List body = (List) index2BodyList.get( currentIndex); 303 304 if (body != null){ 305 307 Iterator itBody = body.iterator(); 308 int nodeNumber=0; 309 while (itBody.hasNext()){ 311 ASTNode temp = (ASTNode) itBody.next(); 312 if(temp instanceof ASTIfElseNode){ 313 IfElseBreaker breaker = new IfElseBreaker(); 314 boolean success=false; 315 if(breaker.isIfElseBreakingPossiblePatternOne((ASTIfElseNode)temp)){ 316 success=true; 317 } 318 else if(breaker.isIfElseBreakingPossiblePatternTwo((ASTIfElseNode)temp)){ 319 success=true; 320 } 321 if(G.v().ASTTransformations_modified) 322 return; 323 if(success){ 324 List newBody = breaker.createNewBody(body,nodeNumber); 325 326 if(newBody!= null){ 327 index2BodyList.put(currentIndex,newBody); 329 node.replaceIndex2BodyList(index2BodyList); 331 G.v().ASTTransformations_modified = true; 332 return; 334 } } 336 } 337 temp.apply(this); 338 nodeNumber++; 339 } 340 } 341 } 342 } 343 } 344 | Popular Tags |