add some assertions

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1498 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-07-17 13:41:34 +00:00
parent dd7daab3ef
commit 2c4fd1fc93
1 changed files with 21 additions and 8 deletions

View File

@ -23,8 +23,7 @@ import com.ibm.wala.util.graph.Graph;
import com.ibm.wala.util.intset.IntegerUnionFind; import com.ibm.wala.util.intset.IntegerUnionFind;
/** /**
* * Iterative solver for a Killdall dataflow framework
* Iterative solver for a killdall dataflow framework
* *
* @author sfink * @author sfink
*/ */
@ -63,7 +62,7 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
/** /**
* @param n * @param n
* a node * a node
* @return a fresh variable to represent the lattice value at the IN or OUT of * @return a fresh variable to represent the lattice value at the IN or OUT of
* n * n
*/ */
@ -78,6 +77,7 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
// create a variable for each node. // create a variable for each node.
for (Iterator<? extends T> it = G.iterator(); it.hasNext();) { for (Iterator<? extends T> it = G.iterator(); it.hasNext();) {
T N = it.next(); T N = it.next();
assert N != null;
IVariable v = makeNodeVariable(N, true); IVariable v = makeNodeVariable(N, true);
node2In.put(N, v); node2In.put(N, v);
@ -90,7 +90,7 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
for (Iterator<? extends T> it2 = G.getSuccNodes(N); it2.hasNext();) { for (Iterator<? extends T> it2 = G.getSuccNodes(N); it2.hasNext();) {
T S = it2.next(); T S = it2.next();
v = makeEdgeVariable(N, S); v = makeEdgeVariable(N, S);
edge2Var.put(new Pair<T,Object>(N, S), v); edge2Var.put(new Pair<T, Object>(N, S), v);
} }
} }
} }
@ -102,7 +102,10 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
} }
public IVariable getOut(Object node) { public IVariable getOut(Object node) {
return node2Out.get(node); assert node != null;
IVariable v = node2Out.get(node);
assert v != null;
return v;
} }
public IVariable getIn(Object node) { public IVariable getIn(Object node) {
@ -114,7 +117,11 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
} }
public IVariable getEdge(Object src, Object dst) { public IVariable getEdge(Object src, Object dst) {
return getEdge(new Pair<Object,Object>(src, dst)); assert src != null;
assert dst != null;
IVariable v = getEdge(new Pair<Object, Object>(src, dst));
assert v != null;
return v;
} }
private class UnionFind { private class UnionFind {
@ -153,6 +160,8 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
* (x,true) = IN(X) and (x,false) = OUT(X) * (x,true) = IN(X) and (x,false) = OUT(X)
*/ */
public void union(Object n1, Object n2) { public void union(Object n1, Object n2) {
assert n1 != null;
assert n2 != null;
int x = map.getMappedIndex(n1); int x = map.getMappedIndex(n1);
int y = map.getMappedIndex(n2); int y = map.getMappedIndex(n2);
uf.union(x, y); uf.union(x, y);
@ -162,7 +171,7 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
public int size() { public int size() {
return map.getMappingSize(); return map.getMappingSize();
} }
public int find(int i) { public int find(int i) {
return uf.find(i); return uf.find(i);
} }
@ -305,16 +314,20 @@ public abstract class DataflowSolver<T> extends DefaultFixedPointSolver {
private void shortCircuitUnaryMeets(Graph<T> G, ITransferFunctionProvider functions, UnionFind uf) { private void shortCircuitUnaryMeets(Graph<T> G, ITransferFunctionProvider functions, UnionFind uf) {
for (Iterator<? extends T> it = G.iterator(); it.hasNext();) { for (Iterator<? extends T> it = G.iterator(); it.hasNext();) {
T node = it.next(); T node = it.next();
assert node != null;
int nPred = G.getPredNodeCount(node); int nPred = G.getPredNodeCount(node);
if (nPred == 1) { if (nPred == 1) {
// short circuit by setting IN = OUT_p // short circuit by setting IN = OUT_p
Object p = G.getPredNodes(node).next(); Object p = G.getPredNodes(node).next();
// if (p == null) {
// p = G.getPredNodes(node).next();
// }
assert p != null;
uf.union(getIn(node), functions.hasEdgeTransferFunctions() ? getEdge(p, node) : getOut(p)); uf.union(getIn(node), functions.hasEdgeTransferFunctions() ? getEdge(p, node) : getOut(p));
} }
} }
} }
public IKilldallFramework getProblem() { public IKilldallFramework getProblem() {
return problem; return problem;
} }