more generalization for partially balanced parens
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2534 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
60f024800e
commit
ba23480667
|
@ -192,6 +192,13 @@ public class TabulationSolver<T, P> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart tabulation from a particular path edge. Use with care.
|
||||||
|
*/
|
||||||
|
public void propagate(PathEdge<T> seed) {
|
||||||
|
propagate(seed.entry, seed.d1, seed.target, seed.d2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See POPL 95 paper for this algorithm, Figure 3
|
* See POPL 95 paper for this algorithm, Figure 3
|
||||||
*
|
*
|
||||||
|
|
|
@ -168,8 +168,7 @@ public class Slicer {
|
||||||
*
|
*
|
||||||
* @throws CancelException
|
* @throws CancelException
|
||||||
*/
|
*/
|
||||||
public static Collection<Statement> computeBackwardSlice(SDG sdg, Statement s)
|
public static Collection<Statement> computeBackwardSlice(SDG sdg, Statement s) throws IllegalArgumentException, CancelException {
|
||||||
throws IllegalArgumentException, CancelException {
|
|
||||||
return computeSlice(sdg, Collections.singleton(s), true);
|
return computeSlice(sdg, Collections.singleton(s), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,8 +177,7 @@ public class Slicer {
|
||||||
*
|
*
|
||||||
* @throws CancelException
|
* @throws CancelException
|
||||||
*/
|
*/
|
||||||
public static Collection<Statement> computeForwardSlice(SDG sdg, Statement s)
|
public static Collection<Statement> computeForwardSlice(SDG sdg, Statement s) throws IllegalArgumentException, CancelException {
|
||||||
throws IllegalArgumentException, CancelException {
|
|
||||||
return computeSlice(sdg, Collections.singleton(s), false);
|
return computeSlice(sdg, Collections.singleton(s), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +186,8 @@ public class Slicer {
|
||||||
*
|
*
|
||||||
* @throws CancelException
|
* @throws CancelException
|
||||||
*/
|
*/
|
||||||
public static Collection<Statement> computeBackwardSlice(SDG sdg, Collection<Statement> ss)
|
public static Collection<Statement> computeBackwardSlice(SDG sdg, Collection<Statement> ss) throws IllegalArgumentException,
|
||||||
throws IllegalArgumentException, CancelException {
|
CancelException {
|
||||||
return computeSlice(sdg, ss, true);
|
return computeSlice(sdg, ss, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +204,14 @@ public class Slicer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main driver logic.
|
* Main driver logic.
|
||||||
|
*
|
||||||
|
* @param sdg governing system dependence graph
|
||||||
|
* @param roots set of roots to slice from
|
||||||
|
* @param backward do a backwards slice?
|
||||||
|
* @return the {@link Statement}s found by the slicer
|
||||||
|
* @throws CancelException
|
||||||
*/
|
*/
|
||||||
public Collection<Statement> slice(SDG sdg, Collection<Statement> ss, boolean backward) throws CancelException {
|
public Collection<Statement> slice(SDG sdg, Collection<Statement> roots, boolean backward) throws CancelException {
|
||||||
|
|
||||||
if (sdg == null) {
|
if (sdg == null) {
|
||||||
throw new IllegalArgumentException("sdg cannot be null");
|
throw new IllegalArgumentException("sdg cannot be null");
|
||||||
|
@ -216,13 +220,14 @@ public class Slicer {
|
||||||
Collection<Statement> rootsConsidered = HashSetFactory.make();
|
Collection<Statement> rootsConsidered = HashSetFactory.make();
|
||||||
Stack<Statement> workList = new Stack<Statement>();
|
Stack<Statement> workList = new Stack<Statement>();
|
||||||
Collection<Statement> result = HashSetFactory.make();
|
Collection<Statement> result = HashSetFactory.make();
|
||||||
for (Statement s : ss) {
|
for (Statement s : roots) {
|
||||||
workList.push(s);
|
workList.push(s);
|
||||||
}
|
}
|
||||||
|
SliceProblem p = makeSliceProblem(roots, sdg, backward);
|
||||||
|
|
||||||
while (!workList.isEmpty()) {
|
while (!workList.isEmpty()) {
|
||||||
Statement root = workList.pop();
|
Statement root = workList.pop();
|
||||||
rootsConsidered.add(root);
|
rootsConsidered.add(root);
|
||||||
SliceProblem p = makeSliceProblem(root, sdg, backward);
|
|
||||||
|
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
System.err.println("worklist now: " + workList.size());
|
System.err.println("worklist now: " + workList.size());
|
||||||
|
@ -231,6 +236,9 @@ public class Slicer {
|
||||||
}
|
}
|
||||||
|
|
||||||
TabulationSolver<Statement, PDG> solver = TabulationSolver.make(p);
|
TabulationSolver<Statement, PDG> solver = TabulationSolver.make(p);
|
||||||
|
if (!roots.contains(root)) {
|
||||||
|
solver.propagate(PathEdge.createPathEdge(new MethodEntryStatement(root.getNode()), 0, root, 0));
|
||||||
|
}
|
||||||
TabulationResult<Statement, PDG> tr = solver.solve();
|
TabulationResult<Statement, PDG> tr = solver.solve();
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -269,8 +277,8 @@ public class Slicer {
|
||||||
* Return an object which encapsulates the tabulation logic for the slice problem. Subclasses can override this method
|
* Return an object which encapsulates the tabulation logic for the slice problem. Subclasses can override this method
|
||||||
* to implement special semantics.
|
* to implement special semantics.
|
||||||
*/
|
*/
|
||||||
protected SliceProblem makeSliceProblem(Statement root, ISDG sdgView, boolean backward) {
|
protected SliceProblem makeSliceProblem(Collection<Statement> roots, ISDG sdgView, boolean backward) {
|
||||||
return new SliceProblem(root, sdgView, backward);
|
return new SliceProblem(roots, sdgView, backward);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<Statement> computeNewRoots(Collection<Statement> slice, Statement root,
|
public static Collection<Statement> computeNewRoots(Collection<Statement> slice, Statement root,
|
||||||
|
@ -376,14 +384,14 @@ public class Slicer {
|
||||||
*/
|
*/
|
||||||
public static class SliceProblem implements TabulationProblem<Statement, PDG> {
|
public static class SliceProblem implements TabulationProblem<Statement, PDG> {
|
||||||
|
|
||||||
private final Statement src;
|
private final Collection<Statement> roots;
|
||||||
|
|
||||||
private final ISupergraph<Statement, PDG> supergraph;
|
private final ISupergraph<Statement, PDG> supergraph;
|
||||||
|
|
||||||
private final IFlowFunctionMap<Statement> f;
|
private final IFlowFunctionMap<Statement> f;
|
||||||
|
|
||||||
public SliceProblem(Statement s, ISDG sdg, boolean backward) {
|
public SliceProblem(Collection<Statement> roots, ISDG sdg, boolean backward) {
|
||||||
this.src = s;
|
this.roots = roots;
|
||||||
SDGSupergraph forwards = new SDGSupergraph(sdg, backward);
|
SDGSupergraph forwards = new SDGSupergraph(sdg, backward);
|
||||||
this.supergraph = backward ? BackwardsSupergraph.make(forwards) : forwards;
|
this.supergraph = backward ? BackwardsSupergraph.make(forwards) : forwards;
|
||||||
f = new SliceFunctions();
|
f = new SliceFunctions();
|
||||||
|
@ -411,7 +419,6 @@ public class Slicer {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see com.ibm.wala.dataflow.IFDS.TabulationProblem#getSupergraph()
|
* @see com.ibm.wala.dataflow.IFDS.TabulationProblem#getSupergraph()
|
||||||
*/
|
*/
|
||||||
|
@ -420,9 +427,13 @@ public class Slicer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<PathEdge<Statement>> initialSeeds() {
|
public Collection<PathEdge<Statement>> initialSeeds() {
|
||||||
PathEdge<Statement> seed = PathEdge.createPathEdge(new MethodEntryStatement(src.getNode()), 0, src, 0);
|
Collection<PathEdge<Statement>> result = HashSetFactory.make();
|
||||||
|
for (Statement st : roots) {
|
||||||
|
PathEdge<Statement> seed = PathEdge.createPathEdge(new MethodEntryStatement(st.getNode()), 0, st, 0);
|
||||||
return Collections.singleton(seed);
|
return Collections.singleton(seed);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue