Search in sources :

Example 11 with IterableSet

use of soot.util.IterableSet in project soot by Sable.

the class AugmentedStmtGraph method clone_Body.

public IterableSet<AugmentedStmt> clone_Body(IterableSet<AugmentedStmt> oldBody) {
    HashMap<AugmentedStmt, AugmentedStmt> old2new = new HashMap<AugmentedStmt, AugmentedStmt>(), new2old = new HashMap<AugmentedStmt, AugmentedStmt>();
    IterableSet<AugmentedStmt> newBody = new IterableSet<AugmentedStmt>();
    for (AugmentedStmt as : oldBody) {
        AugmentedStmt clone = (AugmentedStmt) as.clone();
        original2clone.put(as, clone);
        old2new.put(as, clone);
        new2old.put(clone, as);
        newBody.add(clone);
    }
    for (AugmentedStmt newAs : newBody) {
        AugmentedStmt oldAs = (AugmentedStmt) new2old.get(newAs);
        mirror_PredsSuccs(oldAs, oldAs.bpreds, newAs.bpreds, old2new);
        mirror_PredsSuccs(oldAs, oldAs.cpreds, newAs.cpreds, old2new);
        mirror_PredsSuccs(oldAs, oldAs.bsuccs, newAs.bsuccs, old2new);
        mirror_PredsSuccs(oldAs, oldAs.csuccs, newAs.csuccs, old2new);
    }
    for (AugmentedStmt au : newBody) add_AugmentedStmt(au);
    HashMap<Stmt, Stmt> so2n = new HashMap<Stmt, Stmt>();
    for (AugmentedStmt as : oldBody) {
        Stmt os = as.get_Stmt();
        Stmt ns = old2new.get(as).get_Stmt();
        so2n.put(os, ns);
    }
    for (AugmentedStmt nas : newBody) {
        AugmentedStmt oas = (AugmentedStmt) new2old.get(nas);
        Stmt ns = nas.get_Stmt(), os = oas.get_Stmt();
        if (os instanceof IfStmt) {
            Unit target = ((IfStmt) os).getTarget(), newTgt = null;
            if ((newTgt = so2n.get(target)) != null)
                ((IfStmt) ns).setTarget(newTgt);
            else
                ((IfStmt) ns).setTarget(target);
        } else if (os instanceof TableSwitchStmt) {
            TableSwitchStmt otss = (TableSwitchStmt) os, ntss = (TableSwitchStmt) ns;
            Unit target = otss.getDefaultTarget(), newTgt = null;
            if ((newTgt = so2n.get(target)) != null)
                ntss.setDefaultTarget(newTgt);
            else
                ntss.setDefaultTarget(target);
            LinkedList<Unit> new_target_list = new LinkedList<Unit>();
            int target_count = otss.getHighIndex() - otss.getLowIndex() + 1;
            for (int i = 0; i < target_count; i++) {
                target = otss.getTarget(i);
                newTgt = null;
                if ((newTgt = so2n.get(target)) != null)
                    new_target_list.add(newTgt);
                else
                    new_target_list.add(target);
            }
            ntss.setTargets(new_target_list);
        } else if (os instanceof LookupSwitchStmt) {
            LookupSwitchStmt olss = (LookupSwitchStmt) os, nlss = (LookupSwitchStmt) ns;
            Unit target = olss.getDefaultTarget(), newTgt = null;
            if ((newTgt = so2n.get(target)) != null)
                nlss.setDefaultTarget(newTgt);
            else
                nlss.setDefaultTarget(target);
            Unit[] new_target_list = new Unit[olss.getTargetCount()];
            for (int i = 0; i < new_target_list.length; i++) {
                target = olss.getTarget(i);
                newTgt = null;
                if ((newTgt = so2n.get(target)) != null)
                    new_target_list[i] = newTgt;
                else
                    new_target_list[i] = target;
            }
            nlss.setTargets(new_target_list);
            nlss.setLookupValues(olss.getLookupValues());
        }
    }
    return newBody;
}
Also used : HashMap(java.util.HashMap) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) IterableSet(soot.util.IterableSet) Unit(soot.Unit) LinkedList(java.util.LinkedList) TableSwitchStmt(soot.jimple.TableSwitchStmt) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) Stmt(soot.jimple.Stmt) IfStmt(soot.jimple.IfStmt) TableSwitchStmt(soot.jimple.TableSwitchStmt) IfStmt(soot.jimple.IfStmt)

Example 12 with IterableSet

use of soot.util.IterableSet in project soot by Sable.

the class ExceptionNode method splitOff_ExceptionNode.

public void splitOff_ExceptionNode(IterableSet<AugmentedStmt> newTryBody, AugmentedStmtGraph asg, IterableSet<ExceptionNode> enlist) {
    IterableSet<AugmentedStmt> oldTryBody = new IterableSet<AugmentedStmt>();
    oldTryBody.addAll(tryBody);
    IterableSet<AugmentedStmt> oldBody = new IterableSet<AugmentedStmt>();
    oldBody.addAll(body);
    for (AugmentedStmt as : newTryBody) {
        if (remove(as) == false) {
            StringBuffer b = new StringBuffer();
            for (AugmentedStmt auBody : newTryBody) b.append("\n" + auBody.toString());
            b.append("\n-");
            for (AugmentedStmt auBody : oldTryBody) b.append("\n" + auBody.toString());
            b.append("\n-");
            for (AugmentedStmt auBody : oldBody) b.append("\n" + auBody.toString());
            b.append("\n-");
            throw new RuntimeException("Tried to split off a new try body that isn't in the old one.\n" + as + "\n - " + b.toString());
        }
    }
    asg.clone_Body(catchBody);
    AugmentedStmt oldCatchTarget = handlerAugmentedStmt, newCatchTarget = asg.get_CloneOf(handlerAugmentedStmt);
    for (AugmentedStmt as : newTryBody) {
        as.remove_CSucc(oldCatchTarget);
        oldCatchTarget.remove_CPred(as);
    }
    for (AugmentedStmt as : tryBody) {
        as.remove_CSucc(newCatchTarget);
        newCatchTarget.remove_CPred(as);
    }
    for (ExceptionNode en : enlist) {
        if (this == en)
            continue;
        if (catchBody.isSupersetOf(en.get_Body())) {
            IterableSet<AugmentedStmt> clonedTryBody = new IterableSet<AugmentedStmt>();
            for (AugmentedStmt au : en.get_TryBody()) clonedTryBody.add(asg.get_CloneOf(au));
            enlist.addLast(new ExceptionNode(clonedTryBody, en.exception, asg.get_CloneOf(en.handlerAugmentedStmt)));
        }
    }
    enlist.addLast(new ExceptionNode(newTryBody, exception, asg.get_CloneOf(handlerAugmentedStmt)));
    for (ExceptionNode en : enlist) en.refresh_CatchBody(ExceptionFinder.v());
    asg.find_Dominators();
}
Also used : AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) IterableSet(soot.util.IterableSet)

Aggregations

IterableSet (soot.util.IterableSet)12 Iterator (java.util.Iterator)8 UnmodifiableIterableSet (soot.util.UnmodifiableIterableSet)8 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)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 LongType (soot.LongType)1 RefType (soot.RefType)1 ShortType (soot.ShortType)1 SootClass (soot.SootClass)1 SootField (soot.SootField)1