use of soot.grimp.internal.GReturnStmt in project soot by Sable.
the class SuperFirstStmtHandler method createDavaStoreStmts.
/*
* Create the following code:
*
* DavaSuperHandler handler; handler = new DavaSuperHandler(); //code to
* evaluate all args in args2
*
* //evaluate 1st arg in args2 --------- handler.store(firstArg);
*
* //evaluate 2nd arg in args2 --------- handler.store(secondArg);
*
* //AND SO ON TILL ALL ARGS ARE FINISHED
*
* return handler;
*/
private void createDavaStoreStmts() {
List<AugmentedStmt> davaHandlerStmts = new ArrayList<AugmentedStmt>();
// create object of DavaSuperHandler handler
SootClass sootClass = new SootClass("DavaSuperHandler");
Type localType = sootClass.getType();
Local newLocal = new JimpleLocal("handler", localType);
/*
* Create * DavaSuperHandler handler; *
*/
DVariableDeclarationStmt varStmt = null;
varStmt = new DVariableDeclarationStmt(localType, newPreInitDavaBody);
varStmt.addLocal(newLocal);
AugmentedStmt as = new AugmentedStmt(varStmt);
davaHandlerStmts.add(as);
/*
* create * handler = new DavaSuperHandler(); *
*/
// create RHS
DNewInvokeExpr invokeExpr = new DNewInvokeExpr(RefType.v(sootClass), makeMethodRef("DavaSuperHandler", new ArrayList()), new ArrayList());
// create LHS
GAssignStmt initialization = new GAssignStmt(newLocal, invokeExpr);
// add to stmts
davaHandlerStmts.add(new AugmentedStmt(initialization));
/*
* create * handler.store(firstArg); *
*/
// best done in a loop for all args
Iterator typeIt = argsTwoTypes.iterator();
Iterator valIt = argsTwoValues.iterator();
// make reference to a method of name store takes one Object arg belongs
// to DavaSuperHandler
ArrayList tempList = new ArrayList();
// SHOULD BE OBJECT
tempList.add(RefType.v("java.lang.Object"));
SootMethod method = Scene.v().makeSootMethod("store", tempList, VoidType.v());
// set the declaring class of new method to be the DavaSuperHandler
// class
method.setDeclaringClass(sootClass);
SootMethodRef getMethodRef = method.makeRef();
while (typeIt.hasNext() && valIt.hasNext()) {
Type tempType = (Type) typeIt.next();
Value tempVal = (Value) valIt.next();
AugmentedStmt toAdd = createStmtAccordingToType(tempType, tempVal, newLocal, getMethodRef);
davaHandlerStmts.add(toAdd);
}
// sanity check
if (typeIt.hasNext() || valIt.hasNext())
throw new DecompilationException("Error creating DavaHandler stmts");
/*
* code to add defs
*/
List<Local> uniqueLocals = addDefsToLiveVariables();
Iterator<Local> localIt = uniqueLocals.iterator();
while (localIt.hasNext()) {
Local local = localIt.next();
AugmentedStmt toAdd = createStmtAccordingToType(local.getType(), local, newLocal, getMethodRef);
davaHandlerStmts.add(toAdd);
}
// set the mustInitialize field to uniqueLocals so that before Y we can
// assign these locals
mustInitialize = uniqueLocals;
/*
* create * return handler; *
*/
GReturnStmt returnStmt = new GReturnStmt(newLocal);
davaHandlerStmts.add(new AugmentedStmt(returnStmt));
// the appropriate dava handler stmts are all in place within
// davaHandlerStmts
// store them in an ASTSTatementSequenceNode
ASTStatementSequenceNode addedNode = new ASTStatementSequenceNode(davaHandlerStmts);
// add to method body
List<Object> subBodies = newASTPreInitMethod.get_SubBodies();
if (subBodies.size() != 1)
throw new CorruptASTException("ASTMethodNode does not have one subBody");
List<Object> body = (List<Object>) subBodies.get(0);
body.add(addedNode);
newASTPreInitMethod.replaceBody(body);
}
Aggregations