bug fixes, cleanups, and more generics

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1014 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-04-26 17:29:50 +00:00
parent 4f9d62784e
commit f239bd6148
13 changed files with 65 additions and 64 deletions

View File

@ -34,9 +34,9 @@ public class ExplodedSupergraph<T> implements Graph<ExplodedSupergraphNode<T>> {
private final ISupergraph<T,?> supergraph;
private final IFlowFunctionMap flowFunctions;
private final IFlowFunctionMap<T> flowFunctions;
public ExplodedSupergraph(ISupergraph<T,?> supergraph, IFlowFunctionMap flowFunctions) {
public ExplodedSupergraph(ISupergraph<T,?> supergraph, IFlowFunctionMap<T> flowFunctions) {
this.supergraph = supergraph;
this.flowFunctions = flowFunctions;
}
@ -91,8 +91,8 @@ public class ExplodedSupergraph<T> implements Graph<ExplodedSupergraphNode<T>> {
}
} else {
// special logic for a return edge. dest is a return site
for (Iterator it2 = supergraph.getCallSites(dest); it2.hasNext(); ) {
Object callBlock = it2.next();
for (Iterator<? extends T> it2 = supergraph.getCallSites(dest); it2.hasNext(); ) {
T callBlock = it2.next();
IFlowFunction f = flowFunctions.getReturnFlowFunction(callBlock,src,dest);
if (f instanceof IReversibleFlowFunction) {
IReversibleFlowFunction rf = (IReversibleFlowFunction) f;
@ -160,8 +160,8 @@ public class ExplodedSupergraph<T> implements Graph<ExplodedSupergraphNode<T>> {
}
} else {
// special logic for a return edge. dest is a return site
for (Iterator it2 = supergraph.getCallSites(dest); it2.hasNext(); ) {
Object callBlock = it2.next();
for (Iterator<? extends T> it2 = supergraph.getCallSites(dest); it2.hasNext(); ) {
T callBlock = it2.next();
IUnaryFlowFunction f = (IUnaryFlowFunction) flowFunctions.getReturnFlowFunction(callBlock,src,dest);
IntSet targets = f.getTargets(node.getFact());
if (targets != null) {

View File

@ -34,7 +34,7 @@ public class ExplodedSupergraphWithSummaryEdges<T> extends ExplodedSupergraph<T>
* @param flowFunctions
* @param solver
*/
public ExplodedSupergraphWithSummaryEdges(ISupergraph<T,?> supergraph, IFlowFunctionMap flowFunctions, TabulationSolver<T,?> solver) {
public ExplodedSupergraphWithSummaryEdges(ISupergraph<T,?> supergraph, IFlowFunctionMap<T> flowFunctions, TabulationSolver<T,?> solver) {
super(supergraph, flowFunctions);
this.solver = solver;
}

View File

@ -14,9 +14,11 @@ package com.ibm.wala.dataflow.IFDS;
*
* A map from an edge in a supergraph to a flow function
*
* @param T type of node in the supergraph
*
* @author sfink
*/
public interface IFlowFunctionMap {
public interface IFlowFunctionMap<T> {
/**
* @param src
@ -24,7 +26,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "normal" edge in the supergraph from
* src->dest
*/
public IUnaryFlowFunction getNormalFlowFunction(Object src, Object dest);
public IUnaryFlowFunction getNormalFlowFunction(T src, T dest);
/**
* @param src
@ -32,7 +34,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "call" edge in the supergraph from
* src->dest
*/
public IUnaryFlowFunction getCallFlowFunction(Object src, Object dest);
public IUnaryFlowFunction getCallFlowFunction(T src, T dest);
/**
* @param call
@ -42,7 +44,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "return" edge in the supergraph from
* src->dest
*/
public IFlowFunction getReturnFlowFunction(Object call, Object src, Object dest);
public IFlowFunction getReturnFlowFunction(T call, T src, T dest);
/**
@ -51,7 +53,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "call-to-return" edge in the supergraph
* from src->dest
*/
public IUnaryFlowFunction getCallToReturnFlowFunction(Object src, Object dest);
public IUnaryFlowFunction getCallToReturnFlowFunction(T src, T dest);
/**
* @param src
@ -60,5 +62,5 @@ public interface IFlowFunctionMap {
* from src->dest, when the supergraph does not contain any callees of
* src. This happens via, e.g., slicing.
*/
public IUnaryFlowFunction getCallNoneToReturnFlowFunction(Object src, Object dest);
public IUnaryFlowFunction getCallNoneToReturnFlowFunction(T src, T dest);
}

View File

@ -26,6 +26,9 @@ import com.ibm.wala.util.graph.NumberedGraph;
* Additionally, due to expectional control flow, each method might have
* multiple exits or multiple entries.
*
* @param T type of node in the supergraph
* @param P type of a procedure (like a box in an RSM)
*
* @author sfink
*/
public interface ISupergraph<T,P> extends NumberedGraph<T> {

View File

@ -16,11 +16,12 @@ package com.ibm.wala.dataflow.IFDS;
*
* @author sfink
*/
public class IdentityFlowFunctions implements IFlowFunctionMap {
public class IdentityFlowFunctions<T> implements IFlowFunctionMap<T> {
private final static IdentityFlowFunctions SINGLETON = new IdentityFlowFunctions();
public static IdentityFlowFunctions singleton() {
@SuppressWarnings("unchecked")
public static <T> IdentityFlowFunctions<T> singleton() {
return SINGLETON;
}

View File

@ -36,7 +36,7 @@ public interface TabulationProblem<T,P> {
public TabulationDomain getDomain();
public IFlowFunctionMap getFunctionMap();
public IFlowFunctionMap<T> getFunctionMap();
/**
* @return the set of facts that are live on entry to the analysis. This set

View File

@ -129,7 +129,7 @@ public class TabulationSolver<T, P> {
/**
* A map from an edge in a supergraph to a flow function
*/
protected final IFlowFunctionMap flowFunctionMap;
protected final IFlowFunctionMap<T> flowFunctionMap;
/**
* The problem being solved.

View File

@ -22,13 +22,13 @@ import com.ibm.wala.util.debug.Assertions;
* @author sjfink
*
*/
public class SliceFunctions implements IFlowFunctionMap {
public class SliceFunctions implements IFlowFunctionMap<Statement> {
public IUnaryFlowFunction getCallFlowFunction(Object src, Object dest) {
public IUnaryFlowFunction getCallFlowFunction(Statement src, Statement dest) {
return ReachabilityFunctions.singleton().getCallFlowFunction(src, dest);
}
public IUnaryFlowFunction getCallNoneToReturnFlowFunction(Object src, Object dest) {
public IUnaryFlowFunction getCallNoneToReturnFlowFunction(Statement src, Statement dest) {
Statement s = (Statement) src;
switch (s.getKind()) {
case NORMAL_RET_CALLER:
@ -56,15 +56,15 @@ public class SliceFunctions implements IFlowFunctionMap {
}
}
public IUnaryFlowFunction getCallToReturnFlowFunction(Object src, Object dest) {
public IUnaryFlowFunction getCallToReturnFlowFunction(Statement src, Statement dest) {
return ReachabilityFunctions.singleton().getCallToReturnFlowFunction(src, dest);
}
public IUnaryFlowFunction getNormalFlowFunction(Object src, Object dest) {
public IUnaryFlowFunction getNormalFlowFunction(Statement src, Statement dest) {
return ReachabilityFunctions.singleton().getNormalFlowFunction(src, dest);
}
public IFlowFunction getReturnFlowFunction(Object call, Object src, Object dest) {
public IFlowFunction getReturnFlowFunction(Statement call, Statement src, Statement dest) {
return ReachabilityFunctions.singleton().getReturnFlowFunction(call, src, dest);
}

View File

@ -384,7 +384,7 @@ public class Slicer {
private final ISupergraph<Statement, PDG> supergraph;
private final IFlowFunctionMap f;
private final IFlowFunctionMap<Statement> f;
public SliceProblem(Statement s, CallGraph cg, ISDG sdg, boolean backward) {
this.src = s;
@ -408,7 +408,7 @@ public class Slicer {
*
* @see com.ibm.wala.dataflow.IFDS.TabulationProblem#getFunctionMap()
*/
public IFlowFunctionMap getFunctionMap() {
public IFlowFunctionMap<Statement> getFunctionMap() {
return f;
}

View File

@ -293,7 +293,7 @@ public class SymbolTable {
* @param rhs
* @return int
*/
public int newPhi(int[] rhs) {
public int newPhi(int[] rhs) throws IllegalArgumentException {
int result = getNewValueNumber();
SSAPhiInstruction phi = new SSAPhiInstruction(result, (int[]) rhs.clone());
values[result] = new PhiValue(phi);

View File

@ -49,8 +49,15 @@ public class FileProvider {
super();
}
/**
* @return null if there's a problem
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
try {
return ResourcesPlugin.getWorkspace();
} catch (Throwable t) {
return null;
}
}
/**
@ -59,30 +66,31 @@ public class FileProvider {
* if not found.
*/
public static Module getJarFileModule(String fileName) throws IOException {
// try {
// return (CorePlugin.getDefault() == null) ? getJarFileFromClassLoader(fileName) : getFromPlugin(fileName);
// } catch (IOException e) {
// System.err.println("Problem with file " + fileName);
// throw e;
// }
if(CorePlugin.getDefault() == null ) {
return getJarFileFromClassLoader(fileName);
}
else {
// try to load the path as a full path
try {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile file = workspaceRoot.getFile(new Path(fileName));
if( file != null ) {
return new JarFileModule(new JarFile(fileName, false));
}
} catch(Exception e) { }
// otherwise load from plugin
return getFromPlugin(fileName);
}
// try {
// return (CorePlugin.getDefault() == null) ?
// getJarFileFromClassLoader(fileName) : getFromPlugin(fileName);
// } catch (IOException e) {
// System.err.println("Problem with file " + fileName);
// throw e;
// }
if (CorePlugin.getDefault() == null) {
return getJarFileFromClassLoader(fileName);
} else {
// try to load the path as a full path
try {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IFile file = workspaceRoot.getFile(new Path(fileName));
if (file != null) {
return new JarFileModule(new JarFile(fileName, false));
}
} catch (Exception e) {
}
// otherwise load from plugin
return getFromPlugin(fileName);
}
}
/**

View File

@ -13,8 +13,6 @@ package com.ibm.wala.util.intset;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.ibm.wala.util.debug.Assertions;
/**
* An ordinal set mapping, backed a delegate, but adding an offset to each
* index.
@ -60,11 +58,6 @@ public class OffsetOrdinalSetMapping<T> implements OrdinalSetMapping<T> {
return delegate.hasMappedIndex(o);
}
public OrdinalSet<T> makeSingleton(int i) {
Assertions.UNREACHABLE();
return null;
}
public Iterator<T> iterator() {
return delegate.iterator();
}

View File

@ -40,12 +40,6 @@ public interface OrdinalSetMapping<T> extends Iterable<T> {
* @return the size of the domain of the bijection.
*/
public int getMappingSize();
/**
* @param i
* @return an ordinal set which conains only getMappedObject(i)
*/
public OrdinalSet<T> makeSingleton(int i);
/**
* Add an Object to the set of mapped objects.