1 19 20 package soot.dava.toolkits.base.AST.transformations; 21 22 import java.util.*; 23 import soot.*; 24 import soot.jimple.*; 25 import soot.dava.*; 26 import soot.dava.internal.asg.*; 27 import soot.dava.internal.javaRep.*; 28 import soot.dava.internal.AST.*; 29 import soot.dava.toolkits.base.AST.analysis.*; 30 31 35 public class DecrementIncrementStmtCreation extends DepthFirstAdapter { 36 37 public DecrementIncrementStmtCreation() { 38 } 39 40 public DecrementIncrementStmtCreation(boolean verbose) { 41 super(verbose); 42 } 43 44 public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) { 45 List statements = node.getStatements(); 46 Iterator stmtIt = statements.iterator(); 47 48 while (stmtIt.hasNext()) { 49 Object temp = stmtIt.next(); 50 AugmentedStmt as = (AugmentedStmt)temp; 52 Stmt s = as.get_Stmt(); 53 if (!( s instanceof DefinitionStmt)) 54 continue; 55 56 Value left = ((DefinitionStmt) s).getLeftOp(); 58 Value right = ((DefinitionStmt) s).getRightOp(); 59 60 61 if (right instanceof SubExpr) { 62 Value op1 = ((SubExpr) right).getOp1(); 63 Value op2 = ((SubExpr) right).getOp2(); 64 if (left.toString().compareTo(op1.toString()) != 0) { 65 continue; 67 } 68 70 if (op2 instanceof IntConstant) { 72 if (((IntConstant) op2).value == 1) { 73 DDecrementStmt newStmt = new DDecrementStmt(left, right); 75 as.set_Stmt(newStmt); 76 } else if (((IntConstant) op2).value == -1) { 77 DIncrementStmt newStmt = new DIncrementStmt(left, right); 79 as.set_Stmt(newStmt); 80 } 81 } 82 83 } 84 else if (right instanceof AddExpr) { 85 Value op1 = ((AddExpr) right).getOp1(); 86 Value op2 = ((AddExpr) right).getOp2(); 87 if (left.toString().compareTo(op1.toString()) != 0) { 88 continue; 89 } 90 if (op2 instanceof IntConstant) { 92 if (((IntConstant) op2).value == 1) { 93 DIncrementStmt newStmt = new DIncrementStmt(left, right); 95 as.set_Stmt(newStmt); 96 } else if (((IntConstant) op2).value == -1) { 97 DDecrementStmt newStmt = new DDecrementStmt(left, right); 99 as.set_Stmt(newStmt); 100 } 101 } 102 } } } 105 } 106 107 | Popular Tags |