Search in sources :

Example 11 with CmpgExpr

use of soot.jimple.CmpgExpr in project soot by Sable.

the class UseChecker method handleBinopExpr.

private void handleBinopExpr(BinopExpr be, Stmt stmt, Type tlhs) {
    Value opl = be.getOp1(), opr = be.getOp2();
    Type tl = AugEvalFunction.eval_(this.tg, opl, stmt, this.jb);
    Type tr = AugEvalFunction.eval_(this.tg, opr, stmt, this.jb);
    if (be instanceof AddExpr || be instanceof SubExpr || be instanceof MulExpr || be instanceof DivExpr || be instanceof RemExpr || be instanceof GeExpr || be instanceof GtExpr || be instanceof LeExpr || be instanceof LtExpr || be instanceof ShlExpr || be instanceof ShrExpr || be instanceof UshrExpr) {
        if (tlhs instanceof IntegerType) {
            be.setOp1(this.uv.visit(opl, IntType.v(), stmt, true));
            be.setOp2(this.uv.visit(opr, IntType.v(), stmt, true));
        }
    } else if (be instanceof CmpExpr || be instanceof CmpgExpr || be instanceof CmplExpr) {
    // No checks in the original assigner
    } else if (be instanceof AndExpr || be instanceof OrExpr || be instanceof XorExpr) {
        be.setOp1(this.uv.visit(opl, tlhs, stmt, true));
        be.setOp2(this.uv.visit(opr, tlhs, stmt, true));
    } else if (be instanceof EqExpr || be instanceof NeExpr) {
        if (tl instanceof BooleanType && tr instanceof BooleanType) {
        } else if (tl instanceof Integer1Type || tr instanceof Integer1Type) {
        } else if (tl instanceof IntegerType) {
            be.setOp1(this.uv.visit(opl, IntType.v(), stmt, true));
            be.setOp2(this.uv.visit(opr, IntType.v(), stmt, true));
        }
    }
}
Also used : MulExpr(soot.jimple.MulExpr) AndExpr(soot.jimple.AndExpr) GtExpr(soot.jimple.GtExpr) LtExpr(soot.jimple.LtExpr) GeExpr(soot.jimple.GeExpr) UshrExpr(soot.jimple.UshrExpr) LeExpr(soot.jimple.LeExpr) ShlExpr(soot.jimple.ShlExpr) XorExpr(soot.jimple.XorExpr) NeExpr(soot.jimple.NeExpr) SubExpr(soot.jimple.SubExpr) BooleanType(soot.BooleanType) AddExpr(soot.jimple.AddExpr) OrExpr(soot.jimple.OrExpr) IntegerType(soot.IntegerType) RefType(soot.RefType) BooleanType(soot.BooleanType) Type(soot.Type) IntType(soot.IntType) NullType(soot.NullType) ArrayType(soot.ArrayType) IntegerType(soot.IntegerType) PrimType(soot.PrimType) DivExpr(soot.jimple.DivExpr) RemExpr(soot.jimple.RemExpr) ShrExpr(soot.jimple.ShrExpr) CmpExpr(soot.jimple.CmpExpr) EqExpr(soot.jimple.EqExpr) CmpgExpr(soot.jimple.CmpgExpr) Value(soot.Value) CmplExpr(soot.jimple.CmplExpr)

Example 12 with CmpgExpr

use of soot.jimple.CmpgExpr in project soot by Sable.

the class ConstraintCollector method caseAssignStmt.

