bug fixes to PrunedCFG for getSuccNodes and getPredNodes. Make pruned order reflect original order, and remove nasty bug allowing duplicates
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1830 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
9f5946b163
commit
4176a675cc
|
@ -12,10 +12,26 @@ package com.ibm.wala.ipa.cfg;
|
|||
|
||||
import com.ibm.wala.cfg.IBasicBlock;
|
||||
|
||||
/**
|
||||
* This class is used by the PrunedCFG to determine which edges in
|
||||
* a given CFG should be kept in the pruned version.
|
||||
*/
|
||||
public interface EdgeFilter<T extends IBasicBlock> {
|
||||
|
||||
/**
|
||||
* This method must return true if and only if a normal edge from
|
||||
* src to dst exists in the original CFG and should be kept for the
|
||||
* pruned version of that CFG. Note that this must _must_ return
|
||||
* false for any normal edge that is not in the original CFG.
|
||||
*/
|
||||
boolean hasNormalEdge(T src, T dst);
|
||||
|
||||
/**
|
||||
* This method must return true if and only if an exceptional edge from
|
||||
* src to dst exists in the original CFG and should be kept for the
|
||||
* pruned version of that CFG. Note that this must _must_ return
|
||||
* false for any exceptional edge that is not in the original CFG.
|
||||
*/
|
||||
boolean hasExceptionalEdge(T src, T dst);
|
||||
|
||||
}
|
|
@ -19,16 +19,23 @@ import com.ibm.wala.cfg.IBasicBlock;
|
|||
public class ExceptionPrunedCFG {
|
||||
|
||||
private static class ExceptionEdgePruner<T extends IBasicBlock> implements EdgeFilter<T>{
|
||||
public boolean hasNormalEdge(T src, T dst) {
|
||||
return true;
|
||||
private final ControlFlowGraph<T> cfg;
|
||||
|
||||
ExceptionEdgePruner(ControlFlowGraph<T> cfg) {
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
public boolean hasNormalEdge(T src, T dst) {
|
||||
return cfg.getNormalSuccessors(src).contains(dst);
|
||||
}
|
||||
|
||||
public boolean hasExceptionalEdge(T src, T dst) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public static <T extends IBasicBlock> PrunedCFG<T> make(ControlFlowGraph<T> cfg) {
|
||||
return PrunedCFG.make(cfg, new ExceptionEdgePruner<T>());
|
||||
return PrunedCFG.make(cfg, new ExceptionEdgePruner<T>(cfg));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,8 +109,13 @@ public class PrunedCFG<T extends IBasicBlock> extends AbstractNumberedGraph<T> i
|
|||
});
|
||||
}
|
||||
|
||||
public Iterator<T> getSuccNodes(T N) {
|
||||
return new CompoundIterator<T>(getNormalSuccessors(N), getExceptionalSuccessors(N));
|
||||
public Iterator<T> getSuccNodes(final T N) {
|
||||
return new FilterIterator<T>(cfg.getSuccNodes(N), new Filter<T>() {
|
||||
public boolean accepts(T o) {
|
||||
return currentCFGNodes.containsNode(o) &&
|
||||
(filter.hasNormalEdge(N, o) || filter.hasExceptionalEdge(N, o));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getSuccNodeCount(T N) {
|
||||
|
@ -126,8 +131,13 @@ public class PrunedCFG<T extends IBasicBlock> extends AbstractNumberedGraph<T> i
|
|||
return bits;
|
||||
}
|
||||
|
||||
public Iterator<T> getPredNodes(T N) {
|
||||
return new CompoundIterator<T>(getNormalPredecessors(N), getExceptionalPredecessors(N));
|
||||
public Iterator<T> getPredNodes(final T N) {
|
||||
return new FilterIterator<T>(cfg.getPredNodes(N), new Filter<T>() {
|
||||
public boolean accepts(T o) {
|
||||
return currentCFGNodes.containsNode(o) &&
|
||||
(filter.hasNormalEdge(o, N) || filter.hasExceptionalEdge(o, N));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getPredNodeCount(T N) {
|
||||
|
|
Loading…
Reference in New Issue