Search in sources :

Example 1 with CPFlowSet

use of soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet in project soot by Sable.

the class CPApplication method inASTForLoopNode.

public void inASTForLoopNode(ASTForLoopNode node) {
    /*
		 * For the init part we should actually use the before set for each init
		 * stmt
		 */
    for (AugmentedStmt as : node.getInit()) {
        Stmt s = as.get_Stmt();
        List useBoxes = s.getUseBoxes();
        Object obj = cp.getBeforeSet(s);
        if (obj == null)
            continue;
        if (!(obj instanceof CPFlowSet))
            continue;
        // before set is a non null CPFlowSet
        CPFlowSet beforeSet = (CPFlowSet) obj;
        // System.out.println("Init Statement: "+s);
        // System.out.println("Before set is: "+beforeSet.toString());
        /*
			 * get all use boxes see if their value is determined from the
			 * before set if yes replace them
			 */
        substituteUses(useBoxes, beforeSet);
    }
    // get after set for the condition and update
    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;
    // conditon
    ASTCondition cond = node.get_Condition();
    // System.out.println("For Loop with condition: "+cond);
    // System.out.println("After set is: "+afterSet.toString());
    changedCondition(cond, afterSet);
    // update
    for (AugmentedStmt as : node.getUpdate()) {
        Stmt s = as.get_Stmt();
        List useBoxes = s.getUseBoxes();
        // System.out.println("For update Statement: "+s);
        // System.out.println("After set is: "+afterSet.toString());
        /*
			 * get all use boxes see if their value is determined from the
			 * before set if yes replace them
			 */
        substituteUses(useBoxes, afterSet);
    }
}
Also used : List(java.util.List) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) ASTCondition(soot.dava.internal.AST.ASTCondition) CPFlowSet(soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) Stmt(soot.jimple.Stmt)

Example 2 with CPFlowSet

use of soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet in project soot by Sable.

the class CPApplication method inASTStatementSequenceNode.

public void inASTStatementSequenceNode(ASTStatementSequenceNode node) {
    for (AugmentedStmt as : node.getStatements()) {
        Stmt s = as.get_Stmt();
        List useBoxes = s.getUseBoxes();
        Object obj = cp.getBeforeSet(s);
        if (obj == null)
            continue;
        if (!(obj instanceof CPFlowSet))
            continue;
        // before set is a non null CPFlowSet
        CPFlowSet beforeSet = (CPFlowSet) obj;
        // System.out.println("Statement: "+s);
        // System.out.println("Before set is: "+beforeSet.toString());
        /*
			 * get all use boxes see if their value is determined from the
			 * before set if yes replace them
			 */
        substituteUses(useBoxes, beforeSet);
    }
}
Also used : List(java.util.List) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) CPFlowSet(soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) Stmt(soot.jimple.Stmt)

Example 3 with CPFlowSet

use of soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet in project soot by Sable.

the class CPApplication method inASTIfNode.

public void inASTIfNode(ASTIfNode node) {
    // System.out.println(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;
    // System.out.println("Printing before Set for IF"+beforeSet.toString());
    ASTCondition cond = node.get_Condition();
    // System.out.println("If Statement with condition: "+cond);
    // System.out.println("Before set is: "+beforeSet.toString());
    changedCondition(cond, beforeSet);
}
Also used : ASTCondition(soot.dava.internal.AST.ASTCondition) CPFlowSet(soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet)

Example 4 with CPFlowSet

use of soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet in project soot by Sable.

the class CPApplication method inASTSwitchNode.

public void inASTSwitchNode(ASTSwitchNode 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;
    Value key = node.get_Key();
    if (key instanceof Local) {
        Local useLocal = (Local) key;
        // System.out.println("switch key is a local: "+useLocal);
        Object value = beforeSet.contains(className, useLocal.toString());
        if (value != null) {
            // System.out.println("switch key Local "+useLocal+"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 switch key local use with the constant value"+newValue);
                node.set_Key(newValue);
            } else {
            // System.out.println("FAILED TO Substitute the local use with the constant value");
            }
        }
    } else if (key instanceof FieldRef) {
        FieldRef useField = (FieldRef) key;
        // System.out.println("switch key is a FieldRef which is: "+useField);
        SootField usedSootField = useField.getField();
        Object value = beforeSet.contains(usedSootField.getDeclaringClass().getName(), usedSootField.getName().toString());
        if (value != null) {
            // System.out.println("FieldRef "+usedSootField+"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 constant field ref use with the constant value"+newValue);
                node.set_Key(newValue);
            } else {
            // System.out.println("FAILED TO Substitute the constant field ref use with the constant value");
            }
        }
    }
}
Also used : FieldRef(soot.jimple.FieldRef) Value(soot.Value) Local(soot.Local) SootField(soot.SootField) CPFlowSet(soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet)

Example 5 with CPFlowSet

use of soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet 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);
}
Also used : ASTCondition(soot.dava.internal.AST.ASTCondition) CPFlowSet(soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet)

Aggregations

CPFlowSet (soot.dava.toolkits.base.AST.structuredAnalysis.CPFlowSet)7 ASTCondition (soot.dava.internal.AST.ASTCondition)5 List (java.util.List)2 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)2 Stmt (soot.jimple.Stmt)2 Local (soot.Local)1 SootField (soot.SootField)1 Value (soot.Value)1 FieldRef (soot.jimple.FieldRef)1