use of soot.dava.internal.javaRep.DAbruptStmt in project soot by Sable.
the class IfElseSplitter method bodyTargetsLabel.
/*
* Check that label is non null and the string inside is non null... if yes return false
* Check that the given list (sequeneof ASTNodes have no abrupt edge targeting the label.
*
*/
public boolean bodyTargetsLabel(SETNodeLabel label, List<Object> body) {
// no SETNodeLabel is good
if (label == null)
return false;
// SETNodeLabel but with no string is also good
if (label.toString() == null)
return false;
final String strLabel = label.toString();
// go through the body use traversal to find whether there is an abrupt stmt targeting this
Iterator<Object> it = body.iterator();
targeted = false;
while (it.hasNext()) {
ASTNode temp = (ASTNode) it.next();
temp.apply(new DepthFirstAdapter() {
// set targeted to true if DAbruptStmt targets it
public void inStmt(Stmt s) {
// only interested in abrupt stmts
if (!(s instanceof DAbruptStmt))
return;
DAbruptStmt abrupt = (DAbruptStmt) s;
SETNodeLabel label = abrupt.getLabel();
if (label != null && label.toString() != null && label.toString().equals(strLabel)) {
targeted = true;
}
}
});
if (targeted)
break;
}
return targeted;
}
use of soot.dava.internal.javaRep.DAbruptStmt 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