use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class EliminateConditions method eliminate.
public Boolean eliminate(ASTNode node) {
ASTCondition cond = null;
if (node instanceof ASTControlFlowNode)
cond = ((ASTControlFlowNode) node).get_Condition();
else
return null;
if (cond == null || !(cond instanceof ASTUnaryCondition))
return null;
ASTUnaryCondition unary = (ASTUnaryCondition) cond;
Value unaryValue = unary.getValue();
boolean notted = false;
if (unaryValue instanceof DNotExpr) {
notted = true;
unaryValue = ((DNotExpr) unaryValue).getOp();
}
Boolean isBoolean = isBooleanConstant(unaryValue);
if (isBoolean == null) {
// not a constant
return null;
}
boolean trueOrFalse = isBoolean.booleanValue();
if (notted) {
// since it is notted we reverse the booleans
trueOrFalse = !trueOrFalse;
}
AST.apply(finder);
Object temp = finder.getParentOf(node);
if (temp == null)
return null;
ASTNode parent = (ASTNode) temp;
List<Object> subBodies = parent.get_SubBodies();
Iterator<Object> it = subBodies.iterator();
int index = -1;
while (it.hasNext()) {
bodyContainingNode = (List<Object>) it.next();
index = bodyContainingNode.indexOf(node);
if (index < 0) {
bodyContainingNode = null;
} else {
// bound the body containing Node
return new Boolean(trueOrFalse);
}
}
return null;
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class EliminateConditions method caseASTTryNode.
public void caseASTTryNode(ASTTryNode node) {
modified = false;
inASTTryNode(node);
// get try body iterator
Iterator<Object> it = node.get_TryBody().iterator();
Boolean returned = null;
ASTNode temp = null;
while (it.hasNext()) {
temp = (ASTNode) it.next();
// only check condition if this is a control flow node
if (temp instanceof ASTControlFlowNode) {
bodyContainingNode = null;
returned = eliminateForTry(temp);
if (returned != null && canChange(returned, temp))
break;
else
bodyContainingNode = null;
}
temp.apply(this);
}
// end while
boolean changed = change(returned, temp);
if (changed)
modified = true;
// get catch list and apply on the following
// a, type of exception caught ......... NO NEED
// b, local of exception ............... NO NEED
// c, catchBody
List<Object> catchList = node.get_CatchList();
Iterator itBody = null;
it = catchList.iterator();
while (it.hasNext()) {
ASTTryNode.container catchBody = (ASTTryNode.container) it.next();
List body = (List) catchBody.o;
itBody = body.iterator();
returned = null;
temp = null;
// go over the ASTNodes and apply
while (itBody.hasNext()) {
temp = (ASTNode) itBody.next();
// only check condition if this is a control flow node
if (temp instanceof ASTControlFlowNode) {
bodyContainingNode = null;
returned = eliminateForTry(temp);
if (returned != null && canChange(returned, temp))
break;
else
bodyContainingNode = null;
}
temp.apply(this);
}
changed = change(returned, temp);
if (changed)
modified = true;
}
outASTTryNode(node);
if (modified) {
// repeat the whole thing
caseASTTryNode(node);
}
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class EliminateConditions method dealWithSwitchNode.
public void dealWithSwitchNode(ASTSwitchNode node) {
List<Object> indexList = node.getIndexList();
Map<Object, List<Object>> index2BodyList = node.getIndex2BodyList();
Iterator<Object> it = indexList.iterator();
while (it.hasNext()) {
// going through all the cases of the switch statement
Object currentIndex = it.next();
List body = index2BodyList.get(currentIndex);
if (body != null) {
// this body is a list of ASTNodes
Iterator itBody = body.iterator();
Boolean returned = null;
ASTNode temp = null;
while (itBody.hasNext()) {
temp = (ASTNode) itBody.next();
if (temp instanceof ASTControlFlowNode) {
bodyContainingNode = null;
returned = eliminate(temp);
if (returned != null && canChange(returned, temp))
break;
else
bodyContainingNode = null;
}
temp.apply(this);
}
boolean changed = change(returned, temp);
if (changed)
modified = true;
}
// end while changed
}
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class SuperFirstStmtHandler method finalizePreInitMethod.
// method should return false if the PreInit body(ASTBody that is) is empty
// meaning there is no need to create it all
private boolean finalizePreInitMethod() {
// set davaBody...totally redundant but have to do as this is checked by
// toString of ASTMethodNode
newASTPreInitMethod.setDavaBody(newPreInitDavaBody);
// newPreInitDavaBody is the active body
newPreInitDavaBody.getUnits().clear();
newPreInitDavaBody.getUnits().addLast(newASTPreInitMethod);
// check whether there is something in side the ASTBody
// if its empty (maybe there were only declarations and that got removed
// then no point in creating the preInit method
List<Object> subBodies = newASTPreInitMethod.get_SubBodies();
if (subBodies.size() != 1)
return false;
List body = (List) subBodies.get(0);
// body is NOT allowed to contain one declaration node with whatever in
// it
// after that it is NOT allowed all ASTStatement nodes with empty bodies
Iterator it = body.iterator();
// indicating that method is empty
boolean empty = true;
while (it.hasNext()) {
ASTNode tempNode = (ASTNode) it.next();
if (!(tempNode instanceof ASTStatementSequenceNode)) {
// found some node other than stmtseq...body not empty return
// true
empty = false;
break;
}
List<AugmentedStmt> stmts = ((ASTStatementSequenceNode) tempNode).getStatements();
// all declaration stmts are allowed
for (AugmentedStmt as : stmts) {
Stmt s = as.get_Stmt();
if (!(s instanceof DVariableDeclarationStmt)) {
empty = false;
break;
}
}
if (!empty)
break;
}
if (empty) {
// should not be creating the method
return false;
}
// about to return true enter all DavaSuperHandler stmts to make it part
// of the preinit method
createDavaStoreStmts();
return true;
}
use of soot.dava.internal.AST.ASTNode in project soot by Sable.
the class DavaBody method applyBugFixes.
public void applyBugFixes() {
ASTNode AST = (ASTNode) this.getUnits().getFirst();
debug("applyBugFixes", "Applying AST analyzes for method" + this.getMethod().toString());
AST.apply(new ShortcutIfGenerator());
debug("applyBugFixes", "after ShortcutIfGenerator" + G.v().ASTTransformations_modified);
AST.apply(new TypeCastingError());
debug("applyBugFixes", "after TypeCastingError" + G.v().ASTTransformations_modified);
}
Aggregations