use of soot.dava.internal.AST.ASTControlFlowNode in project soot by Sable.
the class EliminateConditions method normalRetrieving.
public void normalRetrieving(ASTNode node) {
modified = false;
if (node instanceof ASTSwitchNode) {
do {
modified = false;
dealWithSwitchNode((ASTSwitchNode) node);
} while (modified);
return;
}
// from the Node get the subBodes
Iterator<Object> sbit = node.get_SubBodies().iterator();
while (sbit.hasNext()) {
List subBody = (List) sbit.next();
Iterator it = subBody.iterator();
ASTNode temp = null;
Boolean returned = 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 = eliminate(temp);
if (returned != null && canChange(returned, temp)) {
break;
} else {
if (DEBUG)
System.out.println("returned is null" + temp.getClass());
bodyContainingNode = null;
}
}
temp.apply(this);
}
// end while going through nodes in subBody
boolean changed = change(returned, temp);
if (changed)
modified = true;
}
if (modified) {
// repeat the whole thing
normalRetrieving(node);
}
}
use of soot.dava.internal.AST.ASTControlFlowNode 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.ASTControlFlowNode 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.ASTControlFlowNode 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.ASTControlFlowNode in project soot by Sable.
the class EliminateConditions method eliminateForTry.
public Boolean eliminateForTry(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;
if (!(temp instanceof ASTTryNode))
throw new RuntimeException("eliminateTry called when parent was not a try node");
ASTTryNode parent = (ASTTryNode) temp;
List<Object> tryBody = parent.get_TryBody();
int index = tryBody.indexOf(node);
if (index >= 0) {
// bound the body containing Node
bodyContainingNode = tryBody;
return new Boolean(trueOrFalse);
}
List<Object> catchList = parent.get_CatchList();
Iterator<Object> it = catchList.iterator();
while (it.hasNext()) {
ASTTryNode.container catchBody = (ASTTryNode.container) it.next();
List<Object> body = (List<Object>) catchBody.o;
index = body.indexOf(node);
if (index >= 0) {
// bound the body containing Node
bodyContainingNode = body;
return new Boolean(trueOrFalse);
}
}
return null;
}
Aggregations