From 6723d33683c4cf60e332337daa6ad8c9c950cad6 Mon Sep 17 00:00:00 2001 From: sjfink Date: Wed, 5 Dec 2007 19:49:03 +0000 Subject: [PATCH] bug fix and related API changes for interface type tests git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2104 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../analysis/typeInference/PointType.java | 2 +- .../src/com/ibm/wala/classLoader/IClass.java | 8 ++--- .../com/ibm/wala/classLoader/ShrikeClass.java | 26 ++------------- .../ClassHierarchyMethodTargetSelector.java | 2 +- .../callgraph/propagation/ContainerUtil.java | 8 ++--- .../propagation/PointerAnalysisImpl.java | 2 +- .../PropagationCallGraphBuilder.java | 2 +- .../propagation/PropagationSystem.java | 2 +- .../SSAPropagationCallGraphBuilder.java | 2 +- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 32 ++++++------------- .../com/ibm/wala/ipa/cha/IClassHierarchy.java | 6 ++-- .../ipa/summaries/BypassSyntheticClass.java | 24 +++++++------- 12 files changed, 39 insertions(+), 77 deletions(-) diff --git a/com.ibm.wala.core/src/com/ibm/wala/analysis/typeInference/PointType.java b/com.ibm.wala.core/src/com/ibm/wala/analysis/typeInference/PointType.java index b08606cca..dd8d5e593 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/analysis/typeInference/PointType.java +++ b/com.ibm.wala.core/src/com/ibm/wala/analysis/typeInference/PointType.java @@ -66,7 +66,7 @@ public class PointType extends TypeAbstraction { if (type.getClassHierarchy().isSubclassOf(typeKlass, other.getType())) { return other; } else if (other.isInterface()) { - if (type.getClassHierarchy().implementsInterface(typeKlass, T)) { + if (type.getClassHierarchy().implementsInterface(typeKlass, other.getType())) { return other; } } diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java index 091ec952c..c898fe20b 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/IClass.java @@ -68,20 +68,16 @@ public interface IClass extends IClassHierarchyDweller { /** * @return Collection of (IClass) interfaces this class directly implements + * If this class is an interface, returns the interfaces it immediately extends. */ Collection getDirectInterfaces() throws ClassHierarchyException; /** * @return Collection of (IClass) interfaces this class implements, including - * all ancestors of interfaces immediately implemented + * all ancestors of interfaces immediately implemented. */ Collection getAllImplementedInterfaces() throws ClassHierarchyException; - /** - * @return Collection of (IClass) interfaces this class extends, including - * transitive ancestors - */ - Collection getAllAncestorInterfaces() throws ClassHierarchyException; /** * Finds method matching signature. Delegates to superclass if not diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/ShrikeClass.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/ShrikeClass.java index 1cea9cb25..96b608a0e 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/ShrikeClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/ShrikeClass.java @@ -503,8 +503,7 @@ public final class ShrikeClass implements IClass { // didn't find it yet. special logic for interfaces try { if (isInterface() || isAbstract()) { - final Iterator it = (isInterface()) ? getAllAncestorInterfaces().iterator() : getAllImplementedInterfaces() - .iterator(); + final Iterator it = getAllImplementedInterfaces().iterator(); // try each superinterface while (it.hasNext()) { IClass k = it.next(); @@ -544,8 +543,7 @@ public final class ShrikeClass implements IClass { } // try superinterfaces try { - Collection ifaces = isInterface() ? getAllAncestorInterfaces() : getAllImplementedInterfaces(); - for (IClass i : ifaces) { + for (IClass i : getAllImplementedInterfaces()) { f = i.getField(name); if (f != null) { fieldMap.put(name, f); @@ -604,26 +602,6 @@ public final class ShrikeClass implements IClass { } public Collection getAllImplementedInterfaces() throws ClassHierarchyException { - if (Assertions.verifyAssertions) { - if (isInterface()) { - Assertions.UNREACHABLE("shouldn't ask for implemented interfaces of an interface " + this); - } - } - if (allInterfaces != null) { - return allInterfaces; - } else { - Collection C = computeAllInterfacesAsCollection(); - allInterfaces = Collections.unmodifiableCollection(C); - return allInterfaces; - } - } - - public Collection getAllAncestorInterfaces() throws ClassHierarchyException { - if (Assertions.verifyAssertions) { - if (!isInterface()) { - Assertions.UNREACHABLE(); - } - } if (allInterfaces != null) { return allInterfaces; } else { diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/ClassHierarchyMethodTargetSelector.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/ClassHierarchyMethodTargetSelector.java index b9f14fa61..d6e4e88b6 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/ClassHierarchyMethodTargetSelector.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/ClassHierarchyMethodTargetSelector.java @@ -118,7 +118,7 @@ public class ClassHierarchyMethodTargetSelector implements MethodTargetSelector return false; } else { if (resolvedType.isInterface()) { - return cha.implementsInterface(dispatchType,resolvedType.getReference()); + return cha.implementsInterface(dispatchType,resolvedType); } else { return cha.isSubclassOf(dispatchType,resolvedType); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/ContainerUtil.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/ContainerUtil.java index fe948b703..f4ff63ce1 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/ContainerUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/ContainerUtil.java @@ -55,16 +55,16 @@ public class ContainerUtil { } if (ClassLoaderReference.Primordial.equals(C.getClassLoader().getReference())&& TypeReference.JavaUtilCollection.getName().getPackage().equals(C.getReference().getName().getPackage())) { + IClass collection = cha.lookupClass(TypeReference.JavaUtilCollection); + IClass map = cha.lookupClass(TypeReference.JavaUtilMap); if (C.isInterface()) { - IClass collection = cha.lookupClass(TypeReference.JavaUtilCollection); - IClass map = cha.lookupClass(TypeReference.JavaUtilMap); if (Assertions.verifyAssertions) { Assertions._assert(collection != null); Assertions._assert(map != null); } Collection s; try { - s = C.getAllAncestorInterfaces(); + s = C.getAllImplementedInterfaces(); } catch (ClassHierarchyException e) { // give up return false; @@ -73,7 +73,7 @@ public class ContainerUtil { return true; } } else { - if (cha.implementsInterface(C, TypeReference.JavaUtilCollection) || cha.implementsInterface(C, TypeReference.JavaUtilMap)) { + if (cha.implementsInterface(C, collection) || cha.implementsInterface(C, map)) { return true; } } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java index 8b69e4e93..93cf8194c 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PointerAnalysisImpl.java @@ -402,7 +402,7 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis { if (klass.isInterface()) { for (Iterator it = rhsSet.iterator(); it.hasNext();) { InstanceKey ik = (InstanceKey) it.next(); - if (getCallGraph().getClassHierarchy().implementsInterface(ik.getConcreteType(), klass.getReference())) { + if (getCallGraph().getClassHierarchy().implementsInterface(ik.getConcreteType(), klass)) { S.add(getInstanceKeyMapping().getMappedIndex(ik)); } } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java index e464f27e3..b8f398fdd 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java @@ -1601,7 +1601,7 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder { } PointerKey p = getPointerKeyForArrayContents(I); if (contents.isInterface()) { - if (getClassHierarchy().implementsInterface(instance.getConcreteType(), contents.getReference())) { + if (getClassHierarchy().implementsInterface(instance.getConcreteType(), contents)) { sideEffect.b |= system.newConstraint(p, instance); } } else { diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationSystem.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationSystem.java index da4fe6e12..ed234c00e 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationSystem.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationSystem.java @@ -487,7 +487,7 @@ public class PropagationSystem extends DefaultFixedPointSolver { public boolean isSubclassOf(IClass c, IClass T); /** - * Does c implement T? + * Does c implement i? * - * @return true iff T is an interface and c is a class that implements T, + * @return true iff i is an interface and c is a class that implements i, */ - public boolean implementsInterface(IClass c, TypeReference T); + public boolean implementsInterface(IClass c, IClass i); /** * Return set of all subclasses of type in the Class Hierarchy diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java index 000d71a92..4ee3f1dba 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/summaries/BypassSyntheticClass.java @@ -90,7 +90,7 @@ public class BypassSyntheticClass extends SyntheticClass { * @see com.ibm.wala.classLoader.IClass#getAllInterfaces() */ public Collection getAllImplementedInterfaces() throws ClassHierarchyException { - Collection realIfaces = realType.isInterface() ? realType.getAllAncestorInterfaces() : realType.getAllImplementedInterfaces(); + Collection realIfaces = realType.getAllImplementedInterfaces(); if (realType.isInterface()) { HashSet result = HashSetFactory.make(realIfaces); result.add(realType); @@ -100,17 +100,17 @@ public class BypassSyntheticClass extends SyntheticClass { } } - /* - * @see com.ibm.wala.classLoader.IClass#getAllInterfaces() - */ - public Collection getAllAncestorInterfaces() throws ClassHierarchyException { - if (Assertions.verifyAssertions) { - Assertions._assert(realType.isInterface()); - } - HashSet result = HashSetFactory.make(realType.getAllAncestorInterfaces().size() + 1); - result.addAll(realType.getAllAncestorInterfaces()); - return result; - } +// /* +// * @see com.ibm.wala.classLoader.IClass#getAllInterfaces() +// */ +// public Collection getAllAncestorInterfaces() throws ClassHierarchyException { +// if (Assertions.verifyAssertions) { +// Assertions._assert(realType.isInterface()); +// } +// HashSet result = HashSetFactory.make(realType.getAllAncestorInterfaces().size() + 1); +// result.addAll(realType.getAllImplementedInterfaces()()); +// return result; +// } /* * @see com.ibm.wala.classLoader.IClass#getMethod(com.ibm.wala.classLoader.Selector)