@Override
public void caseAssignStmt(AssignStmt stmt) {
    final Value l = stmt.getLeftOp();
    final Value r = stmt.getRightOp();
    TypeVariable left = null;
    TypeVariable right = null;
    if (l instanceof ArrayRef) {
        ArrayRef ref = (ArrayRef) l;
        Type baset = ((Local) ref.getBase()).getType();
        if (baset instanceof ArrayType) {
            ArrayType base = (ArrayType) baset;
            Value index = ref.getIndex();
            if (uses) {
                if ((base.numDimensions == 1) && (base.baseType instanceof IntegerType)) {
                    left = resolver.typeVariable(base.baseType);
                }
                if (index instanceof Local) {
                    resolver.typeVariable((Local) index).addParent(resolver.INT);
                }
            }
        }
    } else if (l instanceof Local) {
        Local loc = (Local) l;
        if (loc.getType() instanceof IntegerType) {
            left = resolver.typeVariable(loc);
        }
    } else if (l instanceof InstanceFieldRef) {
        if (uses) {
            InstanceFieldRef ref = (InstanceFieldRef) l;
            Type fieldType = ref.getFieldRef().type();
            if (fieldType instanceof IntegerType) {
                left = resolver.typeVariable(fieldType);
            }
        }
    } else if (l instanceof StaticFieldRef) {
        if (uses) {
            StaticFieldRef ref = (StaticFieldRef) l;
            Type fieldType = ref.getFieldRef().type();
            if (fieldType instanceof IntegerType) {
                left = resolver.typeVariable(fieldType);
            }
        }
    } else {
        throw new RuntimeException("Unhandled assignment left hand side type: " + l.getClass());
    }
    if (r instanceof ArrayRef) {
        ArrayRef ref = (ArrayRef) r;
        Type baset = ((Local) ref.getBase()).getType();
        if (!(baset instanceof NullType)) {
            Value index = ref.getIndex();
            // Be careful, dex can do some weird object/array casting
            if (baset instanceof ArrayType) {
                ArrayType base = (ArrayType) baset;
                if ((base.numDimensions == 1) && (base.baseType instanceof IntegerType)) {
                    right = resolver.typeVariable(base.baseType);
                }
            } else if (baset instanceof IntegerType) {
                right = resolver.typeVariable(baset);
            }
            if (uses) {
                if (index instanceof Local) {
                    resolver.typeVariable((Local) index).addParent(resolver.INT);
                }
            }
        }
    } else if (r instanceof DoubleConstant) {
    } else if (r instanceof FloatConstant) {
    } else if (r instanceof IntConstant) {
        int value = ((IntConstant) r).value;
        if (value < -32768) {
            right = resolver.INT;
        } else if (value < -128) {
            right = resolver.SHORT;
        } else if (value < 0) {
            right = resolver.BYTE;
        } else if (value < 2) {
            right = resolver.R0_1;
        } else if (value < 128) {
            right = resolver.R0_127;
        } else if (value < 32768) {
            right = resolver.R0_32767;
        } else if (value < 65536) {
            right = resolver.CHAR;
        } else {
            right = resolver.INT;
        }
    } else if (r instanceof LongConstant) {
    } else if (r instanceof NullConstant) {
    } else if (r instanceof StringConstant) {
    } else if (r instanceof ClassConstant) {
    } else if (r instanceof BinopExpr) {
        // ******** BINOP EXPR ********
        BinopExpr be = (BinopExpr) r;
        Value lv = be.getOp1();
        Value rv = be.getOp2();
        TypeVariable lop = null;
        TypeVariable rop = null;
        // ******** LEFT ********
        if (lv instanceof Local) {
            Local loc = (Local) lv;
            if (loc.getType() instanceof IntegerType) {
                lop = resolver.typeVariable(loc);
            }
        } 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) {
            Local loc = (Local) rv;
            if (loc.getType() instanceof IntegerType) {
                rop = resolver.typeVariable(loc);
            }
        } 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 ((be instanceof AddExpr) || (be instanceof SubExpr) || (be instanceof DivExpr) || (be instanceof RemExpr) || (be instanceof MulExpr)) {
            if (lop != null && rop != null) {
                if (uses) {
                    if (lop.type() == null) {
                        lop.addParent(resolver.INT);
                    }
                    if (rop.type() == null) {
                        rop.addParent(resolver.INT);
                    }
                }
                right = resolver.INT;
            }
        } else if ((be instanceof AndExpr) || (be instanceof OrExpr) || (be instanceof XorExpr)) {
            if (lop != null && rop != null) {
                right = resolver.typeVariable();
                rop.addParent(right);
                lop.addParent(right);
            }
        } else if (be instanceof ShlExpr) {
            if (uses) {
                if (lop != null && lop.type() == null) {
                    lop.addParent(resolver.INT);
                }
                if (rop.type() == null) {
                    rop.addParent(resolver.INT);
                }
            }
            right = (lop == null) ? null : resolver.INT;
        } else if ((be instanceof ShrExpr) || (be instanceof UshrExpr)) {
            if (uses) {
                if (lop != null && lop.type() == null) {
                    lop.addParent(resolver.INT);
                }
                if (rop.type() == null) {
                    rop.addParent(resolver.INT);
                }
            }
            right = lop;
        } else if ((be instanceof CmpExpr) || (be instanceof CmpgExpr) || (be instanceof CmplExpr)) {
            right = resolver.BYTE;
        } else if ((be instanceof EqExpr) || (be instanceof GeExpr) || (be instanceof GtExpr) || (be instanceof LeExpr) || (be instanceof LtExpr) || (be instanceof NeExpr)) {
            if (uses) {
                TypeVariable common = resolver.typeVariable();
                if (rop != null) {
                    rop.addParent(common);
                }
                if (lop != null) {
                    lop.addParent(common);
                }
            }
            right = resolver.BOOLEAN;
        } else {
            throw new RuntimeException("Unhandled binary expression type: " + be.getClass());
        }
    } else if (r instanceof CastExpr) {
        Type ty = ((CastExpr) r).getCastType();
        if (ty instanceof IntegerType) {
            right = resolver.typeVariable(ty);
        }
    } else if (r instanceof InstanceOfExpr) {
        right = resolver.BOOLEAN;
    } else if (r instanceof InvokeExpr) {
        InvokeExpr ie = (InvokeExpr) r;
        handleInvokeExpr(ie);
        Type returnType = ie.getMethodRef().getReturnType();
        if (returnType instanceof IntegerType) {
            right = resolver.typeVariable(returnType);
        }
    } else if (r instanceof NewArrayExpr) {
        NewArrayExpr nae = (NewArrayExpr) r;
        if (uses) {
            Value size = nae.getSize();
            if (size instanceof Local) {
                TypeVariable var = resolver.typeVariable((Local) size);
                var.addParent(resolver.INT);
            }
        }
    } else if (r instanceof NewExpr) {
    } else if (r instanceof NewMultiArrayExpr) {
        NewMultiArrayExpr nmae = (NewMultiArrayExpr) r;
        if (uses) {
            for (int i = 0; i < nmae.getSizeCount(); i++) {
                Value size = nmae.getSize(i);
                if (size instanceof Local) {
                    TypeVariable var = resolver.typeVariable((Local) size);
                    var.addParent(resolver.INT);
                }
            }
        }
    } else if (r instanceof LengthExpr) {
        right = resolver.INT;
    } else if (r instanceof NegExpr) {
        NegExpr ne = (NegExpr) r;
        if (ne.getOp() instanceof Local) {
            Local local = (Local) ne.getOp();
            if (local.getType() instanceof IntegerType) {
                if (uses) {
                    resolver.typeVariable(local).addParent(resolver.INT);
                }
                right = resolver.typeVariable();
                right.addChild(resolver.BYTE);
                right.addChild(resolver.typeVariable(local));
            }
        } else if (ne.getOp() instanceof DoubleConstant) {
        } else if (ne.getOp() instanceof FloatConstant) {
        } else if (ne.getOp() instanceof IntConstant) {
            int value = ((IntConstant) ne.getOp()).value;
            if (value < -32768) {
                right = resolver.INT;
            } else if (value < -128) {
                right = resolver.SHORT;
            } else if (value < 0) {
                right = resolver.BYTE;
            } else if (value < 2) {
                right = resolver.BYTE;
            } else if (value < 128) {
                right = resolver.BYTE;
            } else if (value < 32768) {
                right = resolver.SHORT;
            } else if (value < 65536) {
                right = resolver.INT;
            } else {
                right = resolver.INT;
            }
        } else if (ne.getOp() instanceof LongConstant) {
        } else {
            throw new RuntimeException("Unhandled neg expression operand type: " + ne.getOp().getClass());
        }
    } else if (r instanceof Local) {
        Local local = (Local) r;
        if (local.getType() instanceof IntegerType) {
            right = resolver.typeVariable(local);
        }
    } else if (r instanceof InstanceFieldRef) {
        Type type = ((InstanceFieldRef) r).getFieldRef().type();
        if (type instanceof IntegerType) {
            right = resolver.typeVariable(type);
        }
    } else if (r instanceof StaticFieldRef) {
        Type type = ((StaticFieldRef) r).getFieldRef().type();
        if (type instanceof IntegerType) {
            right = resolver.typeVariable(type);
        }
    } else {
        throw new RuntimeException("Unhandled assignment right hand side type: " + r.getClass());
    }
    if (left != null && right != null && (left.type() == null || right.type() == null)) {
        right.addParent(left);
    }
}
Also used : MulExpr(soot.jimple.MulExpr) AndExpr(soot.jimple.AndExpr) DoubleConstant(soot.jimple.DoubleConstant) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) FloatConstant(soot.jimple.FloatConstant) GtExpr(soot.jimple.GtExpr) LtExpr(soot.jimple.LtExpr) NegExpr(soot.jimple.NegExpr) GeExpr(soot.jimple.GeExpr) UshrExpr(soot.jimple.UshrExpr) LeExpr(soot.jimple.LeExpr) ArrayRef(soot.jimple.ArrayRef) ArrayType(soot.ArrayType) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) InstanceFieldRef(soot.jimple.InstanceFieldRef) CastExpr(soot.jimple.CastExpr) IntConstant(soot.jimple.IntConstant) ShlExpr(soot.jimple.ShlExpr) LongConstant(soot.jimple.LongConstant) XorExpr(soot.jimple.XorExpr) NeExpr(soot.jimple.NeExpr) LengthExpr(soot.jimple.LengthExpr) SubExpr(soot.jimple.SubExpr) Local(soot.Local) NullConstant(soot.jimple.NullConstant) AddExpr(soot.jimple.AddExpr) InstanceOfExpr(soot.jimple.InstanceOfExpr) OrExpr(soot.jimple.OrExpr) StaticFieldRef(soot.jimple.StaticFieldRef) IntegerType(soot.IntegerType) Type(soot.Type) NullType(soot.NullType) ArrayType(soot.ArrayType) IntegerType(soot.IntegerType) DivExpr(soot.jimple.DivExpr) NewArrayExpr(soot.jimple.NewArrayExpr) RemExpr(soot.jimple.RemExpr) ShrExpr(soot.jimple.ShrExpr) CmpExpr(soot.jimple.CmpExpr) EqExpr(soot.jimple.EqExpr) CmpgExpr(soot.jimple.CmpgExpr) Value(soot.Value) NewExpr(soot.jimple.NewExpr) NullType(soot.NullType) StringConstant(soot.jimple.StringConstant) CmplExpr(soot.jimple.CmplExpr) ClassConstant(soot.jimple.ClassConstant) BinopExpr(soot.jimple.BinopExpr)

