Search in sources :

Example 6 with ASTTryNode

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

the class UnreachableCodeEliminator method caseASTTryNode.

// TODO
public void caseASTTryNode(ASTTryNode node) {
    // get try body
    List<Object> tryBody = node.get_TryBody();
    Iterator<Object> it = tryBody.iterator();
    // go over the ASTNodes in this tryBody and apply
    List<Object> toReturn = new ArrayList<Object>();
    while (it.hasNext()) {
        ASTNode temp = (ASTNode) it.next();
        if (!codeFinder.isConstructReachable(temp)) {
            toReturn.add(temp);
        } else {
            // only apply on reachable nodes
            temp.apply(this);
        }
    }
    it = toReturn.iterator();
    while (it.hasNext()) {
        tryBody.remove(it.next());
    }
    Map<Object, Object> exceptionMap = node.get_ExceptionMap();
    Map<Object, Object> paramMap = node.get_ParamMap();
    // get catch list and apply on the following
    // a, type of exception caught
    // b, local of exception
    // c, catchBody
    List<Object> catchList = node.get_CatchList();
    Iterator<Object> itBody = null;
    it = catchList.iterator();
    while (it.hasNext()) {
        ASTTryNode.container catchBody = (ASTTryNode.container) it.next();
        SootClass sootClass = ((SootClass) exceptionMap.get(catchBody));
        Type type = sootClass.getType();
        // apply on type of exception
        caseType(type);
        // apply on local of exception
        Local local = (Local) paramMap.get(catchBody);
        /*
			 * March 18th, 2006, Since these are always locals we dont have access to ValueBox
			 */
        decideCaseExprOrRef(local);
        // apply on catchBody
        List<Object> body = (List<Object>) catchBody.o;
        toReturn = new ArrayList<Object>();
        itBody = body.iterator();
        while (itBody.hasNext()) {
            ASTNode temp = (ASTNode) itBody.next();
            if (!codeFinder.isConstructReachable(temp)) {
                toReturn.add(temp);
            } else {
                // only apply on reachable nodes
                temp.apply(this);
            }
        }
        itBody = toReturn.iterator();
        while (itBody.hasNext()) {
            body.remove(itBody.next());
        }
    }
}
Also used : ASTTryNode(soot.dava.internal.AST.ASTTryNode) ArrayList(java.util.ArrayList) Local(soot.Local) SootClass(soot.SootClass) Type(soot.Type) ASTNode(soot.dava.internal.AST.ASTNode) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

List (java.util.List)6 ASTTryNode (soot.dava.internal.AST.ASTTryNode)6 ArrayList (java.util.ArrayList)3 ASTNode (soot.dava.internal.AST.ASTNode)3 Iterator (java.util.Iterator)2 ASTControlFlowNode (soot.dava.internal.AST.ASTControlFlowNode)2 Local (soot.Local)1 SootClass (soot.SootClass)1 Type (soot.Type)1 Value (soot.Value)1 ASTCondition (soot.dava.internal.AST.ASTCondition)1 ASTDoWhileNode (soot.dava.internal.AST.ASTDoWhileNode)1 ASTForLoopNode (soot.dava.internal.AST.ASTForLoopNode)1 ASTIfElseNode (soot.dava.internal.AST.ASTIfElseNode)1 ASTIfNode (soot.dava.internal.AST.ASTIfNode)1 ASTLabeledBlockNode (soot.dava.internal.AST.ASTLabeledBlockNode)1 ASTMethodNode (soot.dava.internal.AST.ASTMethodNode)1 ASTSwitchNode (soot.dava.internal.AST.ASTSwitchNode)1 ASTSynchronizedBlockNode (soot.dava.internal.AST.ASTSynchronizedBlockNode)1 ASTUnaryCondition (soot.dava.internal.AST.ASTUnaryCondition)1