1 19 20 package soot.dava.toolkits.base.AST.transformations; 21 22 import soot.*; 23 import soot.jimple.*; 24 import java.util.*; 25 import soot.dava.internal.SET.*; 26 import soot.dava.internal.AST.*; 27 import soot.dava.internal.javaRep.*; 28 import soot.dava.internal.asg.*; 29 import soot.dava.toolkits.base.AST.analysis.*; 30 31 32 50 51 public class AndAggregator extends DepthFirstAdapter{ 52 53 public AndAggregator(){ 54 } 55 public AndAggregator(boolean verbose){ 56 super(verbose); 57 } 58 59 public void caseASTStatementSequenceNode(ASTStatementSequenceNode node){ 60 } 61 62 public void outASTIfNode(ASTIfNode node){ 63 List bodies = node.get_SubBodies(); 64 if(bodies.size()==1){ List body = (List)bodies.get(0); 66 if(body.size()==1){ ASTNode bodyNode = (ASTNode)body.get(0); 69 if(bodyNode instanceof ASTIfNode){ 70 75 76 ASTCondition outerCond = node.get_Condition(); 77 ASTCondition innerCond = ((ASTIfNode)bodyNode).get_Condition(); 78 79 SETNodeLabel outerLabel = ((ASTIfNode)node).get_Label(); 80 SETNodeLabel innerLabel = ((ASTIfNode)bodyNode).get_Label(); 81 82 SETNodeLabel newLabel = null; 83 if(outerLabel.toString()==null && innerLabel.toString()==null){ 84 newLabel = outerLabel; 85 } 86 else if(outerLabel.toString()!=null && innerLabel.toString()==null){ 87 newLabel = outerLabel; 88 } 89 else if(outerLabel.toString()==null && innerLabel.toString()!=null){ 90 newLabel = innerLabel; 91 } 92 else if(outerLabel.toString()!=null && innerLabel.toString()!=null){ 93 newLabel=outerLabel; 94 changeUses(outerLabel.toString(),innerLabel.toString(),bodyNode); 97 } 98 99 ASTCondition newCond = new ASTAndCondition(outerCond,innerCond); 101 102 List newBodyList = ((ASTIfNode)bodyNode).get_SubBodies(); 104 105 if(newBodyList.size()==1){ List newBody = (List)newBodyList.get(0); 108 node.replace(newLabel,newCond,newBody); 109 G.v().ASTTransformations_modified=true; 111 } 112 } 113 else{ } 115 } 116 else{ } 118 } 119 } 120 121 private void changeUses(String to, String from, ASTNode node){ 122 List subBodies = node.get_SubBodies(); 124 Iterator it = subBodies.iterator(); 125 while(it.hasNext()){ 126 if (node instanceof ASTStatementSequenceNode){ 128 130 ASTStatementSequenceNode stmtSeq = (ASTStatementSequenceNode)node; 131 List statements = stmtSeq.getStatements(); 132 Iterator stmtIt = statements.iterator(); 133 while(stmtIt.hasNext()){ 134 AugmentedStmt as = (AugmentedStmt)stmtIt.next(); 135 Stmt s = as.get_Stmt(); 136 137 138 if(s instanceof DAbruptStmt){ 139 DAbruptStmt abStmt = (DAbruptStmt)s; 140 if(abStmt.is_Break() || abStmt.is_Continue()){ 141 SETNodeLabel label = abStmt.getLabel(); 142 String labelBroken = label.toString(); 143 144 if(labelBroken != null){ if(labelBroken.compareTo(from)==0){ 146 label.set_Name(to); 148 } 149 } 150 } 151 } 152 } 153 } 154 else{ 155 List subBodyNodes=null; 157 158 if(node instanceof ASTTryNode){ 159 ASTTryNode.container subBody = (ASTTryNode.container)it.next(); 160 subBodyNodes=(List)subBody.o; 161 } 162 else{ 163 subBodyNodes = (List)it.next(); 164 } 165 Iterator nodesIt = subBodyNodes.iterator(); 166 while(nodesIt.hasNext()){ 167 changeUses(to,from,(ASTNode)nodesIt.next()); 168 } 169 } 170 171 } 173 } 174 175 } | Popular Tags |