Example 13 with CmpgExpr

use of soot.jimple.CmpgExpr in project soot by Sable.

the class ConstraintChecker method caseAssignStmt.

@Override
public void caseAssignStmt(AssignStmt stmt) {
    final Value l = stmt.getLeftOp();
    final Value r = stmt.getRightOp();
    TypeNode left = null;
    if (l instanceof ArrayRef) {
        ArrayRef ref = (ArrayRef) l;
        TypeNode base = hierarchy.typeNode(((Local) ref.getBase()).getType());
        if (!base.isArray()) {
            error("Type Error(16)");
        }
        left = base.element();
        Value index = ref.getIndex();
        if (index instanceof Local) {
            if (!hierarchy.typeNode(((Local) index).getType()).hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(17)");
            }
        }
    } else if (l instanceof Local) {
        try {
            left = hierarchy.typeNode(((Local) l).getType());
        } catch (InternalTypingException e) {
            logger.debug("untyped local: " + l);
            throw e;
        }
    } else if (l instanceof InstanceFieldRef) {
        InstanceFieldRef ref = (InstanceFieldRef) l;
        Local base = (Local) ref.getBase();
        RefType classTy = ref.getField().getDeclaringClass().getType();
        if (!hierarchy.typeNode(base.getType()).hasAncestorOrSelf(hierarchy.typeNode(classTy))) {
            if (fix) {
                ref.setBase(insertCast(base, classTy, stmt));
            } else {
                error("Type Error(18)");
            }
        }
        left = hierarchy.typeNode(ref.getField().getType());
    } else if (l instanceof StaticFieldRef) {
        StaticFieldRef ref = (StaticFieldRef) l;
        left = hierarchy.typeNode(ref.getField().getType());
    } else {
        throw new RuntimeException("Unhandled assignment left hand side type: " + l.getClass());
    }
    if (r instanceof ArrayRef) {
        ArrayRef ref = (ArrayRef) r;
        Local base = (Local) ref.getBase();
        TypeNode baseTy = hierarchy.typeNode((base).getType());
        if (!baseTy.isArray()) {
            error("Type Error(19): " + baseTy + " is not an array type");
        }
        if (baseTy == hierarchy.NULL) {
            return;
        }
        if (!left.hasDescendantOrSelf(baseTy.element())) {
            if (fix) {
                Type lefttype = left.type();
                if (lefttype instanceof ArrayType) {
                    ArrayType atype = (ArrayType) lefttype;
                    ref.setBase(insertCast(base, ArrayType.v(atype.baseType, atype.numDimensions + 1), stmt));
                } else {
                    ref.setBase(insertCast(base, ArrayType.v(lefttype, 1), stmt));
                }
            } else {
                error("Type Error(20)");
            }
        }
        Value index = ref.getIndex();
        if (index instanceof Local) {
            if (!hierarchy.typeNode(((Local) index).getType()).hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(21)");
            }
        }
    } else if (r instanceof DoubleConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(DoubleType.v()))) {
            error("Type Error(22)");
        }
    } else if (r instanceof FloatConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(FloatType.v()))) {
            error("Type Error(45)");
        }
    } else if (r instanceof IntConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
            error("Type Error(23)");
        }
    } else if (r instanceof LongConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(LongType.v()))) {
            error("Type Error(24)");
        }
    } else if (r instanceof NullConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(NullType.v()))) {
            error("Type Error(25)");
        }
    } else if (r instanceof StringConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(RefType.v("java.lang.String")))) {
            error("Type Error(26)");
        }
    } else if (r instanceof ClassConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(RefType.v("java.lang.Class")))) {
            error("Type Error(27)");
        }
    } else if (r instanceof BinopExpr) {
        // ******** BINOP EXPR ********
        final BinopExpr be = (BinopExpr) r;
        final Value lv = be.getOp1();
        final Value rv = be.getOp2();
        TypeNode lop;
        TypeNode rop;
        // ******** LEFT ********
        if (lv instanceof Local) {
            lop = hierarchy.typeNode(((Local) lv).getType());
        } else if (lv instanceof DoubleConstant) {
            lop = hierarchy.typeNode(DoubleType.v());
        } else if (lv instanceof FloatConstant) {
            lop = hierarchy.typeNode(FloatType.v());
        } else if (lv instanceof IntConstant) {
            lop = hierarchy.typeNode(IntType.v());
        } else if (lv instanceof LongConstant) {
            lop = hierarchy.typeNode(LongType.v());
        } else if (lv instanceof NullConstant) {
            lop = hierarchy.typeNode(NullType.v());
        } else if (lv instanceof StringConstant) {
            lop = hierarchy.typeNode(RefType.v("java.lang.String"));
        } else if (lv instanceof ClassConstant) {
            lop = hierarchy.typeNode(RefType.v("java.lang.Class"));
        } else {
            throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass());
        }
        // ******** RIGHT ********
        if (rv instanceof Local) {
            rop = hierarchy.typeNode(((Local) rv).getType());
        } else if (rv instanceof DoubleConstant) {
            rop = hierarchy.typeNode(DoubleType.v());
        } else if (rv instanceof FloatConstant) {
            rop = hierarchy.typeNode(FloatType.v());
        } else if (rv instanceof IntConstant) {
            rop = hierarchy.typeNode(IntType.v());
        } else if (rv instanceof LongConstant) {
            rop = hierarchy.typeNode(LongType.v());
        } else if (rv instanceof NullConstant) {
            rop = hierarchy.typeNode(NullType.v());
        } else if (rv instanceof StringConstant) {
            rop = hierarchy.typeNode(RefType.v("java.lang.String"));
        } else if (rv instanceof ClassConstant) {
            rop = hierarchy.typeNode(RefType.v("java.lang.Class"));
        } else {
            throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass());
        }
        if ((be instanceof AddExpr) || (be instanceof SubExpr) || (be instanceof MulExpr) || (be instanceof DivExpr) || (be instanceof RemExpr) || (be instanceof AndExpr) || (be instanceof OrExpr) || (be instanceof XorExpr)) {
            if (!(left.hasDescendantOrSelf(lop) && left.hasDescendantOrSelf(rop))) {
                error("Type Error(27)");
            }
        } else if ((be instanceof ShlExpr) || (be instanceof ShrExpr) || (be instanceof UshrExpr)) {
            if (!(left.hasDescendantOrSelf(lop) && hierarchy.typeNode(IntType.v()).hasAncestorOrSelf(rop))) {
                error("Type Error(28)");
            }
        } else if ((be instanceof CmpExpr) || (be instanceof CmpgExpr) || (be instanceof CmplExpr) || (be instanceof EqExpr) || (be instanceof GeExpr) || (be instanceof GtExpr) || (be instanceof LeExpr) || (be instanceof LtExpr) || (be instanceof NeExpr)) {
            try {
                lop.lca(rop);
            } catch (TypeException e) {
                error(e.getMessage());
            }
            if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(29)");
            }
        } else {
            throw new RuntimeException("Unhandled binary expression type: " + be.getClass());
        }
    } else if (r instanceof CastExpr) {
        CastExpr ce = (CastExpr) r;
        TypeNode castTy = hierarchy.typeNode(ce.getCastType());
        Value op = ce.getOp();
        if (op instanceof Local) {
            TypeNode opTy = hierarchy.typeNode(((Local) op).getType());
            try {
                // we must be careful not to reject primitive type casts (e.g. int to long)
                if (castTy.isClassOrInterface() || opTy.isClassOrInterface()) {
                    castTy.lca(opTy);
                }
            } catch (TypeException e) {
                logger.debug(r + "[" + opTy + "<->" + castTy + "]");
                error(e.getMessage());
            }
        }
        if (!left.hasDescendantOrSelf(castTy)) {
            error("Type Error(30)");
        }
    } else if (r instanceof InstanceOfExpr) {
        InstanceOfExpr ioe = (InstanceOfExpr) r;
        TypeNode type = hierarchy.typeNode(ioe.getCheckType());
        TypeNode op = hierarchy.typeNode(ioe.getOp().getType());
        try {
            op.lca(type);
        } catch (TypeException e) {
            logger.debug(r + "[" + op + "<->" + type + "]");
            error(e.getMessage());
        }
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
            error("Type Error(31)");
        }
    } else if (r instanceof InvokeExpr) {
        InvokeExpr ie = (InvokeExpr) r;
        handleInvokeExpr(ie, stmt);
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ie.getMethodRef().getReturnType()))) {
            error("Type Error(32)");
        }
    } else if (r instanceof NewArrayExpr) {
        NewArrayExpr nae = (NewArrayExpr) r;
        Type baseType = nae.getBaseType();
        TypeNode right;
        if (baseType instanceof ArrayType) {
            right = hierarchy.typeNode(ArrayType.v(((ArrayType) baseType).baseType, ((ArrayType) baseType).numDimensions + 1));
        } else {
            right = hierarchy.typeNode(ArrayType.v(baseType, 1));
        }
        if (!left.hasDescendantOrSelf(right)) {
            error("Type Error(33)");
        }
        Value size = nae.getSize();
        if (size instanceof Local) {
            TypeNode var = hierarchy.typeNode(((Local) size).getType());
            if (!var.hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(34)");
            }
        }
    } else if (r instanceof NewExpr) {
        NewExpr ne = (NewExpr) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ne.getBaseType()))) {
            error("Type Error(35)");
        }
    } else if (r instanceof NewMultiArrayExpr) {
        NewMultiArrayExpr nmae = (NewMultiArrayExpr) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(nmae.getBaseType()))) {
            error("Type Error(36)");
        }
        for (int i = 0; i < nmae.getSizeCount(); i++) {
            Value size = nmae.getSize(i);
            if (size instanceof Local) {
                TypeNode var = hierarchy.typeNode(((Local) size).getType());
                if (!var.hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                    error("Type Error(37)");
                }
            }
        }
    } else if (r instanceof LengthExpr) {
        LengthExpr le = (LengthExpr) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
            error("Type Error(38)");
        }
        Value op = le.getOp();
        if (op instanceof Local) {
            if (!hierarchy.typeNode(((Local) op).getType()).isArray()) {
                error("Type Error(39)");
            }
        }
    } else if (r instanceof NegExpr) {
        NegExpr ne = (NegExpr) r;
        TypeNode right;
        Value op = ne.getOp();
        if (op instanceof Local) {
            right = hierarchy.typeNode(((Local) op).getType());
        } else if (op instanceof DoubleConstant) {
            right = hierarchy.typeNode(DoubleType.v());
        } else if (op instanceof FloatConstant) {
            right = hierarchy.typeNode(FloatType.v());
        } else if (op instanceof IntConstant) {
            right = hierarchy.typeNode(IntType.v());
        } else if (op instanceof LongConstant) {
            right = hierarchy.typeNode(LongType.v());
        } else {
            throw new RuntimeException("Unhandled neg expression operand type: " + op.getClass());
        }
        if (!left.hasDescendantOrSelf(right)) {
            error("Type Error(40)");
        }
    } else if (r instanceof Local) {
        Local loc = (Local) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(loc.getType()))) {
            if (fix) {
                stmt.setRightOp(insertCast(loc, left.type(), stmt));
            } else {
                error("Type Error(41)");
            }
        }
    } else if (r instanceof InstanceFieldRef) {
        InstanceFieldRef ref = (InstanceFieldRef) r;
        Local base = (Local) ref.getBase();
        RefType classTy = ref.getField().getDeclaringClass().getType();
        if (!hierarchy.typeNode(base.getType()).hasAncestorOrSelf(hierarchy.typeNode(classTy))) {
            if (fix) {
                ref.setBase(insertCast(base, classTy, stmt));
            } else {
                error("Type Error(42)");
            }
        }
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ref.getField().getType()))) {
            error("Type Error(43)");
        }
    } else if (r instanceof StaticFieldRef) {
        StaticFieldRef ref = (StaticFieldRef) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ref.getField().getType()))) {
            error("Type Error(44)");
        }
    } else {
        throw new RuntimeException("Unhandled assignment right hand side type: " + r.getClass());
    }
}
Also used : AndExpr(soot.jimple.AndExpr) GtExpr(soot.jimple.GtExpr) LtExpr(soot.jimple.LtExpr) RefType(soot.RefType) ArrayType(soot.ArrayType) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) CastExpr(soot.jimple.CastExpr) ShlExpr(soot.jimple.ShlExpr) XorExpr(soot.jimple.XorExpr) NeExpr(soot.jimple.NeExpr) Local(soot.Local) AddExpr(soot.jimple.AddExpr) InstanceOfExpr(soot.jimple.InstanceOfExpr) OrExpr(soot.jimple.OrExpr) StaticFieldRef(soot.jimple.StaticFieldRef) NewArrayExpr(soot.jimple.NewArrayExpr) RemExpr(soot.jimple.RemExpr) ShrExpr(soot.jimple.ShrExpr) CmpExpr(soot.jimple.CmpExpr) Value(soot.Value) NewExpr(soot.jimple.NewExpr) StringConstant(soot.jimple.StringConstant) CmplExpr(soot.jimple.CmplExpr) ClassConstant(soot.jimple.ClassConstant) BinopExpr(soot.jimple.BinopExpr) MulExpr(soot.jimple.MulExpr) DoubleConstant(soot.jimple.DoubleConstant) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) FloatConstant(soot.jimple.FloatConstant) NegExpr(soot.jimple.NegExpr) GeExpr(soot.jimple.GeExpr) UshrExpr(soot.jimple.UshrExpr) LeExpr(soot.jimple.LeExpr) ArrayRef(soot.jimple.ArrayRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) IntConstant(soot.jimple.IntConstant) LongConstant(soot.jimple.LongConstant) LengthExpr(soot.jimple.LengthExpr) SubExpr(soot.jimple.SubExpr) NullConstant(soot.jimple.NullConstant) RefType(soot.RefType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) LongType(soot.LongType) NullType(soot.NullType) ArrayType(soot.ArrayType) DivExpr(soot.jimple.DivExpr) EqExpr(soot.jimple.EqExpr) CmpgExpr(soot.jimple.CmpgExpr)

