Search in sources :

Example 6 with ClassConstant

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

the class ConstraintChecker method caseIfStmt.

public void caseIfStmt(IfStmt stmt) {
    ConditionExpr cond = (ConditionExpr) stmt.getCondition();
    BinopExpr expr = cond;
    Value lv = expr.getOp1();
    Value rv = expr.getOp2();
    TypeNode lop = null;
    TypeNode rop = null;
    // ******** LEFT ********
    if (lv instanceof Local) {
        if (((Local) lv).getType() instanceof IntegerType) {
            lop = ClassHierarchy.v().typeNode(((Local) lv).getType());
        }
    } else if (lv instanceof DoubleConstant) {
    } else if (lv instanceof FloatConstant) {
    } else if (lv instanceof IntConstant) {
        int value = ((IntConstant) lv).value;
        if (value < -32768) {
            lop = ClassHierarchy.v().INT;
        } else if (value < -128) {
            lop = ClassHierarchy.v().SHORT;
        } else if (value < 0) {
            lop = ClassHierarchy.v().BYTE;
        } else if (value < 2) {
            lop = ClassHierarchy.v().R0_1;
        } else if (value < 128) {
            lop = ClassHierarchy.v().R0_127;
        } else if (value < 32768) {
            lop = ClassHierarchy.v().R0_32767;
        } else if (value < 65536) {
            lop = ClassHierarchy.v().CHAR;
        } else {
            lop = ClassHierarchy.v().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 = ClassHierarchy.v().typeNode(((Local) rv).getType());
        }
    } else if (rv instanceof DoubleConstant) {
    } else if (rv instanceof FloatConstant) {
    } else if (rv instanceof IntConstant) {
        int value = ((IntConstant) rv).value;
        if (value < -32768) {
            rop = ClassHierarchy.v().INT;
        } else if (value < -128) {
            rop = ClassHierarchy.v().SHORT;
        } else if (value < 0) {
            rop = ClassHierarchy.v().BYTE;
        } else if (value < 2) {
            rop = ClassHierarchy.v().R0_1;
        } else if (value < 128) {
            rop = ClassHierarchy.v().R0_127;
        } else if (value < 32768) {
            rop = ClassHierarchy.v().R0_32767;
        } else if (value < 65536) {
            rop = ClassHierarchy.v().CHAR;
        } else {
            rop = ClassHierarchy.v().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 (lop != null && rop != null) {
        if (lop.lca_1(rop) == ClassHierarchy.v().TOP) {
            if (fix) {
                if (!lop.hasAncestor_1(ClassHierarchy.v().INT)) {
                    expr.setOp1(insertCast(expr.getOp1(), getTypeForCast(lop), getTypeForCast(rop), stmt));
                }
                if (!rop.hasAncestor_1(ClassHierarchy.v().INT)) {
                    expr.setOp2(insertCast(expr.getOp2(), getTypeForCast(rop), getTypeForCast(lop), stmt));
                }
            } else {
                error("Type Error(17)");
            }
        }
    }
}
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 7 with ClassConstant

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

the class BafASMBackend method getMinJavaVersion.

/*
	 * (non-Javadoc)
	 * 
	 * @see soot.AbstractASMBackend#getMinJavaVersion(soot.SootMethod)
	 */
@Override
protected int getMinJavaVersion(SootMethod method) {
    final BafBody body = getBafBody(method);
    int minVersion = Options.java_version_1_1;
    // http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/87ee5ee27509/src/share/vm/classfile/classFileParser.cpp
    if (method.getDeclaringClass().isInterface()) {
        if (method.isStatic() && !method.isStaticInitializer()) {
            return Options.java_version_1_8;
        }
    }
    for (Unit u : body.getUnits()) {
        if (u instanceof DynamicInvokeInst) {
            return Options.java_version_1_7;
        }
        if (u instanceof PushInst) {
            if (((PushInst) u).getConstant() instanceof ClassConstant) {
                minVersion = Options.java_version_1_5;
            }
        }
    }
    return minVersion;
}
Also used : Unit(soot.Unit) ClassConstant(soot.jimple.ClassConstant)

Example 8 with ClassConstant

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

the class NullnessAnalysis method handleRefTypeAssignment.

private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) {
    Value left = assignStmt.getLeftOp();
    Value right = assignStmt.getRightOp();
    // unbox casted value
    if (right instanceof JCastExpr) {
        JCastExpr castExpr = (JCastExpr) right;
        right = castExpr.getOp();
    }
    // if we have a definition (assignment) statement to a ref-like type, handle it,
    if (isAlwaysNonNull(right) || right instanceof NewExpr || right instanceof NewArrayExpr || right instanceof NewMultiArrayExpr || right instanceof ThisRef || right instanceof StringConstant || right instanceof ClassConstant || right instanceof CaughtExceptionRef) {
        // if we assign new... or @this, the result is non-null
        out.put(left, NON_NULL);
    } else if (right == NullConstant.v()) {
        // if we assign null, well, it's null
        out.put(left, NULL);
    } else if (left instanceof Local && right instanceof Local) {
        out.put(left, out.get(right));
    } else if (left instanceof Local && right instanceof PhiExpr) {
        handlePhiExpr(out, left, (PhiExpr) right);
    } else {
        out.put(left, TOP);
    }
}
Also used : CaughtExceptionRef(soot.jimple.CaughtExceptionRef) NewArrayExpr(soot.jimple.NewArrayExpr) ThisRef(soot.jimple.ThisRef) PhiExpr(soot.shimple.PhiExpr) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) Value(soot.Value) NewExpr(soot.jimple.NewExpr) Local(soot.Local) JCastExpr(soot.jimple.internal.JCastExpr) StringConstant(soot.jimple.StringConstant) ClassConstant(soot.jimple.ClassConstant)

