Search in sources :

Example 1 with DIncrementStmt

use of soot.dava.internal.javaRep.DIncrementStmt in project soot by Sable.

the class DecrementIncrementStmtCreation method caseASTStatementSequenceNode.

public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) {
    for (AugmentedStmt as : node.getStatements()) {
        // System.out.println(temp);
        Stmt s = as.get_Stmt();
        if (!(s instanceof DefinitionStmt))
            continue;
        // check if its i= i+1
        Value left = ((DefinitionStmt) s).getLeftOp();
        Value right = ((DefinitionStmt) s).getRightOp();
        if (right instanceof SubExpr) {
            Value op1 = ((SubExpr) right).getOp1();
            Value op2 = ((SubExpr) right).getOp2();
            if (left.toString().compareTo(op1.toString()) != 0) {
                // not the same
                continue;
            }
            // check if op2 is a constant with value 1 or -1
            if (op2 instanceof IntConstant) {
                if (((IntConstant) op2).value == 1) {
                    // this is i = i-1
                    DDecrementStmt newStmt = new DDecrementStmt(left, right);
                    as.set_Stmt(newStmt);
                } else if (((IntConstant) op2).value == -1) {
                    // this is i = i+1
                    DIncrementStmt newStmt = new DIncrementStmt(left, right);
                    as.set_Stmt(newStmt);
                }
            }
        } else if (right instanceof AddExpr) {
            Value op1 = ((AddExpr) right).getOp1();
            Value op2 = ((AddExpr) right).getOp2();
            if (left.toString().compareTo(op1.toString()) != 0) {
                continue;
            }
            // check if op2 is a constant with value 1 or -1
            if (op2 instanceof IntConstant) {
                if (((IntConstant) op2).value == 1) {
                    // this is i = i+1
                    DIncrementStmt newStmt = new DIncrementStmt(left, right);
                    as.set_Stmt(newStmt);
                } else if (((IntConstant) op2).value == -1) {
                    // this is i = i-1
                    DDecrementStmt newStmt = new DDecrementStmt(left, right);
                    as.set_Stmt(newStmt);
                }
            }
        }
    // right expr was addExpr
    }
// going through statements
}
Also used : DDecrementStmt(soot.dava.internal.javaRep.DDecrementStmt) DIncrementStmt(soot.dava.internal.javaRep.DIncrementStmt) SubExpr(soot.jimple.SubExpr) Value(soot.Value) IntConstant(soot.jimple.IntConstant) AddExpr(soot.jimple.AddExpr) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) DefinitionStmt(soot.jimple.DefinitionStmt) DDecrementStmt(soot.dava.internal.javaRep.DDecrementStmt) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) DIncrementStmt(soot.dava.internal.javaRep.DIncrementStmt) DefinitionStmt(soot.jimple.DefinitionStmt) Stmt(soot.jimple.Stmt)

Aggregations

Value (soot.Value)1 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)1 DDecrementStmt (soot.dava.internal.javaRep.DDecrementStmt)1 DIncrementStmt (soot.dava.internal.javaRep.DIncrementStmt)1 AddExpr (soot.jimple.AddExpr)1 DefinitionStmt (soot.jimple.DefinitionStmt)1 IntConstant (soot.jimple.IntConstant)1 Stmt (soot.jimple.Stmt)1 SubExpr (soot.jimple.SubExpr)1