1 19 20 package soot.dava.toolkits.base.AST.transformations; 21 22 import soot.*; 23 import java.util.*; 24 import soot.jimple.*; 25 import soot.dava.internal.SET.*; 26 import soot.dava.internal.AST.*; 27 import soot.dava.internal.asg.*; 28 import soot.dava.internal.javaRep.*; 29 import soot.dava.toolkits.base.AST.analysis.*; 30 31 32 66 public class OrAggregatorTwo extends DepthFirstAdapter{ 67 68 69 70 public OrAggregatorTwo(){ 71 DEBUG=false; 72 } 73 public OrAggregatorTwo(boolean verbose){ 74 super(verbose); 75 DEBUG=false; 76 } 77 78 public void caseASTStatementSequenceNode(ASTStatementSequenceNode node){ 79 } 80 81 public void outASTIfElseNode(ASTIfElseNode node){ 82 84 List ifBody = node.getIfBody(); 85 List elseBody = node.getElseBody(); 86 87 List innerIfBody=checkElseHasOnlyIf(elseBody); 88 89 if(innerIfBody==null){ 90 92 93 matchPatternTwo(node); 95 96 return; 97 } 98 102 if(ifBody.toString().compareTo(innerIfBody.toString())!=0){ 103 matchPatternTwo(node); 104 return; 105 } 106 107 ASTCondition leftCond = node.get_Condition(); 108 ASTCondition rightCond= getRightCond(elseBody); 109 ASTCondition newCond = new ASTOrCondition(leftCond,rightCond); 110 111 119 node.set_Condition(newCond); 121 122 125 node.replaceElseBody(new ArrayList()); 126 127 128 G.v().ASTTransformations_modified = true; 129 } 130 131 132 public ASTCondition getRightCond(List elseBody){ 133 ASTIfNode innerIfNode = (ASTIfNode)elseBody.get(0); 136 return innerIfNode.get_Condition(); 137 } 138 139 140 141 public List checkElseHasOnlyIf(List elseBody){ 142 if(elseBody.size()!=1){ 143 return null; 145 } 146 ASTNode temp = (ASTNode)elseBody.get(0); 148 if(!(temp instanceof ASTIfNode)){ 149 return null; 151 } 152 ASTIfNode innerIfNode = (ASTIfNode)temp; 153 List innerIfBody = innerIfNode.getIfBody(); 154 return innerIfBody; 155 } 156 157 158 159 160 public void matchPatternTwo(ASTIfElseNode node){ 161 debug("OrAggregatorTwo","matchPatternTwo","Did not match patternOne...trying patternTwo"); 162 List ifBody = node.getIfBody(); 163 if(ifBody.size()!=1){ 164 return; 166 } 167 ASTNode onlyNode=(ASTNode)ifBody.get(0); 168 if(!(onlyNode instanceof ASTStatementSequenceNode)){ 169 return; 171 } 172 ASTStatementSequenceNode stmtNode=(ASTStatementSequenceNode)onlyNode; 173 List statements = stmtNode.getStatements(); 174 if(statements.size()!=1){ 175 return; 177 } 178 179 AugmentedStmt as = (AugmentedStmt)statements.get(0); 181 Stmt stmt = as.get_Stmt(); 182 183 if(!(stmt instanceof DAbruptStmt)){ 184 return; 186 } 187 DAbruptStmt abStmt = (DAbruptStmt)stmt; 188 if(!(abStmt.is_Break() || abStmt.is_Continue())){ 189 return; 191 } 192 193 ASTCondition cond = node.get_Condition(); 196 cond.flip(); 197 198 List elseBody = node.getElseBody(); 199 SETNodeLabel label = node.get_Label(); 200 201 node.replace(label,cond,elseBody,ifBody); 202 debug("","","REVERSED CONDITIONS AND BODIES"); 203 debug("","","elseBody is"+elseBody); 204 debug("","","ifBody is"+ifBody); 205 206 G.v().ASTIfElseFlipped = true; 207 } 208 209 210 } | Popular Tags |