use of soot.dava.DecompilationException in project soot by Sable.
the class SuperFirstStmtHandler method createCallToSuper.
/*
* super( (CAST-TYPE)handler.get(0),
* ((CAST-TYPE)handler.get(1)).CONVERSION(), .......);
*
* returns false if we cant create the call to super
*/
private boolean createCallToSuper() {
// check that whether this call is even to be made or not
if (originalConstructorExpr == null) {
// System.out.println("originalConstructorExpr is null");
return false;
}
// System.out.println("ConstructorExpr is non null...call to super has
// to be made");
// find the parent class of the current method being decompiled
SootClass parentClass = originalSootClass.getSuperclass();
// super method
if (!(parentClass.declaresMethod("<init>", argsTwoTypes))) {
// this name and ParamTypes");
return false;
}
SootMethod superConstructor = parentClass.getMethod("<init>", argsTwoTypes);
// create InstanceInvokeExpr
// need Value base: this??
// need SootMethod Ref...make sootmethoref of the super constructor
// found
// need list of thisLocals.........try empty arrayList since it doesnt
// seem to be used anywhere??
List argsForConstructor = new ArrayList();
int count = 0;
// have to make arg as "handler.get(0)"
// 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);
List tempArgList = null;
Iterator typeIt = argsTwoTypes.iterator();
while (typeIt.hasNext()) {
Type tempType = (Type) typeIt.next();
// takes care
DIntConstant arg = DIntConstant.v(count, IntType.v());
// of the
// index
count++;
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);
// the above virtualInvokeExpr is one of the args for the
// constructor
argsForConstructor.add(toAddExpr);
}
mustInitializeIndex = count;
// we are done with creating all necessary args to the virtualinvoke
// expr constructor
DVirtualInvokeExpr virtualInvoke = new DVirtualInvokeExpr(originalConstructorExpr.getBase(), superConstructor.makeRef(), argsForConstructor, new HashSet<Object>());
// set the constructors constructorExpr
newConstructorDavaBody.set_ConstructorExpr(virtualInvoke);
// create Invoke Stmt with virtualInvoke as the expression
GInvokeStmt s = new GInvokeStmt(virtualInvoke);
newConstructorDavaBody.set_ConstructorUnit(s);
// return true if super call created
return true;
}
use of soot.dava.DecompilationException in project soot by Sable.
the class UselessAbruptStmtRemover method caseASTStatementSequenceNode.
public void caseASTStatementSequenceNode(ASTStatementSequenceNode node) {
Iterator<AugmentedStmt> it = node.getStatements().iterator();
AugmentedStmt remove = null;
ASTLabeledNode target = null;
while (it.hasNext()) {
AugmentedStmt as = it.next();
Stmt s = as.get_Stmt();
// we only care about break and continue stmts
if (!(s instanceof DAbruptStmt)) {
continue;
}
DAbruptStmt abrupt = (DAbruptStmt) s;
String label = abrupt.getLabel().toString();
if (label == null) {
// analysis with implicit abrupt flow but not needed currently
continue;
}
if (it.hasNext()) {
// afterwards...that is for sure dead code
throw new DecompilationException("Dead code detected. Report to developer");
}
// get the target node
Object temp = mapper.getTarget(label);
if (temp == null) {
continue;
// throw new DecompilationException("Could not find target for abrupt stmt"+abrupt.toString());
}
target = (ASTLabeledNode) temp;
// will need to find parents of ancestors see if we need to initialize the finder
if (finder == null) {
finder = new ASTParentNodeFinder();
methodNode.apply(finder);
}
if (DEBUG)
System.out.println("Starting useless check for abrupt stmt: " + abrupt);
// start condition is that ancestor is the stmt seq node
ASTNode ancestor = node;
while (ancestor != target) {
Object tempParent = finder.getParentOf(ancestor);
if (tempParent == null)
throw new DecompilationException("Parent found was null!!. Report to Developer");
ASTNode ancestorsParent = (ASTNode) tempParent;
if (DEBUG)
System.out.println("\tCurrent ancestorsParent has type" + ancestorsParent.getClass());
// ancestor should be last child of ancestorsParent
if (!checkChildLastInParent(ancestor, ancestorsParent)) {
if (DEBUG)
System.out.println("\t\tCurrent ancestorParent has more children after this ancestor");
// return from the method since this is the last stmt and we cant do anything
return;
}
// ancestorsParent should not be a loop of any kind OR A SWITCH
if (ancestorsParent instanceof ASTWhileNode || ancestorsParent instanceof ASTDoWhileNode || ancestorsParent instanceof ASTUnconditionalLoopNode || ancestorsParent instanceof ASTForLoopNode || ancestorsParent instanceof ASTSwitchNode) {
if (DEBUG)
System.out.println("\t\tAncestorsParent is a loop shouldnt remove abrupt stmt");
return;
}
ancestor = ancestorsParent;
}
if (DEBUG)
System.out.println("\tGot to target without returning means we can remove stmt");
remove = as;
}
if (remove != null) {
List<AugmentedStmt> stmts = node.getStatements();
stmts.remove(remove);
if (DEBUG)
System.out.println("\tRemoved abrupt stmt");
if (target != null) {
if (DEBUG)
System.out.println("Invoking findAndKill on the target");
UselessLabelFinder.v().findAndKill(target);
}
// TODO what if we just emptied a stmt seq block??
// not doing this for the moment
// set modified flag make finder null
G.v().ASTTransformations_modified = true;
finder = null;
}
}
Aggregations