Search in sources :

Example 1 with ImmediateBox

use of soot.jimple.internal.ImmediateBox in project soot by Sable.

the class ShortcutIfGenerator method inASTStatementSequenceNode.

public void inASTStatementSequenceNode(ASTStatementSequenceNode node) {
    for (AugmentedStmt as : node.getStatements()) {
        Stmt s = as.get_Stmt();
        if (!(s instanceof DefinitionStmt))
            continue;
        DefinitionStmt ds = (DefinitionStmt) s;
        ValueBox rightBox = ds.getRightOpBox();
        Value right = rightBox.getValue();
        /*
			 * Going to match int i = (int) z where z is a boolean
			 * or int i= z i.e. without the cast
			 */
        // right type should contain the expected type on the left
        // in the case of the cast this is the cast type else just get the left type
        Type rightType = null;
        ValueBox OpBox = null;
        if (right instanceof CastExpr) {
            rightType = ((CastExpr) right).getCastType();
            OpBox = ((CastExpr) right).getOpBox();
        } else {
            rightType = ds.getLeftOp().getType();
            OpBox = rightBox;
        }
        if (!(rightType instanceof IntType)) {
            continue;
        }
        Value Op = OpBox.getValue();
        if (!(Op.getType() instanceof BooleanType)) {
            continue;
        }
        // ready for the switch
        ImmediateBox trueBox = new ImmediateBox(IntConstant.v(1));
        ImmediateBox falseBox = new ImmediateBox(IntConstant.v(0));
        DShortcutIf shortcut = new DShortcutIf(OpBox, trueBox, falseBox);
        if (DEBUG)
            System.out.println("created: " + shortcut);
        rightBox.setValue(shortcut);
    }
}
Also used : IntType(soot.IntType) Type(soot.Type) BooleanType(soot.BooleanType) ImmediateBox(soot.jimple.internal.ImmediateBox) ValueBox(soot.ValueBox) DShortcutIf(soot.dava.internal.javaRep.DShortcutIf) Value(soot.Value) CastExpr(soot.jimple.CastExpr) BooleanType(soot.BooleanType) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) DefinitionStmt(soot.jimple.DefinitionStmt) Stmt(soot.jimple.Stmt) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) DefinitionStmt(soot.jimple.DefinitionStmt) IntType(soot.IntType)

Aggregations

BooleanType (soot.BooleanType)1 IntType (soot.IntType)1 Type (soot.Type)1 Value (soot.Value)1 ValueBox (soot.ValueBox)1 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)1 DShortcutIf (soot.dava.internal.javaRep.DShortcutIf)1 CastExpr (soot.jimple.CastExpr)1 DefinitionStmt (soot.jimple.DefinitionStmt)1 Stmt (soot.jimple.Stmt)1 ImmediateBox (soot.jimple.internal.ImmediateBox)1