Example 9 with ClassConstant

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

the class StmtVisitor method preAllocateMonitorConsts.

/**
 * Pre-allocates and locks registers for the constants used in monitor
 * expressions
 *
 * @param monitorConsts
 *            The set of monitor constants fow which to assign fixed
 *            registers
 */
public void preAllocateMonitorConsts(Set<ClassConstant> monitorConsts) {
    for (ClassConstant c : monitorConsts) {
        Register lhsReg = regAlloc.asImmediate(c, constantV);
        regAlloc.lockRegister(lhsReg);
        monitorRegs.put(c, lhsReg);
    }
}
Also used : ClassConstant(soot.jimple.ClassConstant)

Example 10 with ClassConstant

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

the class CollectConstants method isSuitableClassToAddFieldConstant.

private boolean isSuitableClassToAddFieldConstant(SootClass sc, Constant constant) {
    if (sc.isInterface()) {
        return false;
    }
    if (constant instanceof ClassConstant) {
        ClassConstant classConstant = (ClassConstant) constant;
        RefType type = (RefType) classConstant.toSootType();
        SootClass classFromConstant = type.getSootClass();
        Hierarchy hierarchy = Scene.v().getActiveHierarchy();
        return hierarchy.isVisible(sc, classFromConstant);
    }
    return true;
}
Also used : RefType(soot.RefType) Hierarchy(soot.Hierarchy) SootClass(soot.SootClass) ClassConstant(soot.jimple.ClassConstant)

Aggregations

ClassConstant (soot.jimple.ClassConstant)16 Value (soot.Value)10 Local (soot.Local)9 IntConstant (soot.jimple.IntConstant)9 StringConstant (soot.jimple.StringConstant)9 DoubleConstant (soot.jimple.DoubleConstant)8 FloatConstant (soot.jimple.FloatConstant)8 LongConstant (soot.jimple.LongConstant)8 NullConstant (soot.jimple.NullConstant)8 BinopExpr (soot.jimple.BinopExpr)6 RefType (soot.RefType)5 Type (soot.Type)5 Unit (soot.Unit)5 ArrayType (soot.ArrayType)4 IntegerType (soot.IntegerType)4 NullType (soot.NullType)4 SootClass (soot.SootClass)4 CastExpr (soot.jimple.CastExpr)4 Body (soot.Body)3 SootMethod (soot.SootMethod)3