Example 14 with CmpgExpr

use of soot.jimple.CmpgExpr in project soot by Sable.

the class ConstraintCheckerBV method caseAssignStmt.

public void caseAssignStmt(AssignStmt stmt) {
    Value l = stmt.getLeftOp();
    Value r = stmt.getRightOp();
    TypeNode left = null;
    if (l instanceof ArrayRef) {
        ArrayRef ref = (ArrayRef) l;
        TypeNode base = hierarchy.typeNode(((Local) ref.getBase()).getType());
        if (!base.isArray()) {
            error("Type Error(16)");
        }
        left = base.element();
        Value index = ref.getIndex();
        if (index instanceof Local) {
            if (!hierarchy.typeNode(((Local) index).getType()).hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(17)");
            }
        }
    } else if (l instanceof Local) {
        try {
            left = hierarchy.typeNode(((Local) l).getType());
        } catch (InternalTypingException e) {
            logger.debug("untyped local: " + l);
            throw e;
        }
    } else if (l instanceof InstanceFieldRef) {
        InstanceFieldRef ref = (InstanceFieldRef) l;
        TypeNode base = hierarchy.typeNode(((Local) ref.getBase()).getType());
        if (!base.hasAncestorOrSelf(hierarchy.typeNode(ref.getField().getDeclaringClass().getType()))) {
            if (fix) {
                ref.setBase(insertCast((Local) ref.getBase(), ref.getField().getDeclaringClass().getType(), stmt));
            } else {
                error("Type Error(18)");
            }
        }
        left = hierarchy.typeNode(ref.getField().getType());
    } else if (l instanceof StaticFieldRef) {
        StaticFieldRef ref = (StaticFieldRef) l;
        left = hierarchy.typeNode(ref.getField().getType());
    } else {
        throw new RuntimeException("Unhandled assignment left hand side type: " + l.getClass());
    }
    if (r instanceof ArrayRef) {
        ArrayRef ref = (ArrayRef) r;
        TypeNode base = hierarchy.typeNode(((Local) ref.getBase()).getType());
        if (!base.isArray()) {
            error("Type Error(19): " + base + " is not an array type");
        }
        if (base == hierarchy.NULL) {
            return;
        }
        if (!left.hasDescendantOrSelf(base.element())) {
            if (fix) {
                Type lefttype = left.type();
                if (lefttype instanceof ArrayType) {
                    ArrayType atype = (ArrayType) lefttype;
                    ref.setBase(insertCast((Local) ref.getBase(), ArrayType.v(atype.baseType, atype.numDimensions + 1), stmt));
                } else {
                    ref.setBase(insertCast((Local) ref.getBase(), ArrayType.v(lefttype, 1), stmt));
                }
            } else {
                error("Type Error(20)");
            }
        }
        Value index = ref.getIndex();
        if (index instanceof Local) {
            if (!hierarchy.typeNode(((Local) index).getType()).hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(21)");
            }
        }
    } else if (r instanceof DoubleConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(DoubleType.v()))) {
            error("Type Error(22)");
        }
    } else if (r instanceof FloatConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(FloatType.v()))) {
            error("Type Error(45)");
        }
    } else if (r instanceof IntConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
            error("Type Error(23)");
        }
    } else if (r instanceof LongConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(LongType.v()))) {
            error("Type Error(24)");
        }
    } else if (r instanceof NullConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(NullType.v()))) {
            error("Type Error(25)");
        }
    } else if (r instanceof StringConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(RefType.v("java.lang.String")))) {
            error("Type Error(26)");
        }
    } else if (r instanceof ClassConstant) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(RefType.v("java.lang.Class")))) {
            error("Type Error(27)");
        }
    } else if (r instanceof BinopExpr) {
        // ******** BINOP EXPR ********
        BinopExpr be = (BinopExpr) r;
        Value lv = be.getOp1();
        Value rv = be.getOp2();
        TypeNode lop;
        TypeNode rop;
        // ******** LEFT ********
        if (lv instanceof Local) {
            lop = hierarchy.typeNode(((Local) lv).getType());
        } else if (lv instanceof DoubleConstant) {
            lop = hierarchy.typeNode(DoubleType.v());
        } else if (lv instanceof FloatConstant) {
            lop = hierarchy.typeNode(FloatType.v());
        } else if (lv instanceof IntConstant) {
            lop = hierarchy.typeNode(IntType.v());
        } else if (lv instanceof LongConstant) {
            lop = hierarchy.typeNode(LongType.v());
        } else if (lv instanceof NullConstant) {
            lop = hierarchy.typeNode(NullType.v());
        } else if (lv instanceof StringConstant) {
            lop = hierarchy.typeNode(RefType.v("java.lang.String"));
        } else if (lv instanceof ClassConstant) {
            lop = hierarchy.typeNode(RefType.v("java.lang.Class"));
        } else {
            throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass());
        }
        // ******** RIGHT ********
        if (rv instanceof Local) {
            rop = hierarchy.typeNode(((Local) rv).getType());
        } else if (rv instanceof DoubleConstant) {
            rop = hierarchy.typeNode(DoubleType.v());
        } else if (rv instanceof FloatConstant) {
            rop = hierarchy.typeNode(FloatType.v());
        } else if (rv instanceof IntConstant) {
            rop = hierarchy.typeNode(IntType.v());
        } else if (rv instanceof LongConstant) {
            rop = hierarchy.typeNode(LongType.v());
        } else if (rv instanceof NullConstant) {
            rop = hierarchy.typeNode(NullType.v());
        } else if (rv instanceof StringConstant) {
            rop = hierarchy.typeNode(RefType.v("java.lang.String"));
        } else if (rv instanceof ClassConstant) {
            rop = hierarchy.typeNode(RefType.v("java.lang.Class"));
        } else {
            throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass());
        }
        if ((be instanceof AddExpr) || (be instanceof SubExpr) || (be instanceof MulExpr) || (be instanceof DivExpr) || (be instanceof RemExpr) || (be instanceof AndExpr) || (be instanceof OrExpr) || (be instanceof XorExpr)) {
            if (!(left.hasDescendantOrSelf(lop) && left.hasDescendantOrSelf(rop))) {
                error("Type Error(27)");
            }
        } else if ((be instanceof ShlExpr) || (be instanceof ShrExpr) || (be instanceof UshrExpr)) {
            if (!(left.hasDescendantOrSelf(lop) && hierarchy.typeNode(IntType.v()).hasAncestorOrSelf(rop))) {
                error("Type Error(28)");
            }
        } else if ((be instanceof CmpExpr) || (be instanceof CmpgExpr) || (be instanceof CmplExpr) || (be instanceof EqExpr) || (be instanceof GeExpr) || (be instanceof GtExpr) || (be instanceof LeExpr) || (be instanceof LtExpr) || (be instanceof NeExpr)) {
            try {
                lop.lca(rop);
            } catch (TypeException e) {
                error(e.getMessage());
            }
            if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(29)");
            }
        } else {
            throw new RuntimeException("Unhandled binary expression type: " + be.getClass());
        }
    } else if (r instanceof CastExpr) {
        CastExpr ce = (CastExpr) r;
        TypeNode cast = hierarchy.typeNode(ce.getCastType());
        if (ce.getOp() instanceof Local) {
            TypeNode op = hierarchy.typeNode(((Local) ce.getOp()).getType());
            try {
                // we must be careful not to reject primitive type casts (e.g. int to long)
                if (cast.isClassOrInterface() || op.isClassOrInterface()) {
                    cast.lca(op);
                }
            } catch (TypeException e) {
                logger.debug("" + r + "[" + op + "<->" + cast + "]");
                error(e.getMessage());
            }
        }
        if (!left.hasDescendantOrSelf(cast)) {
            error("Type Error(30)");
        }
    } else if (r instanceof InstanceOfExpr) {
        InstanceOfExpr ioe = (InstanceOfExpr) r;
        TypeNode type = hierarchy.typeNode(ioe.getCheckType());
        TypeNode op = hierarchy.typeNode(ioe.getOp().getType());
        try {
            op.lca(type);
        } catch (TypeException e) {
            logger.debug("" + r + "[" + op + "<->" + type + "]");
            error(e.getMessage());
        }
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
            error("Type Error(31)");
        }
    } else if (r instanceof InvokeExpr) {
        InvokeExpr ie = (InvokeExpr) r;
        handleInvokeExpr(ie, stmt);
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ie.getMethodRef().returnType()))) {
            error("Type Error(32)");
        }
    } else if (r instanceof NewArrayExpr) {
        NewArrayExpr nae = (NewArrayExpr) r;
        Type baseType = nae.getBaseType();
        TypeNode right;
        if (baseType instanceof ArrayType) {
            right = hierarchy.typeNode(ArrayType.v(((ArrayType) baseType).baseType, ((ArrayType) baseType).numDimensions + 1));
        } else {
            right = hierarchy.typeNode(ArrayType.v(baseType, 1));
        }
        if (!left.hasDescendantOrSelf(right)) {
            error("Type Error(33)");
        }
        Value size = nae.getSize();
        if (size instanceof Local) {
            TypeNode var = hierarchy.typeNode(((Local) size).getType());
            if (!var.hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                error("Type Error(34)");
            }
        }
    } else if (r instanceof NewExpr) {
        NewExpr ne = (NewExpr) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ne.getBaseType()))) {
            error("Type Error(35)");
        }
    } else if (r instanceof NewMultiArrayExpr) {
        NewMultiArrayExpr nmae = (NewMultiArrayExpr) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(nmae.getBaseType()))) {
            error("Type Error(36)");
        }
        for (int i = 0; i < nmae.getSizeCount(); i++) {
            Value size = nmae.getSize(i);
            if (size instanceof Local) {
                TypeNode var = hierarchy.typeNode(((Local) size).getType());
                if (!var.hasAncestorOrSelf(hierarchy.typeNode(IntType.v()))) {
                    error("Type Error(37)");
                }
            }
        }
    } else if (r instanceof LengthExpr) {
        LengthExpr le = (LengthExpr) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(IntType.v()))) {
            error("Type Error(38)");
        }
        if (le.getOp() instanceof Local) {
            if (!hierarchy.typeNode(((Local) le.getOp()).getType()).isArray()) {
                error("Type Error(39)");
            }
        }
    } else if (r instanceof NegExpr) {
        NegExpr ne = (NegExpr) r;
        TypeNode right;
        if (ne.getOp() instanceof Local) {
            right = hierarchy.typeNode(((Local) ne.getOp()).getType());
        } else if (ne.getOp() instanceof DoubleConstant) {
            right = hierarchy.typeNode(DoubleType.v());
        } else if (ne.getOp() instanceof FloatConstant) {
            right = hierarchy.typeNode(FloatType.v());
        } else if (ne.getOp() instanceof IntConstant) {
            right = hierarchy.typeNode(IntType.v());
        } else if (ne.getOp() instanceof LongConstant) {
            right = hierarchy.typeNode(LongType.v());
        } else {
            throw new RuntimeException("Unhandled neg expression operand type: " + ne.getOp().getClass());
        }
        if (!left.hasDescendantOrSelf(right)) {
            error("Type Error(40)");
        }
    } else if (r instanceof Local) {
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(((Local) r).getType()))) {
            if (fix) {
                stmt.setRightOp(insertCast((Local) r, left.type(), stmt));
            } else {
                error("Type Error(41)");
            }
        }
    } else if (r instanceof InstanceFieldRef) {
        InstanceFieldRef ref = (InstanceFieldRef) r;
        TypeNode baseType = hierarchy.typeNode(((Local) ref.getBase()).getType());
        if (!baseType.hasAncestorOrSelf(hierarchy.typeNode(ref.getField().getDeclaringClass().getType()))) {
            if (fix) {
                ref.setBase(insertCast((Local) ref.getBase(), ref.getField().getDeclaringClass().getType(), stmt));
            } else {
                error("Type Error(42)");
            }
        }
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ref.getField().getType()))) {
            error("Type Error(43)");
        }
    } else if (r instanceof StaticFieldRef) {
        StaticFieldRef ref = (StaticFieldRef) r;
        if (!left.hasDescendantOrSelf(hierarchy.typeNode(ref.getField().getType()))) {
            error("Type Error(44)");
        }
    } else {
        throw new RuntimeException("Unhandled assignment right hand side type: " + r.getClass());
    }
}
Also used : MulExpr(soot.jimple.MulExpr) AndExpr(soot.jimple.AndExpr) DoubleConstant(soot.jimple.DoubleConstant) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) FloatConstant(soot.jimple.FloatConstant) GtExpr(soot.jimple.GtExpr) LtExpr(soot.jimple.LtExpr) NegExpr(soot.jimple.NegExpr) GeExpr(soot.jimple.GeExpr) UshrExpr(soot.jimple.UshrExpr) LeExpr(soot.jimple.LeExpr) ArrayRef(soot.jimple.ArrayRef) ArrayType(soot.ArrayType) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) InstanceFieldRef(soot.jimple.InstanceFieldRef) CastExpr(soot.jimple.CastExpr) IntConstant(soot.jimple.IntConstant) ShlExpr(soot.jimple.ShlExpr) LongConstant(soot.jimple.LongConstant) XorExpr(soot.jimple.XorExpr) NeExpr(soot.jimple.NeExpr) LengthExpr(soot.jimple.LengthExpr) SubExpr(soot.jimple.SubExpr) Local(soot.Local) NullConstant(soot.jimple.NullConstant) AddExpr(soot.jimple.AddExpr) InstanceOfExpr(soot.jimple.InstanceOfExpr) OrExpr(soot.jimple.OrExpr) StaticFieldRef(soot.jimple.StaticFieldRef) RefType(soot.RefType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) LongType(soot.LongType) NullType(soot.NullType) ArrayType(soot.ArrayType) DivExpr(soot.jimple.DivExpr) NewArrayExpr(soot.jimple.NewArrayExpr) RemExpr(soot.jimple.RemExpr) ShrExpr(soot.jimple.ShrExpr) CmpExpr(soot.jimple.CmpExpr) EqExpr(soot.jimple.EqExpr) CmpgExpr(soot.jimple.CmpgExpr) Value(soot.Value) NewExpr(soot.jimple.NewExpr) StringConstant(soot.jimple.StringConstant) CmplExpr(soot.jimple.CmplExpr) ClassConstant(soot.jimple.ClassConstant) BinopExpr(soot.jimple.BinopExpr)

