use of soot.dava.internal.javaRep.DSpecialInvokeExpr in project soot by Sable.
the class DavaBody method javafy_invoke_expr.
private void javafy_invoke_expr(ValueBox vb) {
InvokeExpr ie = (InvokeExpr) vb.getValue();
String className = ie.getMethodRef().declaringClass().toString();
String packageName = ie.getMethodRef().declaringClass().getJavaPackageName();
String classPackageName = packageName;
if (className.lastIndexOf('.') > 0) {
// 0 doesnt make sense
classPackageName = className.substring(0, className.lastIndexOf('.'));
}
if (!packageName.equals(classPackageName))
throw new DecompilationException("Unable to retrieve package name for identifier. Please report to developer.");
addToImportList(className);
for (int i = 0; i < ie.getArgCount(); i++) {
Value arg = ie.getArg(i);
if (arg instanceof IntConstant)
ie.getArgBox(i).setValue(DIntConstant.v(((IntConstant) arg).value, ie.getMethodRef().parameterType(i)));
else
javafy(ie.getArgBox(i));
}
if (ie instanceof InstanceInvokeExpr) {
javafy(((InstanceInvokeExpr) ie).getBaseBox());
if (ie instanceof VirtualInvokeExpr) {
VirtualInvokeExpr vie = (VirtualInvokeExpr) ie;
vb.setValue(new DVirtualInvokeExpr(vie.getBase(), vie.getMethodRef(), vie.getArgs(), thisLocals));
} else if (ie instanceof SpecialInvokeExpr) {
SpecialInvokeExpr sie = (SpecialInvokeExpr) ie;
vb.setValue(new DSpecialInvokeExpr(sie.getBase(), sie.getMethodRef(), sie.getArgs()));
} else if (ie instanceof InterfaceInvokeExpr) {
InterfaceInvokeExpr iie = (InterfaceInvokeExpr) ie;
vb.setValue(new DInterfaceInvokeExpr(iie.getBase(), iie.getMethodRef(), iie.getArgs()));
} else
throw new RuntimeException("InstanceInvokeExpr " + ie + " not javafied correctly");
} else if (ie instanceof StaticInvokeExpr) {
StaticInvokeExpr sie = (StaticInvokeExpr) ie;
if (sie instanceof NewInvokeExpr) {
NewInvokeExpr nie = (NewInvokeExpr) sie;
RefType rt = nie.getBaseType();
className = rt.getSootClass().toString();
packageName = rt.getSootClass().getJavaPackageName();
classPackageName = packageName;
if (className.lastIndexOf('.') > 0) {
// 0 doesnt make sense
classPackageName = className.substring(0, className.lastIndexOf('.'));
}
if (!packageName.equals(classPackageName))
throw new DecompilationException("Unable to retrieve package name for identifier. Please report to developer.");
addToImportList(className);
vb.setValue(new DNewInvokeExpr((RefType) nie.getType(), nie.getMethodRef(), nie.getArgs()));
} else {
SootMethodRef methodRef = sie.getMethodRef();
className = methodRef.declaringClass().toString();
packageName = methodRef.declaringClass().getJavaPackageName();
classPackageName = packageName;
if (className.lastIndexOf('.') > 0) {
// 0 doesnt make sense
classPackageName = className.substring(0, className.lastIndexOf('.'));
}
if (!packageName.equals(classPackageName))
throw new DecompilationException("Unable to retrieve package name for identifier. Please report to developer.");
addToImportList(className);
// addPackage(methodRef.declaringClass().getJavaPackageName());
vb.setValue(new DStaticInvokeExpr(methodRef, sie.getArgs()));
}
} else
throw new RuntimeException("InvokeExpr " + ie + " not javafied correctly");
}
use of soot.dava.internal.javaRep.DSpecialInvokeExpr in project soot by Sable.
the class SuperFirstStmtHandler method changeOriginalAST.
/*
* Remove the entire body and replace with the statement this(args1,
* B.preInit(args1));
*/
public boolean changeOriginalAST() {
// argsOne followed by a method call to preInit
if (originalConstructorExpr == null) {
// System.out.println("originalConstructorExpr is null");
return false;
}
List thisArgList = new ArrayList();
thisArgList.addAll(argsOneValues);
DStaticInvokeExpr newInvokeExpr = new DStaticInvokeExpr(newSootPreInitMethod.makeRef(), argsOneValues);
thisArgList.add(newInvokeExpr);
// the methodRef of themethod to be called is the new constructor we
// created
InstanceInvokeExpr tempExpr = new DSpecialInvokeExpr(originalConstructorExpr.getBase(), newConstructor.makeRef(), thisArgList);
originalDavaBody.set_ConstructorExpr(tempExpr);
// create Invoke Stmt with tempExpr as the expression
GInvokeStmt s = new GInvokeStmt(tempExpr);
originalDavaBody.set_ConstructorUnit(s);
// originalASTMethod has to be made empty
originalASTMethod.setDeclarations(new ASTStatementSequenceNode(new ArrayList<AugmentedStmt>()));
originalASTMethod.replaceBody(new ArrayList<Object>());
return true;
}
Aggregations