use of soot.grimp.internal.GCastExpr in project soot by Sable.
the class SuperFirstStmtHandler method getProperCasting.
public Value getProperCasting(Type tempType, DVirtualInvokeExpr tempInvokeExpr) {
if (tempType instanceof RefType) {
// System.out.println("This is a reftype:"+tempType);
return new GCastExpr(tempInvokeExpr, tempType);
} else if (tempType instanceof PrimType) {
PrimType t = (PrimType) tempType;
if (t == BooleanType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Boolean"));
// booleanValue
SootMethod tempMethod = Scene.v().makeSootMethod("booleanValue", new ArrayList(), BooleanType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Boolean"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == ByteType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Byte"));
// byteValue
SootMethod tempMethod = Scene.v().makeSootMethod("byteValue", new ArrayList(), ByteType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Byte"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == CharType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Character"));
// charValue
SootMethod tempMethod = Scene.v().makeSootMethod("charValue", new ArrayList(), CharType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Character"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == DoubleType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Double"));
// doubleValue
SootMethod tempMethod = Scene.v().makeSootMethod("doubleValue", new ArrayList(), DoubleType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Double"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == FloatType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Float"));
// floatValue
SootMethod tempMethod = Scene.v().makeSootMethod("floatValue", new ArrayList(), FloatType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Float"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == IntType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Integer"));
// intValue
SootMethod tempMethod = Scene.v().makeSootMethod("intValue", new ArrayList(), IntType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Integer"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == LongType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Long"));
// longValue
SootMethod tempMethod = Scene.v().makeSootMethod("longValue", new ArrayList(), LongType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Long"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else if (t == ShortType.v()) {
Value tempExpr = new GCastExpr(tempInvokeExpr, RefType.v("java.lang.Short"));
// shortValue
SootMethod tempMethod = Scene.v().makeSootMethod("shortValue", new ArrayList(), ShortType.v());
tempMethod.setDeclaringClass(new SootClass("java.lang.Short"));
SootMethodRef tempMethodRef = tempMethod.makeRef();
return new DVirtualInvokeExpr(tempExpr, tempMethodRef, new ArrayList(), new HashSet<Object>());
} else {
throw new DecompilationException("Unhandle primType:" + tempType);
}
} else {
throw new DecompilationException("The type:" + tempType + " was not a reftye or primtype. PLEASE REPORT.");
}
}
use of soot.grimp.internal.GCastExpr in project soot by Sable.
the class TypeCastingError method inASTStatementSequenceNode.
public void inASTStatementSequenceNode(ASTStatementSequenceNode node) {
for (AugmentedStmt as : node.getStatements()) {
Stmt s = as.get_Stmt();
if (!(s instanceof DefinitionStmt))
continue;
DefinitionStmt ds = (DefinitionStmt) s;
if (myDebug)
System.out.println("Definition stmt" + ds);
ValueBox rightBox = ds.getRightOpBox();
ValueBox leftBox = ds.getLeftOpBox();
Value right = rightBox.getValue();
Value left = leftBox.getValue();
if (!(left.getType() instanceof PrimType && right.getType() instanceof PrimType)) {
// only interested in prim type casting errors
if (myDebug)
System.out.println("\tDefinition stmt does not contain prims no need to modify");
continue;
}
Type leftType = left.getType();
Type rightType = right.getType();
if (myDebug)
System.out.println("Left type is: " + leftType);
if (myDebug)
System.out.println("Right type is: " + rightType);
if (leftType.equals(rightType)) {
if (myDebug)
System.out.println("\tTypes are the same");
if (myDebug)
System.out.println("Right value is of instance" + right.getClass());
}
if (!leftType.equals(rightType)) {
if (myDebug)
System.out.println("\tDefinition stmt has to be modified");
/*
* byte Byte-length integer 8-bit two's complement
* short Short integer 16-bit two's complement
* int Integer 32-bit two's complement
* long Long integer 64-bit two's complement
* float Single-precision floating point 32-bit IEEE 754
* double Double-precision floating point 64-bit IEEE 754
*/
if (leftType instanceof ByteType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof IntType || rightType instanceof LongType || rightType instanceof ShortType)) {
if (DEBUG)
System.out.println("Explicit casting to BYTE required");
rightBox.setValue(new GCastExpr(right, ByteType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof ShortType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof IntType || rightType instanceof LongType)) {
if (DEBUG)
System.out.println("Explicit casting to SHORT required");
rightBox.setValue(new GCastExpr(right, ShortType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof IntType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof LongType)) {
if (myDebug)
System.out.println("Explicit casting to INT required");
rightBox.setValue(new GCastExpr(right, IntType.v()));
if (myDebug)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof LongType && (rightType instanceof DoubleType || rightType instanceof FloatType)) {
if (DEBUG)
System.out.println("Explicit casting to LONG required");
rightBox.setValue(new GCastExpr(right, LongType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
if (leftType instanceof FloatType && rightType instanceof DoubleType) {
if (DEBUG)
System.out.println("Explicit casting to FLOAT required");
rightBox.setValue(new GCastExpr(right, FloatType.v()));
if (DEBUG)
System.out.println("New right expr is " + rightBox.getValue().toString());
continue;
}
}
}
}
Aggregations