Search in sources :

Example 1 with DavaFlowAnalysisException

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();
}
Also used : LongType(soot.LongType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) Local(soot.Local) ByteType(soot.ByteType) FloatType(soot.FloatType) IntType(soot.IntType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) ShortType(soot.ShortType) CharType(soot.CharType) LongType(soot.LongType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) PrimType(soot.PrimType) DavaFlowAnalysisException(soot.dava.DavaFlowAnalysisException) DoubleType(soot.DoubleType) Iterator(java.util.Iterator) Collection(java.util.Collection) PrimType(soot.PrimType) ArrayList(java.util.ArrayList) List(java.util.List) CharType(soot.CharType)

Example 2 with DavaFlowAnalysisException

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);
}
Also used : DavaFlowAnalysisException(soot.dava.DavaFlowAnalysisException)

Example 3 with DavaFlowAnalysisException

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;
}
Also used : DavaFlowAnalysisException(soot.dava.DavaFlowAnalysisException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with DavaFlowAnalysisException

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("");
}
Also used : DavaFlowAnalysisException(soot.dava.DavaFlowAnalysisException) PrimType(soot.PrimType) SootField(soot.SootField)

Aggregations

DavaFlowAnalysisException (soot.dava.DavaFlowAnalysisException)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PrimType (soot.PrimType)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 BooleanType (soot.BooleanType)1 ByteType (soot.ByteType)1 CharType (soot.CharType)1 DoubleType (soot.DoubleType)1 FloatType (soot.FloatType)1 IntType (soot.IntType)1 Local (soot.Local)1 LongType (soot.LongType)1 ShortType (soot.ShortType)1 SootField (soot.SootField)1 Type (soot.Type)1