use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class DavaStaticBlockCleaner method staticBlockInlining.
// invoked by the PackManager
public void staticBlockInlining(SootClass sootClass) {
this.sootClass = sootClass;
// the clinit method gets converted into the static block which could initialize the final variable
if (!sootClass.declaresMethod("void <clinit>()")) {
// System.out.println("no clinit");
return;
}
SootMethod clinit = sootClass.getMethod("void <clinit>()");
// retireve the active body
if (!clinit.hasActiveBody())
throw new RuntimeException("method " + clinit.getName() + " has no active body!");
Body clinitBody = clinit.getActiveBody();
Chain units = ((DavaBody) clinitBody).getUnits();
if (units.size() != 1) {
throw new RuntimeException("DavaBody AST doesn't have single root.");
}
ASTNode AST = (ASTNode) units.getFirst();
if (!(AST instanceof ASTMethodNode))
throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode");
// running methodCallFinder on the Clinit method
AST.apply(new MethodCallFinder(this));
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class IfElseSplitter method getLastStmt.
/*
* Given a list of ASTNodes see if the last astnode is a StatementSequenceNode
* if not return null
* else, return the last statement in this node
*/
public Stmt getLastStmt(List<Object> body) {
if (body.size() == 0)
return null;
ASTNode lastNode = (ASTNode) body.get(body.size() - 1);
if (!(lastNode instanceof ASTStatementSequenceNode))
return null;
ASTStatementSequenceNode stmtNode = (ASTStatementSequenceNode) lastNode;
List<AugmentedStmt> stmts = stmtNode.getStatements();
if (stmts.size() == 0)
return null;
AugmentedStmt lastStmt = stmts.get(stmts.size() - 1);
return lastStmt.get_Stmt();
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class DavaPrinter method printStatementsInBody.
private void printStatementsInBody(Body body, java.io.PrintWriter out) {
if (Options.v().verbose())
System.out.println("Printing " + body.getMethod().getName());
Chain<Unit> units = ((DavaBody) body).getUnits();
if (units.size() != 1) {
throw new RuntimeException("DavaBody AST doesn't have single root.");
}
UnitPrinter up = new DavaUnitPrinter((DavaBody) body);
((ASTNode) units.getFirst()).toString(up);
out.print(up.toString());
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class SuperFirstStmtHandler method createNewASTConstructor.
public void createNewASTConstructor(ASTStatementSequenceNode initNode) {
List<Object> newConstructorBody = new ArrayList<Object>();
List<AugmentedStmt> newStmts = new ArrayList<AugmentedStmt>();
/*
* add any definitions to live variables that might be in body X
*/
// we have gotten argsTwoType size() out of the handler so thats the
// index count
// mustInitialize has the live variables that need to be initialized
// create new ReftType for DavaSuperHandler
RefType type = (new SootClass("DavaSuperHandler")).getType();
// make JimpleLocal to be used in each arg
// takes care of
Local jimpleLocal = new JimpleLocal("handler", type);
// handler
// make reference to a method of name get takes one int arg belongs to
// DavaSuperHandler
ArrayList tempList = new ArrayList();
tempList.add(IntType.v());
SootMethodRef getMethodRef = makeMethodRef("get", tempList);
// Iterator typeIt = argsTwoTypes.iterator();
if (mustInitialize != null) {
Iterator<Local> initIt = mustInitialize.iterator();
while (initIt.hasNext()) {
Local initLocal = initIt.next();
Type tempType = initLocal.getType();
// takes
DIntConstant arg = DIntConstant.v(mustInitializeIndex, IntType.v());
// care
// of
// the
// index
mustInitializeIndex++;
ArrayList tempArgList = new ArrayList();
tempArgList.add(arg);
DVirtualInvokeExpr tempInvokeExpr = new DVirtualInvokeExpr(jimpleLocal, getMethodRef, tempArgList, new HashSet<Object>());
// NECESASARY CASTING OR RETRIEVAL OF PRIM TYPES TO BE DONE HERE
Value toAddExpr = getProperCasting(tempType, tempInvokeExpr);
if (toAddExpr == null)
throw new DecompilationException("UNABLE TO CREATE TOADDEXPR:" + tempType);
// need to create a def stmt with the local on the left and
// toAddExpr on the right
GAssignStmt assign = new GAssignStmt(initLocal, toAddExpr);
newStmts.add(new AugmentedStmt(assign));
}
}
// add any statements following the this.<init> statement
Iterator<AugmentedStmt> it = initNode.getStatements().iterator();
while (it.hasNext()) {
AugmentedStmt augStmt = (AugmentedStmt) it.next();
Stmt stmtTemp = augStmt.get_Stmt();
if (stmtTemp == originalConstructorUnit) {
break;
}
}
while (it.hasNext()) {
/*
* notice we dont need to clone these because these will be removed
* from the other method from which we are copying these
*/
newStmts.add(it.next());
}
if (newStmts.size() > 0) {
newConstructorBody.add(new ASTStatementSequenceNode(newStmts));
}
// adding body Y now
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> itOld = oldASTBody.iterator();
boolean sanity = false;
while (itOld.hasNext()) {
// going through originalASTMethodNode's ASTNodes
ASTNode tempNode = (ASTNode) itOld.next();
// enter only if its not the initNode
if (tempNode instanceof ASTStatementSequenceNode) {
if ((((ASTStatementSequenceNode) tempNode).getStatements()).equals(initNode.getStatements())) {
sanity = true;
break;
}
}
}
if (!sanity) {
// means we never found the initNode which shouldnt happen
throw new DecompilationException("never found the init node");
}
// Y are all the nodes following the initNode
while (itOld.hasNext()) {
newConstructorBody.add(itOld.next());
}
// setDeclarations in newNode
// The LocalVariableCleaner which is called in the end of DavaBody will
// clear up any declarations that are not required
List<AugmentedStmt> newConstructorDeclarations = new ArrayList<AugmentedStmt>();
for (AugmentedStmt as : originalASTMethod.getDeclarations().getStatements()) {
DVariableDeclarationStmt varDecStmt = (DVariableDeclarationStmt) as.get_Stmt();
newConstructorDeclarations.add(new AugmentedStmt((DVariableDeclarationStmt) varDecStmt.clone()));
}
ASTStatementSequenceNode newDecs = new ASTStatementSequenceNode(new ArrayList<AugmentedStmt>());
if (newConstructorDeclarations.size() > 0) {
newDecs = new ASTStatementSequenceNode(newConstructorDeclarations);
// DONT FORGET TO SET THE DECLARATIONS IN THE METHOD ONCE IT IS
// CREATED
// newASTConstructorMethod.setDeclarations(newDecs);
// declarations are always the first element
newConstructorBody.add(0, newDecs);
}
// so we have any declarations followed by body Y
// have to put the newConstructorBody into an list of subBodies which
// goes into the newASTConstructorMethod
newASTConstructorMethod = new ASTMethodNode(newConstructorBody);
// dont forget to set the declarations
newASTConstructorMethod.setDeclarations(newDecs);
}
use of soot.dava.internal.AST.ASTNode 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);
}
Aggregations