use of soot.dava.internal.AST.ASTStatementSequenceNode in project soot by Sable.
the class SuperFirstStmtHandler method removeInit.
/*
* When we havent created the indirection to take care of super bug be it
* cos we dont need to or that we CANT cos of some limitation....should
* atleast remove the jimple this.init call from the statements
*/
public void removeInit() {
// remove constructorUnit from originalASTMethod
List<Object> newBody = new ArrayList<Object>();
List<Object> subBody = originalASTMethod.get_SubBodies();
if (subBody.size() != 1)
return;
List oldBody = (List) subBody.get(0);
Iterator oldIt = oldBody.iterator();
while (oldIt.hasNext()) {
// going through each node in the old body
ASTNode node = (ASTNode) oldIt.next();
// copy the node as is unless its an ASTStatementSequence
if (!(node instanceof ASTStatementSequenceNode)) {
newBody.add(node);
continue;
}
// if the node is an ASTStatementSequenceNode
// copy all stmts unless it is a constructorUnit
ASTStatementSequenceNode seqNode = (ASTStatementSequenceNode) node;
List<AugmentedStmt> newStmtList = new ArrayList<AugmentedStmt>();
for (AugmentedStmt augStmt : seqNode.getStatements()) {
Stmt stmtTemp = augStmt.get_Stmt();
if (stmtTemp == originalConstructorUnit) {
// do nothing
} else {
newStmtList.add(augStmt);
}
}
if (newStmtList.size() != 0) {
newBody.add(new ASTStatementSequenceNode(newStmtList));
}
}
originalASTMethod.replaceBody(newBody);
}
use of soot.dava.internal.AST.ASTStatementSequenceNode in project soot by Sable.
the class SuperFirstStmtHandler method createNewASTPreInitMethod.
/*
* January 23rd New Algorithm Leave originalASTMethod unchanged Clone
* everything and copy only those which are needed in the
* newASTPreInitMethod
*/
private void createNewASTPreInitMethod(ASTStatementSequenceNode initNode) {
List<Object> newPreinitBody = new ArrayList<Object>();
// start adding ASTNodes into newPreinitBody from the
// originalASTMethod's body until we reach initNode
List<Object> originalASTMethodSubBodies = originalASTMethod.get_SubBodies();
if (originalASTMethodSubBodies.size() != 1)
throw new CorruptASTException("size of ASTMethodNode subBody not 1");
List<Object> oldASTBody = (List<Object>) originalASTMethodSubBodies.get(0);
Iterator<Object> it = oldASTBody.iterator();
boolean sanity = false;
while (it.hasNext()) {
// going through originalASTMethodNode's ASTNodes
ASTNode tempNode = (ASTNode) it.next();
// enter only if its not the initNode
if (tempNode instanceof ASTStatementSequenceNode) {
if ((((ASTStatementSequenceNode) tempNode).getStatements()).equals(initNode.getStatements())) {
sanity = true;
break;
} else {
// this was not the initNode so we add
newPreinitBody.add(tempNode);
}
} else {
// not a stmtseq so simply add it
newPreinitBody.add(tempNode);
}
}
if (!sanity) {
// means we never found the initNode which shouldnt happen
throw new DecompilationException("never found the init node");
}
// at this moment newPreinitBody contains all of X except for any stmts
// above the this.init call in the stmtseq node
// copy those
List<AugmentedStmt> newStmts = new ArrayList<AugmentedStmt>();
for (AugmentedStmt augStmt : initNode.getStatements()) {
Stmt stmtTemp = augStmt.get_Stmt();
if (stmtTemp == originalConstructorUnit) {
break;
}
// adding any stmt until constructorUnit into topList for
// newMethodNode
/*
* notice we dont need to clone these because these will be removed
* from the other method from which we are copying these
*/
newStmts.add(augStmt);
}
if (newStmts.size() > 0) {
newPreinitBody.add(new ASTStatementSequenceNode(newStmts));
}
// setDeclarations in newNode
// The LocalVariableCleaner which is called in the end of DavaBody will
// clear up any declarations that are not required
List<AugmentedStmt> newPreinitDeclarations = new ArrayList<AugmentedStmt>();
for (AugmentedStmt as : originalASTMethod.getDeclarations().getStatements()) {
DVariableDeclarationStmt varDecStmt = (DVariableDeclarationStmt) as.get_Stmt();
newPreinitDeclarations.add(new AugmentedStmt((DVariableDeclarationStmt) varDecStmt.clone()));
}
ASTStatementSequenceNode newDecs = new ASTStatementSequenceNode(new ArrayList<AugmentedStmt>());
if (newPreinitDeclarations.size() > 0) {
newDecs = new ASTStatementSequenceNode(newPreinitDeclarations);
// DONT FORGET TO SET THE DECLARATIONS IN THE METHOD ONCE IT IS
// CREATED
// newASTPreInitMethod.setDeclarations(newDecs);
// when we copied the body X the first Node copied was the
// Declarations from the originalASTMethod
// replace that with this new one
newPreinitBody.remove(0);
newPreinitBody.add(0, newDecs);
}
// otherwise super is infact the first stmt
if (newPreinitBody.size() < 1) {
// System.out.println("Method node empty doing nothing returning");
// meaning ASTMethodNode for this method
newASTPreInitMethod = null;
// not created
return;
}
// so we have any declarations followed by body X
// NEXT THING SHOULD BE CODE TO CREATE A DAVAHANDLER AND STORE THE ARGS
// TO SUPER IN IT
// HOWEVER WE WILL DELAY THIS TILL UNTIL WE ARE READY TO FINALIZE the
// PREINIT
// reason for delaying is that even though we know that the body is not
// empty the body
// could be made empty by the transformations which act in the finalize
// method
// have to put the newPreinitBody into an list of subBodies which goes
// into the newASTPreInitMethod
newASTPreInitMethod = new ASTMethodNode(newPreinitBody);
// dont forget to set the declarations
newASTPreInitMethod.setDeclarations(newDecs);
}
Aggregations