Search in sources :

Example 11 with IntegerType

use of soot.IntegerType in project soot by Sable.

the class ConstraintCollector method caseIfStmt.

public void caseIfStmt(IfStmt stmt) {
    if (uses) {
        ConditionExpr cond = (ConditionExpr) stmt.getCondition();
        BinopExpr expr = cond;
        Value lv = expr.getOp1();
        Value rv = expr.getOp2();
        TypeVariable lop = null;
        TypeVariable rop = null;
        // ******** LEFT ********
        if (lv instanceof Local) {
            if (((Local) lv).getType() instanceof IntegerType) {
                lop = resolver.typeVariable((Local) lv);
            }
        } else if (lv instanceof DoubleConstant) {
        } else if (lv instanceof FloatConstant) {
        } else if (lv instanceof IntConstant) {
            int value = ((IntConstant) lv).value;
            if (value < -32768) {
                lop = resolver.INT;
            } else if (value < -128) {
                lop = resolver.SHORT;
            } else if (value < 0) {
                lop = resolver.BYTE;
            } else if (value < 2) {
                lop = resolver.R0_1;
            } else if (value < 128) {
                lop = resolver.R0_127;
            } else if (value < 32768) {
                lop = resolver.R0_32767;
            } else if (value < 65536) {
                lop = resolver.CHAR;
            } else {
                lop = resolver.INT;
            }
        } else if (lv instanceof LongConstant) {
        } else if (lv instanceof NullConstant) {
        } else if (lv instanceof StringConstant) {
        } else if (lv instanceof ClassConstant) {
        } else {
            throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass());
        }
        // ******** RIGHT ********
        if (rv instanceof Local) {
            if (((Local) rv).getType() instanceof IntegerType) {
                rop = resolver.typeVariable((Local) rv);
            }
        } else if (rv instanceof DoubleConstant) {
        } else if (rv instanceof FloatConstant) {
        } else if (rv instanceof IntConstant) {
            int value = ((IntConstant) rv).value;
            if (value < -32768) {
                rop = resolver.INT;
            } else if (value < -128) {
                rop = resolver.SHORT;
            } else if (value < 0) {
                rop = resolver.BYTE;
            } else if (value < 2) {
                rop = resolver.R0_1;
            } else if (value < 128) {
                rop = resolver.R0_127;
            } else if (value < 32768) {
                rop = resolver.R0_32767;
            } else if (value < 65536) {
                rop = resolver.CHAR;
            } else {
                rop = resolver.INT;
            }
        } else if (rv instanceof LongConstant) {
        } else if (rv instanceof NullConstant) {
        } else if (rv instanceof StringConstant) {
        } else if (rv instanceof ClassConstant) {
        } else {
            throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass());
        }
        if (rop != null && lop != null) {
            TypeVariable common = resolver.typeVariable();
            if (rop != null)
                rop.addParent(common);
            if (lop != null)
                lop.addParent(common);
        }
    }
}
Also used : LongConstant(soot.jimple.LongConstant) DoubleConstant(soot.jimple.DoubleConstant) FloatConstant(soot.jimple.FloatConstant) Local(soot.Local) NullConstant(soot.jimple.NullConstant) IntegerType(soot.IntegerType) ConditionExpr(soot.jimple.ConditionExpr) Value(soot.Value) IntConstant(soot.jimple.IntConstant) StringConstant(soot.jimple.StringConstant) ClassConstant(soot.jimple.ClassConstant) BinopExpr(soot.jimple.BinopExpr)

Example 12 with IntegerType

use of soot.IntegerType in project soot by Sable.

the class ConstraintCollector method caseIdentityStmt.

public void caseIdentityStmt(IdentityStmt stmt) {
    Value l = stmt.getLeftOp();
    Value r = stmt.getRightOp();
    if (l instanceof Local) {
        if (((Local) l).getType() instanceof IntegerType) {
            TypeVariable left = resolver.typeVariable((Local) l);
            TypeVariable right = resolver.typeVariable(r.getType());
            right.addParent(left);
        }
    }
}
Also used : IntegerType(soot.IntegerType) Value(soot.Value) Local(soot.Local)

Example 13 with IntegerType

use of soot.IntegerType in project soot by Sable.

the class ConstraintCollector method handleInvokeExpr.

private void handleInvokeExpr(InvokeExpr ie) {
    if (!uses)
        return;
    // Handle the parameters
    SootMethodRef method = ie.getMethodRef();
    for (int i = 0; i < ie.getArgCount(); i++) {
        if (ie.getArg(i) instanceof Local) {
            Local local = (Local) ie.getArg(i);
            if (local.getType() instanceof IntegerType) {
                TypeVariable localType = resolver.typeVariable(local);
                localType.addParent(resolver.typeVariable(method.parameterType(i)));
            }
        }
    }
    if (ie instanceof DynamicInvokeExpr) {
        DynamicInvokeExpr die = (DynamicInvokeExpr) ie;
        SootMethodRef bootstrapMethod = die.getBootstrapMethodRef();
        for (int i = 0; i < die.getBootstrapArgCount(); i++) {
            if (die.getBootstrapArg(i) instanceof Local) {
                Local local = (Local) die.getBootstrapArg(i);
                if (local.getType() instanceof IntegerType) {
                    TypeVariable localType = resolver.typeVariable(local);
                    localType.addParent(resolver.typeVariable(bootstrapMethod.parameterType(i)));
                }
            }
        }
    }
}
Also used : IntegerType(soot.IntegerType) SootMethodRef(soot.SootMethodRef) Local(soot.Local) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr)

Aggregations

IntegerType (soot.IntegerType)13 Local (soot.Local)10 Value (soot.Value)8 ArrayType (soot.ArrayType)6 Type (soot.Type)6 IntType (soot.IntType)5 NullType (soot.NullType)5 RefType (soot.RefType)5 BinopExpr (soot.jimple.BinopExpr)4 ClassConstant (soot.jimple.ClassConstant)4 DoubleConstant (soot.jimple.DoubleConstant)4 DynamicInvokeExpr (soot.jimple.DynamicInvokeExpr)4 FloatConstant (soot.jimple.FloatConstant)4 IntConstant (soot.jimple.IntConstant)4 LongConstant (soot.jimple.LongConstant)4 NullConstant (soot.jimple.NullConstant)4 StringConstant (soot.jimple.StringConstant)4 BooleanType (soot.BooleanType)3 PrimType (soot.PrimType)3 AddExpr (soot.jimple.AddExpr)3