Example 15 with CmpgExpr

use of soot.jimple.CmpgExpr in project soot by Sable.

the class Grimp method newExpr.

/**
 * Carries out the mapping from other Value's to Grimp Value's
 */
public Value newExpr(Value value) {
    if (value instanceof Expr) {
        final ExprBox returnedExpr = new ExprBox(IntConstant.v(0));
        ((Expr) value).apply(new AbstractExprSwitch() {

            public void caseAddExpr(AddExpr v) {
                returnedExpr.setValue(newAddExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseAndExpr(AndExpr v) {
                returnedExpr.setValue(newAndExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseCmpExpr(CmpExpr v) {
                returnedExpr.setValue(newCmpExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseCmpgExpr(CmpgExpr v) {
                returnedExpr.setValue(newCmpgExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseCmplExpr(CmplExpr v) {
                returnedExpr.setValue(newCmplExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseDivExpr(DivExpr v) {
                returnedExpr.setValue(newDivExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseEqExpr(EqExpr v) {
                returnedExpr.setValue(newEqExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseNeExpr(NeExpr v) {
                returnedExpr.setValue(newNeExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseGeExpr(GeExpr v) {
                returnedExpr.setValue(newGeExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseGtExpr(GtExpr v) {
                returnedExpr.setValue(newGtExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseLeExpr(LeExpr v) {
                returnedExpr.setValue(newLeExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseLtExpr(LtExpr v) {
                returnedExpr.setValue(newLtExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseMulExpr(MulExpr v) {
                returnedExpr.setValue(newMulExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseOrExpr(OrExpr v) {
                returnedExpr.setValue(newOrExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseRemExpr(RemExpr v) {
                returnedExpr.setValue(newRemExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseShlExpr(ShlExpr v) {
                returnedExpr.setValue(newShlExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseShrExpr(ShrExpr v) {
                returnedExpr.setValue(newShrExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseUshrExpr(UshrExpr v) {
                returnedExpr.setValue(newUshrExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseSubExpr(SubExpr v) {
                returnedExpr.setValue(newSubExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseXorExpr(XorExpr v) {
                returnedExpr.setValue(newXorExpr(newExpr(v.getOp1()), newExpr(v.getOp2())));
            }

            public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v) {
                ArrayList newArgList = new ArrayList();
                for (int i = 0; i < v.getArgCount(); i++) {
                    newArgList.add(newExpr(v.getArg(i)));
                }
                returnedExpr.setValue(newInterfaceInvokeExpr((Local) (v.getBase()), v.getMethodRef(), newArgList));
            }

            public void caseSpecialInvokeExpr(SpecialInvokeExpr v) {
                ArrayList newArgList = new ArrayList();
                for (int i = 0; i < v.getArgCount(); i++) {
                    newArgList.add(newExpr(v.getArg(i)));
                }
                returnedExpr.setValue(newSpecialInvokeExpr((Local) (v.getBase()), v.getMethodRef(), newArgList));
            }

            public void caseStaticInvokeExpr(StaticInvokeExpr v) {
                ArrayList newArgList = new ArrayList();
                for (int i = 0; i < v.getArgCount(); i++) {
                    newArgList.add(newExpr(v.getArg(i)));
                }
                returnedExpr.setValue(newStaticInvokeExpr(v.getMethodRef(), newArgList));
            }

            public void caseVirtualInvokeExpr(VirtualInvokeExpr v) {
                ArrayList newArgList = new ArrayList();
                for (int i = 0; i < v.getArgCount(); i++) {
                    newArgList.add(newExpr(v.getArg(i)));
                }
                returnedExpr.setValue(newVirtualInvokeExpr((Local) (v.getBase()), v.getMethodRef(), newArgList));
            }

            public void caseDynamicInvokeExpr(DynamicInvokeExpr v) {
                ArrayList newArgList = new ArrayList();
                for (int i = 0; i < v.getArgCount(); i++) {
                    newArgList.add(newExpr(v.getArg(i)));
                }
                returnedExpr.setValue(newDynamicInvokeExpr(v.getBootstrapMethodRef(), v.getBootstrapArgs(), v.getMethodRef(), v.getHandleTag(), newArgList));
            }

            public void caseCastExpr(CastExpr v) {
                returnedExpr.setValue(newCastExpr(newExpr(v.getOp()), v.getType()));
            }

            public void caseInstanceOfExpr(InstanceOfExpr v) {
                returnedExpr.setValue(newInstanceOfExpr(newExpr(v.getOp()), v.getCheckType()));
            }

            public void caseNewArrayExpr(NewArrayExpr v) {
                returnedExpr.setValue(newNewArrayExpr(v.getBaseType(), v.getSize()));
            }

            public void caseNewMultiArrayExpr(NewMultiArrayExpr v) {
                returnedExpr.setValue(newNewMultiArrayExpr(v.getBaseType(), v.getSizes()));
            }

            public void caseNewExpr(NewExpr v) {
                returnedExpr.setValue(newNewExpr(v.getBaseType()));
            }

            public void caseLengthExpr(LengthExpr v) {
                returnedExpr.setValue(newLengthExpr(newExpr(v.getOp())));
            }

            public void caseNegExpr(NegExpr v) {
                returnedExpr.setValue(newNegExpr(newExpr(v.getOp())));
            }

            public void defaultCase(Object v) {
                returnedExpr.setValue((Expr) v);
            }
        });
        return returnedExpr.getValue();
    } else {
        if (value instanceof ArrayRef) {
            return newArrayRef(((ArrayRef) value).getBase(), newExpr(((ArrayRef) value).getIndex()));
        }
        if (value instanceof InstanceFieldRef) {
            return newInstanceFieldRef(newExpr((((InstanceFieldRef) value).getBase())), ((InstanceFieldRef) value).getFieldRef());
        }
        /* have Ref/Value, which is fine -- not Jimple-specific. */
        return value;
    }
}
Also used : GAndExpr(soot.grimp.internal.GAndExpr) AndExpr(soot.jimple.AndExpr) MulExpr(soot.jimple.MulExpr) GMulExpr(soot.grimp.internal.GMulExpr) ObjExprBox(soot.grimp.internal.ObjExprBox) ExprBox(soot.grimp.internal.ExprBox) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) GNewMultiArrayExpr(soot.grimp.internal.GNewMultiArrayExpr) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) GSpecialInvokeExpr(soot.grimp.internal.GSpecialInvokeExpr) ArrayList(java.util.ArrayList) GGtExpr(soot.grimp.internal.GGtExpr) GtExpr(soot.jimple.GtExpr) GLtExpr(soot.grimp.internal.GLtExpr) LtExpr(soot.jimple.LtExpr) NegExpr(soot.jimple.NegExpr) GNegExpr(soot.grimp.internal.GNegExpr) GeExpr(soot.jimple.GeExpr) GGeExpr(soot.grimp.internal.GGeExpr) UshrExpr(soot.jimple.UshrExpr) GUshrExpr(soot.grimp.internal.GUshrExpr) LeExpr(soot.jimple.LeExpr) GLeExpr(soot.grimp.internal.GLeExpr) GStaticInvokeExpr(soot.grimp.internal.GStaticInvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) GArrayRef(soot.grimp.internal.GArrayRef) ArrayRef(soot.jimple.ArrayRef) GCastExpr(soot.grimp.internal.GCastExpr) CastExpr(soot.jimple.CastExpr) GInstanceFieldRef(soot.grimp.internal.GInstanceFieldRef) InstanceFieldRef(soot.jimple.InstanceFieldRef) GShlExpr(soot.grimp.internal.GShlExpr) ShlExpr(soot.jimple.ShlExpr) GVirtualInvokeExpr(soot.grimp.internal.GVirtualInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) AbstractExprSwitch(soot.jimple.AbstractExprSwitch) GXorExpr(soot.grimp.internal.GXorExpr) XorExpr(soot.jimple.XorExpr) GNeExpr(soot.grimp.internal.GNeExpr) NeExpr(soot.jimple.NeExpr) GLengthExpr(soot.grimp.internal.GLengthExpr) LengthExpr(soot.jimple.LengthExpr) SubExpr(soot.jimple.SubExpr) GSubExpr(soot.grimp.internal.GSubExpr) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) GInterfaceInvokeExpr(soot.grimp.internal.GInterfaceInvokeExpr) GAddExpr(soot.grimp.internal.GAddExpr) AddExpr(soot.jimple.AddExpr) GInstanceOfExpr(soot.grimp.internal.GInstanceOfExpr) InstanceOfExpr(soot.jimple.InstanceOfExpr) OrExpr(soot.jimple.OrExpr) GOrExpr(soot.grimp.internal.GOrExpr) DivExpr(soot.jimple.DivExpr) GDivExpr(soot.grimp.internal.GDivExpr) GCastExpr(soot.grimp.internal.GCastExpr) NegExpr(soot.jimple.NegExpr) UshrExpr(soot.jimple.UshrExpr) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) GCmplExpr(soot.grimp.internal.GCmplExpr) GeExpr(soot.jimple.GeExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) DivExpr(soot.jimple.DivExpr) GLengthExpr(soot.grimp.internal.GLengthExpr) GNewInvokeExpr(soot.grimp.internal.GNewInvokeExpr) GDynamicInvokeExpr(soot.grimp.internal.GDynamicInvokeExpr) SubExpr(soot.jimple.SubExpr) GDivExpr(soot.grimp.internal.GDivExpr) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) GNeExpr(soot.grimp.internal.GNeExpr) OrExpr(soot.jimple.OrExpr) GOrExpr(soot.grimp.internal.GOrExpr) GSubExpr(soot.grimp.internal.GSubExpr) GUshrExpr(soot.grimp.internal.GUshrExpr) GNewArrayExpr(soot.grimp.internal.GNewArrayExpr) GCmpgExpr(soot.grimp.internal.GCmpgExpr) GShlExpr(soot.grimp.internal.GShlExpr) Expr(soot.jimple.Expr) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) GLtExpr(soot.grimp.internal.GLtExpr) GVirtualInvokeExpr(soot.grimp.internal.GVirtualInvokeExpr) LengthExpr(soot.jimple.LengthExpr) GGeExpr(soot.grimp.internal.GGeExpr) ShlExpr(soot.jimple.ShlExpr) GEqExpr(soot.grimp.internal.GEqExpr) NeExpr(soot.jimple.NeExpr) CmpExpr(soot.jimple.CmpExpr) GSpecialInvokeExpr(soot.grimp.internal.GSpecialInvokeExpr) MulExpr(soot.jimple.MulExpr) LtExpr(soot.jimple.LtExpr) ShrExpr(soot.jimple.ShrExpr) GAndExpr(soot.grimp.internal.GAndExpr) CmpgExpr(soot.jimple.CmpgExpr) EqExpr(soot.jimple.EqExpr) NewArrayExpr(soot.jimple.NewArrayExpr) GStaticInvokeExpr(soot.grimp.internal.GStaticInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) GInstanceOfExpr(soot.grimp.internal.GInstanceOfExpr) AndExpr(soot.jimple.AndExpr) LeExpr(soot.jimple.LeExpr) CastExpr(soot.jimple.CastExpr) GXorExpr(soot.grimp.internal.GXorExpr) GAddExpr(soot.grimp.internal.GAddExpr) GInterfaceInvokeExpr(soot.grimp.internal.GInterfaceInvokeExpr) GGtExpr(soot.grimp.internal.GGtExpr) NewExpr(soot.jimple.NewExpr) CmplExpr(soot.jimple.CmplExpr) GMulExpr(soot.grimp.internal.GMulExpr) InstanceOfExpr(soot.jimple.InstanceOfExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) GLeExpr(soot.grimp.internal.GLeExpr) GNegExpr(soot.grimp.internal.GNegExpr) RemExpr(soot.jimple.RemExpr) XorExpr(soot.jimple.XorExpr) GShrExpr(soot.grimp.internal.GShrExpr) GCmpExpr(soot.grimp.internal.GCmpExpr) GRemExpr(soot.grimp.internal.GRemExpr) GNewMultiArrayExpr(soot.grimp.internal.GNewMultiArrayExpr) AddExpr(soot.jimple.AddExpr) GtExpr(soot.jimple.GtExpr) GNewArrayExpr(soot.grimp.internal.GNewArrayExpr) NewArrayExpr(soot.jimple.NewArrayExpr) CmpExpr(soot.jimple.CmpExpr) GCmpExpr(soot.grimp.internal.GCmpExpr) GEqExpr(soot.grimp.internal.GEqExpr) EqExpr(soot.jimple.EqExpr) RemExpr(soot.jimple.RemExpr) GRemExpr(soot.grimp.internal.GRemExpr) ShrExpr(soot.jimple.ShrExpr) GShrExpr(soot.grimp.internal.GShrExpr) GCmpgExpr(soot.grimp.internal.GCmpgExpr) CmpgExpr(soot.jimple.CmpgExpr) NewExpr(soot.jimple.NewExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) GDynamicInvokeExpr(soot.grimp.internal.GDynamicInvokeExpr) GCmplExpr(soot.grimp.internal.GCmplExpr) CmplExpr(soot.jimple.CmplExpr)

Aggregations

CmpExpr (soot.jimple.CmpExpr)24 CmpgExpr (soot.jimple.CmpgExpr)24 CmplExpr (soot.jimple.CmplExpr)24 AddExpr (soot.jimple.AddExpr)22 AndExpr (soot.jimple.AndExpr)22 DivExpr (soot.jimple.DivExpr)22 EqExpr (soot.jimple.EqExpr)22 GeExpr (soot.jimple.GeExpr)22 GtExpr (soot.jimple.GtExpr)22 LeExpr (soot.jimple.LeExpr)22 LtExpr (soot.jimple.LtExpr)22 MulExpr (soot.jimple.MulExpr)22 NeExpr (soot.jimple.NeExpr)22 OrExpr (soot.jimple.OrExpr)22 RemExpr (soot.jimple.RemExpr)22 ShlExpr (soot.jimple.ShlExpr)22 ShrExpr (soot.jimple.ShrExpr)22 SubExpr (soot.jimple.SubExpr)22 UshrExpr (soot.jimple.UshrExpr)22 XorExpr (soot.jimple.XorExpr)22