use of soot.dava.DavaFlowAnalysisException in project soot by Sable.
the class CP method createInitialInput.
/*
* constant fields added with KNOWN CONSTANT VALUE formals added with TOP
* locals added with 0 other fields IGNORED
*/
public void createInitialInput() {
initialInput = new ArrayList<CPTuple>();
// adding constant fields
initialInput.addAll(constantFieldTuples);
// String className =
// analyze.getDavaBody().getMethod().getDeclaringClass().getName();
// adding formals
formals = new ArrayList<CPTuple>();
// System.out.println("Adding following formals: with TOP");
Collection col = methodNode.getDavaBody().get_ParamMap().values();
Iterator it = col.iterator();
while (it.hasNext()) {
Object temp = it.next();
if (temp instanceof Local) {
Local tempLocal = (Local) temp;
if (!(tempLocal.getType() instanceof PrimType))
continue;
CPVariable newVar = new CPVariable(tempLocal);
// new tuple set to top since this is a formal and we dont know
// what value we will get into it
CPTuple newTuple = new CPTuple(localClassName, newVar, true);
initialInput.add(newTuple);
formals.add(newTuple);
// System.out.print("\t"+tempLocal.getName());
}
}
// System.out.println();
// adding locals
List decLocals = methodNode.getDeclaredLocals();
it = decLocals.iterator();
locals = new ArrayList<CPTuple>();
// System.out.println("Adding following locals with default values:");
while (it.hasNext()) {
Object temp = it.next();
if (temp instanceof Local) {
Local tempLocal = (Local) temp;
Type localType = tempLocal.getType();
if (!(localType instanceof PrimType))
continue;
CPVariable newVar = new CPVariable(tempLocal);
// store the default value into this object
Object value;
// depending on its type
if (localType instanceof BooleanType)
value = new Boolean(false);
else if (localType instanceof ByteType)
value = new Integer(0);
else if (localType instanceof CharType)
value = new Integer(0);
else if (localType instanceof DoubleType)
value = new Double(0);
else if (localType instanceof FloatType)
value = new Float(0);
else if (localType instanceof IntType)
value = new Integer(0);
else if (localType instanceof LongType)
value = new Long(0);
else if (localType instanceof ShortType)
value = new Integer(0);
else
throw new DavaFlowAnalysisException("Unknown PrimType");
CPTuple newTuple = new CPTuple(localClassName, newVar, value);
/*
* Commenting the next line since we dont want initial Input to
* have any locals in it all locals are considered bottom
* initially
*/
// initialInput.add(newTuple);
locals.add(newTuple);
// System.out.print("\t"+tempLocal.getName());
}
// was a local
}
// System.out.println();
}
use of soot.dava.DavaFlowAnalysisException in project soot by Sable.
the class CPTuple method setValue.
public void setValue(Object constant) {
// System.out.println("here currently valued as"+this.constant);
if (!(constant instanceof Float || constant instanceof Double || constant instanceof Long || constant instanceof Boolean || constant instanceof Integer))
throw new DavaFlowAnalysisException("argument to setValue not an acceptable constant value...report to developer");
this.constant = constant;
TOP = new Boolean(false);
}
use of soot.dava.DavaFlowAnalysisException in project soot by Sable.
the class CP method processASTIfElseNode.
@Override
public DavaFlowSet processASTIfElseNode(ASTIfElseNode node, DavaFlowSet input) {
if (DEBUG_IF)
System.out.println("Processing IF-ELSE node using over-ridden process if method" + input.toString());
;
if (!(input instanceof CPFlowSet)) {
throw new DavaFlowAnalysisException("not a flow set");
}
// get the subBodies
List<Object> subBodies = node.get_SubBodies();
if (subBodies.size() != 2) {
throw new RuntimeException("processASTIfElseNode called with a node without two subBodies");
}
// we know there is only two subBodies
List subBodyOne = (List) subBodies.get(0);
List subBodyTwo = (List) subBodies.get(1);
// process Condition
input = processCondition(node.get_Condition(), input);
// the current input flowset is sent to both branches
DavaFlowSet clonedInput = cloneFlowSet(input);
CPTuple tuple = checkForValueHints(node.get_Condition(), (CPFlowSet) clonedInput, false);
if (tuple != null) {
// if not null, is a belief going into the if branch simply add it
// into the input set
// System.out.println(">>>>>Adding tuple because of condition into if branch"+tuple.toString());
((CPFlowSet) clonedInput).addIfNotPresentButDontUpdate(tuple);
}
DavaFlowSet output1 = process(subBodyOne, clonedInput);
clonedInput = cloneFlowSet(input);
CPTuple tuple1 = checkForValueHints(node.get_Condition(), (CPFlowSet) clonedInput, true);
if (tuple1 != null) {
// if not null, is a belief going into the else branch simply add it
// into the input set
// System.out.println(">>>>>Adding tuple because of condition into else branch"+tuple1.toString());
((CPFlowSet) clonedInput).addIfNotPresentButDontUpdate(tuple1);
}
DavaFlowSet output2 = process(subBodyTwo, clonedInput);
if (DEBUG_IF) {
System.out.println("\n\n IF-ELSE INPUTS TO MERGE ARE input (if):" + output1.toString() + " else:" + output2.toString() + "\n\n\n");
}
DavaFlowSet temp = merge(output1, output2);
// notice we handle breaks only once since these are breaks to the same
// label or same node
String label = getLabel(node);
output1 = handleBreak(label, temp, node);
if (DEBUG_IF) {
System.out.println("Exiting ifelse node" + output1.toString());
;
}
return output1;
}
use of soot.dava.DavaFlowAnalysisException in project soot by Sable.
the class CP method createConstantFieldsList.
/*
* Uses the results of the ConstantValueFinder to create a list of
* constantField CPTuple
*/
private void createConstantFieldsList(HashMap<String, Object> constantFields, HashMap<String, SootField> classNameFieldNameToSootFieldMapping) {
constantFieldTuples = new ArrayList<CPTuple>();
Iterator<String> it = constantFields.keySet().iterator();
// System.out.println("Adding constant fields to initial set: ");
while (it.hasNext()) {
String combined = it.next();
int temp = combined.indexOf(ConstantFieldValueFinder.combiner, 0);
if (temp > 0) {
String className = combined.substring(0, temp);
// String fieldName = combined.substring(temp+
// ConstantFieldValueFinder.combiner.length());
SootField field = classNameFieldNameToSootFieldMapping.get(combined);
if (!(field.getType() instanceof PrimType)) {
// we only care about PrimTypes
continue;
}
// object type is double float long boolean or integer
Object value = constantFields.get(combined);
CPVariable var = new CPVariable(field);
CPTuple newTuples = new CPTuple(className, var, value);
constantFieldTuples.add(newTuples);
// System.out.print("Class: "+className +
// " Field: "+fieldName+" Value: "+value+" ");
} else {
throw new DavaFlowAnalysisException("Second argument of VariableValuePair not a variable");
}
}
// System.out.println("");
}
Aggregations