Added code to methods missing implementations.
Added a make method for a partial graph with a given set of roots and a given set of nodes. Added checks for containment of pred/succ nodes to get[Pred/Succ]NodeNumbers, which were missing the checks. Made getNode/getNumber methods return null/-1 for nodes not in partial graph (instead of throwing an exception). May reconsider this later. git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1467 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
d602c65f6b
commit
cb4012d939
|
@ -35,6 +35,16 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
||||||
this.partialRoots = partialRoots;
|
this.partialRoots = partialRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PartialCallGraph make(final CallGraph CG, final Set<CGNode> partialRoots, final Collection<CGNode> nodes) {
|
||||||
|
Graph<CGNode> partialGraph = GraphSlicer.prune(CG, new Filter() {
|
||||||
|
public boolean accepts(Object o) {
|
||||||
|
return nodes.contains(o);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return new PartialCallGraph(CG, partialRoots, partialGraph);
|
||||||
|
}
|
||||||
|
|
||||||
public static PartialCallGraph make(CallGraph CG, Set<CGNode> partialRoots) {
|
public static PartialCallGraph make(CallGraph CG, Set<CGNode> partialRoots) {
|
||||||
final Set<CGNode> nodes = DFS.getReachableNodes(CG, partialRoots);
|
final Set<CGNode> nodes = DFS.getReachableNodes(CG, partialRoots);
|
||||||
Graph<CGNode> partialGraph = GraphSlicer.prune(CG, new Filter() {
|
Graph<CGNode> partialGraph = GraphSlicer.prune(CG, new Filter() {
|
||||||
|
@ -57,11 +67,7 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
||||||
|
|
||||||
public CGNode getNode(IMethod method, Context C) {
|
public CGNode getNode(IMethod method, Context C) {
|
||||||
CGNode x = cg.getNode(method, C);
|
CGNode x = cg.getNode(method, C);
|
||||||
if (containsNode(x)) {
|
return (containsNode(x) ? x : null);
|
||||||
return x;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<CGNode> getNodes(MethodReference m) {
|
public Set<CGNode> getNodes(MethodReference m) {
|
||||||
|
@ -98,20 +104,21 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
||||||
|
|
||||||
public CGNode getNode(int index) {
|
public CGNode getNode(int index) {
|
||||||
CGNode n = cg.getNode(index);
|
CGNode n = cg.getNode(index);
|
||||||
Assertions._assert(containsNode(n));
|
return (containsNode(n) ? n : null);
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumber(CGNode n) {
|
public int getNumber(CGNode n) {
|
||||||
Assertions._assert(containsNode(n));
|
return (containsNode(n) ? cg.getNumber(n) : -1);
|
||||||
return cg.getNumber(n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntSet getSuccNodeNumbers(CGNode node) {
|
public IntSet getSuccNodeNumbers(CGNode node) {
|
||||||
Assertions._assert(containsNode(node));
|
Assertions._assert(containsNode(node));
|
||||||
MutableIntSet x = IntSetUtil.make();
|
MutableIntSet x = IntSetUtil.make();
|
||||||
for (Iterator ns = getSuccNodes(node); ns.hasNext();) {
|
for (Iterator ns = getSuccNodes(node); ns.hasNext();) {
|
||||||
x.add(getNumber((CGNode) ns.next()));
|
CGNode succ = (CGNode) ns.next();
|
||||||
|
if (containsNode(succ)) {
|
||||||
|
x.add(getNumber(succ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
|
@ -121,24 +128,35 @@ public class PartialCallGraph extends DelegatingGraph<CGNode> implements CallGra
|
||||||
Assertions._assert(containsNode(node));
|
Assertions._assert(containsNode(node));
|
||||||
MutableIntSet x = IntSetUtil.make();
|
MutableIntSet x = IntSetUtil.make();
|
||||||
for (Iterator ns = getPredNodes(node); ns.hasNext();) {
|
for (Iterator ns = getPredNodes(node); ns.hasNext();) {
|
||||||
x.add(getNumber((CGNode) ns.next()));
|
CGNode pred = (CGNode) ns.next();
|
||||||
|
if (containsNode(pred)) {
|
||||||
|
x.add(getNumber(pred));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfTargets(CGNode node, CallSiteReference site) {
|
public int getNumberOfTargets(CGNode node, CallSiteReference site) {
|
||||||
Assertions.UNREACHABLE("TODO");
|
return (containsNode(node) ? getPossibleTargets(node, site).size() : -1);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<CallSiteReference> getPossibleSites(CGNode src, CGNode target) {
|
public Iterator<CallSiteReference> getPossibleSites(CGNode src, CGNode target) {
|
||||||
Assertions.UNREACHABLE("TODO");
|
return ((containsNode(src) && containsNode(target)) ? cg.getPossibleSites(src, target) : null);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<CGNode> getPossibleTargets(CGNode node, CallSiteReference site) {
|
public Set<CGNode> getPossibleTargets(CGNode node, CallSiteReference site) {
|
||||||
Assertions.UNREACHABLE("TODO");
|
if (!containsNode(node)) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
Set<CGNode> result = HashSetFactory.make();
|
||||||
|
for (Iterator ns = cg.getPossibleTargets(node, site).iterator(); ns.hasNext();) {
|
||||||
|
CGNode target = (CGNode) ns.next();
|
||||||
|
if (containsNode(target)) {
|
||||||
|
result.add(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue