misc. small cleanups

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3384 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-03-30 21:04:17 +00:00
parent 14d06f4d52
commit f1319edeb6
17 changed files with 76 additions and 103 deletions

View File

@ -19,9 +19,6 @@ import com.ibm.wala.util.intset.BitVector;
/**
* An interface that is common to the Shrike and SSA CFG implementations.
*
* @author cahoon
* @author sfink
*/
public interface ControlFlowGraph<I, T extends IBasicBlock<I>> extends NumberedGraph<T> {
@ -41,8 +38,7 @@ public interface ControlFlowGraph<I, T extends IBasicBlock<I>> extends NumberedG
public BitVector getCatchBlocks();
/**
* @param index
* an instruction index
* @param index an instruction index
* @return the basic block which contains this instruction.
*/
public T getBlockForInstruction(int index);
@ -54,10 +50,9 @@ public interface ControlFlowGraph<I, T extends IBasicBlock<I>> extends NumberedG
/**
* TODO: move this into IR?
* @param index
* an instruction index
* @return the program counter (bytecode index) corresponding to that
* instruction
*
* @param index an instruction index
* @return the program counter (bytecode index) corresponding to that instruction
*/
public int getProgramCounter(int index);
@ -67,30 +62,26 @@ public interface ControlFlowGraph<I, T extends IBasicBlock<I>> extends NumberedG
public IMethod getMethod();
/**
* The order of blocks returned must indicate the exception-handling scope.
* So the first block is the first candidate catch block, and so on.
* With this invariant one can compute the exceptional control flow for
* a given exception type.
* The order of blocks returned must indicate the exception-handling scope. So the first block is the first candidate catch block,
* and so on. With this invariant one can compute the exceptional control flow for a given exception type.
*
* @return the basic blocks which may be reached from b via exceptional
* control flow
* @return the basic blocks which may be reached from b via exceptional control flow
*/
public List<T> getExceptionalSuccessors(T b);
/**
* The order of blocks returned should be arbitrary but deterministic.
*
* @param b
* @return the basic blocks which may be reached from b via normal control
* flow
* @return the basic blocks which may be reached from b via normal control flow
*/
public Collection<T> getNormalSuccessors(T b);
/**
* The order of blocks returned should be arbitrary but deterministic.
*
* @param b
* @return the basic blocks from which b may be reached via exceptional
* control flow
* @return the basic blocks from which b may be reached via exceptional control flow
*/
public Collection<T> getExceptionalPredecessors(T b);
@ -98,8 +89,7 @@ public interface ControlFlowGraph<I, T extends IBasicBlock<I>> extends NumberedG
* The order of blocks returned should be arbitrary but deterministic.
*
* @param b
* @return the basic blocks from which b may be reached via normal
* control flow
* @return the basic blocks from which b may be reached via normal control flow
*/
public Collection<T> getNormalPredecessors(T b);
}

View File

@ -62,6 +62,9 @@ public abstract class AbstractJavaAnalysisAction implements IObjectActionDelegat
}
public static AnalysisScope computeScope(IStructuredSelection selection, boolean includeSource) throws IOException {
if (selection == null) {
throw new IllegalArgumentException("null selection");
}
Collection<EclipseProjectPath> projectPaths = new LinkedList<EclipseProjectPath>();
for (Iterator it = selection.iterator(); it.hasNext();) {
Object object = it.next();

View File

@ -349,6 +349,9 @@ public class AnalysisScope {
* Utility function. Useful when parsing input.
*/
public MethodReference findMethod(Atom loader, String klass, Atom name, ImmutableByteArray desc) {
if (desc == null) {
throw new IllegalArgumentException("null desc");
}
ClassLoaderReference clr = getLoader(loader);
Descriptor ddesc = Descriptor.findOrCreate(languages.get(clr.getLanguage()), desc);
TypeReference type = TypeReference.findOrCreate(clr, TypeName.string2TypeName(klass));

View File

@ -145,6 +145,9 @@ public class PointsToMap {
* points-to-sets are the primordial assignments from which the transitive closure flows.
*/
public void recordTransitiveRoot(PointerKey key) {
if (key == null) {
throw new IllegalArgumentException("null key");
}
int i = findOrCreateIndex(key);
transitiveRoots.set(i);
}

View File

@ -113,6 +113,9 @@ public final class WalaProperties {
if (loader == null) {
throw new IllegalArgumentException("loader is null");
}
if (fileName == null) {
throw new IllegalArgumentException("null fileName");
}
final InputStream propertyStream = loader.getResourceAsStream(fileName);
if (propertyStream == null) {
throw new IOException("property_file_unreadable " + fileName);

View File

@ -16,11 +16,8 @@ import com.ibm.wala.util.graph.impl.NumberedNodeIterator;
import com.ibm.wala.util.intset.IntSet;
/**
*
* Basic functionality for a graph that delegates node and edge management, and
* tracks node numbers
*
* @author sfink
*/
public abstract class AbstractNumberedGraph<T> extends AbstractGraph<T> implements NumberedGraph<T> {

View File

@ -163,6 +163,9 @@ public class DelegatingNumberedNodeManager<T extends INodeWithNumber> implements
}
INodeWithNumber N = n;
int number = N.getGraphNodeId();
if (number == -1) {
throw new IllegalArgumentException("Cannot remove node, not in graph");
}
if (nodes[number] != null) {
nodes[number] = null;
numberOfNodes--;

View File

@ -77,6 +77,9 @@ public class BFSIterator<T> implements Iterator<T> {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
if (nodes == null) {
throw new IllegalArgumentException("nodes is null");
}
init(G, nodes);
}

View File

@ -26,14 +26,12 @@ import com.ibm.wala.util.debug.Trace;
import com.ibm.wala.util.graph.Graph;
/**
* This class searches breadth-first for node that matches some criteria. If
* found, it reports a path to the first node found.
* This class searches breadth-first for node that matches some criteria. If found, it reports a path to the first node found.
*
* This class follows the outNodes of the graph nodes to define the graph, but
* this behavior can be changed by overriding the getConnected method.
* This class follows the outNodes of the graph nodes to define the graph, but this behavior can be changed by overriding the
* getConnected method.
*
* TODO: if finding many paths, use a dynamic programming algorithm instead of
* calling this repeatedly.
* TODO: if finding many paths, use a dynamic programming algorithm instead of calling this repeatedly.
*
* @author Stephen Fink
*/
@ -57,28 +55,27 @@ public class BFSPathFinder<T> {
final private Iterator<T> roots;
/**
* Construct a breadth-first enumerator starting with a particular node in a
* directed graph.
* Construct a breadth-first enumerator starting with a particular node in a directed graph.
*
* @param G
* the graph whose nodes to enumerate
* @param G the graph whose nodes to enumerate
*/
public BFSPathFinder(Graph<T> G, T N, Filter<T> f) {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
if (f == null) {
throw new IllegalArgumentException("null f");
}
this.G = G;
this.roots = new NonNullSingletonIterator<T>(N);
this.filter = f;
}
/**
* Construct a breadth-first enumerator starting with a particular node in a
* directed graph.
* Construct a breadth-first enumerator starting with a particular node in a directed graph.
*
* @param G
* the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
* @param G the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
*/
public BFSPathFinder(Graph<T> G, T src, final T target) throws IllegalArgumentException {
if (G == null) {
@ -97,11 +94,9 @@ public class BFSPathFinder<T> {
}
/**
* Construct a breadth-first enumerator starting with a particular node in a
* directed graph.
* Construct a breadth-first enumerator starting with a particular node in a directed graph.
*
* @param G
* the graph whose nodes to enumerate
* @param G the graph whose nodes to enumerate
*/
public BFSPathFinder(Graph<T> G, T src, Iterator<T> targets) {
if (targets == null) {
@ -123,11 +118,9 @@ public class BFSPathFinder<T> {
}
/**
* Construct a breadth-first enumerator starting with any of a set of nodes in
* a directed graph.
* Construct a breadth-first enumerator starting with any of a set of nodes in a directed graph.
*
* @param G
* the graph whose nodes to enumerate
* @param G the graph whose nodes to enumerate
*/
public BFSPathFinder(Graph<T> G, Iterator<T> sources, final T target) {
if (G == null) {
@ -146,11 +139,10 @@ public class BFSPathFinder<T> {
}
/**
* Construct a breadth-first enumerator across the (possibly improper) subset
* of nodes reachable from the nodes in the given enumeration.
* Construct a breadth-first enumerator across the (possibly improper) subset of nodes reachable from the nodes in the given
* enumeration.
*
* @param nodes
* the set of nodes from which to start searching
* @param nodes the set of nodes from which to start searching
*/
public BFSPathFinder(Graph<T> G, Iterator<T> nodes, Filter<T> f) {
this.G = G;
@ -165,8 +157,8 @@ public class BFSPathFinder<T> {
}
/**
* @return a List of nodes that specifies the first path found from a root to
* a node accepted by the filter. Returns null if no path found.
* @return a List of nodes that specifies the first path found from a root to a node accepted by the filter. Returns null if no
* path found.
*/
public List<T> find() {
@ -199,8 +191,7 @@ public class BFSPathFinder<T> {
}
/**
* @return a List which represents a path in the breadth-first search to Q[i].
* Q holds the nodes visited during the BFS, in order.
* @return a List which represents a path in the breadth-first search to Q[i]. Q holds the nodes visited during the BFS, in order.
*/
private List<T> makePath(T node, Map<Object, T> history) {
ArrayList<T> result = new ArrayList<T>();
@ -220,8 +211,7 @@ public class BFSPathFinder<T> {
/**
* get the out edges of a given node
*
* @param n
* the node of which to get the out edges
* @param n the node of which to get the out edges
* @return the out edges
*
*/

View File

@ -93,6 +93,9 @@ public class BoundedBFSIterator<T> implements Iterator<T> {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
if (k < 0) {
throw new IllegalArgumentException("invalid k: " + k);
}
this.k = k;
boundary = new int[k];
init(G, nodes);

View File

@ -74,24 +74,6 @@ public class DFS {
return result;
}
// need to comment this out to avoid ambiguous type failure from javac
// /**
// * Perform a DFS starting with a particular node and return the set of all
// * nodes visited.
// *
// * @param G
// * the graph containing n
// * @param n
// * @return Set
// */
// public static <T> Set<T> getReachableNodes(Graph<T> G, T n) {
// HashSet<T> result = HashSetFactory.make();
// Iterator<T> dfs = iterateFinishTime(G, new NonNullSingletonIterator<T>(n));
// while (dfs.hasNext()) {
// result.add(dfs.next());
// }
// return result;
// }
/**
* Perform a DFS and return the set of all nodes visited.
@ -200,7 +182,7 @@ public class DFS {
}
/**
* @param G
* @param G a graph
* @return iterator of nodes of G in order of DFS finish time
* @throws IllegalArgumentException if G == null
*/
@ -216,30 +198,18 @@ public class DFS {
}
/**
* @param G
* @param G a graph
* @param ie roots of traversal, in order to visit in outermost loop of DFS
* @return iterator of nodes of G in order of DFS finish time
*/
public static <T> DFSFinishTimeIterator<T> iterateFinishTime(Graph<T> G, Iterator<? extends T> ie) {
if (ie == null) {
throw new IllegalArgumentException("null ie");
}
if (G instanceof NumberedGraph) {
return new NumberedDFSFinishTimeIterator<T>((NumberedGraph<T>) G, ie);
} else {
return new SlowDFSFinishTimeIterator<T>(G, ie);
}
}
// need to comment out to avoid ambiguous type error from javac
// /**
// * @param G
// * @param n
// * @return iterator of nodes of G in order of DFS finish time
// */
// public static <T> DFSFinishTimeIterator<T> iterateFinishTime(Graph<T> G, T
// n) {
// if (G instanceof NumberedGraph) {
// return new NumberedDFSFinishTimeIterator<T>((NumberedGraph<T>) G, n);
// } else {
// return new SlowDFSFinishTimeIterator<T>(G, n);
// }
// }
}

View File

@ -60,6 +60,9 @@ public class SlowDFSDiscoverTimeIterator<T> extends GraphDFSDiscoverTimeIterator
* @param nodes the set of nodes from which to start searching
*/
public SlowDFSDiscoverTimeIterator(Graph<T> G, Iterator<T> nodes) {
if (nodes == null) {
throw new IllegalArgumentException("null nodes");
}
init(G, nodes);
}

View File

@ -219,6 +219,9 @@ public final class BitVectorIntSet implements MutableIntSet {
* @see com.ibm.wala.util.intset.IntSet#foreach(com.ibm.wala.util.intset.IntSetAction)
*/
public void foreach(IntSetAction action) {
if (action == null) {
throw new IllegalArgumentException("null action");
}
int nextBit = bitVector.nextSetBit(0);
populationCount = (populationCount == UNDEFINED) ? bitVector.populationCount() : populationCount;
for (int i = 0; i < populationCount; i++) {

View File

@ -11,10 +11,7 @@
package com.ibm.wala.util.intset;
/**
*
* Set of integers; not necessary mutable TODO: extract a smaller interface?
*
* @author sfink
*/
public interface IntSet {
@ -60,15 +57,11 @@ public interface IntSet {
/**
* Invoke an action on each element of the Set
*
* @param action
*/
public void foreach(IntSetAction action);
/**
* Invoke an action on each element of the Set, excluding elements of Set X
*
* @param action
*/
public void foreachExcluding(IntSet X, IntSetAction action);

View File

@ -36,10 +36,10 @@ public class IntegerUnionFind {
}
/**
* @param size
* @param size initial size of the tables
*/
public IntegerUnionFind(int size) {
if (size + 1 < 0) {
if (size < 0) {
throw new IllegalArgumentException("illegal size: " + size);
}
parent = new int[size + 1];

View File

@ -414,7 +414,7 @@ public class SparseLongSet implements LongSet {
if (elements == null) {
throw new IllegalStateException("Illegal to ask max() on an empty int set");
}
return elements[size - 1];
return (size > 0) ? elements[size - 1] : -1;
}
/**

View File

@ -95,6 +95,9 @@ public class FileProvider {
}
public static URL getResource(String fileName, ClassLoader loader) throws IOException {
if (fileName == null) {
throw new IllegalArgumentException("null fileName");
}
if (CorePlugin.getDefault() == null && loader == null) {
throw new IllegalArgumentException("null loader");
}
@ -215,6 +218,9 @@ public class FileProvider {
if (loader == null) {
throw new IllegalArgumentException("null loader");
}
if (fileName == null) {
throw new IllegalArgumentException("null fileName");
}
URL url = loader.getResource(fileName);
if (DEBUG_LEVEL > 0) {
Trace.println("FileProvider got url: " + url + " for " + fileName);