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

View File

@ -34,7 +34,7 @@ public class ExplodedSupergraphWithSummaryEdges<T> extends ExplodedSupergraph<T>
* @param flowFunctions * @param flowFunctions
* @param solver * @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); super(supergraph, flowFunctions);
this.solver = solver; 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 * A map from an edge in a supergraph to a flow function
* *
* @param T type of node in the supergraph
*
* @author sfink * @author sfink
*/ */
public interface IFlowFunctionMap { public interface IFlowFunctionMap<T> {
/** /**
* @param src * @param src
@ -24,7 +26,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "normal" edge in the supergraph from * @return the flow function for a "normal" edge in the supergraph from
* src->dest * src->dest
*/ */
public IUnaryFlowFunction getNormalFlowFunction(Object src, Object dest); public IUnaryFlowFunction getNormalFlowFunction(T src, T dest);
/** /**
* @param src * @param src
@ -32,7 +34,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "call" edge in the supergraph from * @return the flow function for a "call" edge in the supergraph from
* src->dest * src->dest
*/ */
public IUnaryFlowFunction getCallFlowFunction(Object src, Object dest); public IUnaryFlowFunction getCallFlowFunction(T src, T dest);
/** /**
* @param call * @param call
@ -42,7 +44,7 @@ public interface IFlowFunctionMap {
* @return the flow function for a "return" edge in the supergraph from * @return the flow function for a "return" edge in the supergraph from
* src->dest * 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 * @return the flow function for a "call-to-return" edge in the supergraph
* from src->dest * from src->dest
*/ */
public IUnaryFlowFunction getCallToReturnFlowFunction(Object src, Object dest); public IUnaryFlowFunction getCallToReturnFlowFunction(T src, T dest);
/** /**
* @param src * @param src
@ -60,5 +62,5 @@ public interface IFlowFunctionMap {
* from src->dest, when the supergraph does not contain any callees of * from src->dest, when the supergraph does not contain any callees of
* src. This happens via, e.g., slicing. * 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 * Additionally, due to expectional control flow, each method might have
* multiple exits or multiple entries. * 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 * @author sfink
*/ */
public interface ISupergraph<T,P> extends NumberedGraph<T> { public interface ISupergraph<T,P> extends NumberedGraph<T> {

View File

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

View File

@ -36,7 +36,7 @@ public interface TabulationProblem<T,P> {
public TabulationDomain getDomain(); 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 * @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 * 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. * The problem being solved.

View File

@ -22,13 +22,13 @@ import com.ibm.wala.util.debug.Assertions;
* @author sjfink * @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); return ReachabilityFunctions.singleton().getCallFlowFunction(src, dest);
} }
public IUnaryFlowFunction getCallNoneToReturnFlowFunction(Object src, Object dest) { public IUnaryFlowFunction getCallNoneToReturnFlowFunction(Statement src, Statement dest) {
Statement s = (Statement) src; Statement s = (Statement) src;
switch (s.getKind()) { switch (s.getKind()) {
case NORMAL_RET_CALLER: 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); 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); 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); return ReachabilityFunctions.singleton().getReturnFlowFunction(call, src, dest);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -41,12 +41,6 @@ public interface OrdinalSetMapping<T> extends Iterable<T> {
*/ */
public int getMappingSize(); 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. * Add an Object to the set of mapped objects.
* @return the integer to which the object is mapped. * @return the integer to which the object is mapped.