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)");
}
}
}
}
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;
}
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);
}
}
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);
}
}
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;
}
Aggregations