Search in sources :

Example 1 with DCmpgExpr

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

the class SimplifyExpressions method getResult.

public NumericConstant getResult(BinopExpr binop) {
    if (DEBUG)
        System.out.println("Binop expr" + binop);
    Value leftOp = binop.getOp1();
    Value rightOp = binop.getOp2();
    int op = 0;
    if (binop instanceof AddExpr) {
        op = 1;
    } else if (binop instanceof SubExpr || binop instanceof DCmpExpr || binop instanceof DCmpgExpr || binop instanceof DCmplExpr) {
        op = 2;
    } else if (binop instanceof MulExpr) {
        op = 3;
    }
    if (op == 0) {
        if (DEBUG) {
            System.out.println("not add sub or mult");
            System.out.println(binop.getClass().getName());
        }
        return null;
    }
    NumericConstant constant = null;
    if (leftOp instanceof LongConstant && rightOp instanceof LongConstant) {
        if (DEBUG)
            System.out.println("long constants!!");
        if (op == 1)
            constant = ((LongConstant) leftOp).add((LongConstant) rightOp);
        else if (op == 2)
            constant = ((LongConstant) leftOp).subtract((LongConstant) rightOp);
        else if (op == 3)
            constant = ((LongConstant) leftOp).multiply((LongConstant) rightOp);
    } else if (leftOp instanceof DoubleConstant && rightOp instanceof DoubleConstant) {
        if (DEBUG)
            System.out.println("double constants!!");
        if (op == 1)
            constant = ((DoubleConstant) leftOp).add((DoubleConstant) rightOp);
        else if (op == 2)
            constant = ((DoubleConstant) leftOp).subtract((DoubleConstant) rightOp);
        else if (op == 3)
            constant = ((DoubleConstant) leftOp).multiply((DoubleConstant) rightOp);
    } else if (leftOp instanceof FloatConstant && rightOp instanceof FloatConstant) {
        if (DEBUG)
            System.out.println("Float constants!!");
        if (op == 1)
            constant = ((FloatConstant) leftOp).add((FloatConstant) rightOp);
        else if (op == 2)
            constant = ((FloatConstant) leftOp).subtract((FloatConstant) rightOp);
        else if (op == 3)
            constant = ((FloatConstant) leftOp).multiply((FloatConstant) rightOp);
    } else if (leftOp instanceof IntConstant && rightOp instanceof IntConstant) {
        if (DEBUG)
            System.out.println("Integer constants!!");
        if (op == 1)
            constant = ((IntConstant) leftOp).add((IntConstant) rightOp);
        else if (op == 2)
            constant = ((IntConstant) leftOp).subtract((IntConstant) rightOp);
        else if (op == 3)
            constant = ((IntConstant) leftOp).multiply((IntConstant) rightOp);
    }
    return constant;
}
Also used : MulExpr(soot.jimple.MulExpr) LongConstant(soot.jimple.LongConstant) DoubleConstant(soot.jimple.DoubleConstant) SubExpr(soot.jimple.SubExpr) FloatConstant(soot.jimple.FloatConstant) AddExpr(soot.jimple.AddExpr) DCmpExpr(soot.dava.internal.javaRep.DCmpExpr) DCmplExpr(soot.dava.internal.javaRep.DCmplExpr) DCmpgExpr(soot.dava.internal.javaRep.DCmpgExpr) NumericConstant(soot.jimple.NumericConstant) Value(soot.Value) IntConstant(soot.jimple.IntConstant)

Example 2 with DCmpgExpr

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

the class DavaBody method javafy_binop_expr.

private void javafy_binop_expr(ValueBox vb) {
    BinopExpr boe = (BinopExpr) vb.getValue();
    ValueBox leftOpBox = boe.getOp1Box(), rightOpBox = boe.getOp2Box();
    Value leftOp = leftOpBox.getValue(), rightOp = rightOpBox.getValue();
    if (rightOp instanceof IntConstant) {
        if ((leftOp instanceof IntConstant) == false) {
            javafy(leftOpBox);
            leftOp = leftOpBox.getValue();
            if (boe instanceof ConditionExpr)
                rightOpBox.setValue(DIntConstant.v(((IntConstant) rightOp).value, leftOp.getType()));
            else
                rightOpBox.setValue(DIntConstant.v(((IntConstant) rightOp).value, null));
        }
    } else if (leftOp instanceof IntConstant) {
        javafy(rightOpBox);
        rightOp = rightOpBox.getValue();
        if (boe instanceof ConditionExpr)
            leftOpBox.setValue(DIntConstant.v(((IntConstant) leftOp).value, rightOp.getType()));
        else
            leftOpBox.setValue(DIntConstant.v(((IntConstant) leftOp).value, null));
    } else {
        javafy(rightOpBox);
        rightOp = rightOpBox.getValue();
        javafy(leftOpBox);
        leftOp = leftOpBox.getValue();
    }
    if (boe instanceof CmpExpr)
        vb.setValue(new DCmpExpr(leftOp, rightOp));
    else if (boe instanceof CmplExpr)
        vb.setValue(new DCmplExpr(leftOp, rightOp));
    else if (boe instanceof CmpgExpr)
        vb.setValue(new DCmpgExpr(leftOp, rightOp));
}
Also used : DCmpgExpr(soot.dava.internal.javaRep.DCmpgExpr) ValueBox(soot.ValueBox) DCmpExpr(soot.dava.internal.javaRep.DCmpExpr) CmpExpr(soot.jimple.CmpExpr) ConditionExpr(soot.jimple.ConditionExpr) DCmpgExpr(soot.dava.internal.javaRep.DCmpgExpr) CmpgExpr(soot.jimple.CmpgExpr) Value(soot.Value) IntConstant(soot.jimple.IntConstant) DIntConstant(soot.dava.internal.javaRep.DIntConstant) DCmpExpr(soot.dava.internal.javaRep.DCmpExpr) DCmplExpr(soot.dava.internal.javaRep.DCmplExpr) DCmplExpr(soot.dava.internal.javaRep.DCmplExpr) CmplExpr(soot.jimple.CmplExpr) BinopExpr(soot.jimple.BinopExpr)

Aggregations

Value (soot.Value)2 DCmpExpr (soot.dava.internal.javaRep.DCmpExpr)2 DCmpgExpr (soot.dava.internal.javaRep.DCmpgExpr)2 DCmplExpr (soot.dava.internal.javaRep.DCmplExpr)2 IntConstant (soot.jimple.IntConstant)2 ValueBox (soot.ValueBox)1 DIntConstant (soot.dava.internal.javaRep.DIntConstant)1 AddExpr (soot.jimple.AddExpr)1 BinopExpr (soot.jimple.BinopExpr)1 CmpExpr (soot.jimple.CmpExpr)1 CmpgExpr (soot.jimple.CmpgExpr)1 CmplExpr (soot.jimple.CmplExpr)1 ConditionExpr (soot.jimple.ConditionExpr)1 DoubleConstant (soot.jimple.DoubleConstant)1 FloatConstant (soot.jimple.FloatConstant)1 LongConstant (soot.jimple.LongConstant)1 MulExpr (soot.jimple.MulExpr)1 NumericConstant (soot.jimple.NumericConstant)1 SubExpr (soot.jimple.SubExpr)1