Search in sources :

Example 6 with ASTNode

use of soot.dava.internal.AST.ASTNode in project soot by Sable.

the class DavaFlowSet method addToImplicitContinues.

public void addToImplicitContinues(DAbruptStmt ab, DavaFlowSet<T> set) {
    if (!checkImplicit(ab))
        throw new RuntimeException("Tried to add explicit continue statement in the implicit list ");
    if (!ab.is_Continue())
        throw new RuntimeException("Tried to add break statement in the continue list");
    // okkay so its an implicit continue
    // get the targetted node, use the ClosestAbruptTargetFinder
    ASTNode node = ClosestAbruptTargetFinder.v().getTarget(ab);
    // get the list of flow sets already stored for this node
    List<DavaFlowSet<T>> listSets = implicitContinues.get(node);
    if (listSets == null)
        listSets = new ArrayList<DavaFlowSet<T>>();
    // if set is not already present in listSets add it and update hashMap
    implicitContinues.put(node, addIfNotDuplicate(listSets, set));
}
Also used : ASTNode(soot.dava.internal.AST.ASTNode) ArrayList(java.util.ArrayList)

Example 7 with ASTNode

use of soot.dava.internal.AST.ASTNode in project soot by Sable.

the class DavaFlowSet method addToImplicitBreaks.

/**
 * The next two methods take an abruptStmt as input along with a flowSet. It
 * should be only invoked for abrupt stmts which do not have explicit labels
 *
 * The node being targeted by this implicit stmt should be found Then the
 * flow set should be added to the list within the appropriate hashmap
 */
public void addToImplicitBreaks(DAbruptStmt ab, DavaFlowSet<T> set) {
    if (!checkImplicit(ab))
        throw new RuntimeException("Tried to add explicit break statement in the implicit list in");
    if (!ab.is_Break())
        throw new RuntimeException("Tried to add continue statement in the break list in DavaFlowSet.addToImplicitBreaks");
    // okkay so its an implicit break
    // get the targetted node, use the ClosestAbruptTargetFinder
    ASTNode node = ClosestAbruptTargetFinder.v().getTarget(ab);
    // get the list of flow sets already stored for this node
    List<DavaFlowSet<T>> listSets = implicitBreaks.get(node);
    if (listSets == null)
        listSets = new ArrayList<DavaFlowSet<T>>();
    // if set is not already present in listSets add it and update hashMap
    implicitBreaks.put(node, addIfNotDuplicate(listSets, set));
}
Also used : ASTNode(soot.dava.internal.AST.ASTNode) ArrayList(java.util.ArrayList)

Example 8 with ASTNode

use of soot.dava.internal.AST.ASTNode 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);
    }
}
Also used : ASTControlFlowNode(soot.dava.internal.AST.ASTControlFlowNode) Iterator(java.util.Iterator) ASTNode(soot.dava.internal.AST.ASTNode) List(java.util.List) ASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode)

Example 9 with ASTNode

use of soot.dava.internal.AST.ASTNode in project soot by Sable.

the class SETNode method emit_ASTBody.

public List<Object> emit_ASTBody(IterableSet children) {
    LinkedList<Object> l = new LinkedList<Object>();
    Iterator cit = children.iterator();
    while (cit.hasNext()) {
        ASTNode astNode = ((SETNode) cit.next()).emit_AST();
        if (astNode != null)
            l.addLast(astNode);
    }
    return l;
}
Also used : Iterator(java.util.Iterator) ASTNode(soot.dava.internal.AST.ASTNode) LinkedList(java.util.LinkedList)

Example 10 with ASTNode

use of soot.dava.internal.AST.ASTNode in project soot by Sable.

the class UnreachableCodeEliminator method normalRetrieving.

public void normalRetrieving(ASTNode node) {
    if (node instanceof ASTSwitchNode) {
        dealWithSwitchNode((ASTSwitchNode) node);
        return;
    }
    // from the Node get the subBodes
    List<ASTNode> toReturn = new ArrayList<ASTNode>();
    Iterator<Object> sbit = node.get_SubBodies().iterator();
    while (sbit.hasNext()) {
        Object subBody = sbit.next();
        Iterator<ASTNode> it = ((List<ASTNode>) subBody).iterator();
        // go over the ASTNodes in this subBody and apply
        while (it.hasNext()) {
            ASTNode temp = it.next();
            if (!codeFinder.isConstructReachable(temp)) {
                // System.out.println("-------------------------A child of node of type "+node.getClass()+" whose type is "+temp.getClass()+" is unreachable");
                toReturn.add(temp);
            } else {
                // only apply on reachable nodes
                temp.apply(this);
            }
        }
        it = toReturn.iterator();
        while (it.hasNext()) {
            // System.out.println("Removed");
            ((List) subBody).remove(it.next());
        }
    }
// end of going over subBodies
}
Also used : ASTNode(soot.dava.internal.AST.ASTNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ASTSwitchNode(soot.dava.internal.AST.ASTSwitchNode)

Aggregations

ASTNode (soot.dava.internal.AST.ASTNode)29 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Iterator (java.util.Iterator)12 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)9 Stmt (soot.jimple.Stmt)9 ASTMethodNode (soot.dava.internal.AST.ASTMethodNode)7 ASTStatementSequenceNode (soot.dava.internal.AST.ASTStatementSequenceNode)7 DefinitionStmt (soot.jimple.DefinitionStmt)6 SootClass (soot.SootClass)4 SootMethod (soot.SootMethod)4 ASTControlFlowNode (soot.dava.internal.AST.ASTControlFlowNode)4 ASTSwitchNode (soot.dava.internal.AST.ASTSwitchNode)4 DVariableDeclarationStmt (soot.dava.internal.javaRep.DVariableDeclarationStmt)4 Body (soot.Body)3 Value (soot.Value)3 DavaBody (soot.dava.DavaBody)3 DecompilationException (soot.dava.DecompilationException)3 ASTTryNode (soot.dava.internal.AST.ASTTryNode)3 GAssignStmt (soot.grimp.internal.GAssignStmt)3