Java Code Examples for soot.util.Chain#remove()
The following examples show how to use
soot.util.Chain#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NopEliminator.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** Removes {@link NopStmt}s from the passed body (which must be a {@link JimpleBody}). Complexity is linear with respect to the statements. */ protected void internalTransform(Body b, String phaseName, Map<String, String> options) { JimpleBody body = (JimpleBody)b; if(Options.v().verbose()) G.v().out.println("[" + body.getMethod().getName() + "] Removing nops..."); Chain<Unit> units = body.getUnits(); // Just do one trivial pass. { Iterator<Unit> stmtIt = units.snapshotIterator(); while(stmtIt.hasNext()) { Unit u = stmtIt.next(); if (u instanceof NopStmt) { // Hack: do not remove nop, if is is used for a Trap which // is at the very end of the code. boolean keepNop = false; if (b.getUnits().getLast() == u) { for (Trap t : b.getTraps()) { if (t.getEndUnit() == u) { keepNop = true; } } } if (!keepNop) { units.remove(u); } } } } }
Example 2
Source File: SootClass.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** Makes this class an application class. */ public void setApplicationClass() { Chain<SootClass> c = Scene.v().getContainingChain(this); if (c != null) c.remove(this); Scene.v().getApplicationClasses().add(this); isPhantom = false; }
Example 3
Source File: SootClass.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** Makes this class a library class. */ public void setLibraryClass() { Chain<SootClass> c = Scene.v().getContainingChain(this); if (c != null) c.remove(this); Scene.v().getLibraryClasses().add(this); isPhantom = false; }
Example 4
Source File: SootClass.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** Makes this class a phantom class. */ public void setPhantomClass() { Chain<SootClass> c = Scene.v().getContainingChain(this); if (c != null) c.remove(this); Scene.v().getPhantomClasses().add(this); isPhantom = true; }
Example 5
Source File: EnhancedUnitGraph.java From JAADAS with GNU General Public License v3.0 | 4 votes |
/** * This method removes all the heads in the CFG except the one * that corresponds to the first unit in the method. */ protected void removeBogusHeads() { Chain<Unit> units = body.getUnits(); Unit trueHead = units.getFirst(); while(this.getHeads().size() > 1) { for(Iterator<Unit> headItr = this.getHeads().iterator(); headItr.hasNext(); ) { Unit head = headItr.next(); if(trueHead == head) continue; this.unitToPreds.remove(head); List<Unit> succs = this.unitToSuccs.get(head); for(Iterator<Unit> succsItr = succs.iterator(); succsItr.hasNext(); ) { List<Unit> tobeRemoved = new ArrayList<Unit>(); Unit succ = succsItr.next(); List<Unit> predOfSuccs = this.unitToPreds.get(succ); for(Iterator<Unit> predItr = predOfSuccs.iterator(); predItr.hasNext(); ) { Unit pred = predItr.next(); if(pred == head) tobeRemoved.add(pred); } predOfSuccs.removeAll(tobeRemoved); } this.unitToSuccs.remove(head); if(units.contains(head)) units.remove(head); } this.buildHeadsAndTails(); } }
Example 6
Source File: ConstructorFolder.java From JAADAS with GNU General Public License v3.0 | 4 votes |
/** This method change all new Obj/<init>(args) pairs to new Obj(args) idioms. */ protected void internalTransform(Body b, String phaseName, Map options) { GrimpBody body = (GrimpBody)b; if(Options.v().verbose()) G.v().out.println("[" + body.getMethod().getName() + "] Folding constructors..."); Chain units = body.getUnits(); List<Unit> stmtList = new ArrayList<Unit>(); stmtList.addAll(units); Iterator<Unit> it = stmtList.iterator(); LocalUses localUses = LocalUses.Factory.newLocalUses(b); /* fold in NewExpr's with specialinvoke's */ while (it.hasNext()) { Stmt s = (Stmt)it.next(); if (!(s instanceof AssignStmt)) continue; /* this should be generalized to ArrayRefs */ Value lhs = ((AssignStmt)s).getLeftOp(); if (!(lhs instanceof Local)) continue; Value rhs = ((AssignStmt)s).getRightOp(); if (!(rhs instanceof NewExpr)) continue; /* TO BE IMPLEMENTED LATER: move any copy of the object reference for lhs down beyond the NewInvokeExpr, with the rationale being that you can't modify the object before the constructor call in any case. Also, do note that any new's (object creation) without corresponding constructors must be dead. */ List lu = localUses.getUsesOf(s); Iterator luIter = lu.iterator(); boolean MadeNewInvokeExpr = false; while (luIter.hasNext()) { Unit use = ((UnitValueBoxPair)(luIter.next())).unit; if (!(use instanceof InvokeStmt)) continue; InvokeStmt is = (InvokeStmt)use; if (!(is.getInvokeExpr() instanceof SpecialInvokeExpr) || lhs != ((SpecialInvokeExpr)is.getInvokeExpr()).getBase()) continue; SpecialInvokeExpr oldInvoke = ((SpecialInvokeExpr)is.getInvokeExpr()); LinkedList invokeArgs = new LinkedList(); for (int i = 0; i < oldInvoke.getArgCount(); i++) invokeArgs.add(oldInvoke.getArg(i)); AssignStmt constructStmt = Grimp.v().newAssignStmt ((AssignStmt)s); constructStmt.setRightOp (Grimp.v().newNewInvokeExpr (((NewExpr)rhs).getBaseType(), oldInvoke.getMethodRef(), invokeArgs)); MadeNewInvokeExpr = true; use.redirectJumpsToThisTo(constructStmt); units.insertBefore(constructStmt, use); units.remove(use); } if (MadeNewInvokeExpr) { units.remove(s); } } }