use of soot.dava.internal.AST.ASTCondition in project soot by Sable.
the class CPApplication method changedCondition.
/*
* Given a unary/binary or aggregated condition this method is used to find
* all the useBoxes or locals or fieldref in the case of unary conditions
* and then the set is checked for appropriate substitutions
*/
public ASTCondition changedCondition(ASTCondition cond, CPFlowSet set) {
if (cond instanceof ASTAggregatedCondition) {
ASTCondition left = changedCondition(((ASTAggregatedCondition) cond).getLeftOp(), set);
ASTCondition right = changedCondition(((ASTAggregatedCondition) cond).getRightOp(), set);
((ASTAggregatedCondition) cond).setLeftOp(left);
((ASTAggregatedCondition) cond).setRightOp(right);
// System.out.println("New condition is: "+cond);
return cond;
} else if (cond instanceof ASTUnaryCondition) {
Value val = ((ASTUnaryCondition) cond).getValue();
if (val instanceof Local) {
Object value = set.contains(className, ((Local) val).toString());
if (value != null) {
// System.out.println("if Condition Local "+((Local)val)+"is present in before set with value"+value);
// create constant value for the value and replace this
// local use with the constant value use
Value newValue = CPHelper.createConstant(value);
if (newValue != null) {
// System.out.println("Substituted the local use with the constant value"+newValue);
((ASTUnaryCondition) cond).setValue(newValue);
} else {
// System.out.println("FAILED TO Substitute the local use with the constant value");
}
}
} else if (val instanceof FieldRef) {
FieldRef useField = (FieldRef) val;
SootField usedSootField = useField.getField();
Object value = set.contains(usedSootField.getDeclaringClass().getName(), usedSootField.getName().toString());
if (value != null) {
// System.out.println("if condition FieldRef "+usedSootField+"is present in before set with value"+value);
// create constant value for the value and replace this
// field use with the constant value use
Value newValue = CPHelper.createConstant(value);
if (newValue != null) {
// System.out.println("Substituted the constant field ref use with the constant value"+newValue);
((ASTUnaryCondition) cond).setValue(newValue);
} else {
// System.out.println("FAILED TO Substitute the constant field ref use with the constant value");
}
}
} else {
substituteUses(val.getUseBoxes(), set);
}
// System.out.println("New condition is: "+cond);
return cond;
} else if (cond instanceof ASTBinaryCondition) {
// get uses from binaryCondition
Value val = ((ASTBinaryCondition) cond).getConditionExpr();
substituteUses(val.getUseBoxes(), set);
// System.out.println("New condition is: "+cond);
return cond;
} else {
throw new RuntimeException("Method getUseList in ASTUsesAndDefs encountered unknown condition type");
}
}
use of soot.dava.internal.AST.ASTCondition in project soot by Sable.
the class CPApplication method inASTDoWhileNode.
public void inASTDoWhileNode(ASTDoWhileNode node) {
Object obj = cp.getAfterSet(node);
if (obj == null)
return;
if (!(obj instanceof CPFlowSet))
return;
// after set is a non null CPFlowSet
CPFlowSet afterSet = (CPFlowSet) obj;
ASTCondition cond = node.get_Condition();
// System.out.println("Do While Statement with condition: "+cond);
// System.out.println("After set is: "+afterSet.toString());
changedCondition(cond, afterSet);
}
use of soot.dava.internal.AST.ASTCondition in project soot by Sable.
the class CPApplication method inASTWhileNode.
public void inASTWhileNode(ASTWhileNode node) {
Object obj = cp.getAfterSet(node);
if (obj == null)
return;
if (!(obj instanceof CPFlowSet))
return;
// after set is a non null CPFlowSet
CPFlowSet afterSet = (CPFlowSet) obj;
ASTCondition cond = node.get_Condition();
// System.out.println("While Statement with condition: "+cond);
// System.out.println("After set is: "+afterSet.toString());
changedCondition(cond, afterSet);
}
use of soot.dava.internal.AST.ASTCondition in project soot by Sable.
the class CPApplication method inASTIfElseNode.
public void inASTIfElseNode(ASTIfElseNode node) {
Object obj = cp.getBeforeSet(node);
if (obj == null)
return;
if (!(obj instanceof CPFlowSet))
return;
// before set is a non null CPFlowSet
CPFlowSet beforeSet = (CPFlowSet) obj;
ASTCondition cond = node.get_Condition();
// System.out.println("IfElse Statement with condition: "+cond);
// System.out.println("Before set is: "+beforeSet.toString());
changedCondition(cond, beforeSet);
}
use of soot.dava.internal.AST.ASTCondition 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