soot.jimple.toolkits.callgraph.TransitiveTargets Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soot Show documentation
Show all versions of soot Show documentation
A Java Optimization Framework
package soot.jimple.toolkits.callgraph;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2003 - 2004 Ondrej Lhotak
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import soot.MethodOrMethodContext;
import soot.Unit;
/**
* Extends a TargetsOfMethod or TargetsOfUnit to include edges transitively reachable from any target methods.
*
* @author Ondrej Lhotak
*/
public class TransitiveTargets {
private CallGraph cg;
private Filter filter;
public TransitiveTargets(CallGraph cg) {
this.cg = cg;
}
public TransitiveTargets(CallGraph cg, Filter filter) {
this.cg = cg;
this.filter = filter;
}
public Iterator iterator(Unit u) {
ArrayList methods = new ArrayList();
Iterator it = cg.edgesOutOf(u);
if (filter != null) {
it = filter.wrap(it);
}
while (it.hasNext()) {
Edge e = (Edge) it.next();
methods.add(e.getTgt());
}
return iterator(methods.iterator());
}
public Iterator iterator(MethodOrMethodContext momc) {
ArrayList methods = new ArrayList();
Iterator it = cg.edgesOutOf(momc);
if (filter != null) {
it = filter.wrap(it);
}
while (it.hasNext()) {
Edge e = (Edge) it.next();
methods.add(e.getTgt());
}
return iterator(methods.iterator());
}
public Iterator iterator(Iterator extends MethodOrMethodContext> methods) {
Set s = new HashSet();
ArrayList worklist = new ArrayList();
while (methods.hasNext()) {
MethodOrMethodContext method = methods.next();
if (s.add(method)) {
worklist.add(method);
}
}
return iterator(s, worklist);
}
private Iterator iterator(Set s, ArrayList worklist) {
for (int i = 0; i < worklist.size(); i++) {
MethodOrMethodContext method = worklist.get(i);
Iterator it = cg.edgesOutOf(method);
if (filter != null) {
it = filter.wrap(it);
}
while (it.hasNext()) {
Edge e = (Edge) it.next();
if (s.add(e.getTgt())) {
worklist.add(e.getTgt());
}
}
}
return worklist.iterator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy