Search in sources :

Example 1 with GReturnStmt

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);
}
Also used : GAssignStmt(soot.grimp.internal.GAssignStmt) DVariableDeclarationStmt(soot.dava.internal.javaRep.DVariableDeclarationStmt) SootMethodRef(soot.SootMethodRef) CorruptASTException(soot.dava.CorruptASTException) ArrayList(java.util.ArrayList) JimpleLocal(soot.jimple.internal.JimpleLocal) Local(soot.Local) DecompilationException(soot.dava.DecompilationException) ASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) SootClass(soot.SootClass) GReturnStmt(soot.grimp.internal.GReturnStmt) JimpleLocal(soot.jimple.internal.JimpleLocal) DNewInvokeExpr(soot.dava.internal.javaRep.DNewInvokeExpr) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) PrimType(soot.PrimType) VoidType(soot.VoidType) Iterator(java.util.Iterator) Value(soot.Value) SootMethod(soot.SootMethod) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 BooleanType (soot.BooleanType)1 ByteType (soot.ByteType)1 CharType (soot.CharType)1 DoubleType (soot.DoubleType)1 FloatType (soot.FloatType)1 IntType (soot.IntType)1 Local (soot.Local)1 LongType (soot.LongType)1 PrimType (soot.PrimType)1 RefType (soot.RefType)1 ShortType (soot.ShortType)1 SootClass (soot.SootClass)1 SootMethod (soot.SootMethod)1 SootMethodRef (soot.SootMethodRef)1 Type (soot.Type)1 Value (soot.Value)1 VoidType (soot.VoidType)1