misc minor cleanups, annotations, and bug fixes
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1009 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
4a29f033c8
commit
ec2e0f5967
|
@ -120,7 +120,7 @@ public class ECallGraphWrapper extends EObjectGraphImpl {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ECallGraphWrapper load(String fileName, ClassLoader loader) {
|
||||
public static ECallGraphWrapper load(String fileName, ClassLoader loader) throws IllegalArgumentException {
|
||||
ECallGraph G = loadFromFile(fileName, loader);
|
||||
Assertions.productionAssertion(G != null);
|
||||
ECallGraphWrapper result = new ECallGraphWrapper();
|
||||
|
@ -136,7 +136,7 @@ public class ECallGraphWrapper extends EObjectGraphImpl {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static ECallGraph loadFromFile(String fileName, ClassLoader loader) {
|
||||
private static ECallGraph loadFromFile(String fileName, ClassLoader loader) throws IllegalArgumentException {
|
||||
|
||||
Resource r = new XMIResourceImpl(URI.createURI(fileName));
|
||||
XMLResource.XMLMap xmlMap = new XMLMapImpl();
|
||||
|
@ -149,7 +149,9 @@ public class ECallGraphWrapper extends EObjectGraphImpl {
|
|||
// try again a different way
|
||||
// This is offensive. TODO: fix this.
|
||||
InputStream s = loader.getResourceAsStream(fileName);
|
||||
Assertions.productionAssertion(s != null, "null resource for " + fileName);
|
||||
if (s == null) {
|
||||
throw new IllegalArgumentException("null resource for " + fileName);
|
||||
}
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
r = resSet.createResource(URI.createURI("junk"));
|
||||
options = new HashMap<String, XMLMap>();
|
||||
|
|
|
@ -10,24 +10,11 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.emf.wrappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.xmi.XMLResource.XMLMap;
|
||||
|
||||
import com.ibm.wala.ecore.common.CommonFactory;
|
||||
import com.ibm.wala.ecore.common.EContainer;
|
||||
|
@ -98,22 +85,13 @@ public class EClassHierarchyWrapper extends EObjectTree {
|
|||
cha.setNodes(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class hierarchy from a file
|
||||
* @param loader loader that knows how to find the file
|
||||
*/
|
||||
public static EClassHierarchyWrapper load(String fileName, ClassLoader loader) {
|
||||
EClassHierarchy cha = loadFromFile(fileName,loader);
|
||||
return load(cha);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param o an EClassHierarchy
|
||||
* @return a ClassHierarchy populated according to the contents of o
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static EClassHierarchyWrapper load(EObject o) {
|
||||
EClassHierarchy cha = (EClassHierarchy)o;
|
||||
public static EClassHierarchyWrapper load(EClassHierarchy cha) {
|
||||
Assertions.productionAssertion(cha != null);
|
||||
EClassHierarchyWrapper result = new EClassHierarchyWrapper();
|
||||
|
||||
|
@ -128,39 +106,7 @@ public class EClassHierarchyWrapper extends EObjectTree {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: this should go away?
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static EClassHierarchy loadFromFile(String fileName, ClassLoader loader) {
|
||||
// InputStream s = loader.getResourceAsStream(fileName);
|
||||
File f = new File(fileName);
|
||||
InputStream s = null;
|
||||
try {
|
||||
s = new FileInputStream(f);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
Assertions.productionAssertion(f != null, " could not find " + fileName);
|
||||
}
|
||||
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
Resource r = resSet.createResource(URI.createURI("junk"));
|
||||
Map<String, XMLMap> options = new HashMap<String, XMLMap>();
|
||||
try {
|
||||
r.load(s, options);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
EList contents = r.getContents();
|
||||
for (Iterator<EObject> it = contents.iterator(); it.hasNext();) {
|
||||
Object o = it.next();
|
||||
if (o instanceof EClassHierarchy) {
|
||||
return (EClassHierarchy)o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a class to this hierarchy
|
||||
|
|
|
@ -10,24 +10,11 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.emf.wrappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.xmi.XMLResource.XMLMap;
|
||||
|
||||
import com.ibm.wala.ecore.common.CommonFactory;
|
||||
import com.ibm.wala.ecore.common.EContainer;
|
||||
|
@ -83,17 +70,11 @@ public class EInterfaceHierarchyWrapper extends EObjectGraphImpl {
|
|||
h.setNodes(c);
|
||||
}
|
||||
|
||||
public static EInterfaceHierarchyWrapper load(String fileName, ClassLoader loader) {
|
||||
EInterfaceHierarchy h = loadFromFile(fileName, loader);
|
||||
return load(h);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: refactor
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static EInterfaceHierarchyWrapper load(EObject o) {
|
||||
EInterfaceHierarchy h = (EInterfaceHierarchy) o;
|
||||
public static EInterfaceHierarchyWrapper load(EInterfaceHierarchy h) {
|
||||
Assertions.productionAssertion(h != null);
|
||||
EInterfaceHierarchyWrapper result = new EInterfaceHierarchyWrapper();
|
||||
|
||||
|
@ -107,38 +88,6 @@ public class EInterfaceHierarchyWrapper extends EObjectGraphImpl {
|
|||
return result;
|
||||
}
|
||||
|
||||
// TODO: refactor!!
|
||||
@SuppressWarnings("unchecked")
|
||||
private static EInterfaceHierarchy loadFromFile(String fileName, ClassLoader loader) {
|
||||
// InputStream s = loader.getResourceAsStream(fileName);
|
||||
File f = new File(fileName);
|
||||
InputStream s = null;
|
||||
try {
|
||||
s = new FileInputStream(f);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
Assertions.productionAssertion(f != null, " could not find " + fileName);
|
||||
}
|
||||
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
Resource r = resSet.createResource(URI.createURI("junk"));
|
||||
Map<String, XMLMap> options = new HashMap<String, XMLMap>();
|
||||
try {
|
||||
r.load(s, options);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
EList contents = r.getContents();
|
||||
for (Iterator<EObject> it = contents.iterator(); it.hasNext();) {
|
||||
Object o = it.next();
|
||||
if (o instanceof EInterfaceHierarchy) {
|
||||
return (EInterfaceHierarchy) o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a class to this hierarchy
|
||||
*
|
||||
|
|
|
@ -89,7 +89,7 @@ public class EUtil {
|
|||
* an xml file
|
||||
* @return List<EObject> serialized in said file.
|
||||
*/
|
||||
public static List<EObject> readEObjects(String xmlFile, ClassLoader loader) {
|
||||
public static List<EObject> readEObjects(String xmlFile, ClassLoader loader) throws WalaException {
|
||||
|
||||
URL url = loader.getResource(xmlFile);
|
||||
URI fileURI = null;
|
||||
|
@ -108,8 +108,7 @@ public class EUtil {
|
|||
try {
|
||||
resource.load(null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
assert false : "failure to load " + xmlFile + ".";
|
||||
throw new WalaException("failure to load " + xmlFile + ".", e);
|
||||
}
|
||||
|
||||
return resource.getContents();
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
|
||||
/**
|
||||
* @author sfink
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SSAComparisonInstruction extends SSAInstruction {
|
||||
private final int result;
|
||||
|
@ -25,7 +25,7 @@ public class SSAComparisonInstruction extends SSAInstruction {
|
|||
private final int val1;
|
||||
|
||||
private final int val2;
|
||||
|
||||
|
||||
private final short opcode;
|
||||
|
||||
SSAComparisonInstruction(short opcode, int result, int val1, int val2) {
|
||||
|
@ -38,8 +38,8 @@ public class SSAComparisonInstruction extends SSAInstruction {
|
|||
|
||||
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
|
||||
// TODO: Julian ... is this correct when defs == null or defs.length == 0?
|
||||
return new SSAComparisonInstruction(opcode, defs == null || defs.length == 0 ? result : defs[0], uses == null ? val1 : uses[0], uses == null ? val2
|
||||
: uses[1]);
|
||||
return new SSAComparisonInstruction(opcode, defs == null || defs.length == 0 ? result : defs[0], uses == null
|
||||
|| uses.length == 0 ? val1 : uses[0], uses == null ? val2 : uses[1]);
|
||||
}
|
||||
|
||||
public String toString(SymbolTable symbolTable, ValueDecorator d) {
|
||||
|
|
|
@ -17,21 +17,22 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
|
||||
/**
|
||||
* @author sfink
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
|
||||
private final int exceptionValueNumber;
|
||||
|
||||
private final int bbNumber;
|
||||
|
||||
SSAGetCaughtExceptionInstruction(int bbNumber, int exceptionValueNumber) {
|
||||
super();
|
||||
this.exceptionValueNumber = exceptionValueNumber;
|
||||
this.bbNumber = bbNumber;
|
||||
}
|
||||
|
||||
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
|
||||
return
|
||||
new SSAGetCaughtExceptionInstruction(
|
||||
bbNumber,
|
||||
defs==null? exceptionValueNumber: defs[0]);
|
||||
// TODO: check that this is the intended behavior. Julian?
|
||||
return new SSAGetCaughtExceptionInstruction(bbNumber, defs == null || defs.length == 0 ? exceptionValueNumber : defs[0]);
|
||||
}
|
||||
|
||||
public String toString(SymbolTable symbolTable, ValueDecorator d) {
|
||||
|
@ -47,8 +48,10 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
|
|||
public void visit(IVisitor v) {
|
||||
v.visitGetCaughtException(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getException() {
|
||||
|
@ -77,6 +80,7 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
|
|||
|
||||
/**
|
||||
* Returns the bb.
|
||||
*
|
||||
* @return BasicBlock
|
||||
*/
|
||||
public int getBasicBlockNumber() {
|
||||
|
@ -87,14 +91,18 @@ public class SSAGetCaughtExceptionInstruction extends SSAInstruction {
|
|||
return 2243 * exceptionValueNumber;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.ibm.wala.ssa.Instruction#isFallThrough()
|
||||
*/
|
||||
public boolean isFallThrough() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.ibm.wala.ssa.Instruction#getExceptionTypes()
|
||||
*/
|
||||
public Collection<TypeReference> getExceptionTypes() {
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.Collection;
|
|||
|
||||
import com.ibm.wala.shrikeBT.IInstruction;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -212,9 +211,8 @@ public abstract class SSAInstruction implements IInstruction {
|
|||
* @return value number representing the jth use in this instruction. -1 means
|
||||
* TOP (i.e., the value doesn't matter)
|
||||
*/
|
||||
public int getUse(int j) {
|
||||
Assertions.UNREACHABLE();
|
||||
return -1;
|
||||
public int getUse(int j) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public abstract int hashCode();
|
||||
|
|
|
@ -18,32 +18,35 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
|
||||
/**
|
||||
* @author sfink
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SSAMonitorInstruction extends SSAInstruction {
|
||||
private final int ref;
|
||||
|
||||
private final boolean isEnter;
|
||||
|
||||
SSAMonitorInstruction(int ref, boolean isEnter) {
|
||||
super();
|
||||
this.ref = ref;
|
||||
this.isEnter = isEnter;
|
||||
}
|
||||
|
||||
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
|
||||
return
|
||||
new SSAMonitorInstruction(
|
||||
uses==null? ref: uses[0],
|
||||
isEnter);
|
||||
// todo: check that this is the intended behavior. julian?
|
||||
return new SSAMonitorInstruction(uses == null || uses.length == 0 ? ref : uses[0], isEnter);
|
||||
}
|
||||
|
||||
public String toString(SymbolTable symbolTable, ValueDecorator d) {
|
||||
return "monitor " + getValueString(symbolTable, d, ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
|
||||
*/
|
||||
public void visit(IVisitor v) {
|
||||
v.visitMonitor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.ibm.wala.ssa.SSAInstruction#getNumberOfUses()
|
||||
*/
|
||||
|
@ -63,19 +66,28 @@ public class SSAMonitorInstruction extends SSAInstruction {
|
|||
public int hashCode() {
|
||||
return ref * 6173 ^ 4423;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.ibm.wala.ssa.Instruction#isPEI()
|
||||
*/
|
||||
public boolean isPEI() {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.ibm.wala.ssa.Instruction#isFallThrough()
|
||||
*/
|
||||
public boolean isFallThrough() {
|
||||
return true;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.ibm.wala.ssa.Instruction#getExceptionTypes()
|
||||
*/
|
||||
public Collection<TypeReference> getExceptionTypes() {
|
||||
|
|
|
@ -44,6 +44,9 @@ public final class Descriptor {
|
|||
* @return the canonical representative for this descriptor value
|
||||
*/
|
||||
public static Descriptor findOrCreate(TypeName[] parameters, TypeName returnType) {
|
||||
if (parameters != null && parameters.length == 0) {
|
||||
parameters = null;
|
||||
}
|
||||
Key k = new Key(returnType, parameters);
|
||||
Descriptor result = map.get(k);
|
||||
if (result == null) {
|
||||
|
|
|
@ -58,13 +58,15 @@ public class ClassSignature extends Signature {
|
|||
return result;
|
||||
}
|
||||
|
||||
public ClassTypeSignature getSuperclassSignature() {
|
||||
public ClassTypeSignature getSuperclassSignature() throws IllegalArgumentException {
|
||||
return ClassTypeSignature.makeClassTypeSig(rawString().substring(endOfFormalTypeParameters(),endOfClassTypeSig(endOfFormalTypeParameters())));
|
||||
}
|
||||
|
||||
private int endOfClassTypeSig(int start) {
|
||||
private int endOfClassTypeSig(int start) throws IllegalArgumentException {
|
||||
String s = rawString().substring(start);
|
||||
assert s.charAt(0) == 'L';
|
||||
if (s.charAt(0) != 'L') {
|
||||
throw new IllegalArgumentException("malformed ClassSignature " + rawString());
|
||||
}
|
||||
int i = 1;
|
||||
int depth = 0;
|
||||
while (depth > 0 || s.charAt(i) != ';') {
|
||||
|
@ -79,7 +81,7 @@ public class ClassSignature extends Signature {
|
|||
return start + i + 1;
|
||||
}
|
||||
|
||||
public ClassTypeSignature[] getSuperinterfaceSignatures() {
|
||||
public ClassTypeSignature[] getSuperinterfaceSignatures() throws IllegalArgumentException {
|
||||
int start = endOfClassTypeSig(endOfFormalTypeParameters());
|
||||
ArrayList<ClassTypeSignature> result = new ArrayList<ClassTypeSignature>();
|
||||
while (start < rawString().length() - 1) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package com.ibm.wala.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,7 +41,7 @@ public class CompoundIterator<T> implements Iterator<T> {
|
|||
/**
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public T next() {
|
||||
public T next() throws NoSuchElementException {
|
||||
if (A.hasNext()) {
|
||||
return A.next();
|
||||
} else {
|
||||
|
|
|
@ -12,8 +12,6 @@ package com.ibm.wala.util;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
*
|
||||
* A utility to efficiently compose an iterator and a singleton
|
||||
|
@ -54,7 +52,7 @@ public class IteratorPlusOne<T> implements Iterator<T> {
|
|||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
Assertions.UNREACHABLE();
|
||||
public void remove() throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
package com.ibm.wala.util.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* A <code>FilterIterator</code> filters an
|
||||
* <code>Iterator</code> to generate a new one.
|
||||
* A <code>FilterIterator</code> filters an <code>Iterator</code> to
|
||||
* generate a new one.
|
||||
*
|
||||
* @author Mauricio J. Serrano
|
||||
* @author John Whaley
|
||||
|
@ -23,13 +23,19 @@ import java.util.Iterator;
|
|||
*/
|
||||
public class FilterIterator<T> implements java.util.Iterator<T> {
|
||||
final Iterator<?> i;
|
||||
|
||||
final Filter f;
|
||||
|
||||
private T next = null;
|
||||
|
||||
private boolean done = false;
|
||||
|
||||
/**
|
||||
* @param i the original iterator
|
||||
* @param f a filter which defines which elements belong to the generated iterator
|
||||
* @param i
|
||||
* the original iterator
|
||||
* @param f
|
||||
* a filter which defines which elements belong to the generated
|
||||
* iterator
|
||||
*/
|
||||
public FilterIterator(Iterator<?> i, Filter f) {
|
||||
this.i = i;
|
||||
|
@ -37,7 +43,6 @@ public class FilterIterator<T> implements java.util.Iterator<T> {
|
|||
advance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* update the internal state to prepare for the next access to this iterator
|
||||
*/
|
||||
|
@ -53,33 +58,42 @@ public class FilterIterator<T> implements java.util.Iterator<T> {
|
|||
done = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T next() {
|
||||
if (done)
|
||||
public T next() throws NoSuchElementException {
|
||||
if (done) {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
T o = (T) next;
|
||||
advance();
|
||||
return o;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.Iterator#hasNext()
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return !done;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
public void remove() throws UnsupportedOperationException {
|
||||
throw new java.lang.UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
|
|
|
@ -12,8 +12,7 @@ package com.ibm.wala.util.collections;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,15 +46,18 @@ public class ReverseIterator<T> implements Iterator<T> {
|
|||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#next()
|
||||
*/
|
||||
public T next() {
|
||||
public T next() throws NoSuchElementException {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return list.get(nextIndex--);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Iterator#remove()
|
||||
*/
|
||||
public void remove() {
|
||||
Assertions.UNREACHABLE();
|
||||
public void remove() throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,11 +19,13 @@ import com.ibm.wala.emf.wrappers.EUtil;
|
|||
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.PatternSetUtil;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
/**
|
||||
*
|
||||
* An object which represents a set of classes read from an XML file.
|
||||
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
public class XMLSetOfClasses extends SetOfClasses {
|
||||
|
@ -31,13 +33,21 @@ public class XMLSetOfClasses extends SetOfClasses {
|
|||
private static final boolean DEBUG = false;
|
||||
|
||||
private Pattern pattern;
|
||||
|
||||
private String regex;
|
||||
|
||||
private boolean needsCompile = true;
|
||||
|
||||
public XMLSetOfClasses(String xmlFile, ClassLoader loader) {
|
||||
public XMLSetOfClasses(String xmlFile, ClassLoader loader) {
|
||||
super();
|
||||
|
||||
EContainer c = (EContainer)EUtil.readEObjects(xmlFile, loader).get(0);
|
||||
EContainer c = null;
|
||||
try {
|
||||
c = (EContainer) EUtil.readEObjects(xmlFile, loader).get(0);
|
||||
} catch (WalaException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
regex = PatternSetUtil.composeRegularExpression(c);
|
||||
needsCompile = true;
|
||||
|
|
|
@ -71,7 +71,10 @@ public class GraphReachability <T>{
|
|||
* @param n
|
||||
* @return the set of interesting nodes reachable from n
|
||||
*/
|
||||
public OrdinalSet<T> getReachableSet(Object n) {
|
||||
public OrdinalSet<T> getReachableSet(Object n) throws IllegalStateException {
|
||||
if (solver == null) {
|
||||
throw new IllegalStateException("must call solve() before calling getReachableSet()");
|
||||
}
|
||||
BitVectorVariable v = (BitVectorVariable) solver.getOut(n);
|
||||
if (Assertions.verifyAssertions) {
|
||||
if (v == null) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Map;
|
|||
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.UnimplementedError;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.OrderedMultiGraph;
|
||||
import com.ibm.wala.util.intset.SimpleVector;
|
||||
|
@ -44,7 +45,7 @@ public class BasicOrderedMultiGraph<T> implements OrderedMultiGraph<T> {
|
|||
* @see com.ibm.wala.util.graph.EdgeManager#addEdge(java.lang.Object,
|
||||
* java.lang.Object)
|
||||
*/
|
||||
public void addEdge(T src, T dst) throws IllegalArgumentException{
|
||||
public void addEdge(T src, T dst) throws IllegalArgumentException {
|
||||
delegate.addEdge(src, dst);
|
||||
SimpleVector<T> s = successorEdges.get(src);
|
||||
if (s == null) {
|
||||
|
@ -53,9 +54,8 @@ public class BasicOrderedMultiGraph<T> implements OrderedMultiGraph<T> {
|
|||
}
|
||||
s.set(s.getMaxIndex() + 1, dst);
|
||||
}
|
||||
|
||||
|
||||
public void addEdge(int i, T src, T dst) throws IllegalArgumentException{
|
||||
public void addEdge(int i, T src, T dst) throws IllegalArgumentException {
|
||||
delegate.addEdge(src, dst);
|
||||
SimpleVector<T> s = successorEdges.get(src);
|
||||
if (s == null) {
|
||||
|
@ -77,7 +77,7 @@ public class BasicOrderedMultiGraph<T> implements OrderedMultiGraph<T> {
|
|||
return delegate.getNumberOfNodes();
|
||||
}
|
||||
|
||||
public int getPredNodeCount(T N) throws IllegalArgumentException{
|
||||
public int getPredNodeCount(T N) throws IllegalArgumentException {
|
||||
return delegate.getPredNodeCount(N);
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,15 @@ public class BasicOrderedMultiGraph<T> implements OrderedMultiGraph<T> {
|
|||
*
|
||||
* @see com.ibm.wala.util.graph.EdgeManager#getPredNodes(java.lang.Object)
|
||||
*/
|
||||
public Iterator<? extends T> getPredNodes(T N) throws IllegalArgumentException{
|
||||
public Iterator<? extends T> getPredNodes(T N) throws IllegalArgumentException {
|
||||
return delegate.getPredNodes(N);
|
||||
}
|
||||
|
||||
public int getSuccNodeCount(T N) throws IllegalArgumentException{
|
||||
public int getSuccNodeCount(T N) throws IllegalArgumentException {
|
||||
return delegate.getSuccNodeCount(N);
|
||||
}
|
||||
|
||||
public Iterator<? extends T> getSuccNodes(T N) throws IllegalArgumentException{
|
||||
public Iterator<? extends T> getSuccNodes(T N) throws IllegalArgumentException {
|
||||
return delegate.getSuccNodes(N);
|
||||
}
|
||||
|
||||
|
@ -106,37 +106,37 @@ public class BasicOrderedMultiGraph<T> implements OrderedMultiGraph<T> {
|
|||
return delegate.iterator();
|
||||
}
|
||||
|
||||
public void removeAllIncidentEdges(T node) {
|
||||
public void removeAllIncidentEdges(T node) throws UnimplementedError {
|
||||
Assertions.UNREACHABLE();
|
||||
delegate.removeAllIncidentEdges(node);
|
||||
}
|
||||
|
||||
public void removeEdge(T src, T dst) {
|
||||
public void removeEdge(T src, T dst) throws UnimplementedError {
|
||||
Assertions.UNREACHABLE();
|
||||
delegate.removeEdge(src, dst);
|
||||
}
|
||||
|
||||
public void removeIncomingEdges(T node) {
|
||||
public void removeIncomingEdges(T node) throws UnimplementedError {
|
||||
Assertions.UNREACHABLE();
|
||||
delegate.removeIncomingEdges(node);
|
||||
}
|
||||
|
||||
public void removeNode(T n) {
|
||||
public void removeNode(T n) throws UnimplementedError {
|
||||
Assertions.UNREACHABLE();
|
||||
delegate.removeNode(n);
|
||||
}
|
||||
|
||||
public void removeNodeAndEdges(T N) {
|
||||
public void removeNodeAndEdges(T N) throws UnimplementedError {
|
||||
Assertions.UNREACHABLE();
|
||||
delegate.removeNodeAndEdges(N);
|
||||
}
|
||||
|
||||
public void removeOutgoingEdges(T node) {
|
||||
public void removeOutgoingEdges(T node) throws UnimplementedError {
|
||||
Assertions.UNREACHABLE();
|
||||
delegate.removeOutgoingEdges(node);
|
||||
}
|
||||
|
||||
public T getSuccessor(T node, int i) throws IllegalArgumentException{
|
||||
public T getSuccessor(T node, int i) throws IllegalArgumentException {
|
||||
SimpleVector<T> s = successorEdges.get(node);
|
||||
if (s == null) {
|
||||
throw new IllegalArgumentException("no successors for node " + node);
|
||||
|
@ -147,5 +147,4 @@ public class BasicOrderedMultiGraph<T> implements OrderedMultiGraph<T> {
|
|||
return s.get(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package com.ibm.wala.util.graph.traverse;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.ibm.wala.util.collections.EmptyIterator;
|
||||
|
@ -87,7 +88,10 @@ public abstract class DFSFinishTimeIterator<T> extends Stack<T> implements Itera
|
|||
* @return the next graph node in finishing time order.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public T next() {
|
||||
public T next() throws NoSuchElementException {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
if (empty()) {
|
||||
T v = theNextElement;
|
||||
setPendingChildren(v, getConnected(v));
|
||||
|
|
|
@ -12,6 +12,7 @@ package com.ibm.wala.util.graph.traverse;
|
|||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.util.collections.ReverseIterator;
|
||||
|
@ -65,7 +66,7 @@ public class SCCIterator<T> implements Iterator<Set<T>> {
|
|||
/**
|
||||
* Find the next SCC in this enumeration
|
||||
*/
|
||||
public Set<T> next() {
|
||||
public Set<T> next() throws NoSuchElementException {
|
||||
Set<T> currentSCC = new HashSet<T>();
|
||||
|
||||
T v = rev.next();
|
||||
|
|
|
@ -92,7 +92,7 @@ public class HeapTracer {
|
|||
internalClasses.add(Class.forName("com.ibm.wala.util.collections.SmallMap"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.SimpleVector"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.SimpleIntVector"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.BasicNonNegativeIntRelation"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.BasicNaturalRelation"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.SparseIntSet"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.SparseVector"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.intset.MutableSharedBitVectorIntSet"));
|
||||
|
@ -101,6 +101,7 @@ public class HeapTracer {
|
|||
internalClasses.add(Class.forName("com.ibm.wala.util.graph.impl.DelegatingNumberedNodeManager"));
|
||||
internalClasses.add(Class.forName("com.ibm.wala.util.graph.impl.SparseNumberedEdgeManager"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
/**
|
||||
*
|
||||
* The shared bit vector implementation described by [Heintze 1999] TODO: much
|
||||
* optimization possible.
|
||||
* optimization possible.
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
|
@ -181,9 +181,9 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
|
|||
BitVectorIntSet bv = new BitVectorIntSet(that);
|
||||
return intersection(bv);
|
||||
} else {
|
||||
// really slow. optimize as needed.
|
||||
// really slow. optimize as needed.
|
||||
BitVectorIntSet result = new BitVectorIntSet();
|
||||
for (IntIterator it = intIterator(); it.hasNext(); ) {
|
||||
for (IntIterator it = intIterator(); it.hasNext();) {
|
||||
int x = it.next();
|
||||
if (that.contains(x)) {
|
||||
result.add(x);
|
||||
|
@ -343,7 +343,7 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
|
|||
} else if (that instanceof BitVectorIntSet) {
|
||||
return sameValue((BitVectorIntSet) that);
|
||||
} else if (that instanceof SemiSparseMutableIntSet) {
|
||||
return that.sameValue(this);
|
||||
return that.sameValue(this);
|
||||
} else {
|
||||
Assertions.UNREACHABLE("unexpected class " + that.getClass());
|
||||
return false;
|
||||
|
@ -471,12 +471,14 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
|
|||
public boolean isSubset(IntSet that) {
|
||||
if (that instanceof MutableSharedBitVectorIntSet) {
|
||||
return isSubset((MutableSharedBitVectorIntSet) that);
|
||||
} else if (that instanceof SparseIntSet) {
|
||||
Assertions.UNREACHABLE("unexpected class " + that.getClass());
|
||||
return false;
|
||||
} else {
|
||||
Assertions.UNREACHABLE("unexpected class " + that.getClass());
|
||||
return false;
|
||||
// really slow. optimize as needed.
|
||||
for (IntIterator it = intIterator(); it.hasNext();) {
|
||||
if (!that.contains(it.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -822,7 +824,7 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
|
|||
privatePart = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sharedPart != null) {
|
||||
if (sharedPart.contains(i)) {
|
||||
|
@ -850,8 +852,8 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
|
|||
} else if (set instanceof BitVectorIntSet) {
|
||||
intersectWithInternal(new MutableSharedBitVectorIntSet((BitVectorIntSet) set));
|
||||
} else {
|
||||
// this is really slow. optimize as needed.
|
||||
for (IntIterator it = intIterator(); it.hasNext(); ) {
|
||||
// this is really slow. optimize as needed.
|
||||
for (IntIterator it = intIterator(); it.hasNext();) {
|
||||
int x = it.next();
|
||||
if (!set.contains(x)) {
|
||||
remove(x);
|
||||
|
@ -986,9 +988,10 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
|
|||
*/
|
||||
public boolean containsAny(IntSet set) {
|
||||
if (set instanceof MutableSharedBitVectorIntSet) {
|
||||
MutableSharedBitVectorIntSet other = (MutableSharedBitVectorIntSet)set;
|
||||
MutableSharedBitVectorIntSet other = (MutableSharedBitVectorIntSet) set;
|
||||
if (sharedPart != null) {
|
||||
// an optimization to make life easier on the underlying bitvectorintsets
|
||||
// an optimization to make life easier on the underlying
|
||||
// bitvectorintsets
|
||||
if (other.sharedPart != null && sharedPart.containsAny(other.sharedPart)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -389,8 +389,15 @@ public class SparseIntSet implements IntSet {
|
|||
temp.intersectWith(that);
|
||||
return temp;
|
||||
} else {
|
||||
Assertions.UNREACHABLE("Unexpected: " + that.getClass());
|
||||
return null;
|
||||
// this is really slow. optimize as needed.
|
||||
MutableSparseIntSet temp = new MutableSparseIntSet();
|
||||
for (IntIterator it = intIterator(); it.hasNext(); ) {
|
||||
int x = it.next();
|
||||
if (that.contains(x)) {
|
||||
temp.add(x);
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -492,8 +499,13 @@ public class SparseIntSet implements IntSet {
|
|||
} else if (that instanceof BitVectorIntSet) {
|
||||
return isSubsetInternal((BitVectorIntSet) that);
|
||||
} else {
|
||||
Assertions.UNREACHABLE("Unexpected type " + that.getClass());
|
||||
return false;
|
||||
// really slow. optimize as needed.
|
||||
for (IntIterator it = intIterator(); it.hasNext(); ) {
|
||||
if (!that.contains(it.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,10 @@ public abstract class Warning implements Comparable {
|
|||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*
|
||||
* @throws ClassCastException if o is not a Warning
|
||||
*/
|
||||
public int compareTo(Object o) {
|
||||
if (Assertions.verifyAssertions) {
|
||||
Assertions._assert(o instanceof Warning);
|
||||
}
|
||||
public int compareTo(Object o) throws ClassCastException {
|
||||
Warning other = (Warning) o;
|
||||
if (level < other.level) {
|
||||
return -1;
|
||||
|
@ -70,11 +69,12 @@ public abstract class Warning implements Comparable {
|
|||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (Assertions.verifyAssertions) {
|
||||
Assertions._assert(obj instanceof Warning);
|
||||
if (obj instanceof Warning) {
|
||||
Warning other = (Warning) obj;
|
||||
return (getMsg().equals(other.getMsg()) && getLevel() == other.getLevel());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
Warning other = (Warning) obj;
|
||||
return (getMsg().equals(other.getMsg()) && getLevel() == other.getLevel());
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue