Merge branch 'wala' into master
This commit is contained in:
commit
1090e59717
|
@ -153,6 +153,10 @@ abstract public class AstClass implements IClass, ClassConstants {
|
|||
}
|
||||
}
|
||||
|
||||
public IField getField(Atom name, TypeName type) {
|
||||
// assume that for AST classes, you can't have multiple fields with the same name
|
||||
return getField(name);
|
||||
}
|
||||
public Collection<IMethod> getDeclaredMethods() {
|
||||
return declaredMethods.values();
|
||||
}
|
||||
|
|
|
@ -117,6 +117,11 @@ abstract public class AstFunctionClass implements IClass, ClassConstants {
|
|||
return loader.lookupClass(superReference.getName()).getField(name);
|
||||
}
|
||||
|
||||
public IField getField(Atom name, TypeName type) {
|
||||
// assume that for AST classes, you can't have multiple fields with the same name
|
||||
return loader.lookupClass(superReference.getName()).getField(name);
|
||||
}
|
||||
|
||||
public TypeReference getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
|
|
@ -152,6 +152,9 @@
|
|||
<copy todir="${destination.temp.folder}/com.ibm.wala.core.testdata_1.0.0" failonerror="true" overwrite="false">
|
||||
<fileset dir="${basedir}" includes="META-INF/" />
|
||||
</copy>
|
||||
<copy todir="${destination.temp.folder}/com.ibm.wala.core.testdata_1.0.0" failonerror="true" overwrite="false">
|
||||
<fileset dir="${basedir}/classes" includes="**" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="build.zips" depends="init">
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,53 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.core.tests.cha;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IField;
|
||||
import com.ibm.wala.core.tests.util.TestConstants;
|
||||
import com.ibm.wala.core.tests.util.WalaTestCase;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.types.FieldReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.io.FileProvider;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
|
||||
public class DupFieldsTest extends WalaTestCase {
|
||||
|
||||
@Test public void testDupFieldNames() throws IOException, ClassHierarchyException {
|
||||
AnalysisScope scope = null;
|
||||
scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, FileProvider.getFile("J2SEClassHierarchyExclusions.txt"), DupFieldsTest.class.getClassLoader());
|
||||
ClassHierarchy cha = ClassHierarchy.make(scope);
|
||||
TypeReference ref = TypeReference.findOrCreate(ClassLoaderReference.Application, "LDupFieldName");
|
||||
IClass klass = cha.lookupClass(ref);
|
||||
boolean threwException = false;
|
||||
try {
|
||||
klass.getField(Atom.findOrCreateUnicodeAtom("a"));
|
||||
} catch (IllegalStateException e) {
|
||||
threwException = true;
|
||||
}
|
||||
Assert.assertTrue(threwException);
|
||||
IField f = cha.resolveField(FieldReference.findOrCreate(ref, Atom.findOrCreateUnicodeAtom("a"), TypeReference.Int));
|
||||
Assert.assertEquals(f.getFieldTypeReference(), TypeReference.Int);
|
||||
f = cha.resolveField(FieldReference.findOrCreate(ref, Atom.findOrCreateUnicodeAtom("a"), TypeReference.Boolean));
|
||||
Assert.assertEquals(f.getFieldTypeReference(), TypeReference.Boolean);
|
||||
}
|
||||
}
|
|
@ -129,6 +129,10 @@ public class ArrayClass implements IClass, Constants {
|
|||
return getSuperclass().getField(name);
|
||||
}
|
||||
|
||||
public IField getField(Atom name, TypeName typeName) {
|
||||
return getSuperclass().getField(name, typeName);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.classLoader.IClass#getDeclaredMethods()
|
||||
*/
|
||||
|
|
|
@ -121,7 +121,7 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
|
|||
protected int hashCode;
|
||||
|
||||
private final HashMap<Atom, IField> fieldMap = HashMapFactory.make(5);
|
||||
|
||||
|
||||
/**
|
||||
* A warning for when we get a class not found exception
|
||||
*/
|
||||
|
@ -192,12 +192,17 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
|
|||
if (fieldMap.containsKey(name)) {
|
||||
return fieldMap.get(name);
|
||||
} else {
|
||||
IField f = findDeclaredField(name);
|
||||
if (f != null) {
|
||||
fieldMap.put(name, f);
|
||||
return f;
|
||||
List<IField> fields = findDeclaredField(name);
|
||||
if (!fields.isEmpty()) {
|
||||
if (fields.size() == 1) {
|
||||
IField f = fields.iterator().next();
|
||||
fieldMap.put(name, f);
|
||||
return f;
|
||||
} else {
|
||||
throw new IllegalStateException("multiple fields with name " + name);
|
||||
}
|
||||
} else if ((superClass = getSuperclass()) != null) {
|
||||
f = superClass.getField(name);
|
||||
IField f = superClass.getField(name);
|
||||
if (f != null) {
|
||||
fieldMap.put(name, f);
|
||||
return f;
|
||||
|
@ -205,7 +210,7 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
|
|||
}
|
||||
// try superinterfaces
|
||||
for (IClass i : getAllImplementedInterfaces()) {
|
||||
f = i.getField(name);
|
||||
IField f = i.getField(name);
|
||||
if (f != null) {
|
||||
fieldMap.put(name, f);
|
||||
return f;
|
||||
|
@ -216,6 +221,43 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public IField getField(Atom name, TypeName type) {
|
||||
try {
|
||||
// typically, there will be at most one field with the name
|
||||
IField field = getField(name);
|
||||
if (field != null && field.getFieldTypeReference().getName().equals(type)) {
|
||||
return field;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
assert e.getMessage().startsWith("multiple fields with");
|
||||
// multiple fields. look through all of them and see if any have the appropriate type
|
||||
List<IField> fields = findDeclaredField(name);
|
||||
for (IField f : fields) {
|
||||
if (f.getFieldTypeReference().getName().equals(type)) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
// check superclass
|
||||
if (getSuperclass() != null) {
|
||||
IField f = superClass.getField(name, type);
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
// try superinterfaces
|
||||
for (IClass i : getAllImplementedInterfaces()) {
|
||||
IField f = i.getField(name, type);
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void computeSuperclass() {
|
||||
superclassComputed = true;
|
||||
|
||||
|
@ -466,11 +508,14 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected IField findDeclaredField(Atom name) {
|
||||
protected List<IField> findDeclaredField(Atom name) {
|
||||
|
||||
List<IField> result = new ArrayList<IField>(1);
|
||||
|
||||
if (instanceFields != null) {
|
||||
for (int i = 0; i < instanceFields.length; i++) {
|
||||
if (instanceFields[i].getName() == name) {
|
||||
return instanceFields[i];
|
||||
result.add(instanceFields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -478,12 +523,12 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
|
|||
if (staticFields != null) {
|
||||
for (int i = 0; i < staticFields.length; i++) {
|
||||
if (staticFields[i].getName() == name) {
|
||||
return staticFields[i];
|
||||
result.add(staticFields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void addFieldToList(List<FieldImpl> L, Atom name, ImmutableByteArray fieldType, int accessFlags,
|
||||
|
|
|
@ -88,9 +88,16 @@ public interface IClass extends IClassHierarchyDweller {
|
|||
|
||||
/**
|
||||
* Finds a field.
|
||||
*
|
||||
* @throws IllegalStateException if the class contains multiple fields with name <code>name</code>.
|
||||
*/
|
||||
IField getField(Atom name);
|
||||
|
||||
/**
|
||||
* Finds a field, given a name and a type. Returns <code>null</code> if not found.
|
||||
*/
|
||||
IField getField(Atom name, TypeName type);
|
||||
|
||||
/**
|
||||
* @return canonical TypeReference corresponding to this class
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy;
|
|||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.strings.Atom;
|
||||
|
||||
/**
|
||||
* An {@link IClass} that exists nowhere in bytecode.
|
||||
|
@ -121,4 +122,11 @@ public abstract class SyntheticClass implements IClass {
|
|||
public TypeName getName() {
|
||||
return getReference().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* we assume synthetic classes do not need to have multiple fields with the same name.
|
||||
*/
|
||||
public IField getField(Atom name, TypeName typeName) {
|
||||
return getField(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -532,7 +532,7 @@ public class ClassHierarchy implements IClassHierarchy {
|
|||
if (f == null) {
|
||||
throw new IllegalArgumentException("f is null");
|
||||
}
|
||||
return klass.getField(f.getName());
|
||||
return klass.getField(f.getName(), f.getFieldType().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,14 +15,10 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.intset.BasicNaturalRelation;
|
||||
import com.ibm.wala.util.intset.IBinaryNaturalRelation;
|
||||
import com.ibm.wala.util.intset.IntIterator;
|
||||
import com.ibm.wala.util.intset.IntPair;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
import com.ibm.wala.util.intset.MutableIntSet;
|
||||
import com.ibm.wala.util.intset.MutableSparseIntSet;
|
||||
|
||||
/**
|
||||
* Utilities for dealing with acyclic subgraphs
|
||||
|
@ -103,7 +99,7 @@ public class Acyclic {
|
|||
*/
|
||||
public static <T> Collection<Path> computeAcyclicPaths(NumberedGraph<T> G, T root, T src, T sink, int max) {
|
||||
Collection<Path> result = HashSetFactory.make();
|
||||
SubGraph<T> acyclic = new SubGraph<T>(G, computeBackEdges(G, root));
|
||||
EdgeFilteredNumberedGraph<T> acyclic = new EdgeFilteredNumberedGraph<T>(G, computeBackEdges(G, root));
|
||||
|
||||
Collection<Path> worklist = HashSetFactory.make();
|
||||
Path sinkPath = Path.make(G.getNumber(sink));
|
||||
|
@ -123,96 +119,4 @@ public class Acyclic {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class SubGraph<T> extends AbstractNumberedGraph<T> {
|
||||
|
||||
private final NumberedGraph<T> delegate;
|
||||
|
||||
private final IBinaryNaturalRelation ignoreEdges;
|
||||
|
||||
private final Edges edges;
|
||||
|
||||
SubGraph(NumberedGraph<T> delegate, IBinaryNaturalRelation ignoreEdges) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
this.ignoreEdges = ignoreEdges;
|
||||
this.edges = new Edges();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberedEdgeManager<T> getEdgeManager() {
|
||||
return edges;
|
||||
}
|
||||
|
||||
private final class Edges implements NumberedEdgeManager<T> {
|
||||
|
||||
public void addEdge(T src, T dst) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public int getPredNodeCount(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Iterator<T> getPredNodes(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSuccNodeCount(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Iterator<T> getSuccNodes(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasEdge(T src, T dst) {
|
||||
Assertions.UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeAllIncidentEdges(T node) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public void removeEdge(T src, T dst) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public void removeIncomingEdges(T node) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public void removeOutgoingEdges(T node) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public IntSet getPredNodeNumbers(T node) {
|
||||
IntSet s = delegate.getPredNodeNumbers(node);
|
||||
MutableIntSet result = MutableSparseIntSet.makeEmpty();
|
||||
for (IntIterator it = s.intIterator(); it.hasNext();) {
|
||||
int y = it.next();
|
||||
if (!ignoreEdges.contains(y, getNumber(node))) {
|
||||
result.add(y);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public IntSet getSuccNodeNumbers(T node) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberedNodeManager<T> getNodeManager() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.util.graph;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.intset.IBinaryNaturalRelation;
|
||||
import com.ibm.wala.util.intset.IntIterator;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
import com.ibm.wala.util.intset.MutableIntSet;
|
||||
import com.ibm.wala.util.intset.MutableSparseIntSet;
|
||||
|
||||
/**
|
||||
* View of a {@link NumberedGraph} in which some edges have been filtered out
|
||||
*/
|
||||
public class EdgeFilteredNumberedGraph<T> extends AbstractNumberedGraph<T> {
|
||||
|
||||
private final NumberedGraph<T> delegate;
|
||||
|
||||
private final IBinaryNaturalRelation ignoreEdges;
|
||||
|
||||
private final Edges edges;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param delegate the underlying graph
|
||||
* @param ignoreEdges relation specifying which edges should be filtered out
|
||||
*/
|
||||
public EdgeFilteredNumberedGraph(NumberedGraph<T> delegate, IBinaryNaturalRelation ignoreEdges) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
this.ignoreEdges = ignoreEdges;
|
||||
this.edges = new Edges();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberedEdgeManager<T> getEdgeManager() {
|
||||
return edges;
|
||||
}
|
||||
|
||||
private final class Edges implements NumberedEdgeManager<T> {
|
||||
|
||||
public void addEdge(T src, T dst) {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public int getPredNodeCount(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Iterator<T> getPredNodes(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSuccNodeCount(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Iterator<T> getSuccNodes(T N) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasEdge(T src, T dst) {
|
||||
Assertions.UNREACHABLE();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeAllIncidentEdges(T node) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public void removeEdge(T src, T dst) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public void removeIncomingEdges(T node) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public void removeOutgoingEdges(T node) throws UnsupportedOperationException {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
public IntSet getPredNodeNumbers(T node) {
|
||||
IntSet s = delegate.getPredNodeNumbers(node);
|
||||
MutableIntSet result = MutableSparseIntSet.makeEmpty();
|
||||
for (IntIterator it = s.intIterator(); it.hasNext();) {
|
||||
int y = it.next();
|
||||
if (!ignoreEdges.contains(y, getNumber(node))) {
|
||||
result.add(y);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public IntSet getSuccNodeNumbers(T node) {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NumberedNodeManager<T> getNodeManager() {
|
||||
return delegate;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue