misc. cleanups and refactoring

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1168 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-05-23 13:43:11 +00:00
parent afc1dc0a59
commit 3a07a1a1f7
10 changed files with 48 additions and 49 deletions

View File

@ -614,7 +614,7 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
private TypeAbstraction typeRef2TypeAbstraction(TypeReference type) {
IClass klass = cha.lookupClass(type);
if (klass != null) {
return new ConeType(klass, cha);
return new ConeType(klass);
// if (klass.isAbstract() || klass.isInterface()) {
// return new ConeType(klass, cha);
// } else {

View File

@ -18,20 +18,21 @@ import com.ibm.wala.util.debug.Assertions;
/**
*
* Absraction of a Java type. These are immutable.
* Absraction of a Java type. These are immutable.
*
* @author sfink
*/
public class ConeType extends TypeAbstraction {
private final IClass type;
private final ClassHierarchy cha;
/**
* default constructor
* @throws IllegalArgumentException if type is null
*
* @throws IllegalArgumentException
* if type is null
*/
public ConeType(IClass type, ClassHierarchy cha) {
public ConeType(IClass type) {
if (type == null) {
throw new IllegalArgumentException("type is null");
}
@ -39,7 +40,6 @@ public class ConeType extends TypeAbstraction {
Assertions._assert(type.getReference().isReferenceType());
}
this.type = type;
this.cha = cha;
}
public TypeAbstraction meet(TypeAbstraction rhs) {
@ -50,10 +50,10 @@ public class ConeType extends TypeAbstraction {
if (type.equals(other.type)) {
return this;
} else if (type.isArrayClass() || other.type.isArrayClass()) {
// give up on arrays. We don't care anyway.
return new ConeType(cha.getRootClass(), cha);
// give up on arrays. We don't care anyway.
return new ConeType(type.getClassHierarchy().getRootClass());
} else {
return new ConeType(cha.getLeastCommonSuperclass(this.type, other.type), cha);
return new ConeType(type.getClassHierarchy().getLeastCommonSuperclass(this.type, other.type));
}
} else if (rhs instanceof PointType) {
return rhs.meet(this);
@ -74,6 +74,7 @@ public class ConeType extends TypeAbstraction {
/**
* Method getType.
*
* @return TypeReference
*/
public IClass getType() {
@ -90,8 +91,8 @@ public class ConeType extends TypeAbstraction {
if (other == TOP)
return false;
if (Assertions.verifyAssertions) {
if (!cha.equals(other.cha)) {
Assertions._assert(cha.equals(other.cha), "different chas " + this +" " + other);
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
Assertions.UNREACHABLE("different chas " + this + " " + other);
}
}
return type.equals(other.type);
@ -116,10 +117,10 @@ public class ConeType extends TypeAbstraction {
* @return an Iteration of IClass that implement this interface
*/
public Iterator iterateImplementors() {
return cha.getImplementors(getType().getReference()).iterator();
return type.getClassHierarchy().getImplementors(getType().getReference()).iterator();
}
public ClassHierarchy getClassHierarchy() {
return cha;
return type.getClassHierarchy();
}
}

View File

@ -11,7 +11,6 @@
package com.ibm.wala.analysis.typeInference;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
@ -23,13 +22,12 @@ import com.ibm.wala.util.debug.Assertions;
public class PointType extends TypeAbstraction {
private final IClass type;
private final ClassHierarchy cha;
/**
* Private constructor ... only for internal use.
* @throws IllegalArgumentException if type is null
*/
public PointType(IClass type, ClassHierarchy cha) {
public PointType(IClass type) {
if (type == null) {
throw new IllegalArgumentException("type is null");
}
@ -37,7 +35,6 @@ public class PointType extends TypeAbstraction {
if (Assertions.verifyAssertions) {
Assertions._assert(type.getReference().isReferenceType());
}
this.cha = cha;
}
public TypeAbstraction meet(TypeAbstraction rhs) {
@ -50,28 +47,28 @@ public class PointType extends TypeAbstraction {
return this;
} else if (type.isArrayClass() || other.type.isArrayClass()) {
// give up on arrays. We don't care anyway.
return new ConeType(cha.getRootClass(), cha);
return new ConeType(type.getClassHierarchy().getRootClass());
} else {
return new ConeType(cha.getLeastCommonSuperclass(this.type, other.type), cha);
return new ConeType(type.getClassHierarchy().getLeastCommonSuperclass(this.type, other.type));
}
} else if (rhs instanceof ConeType) {
ConeType other = (ConeType) rhs;
TypeReference T = other.getType().getReference();
if (type.isArrayClass() || T.isArrayType()) {
// give up on arrays. We don't care anyway.
return new ConeType(cha.getRootClass(), cha);
return new ConeType(type.getClassHierarchy().getRootClass());
}
IClass typeKlass = type;
if (cha.isSubclassOf(typeKlass, other.getType())) {
if (type.getClassHierarchy().isSubclassOf(typeKlass, other.getType())) {
return other;
} else if (other.isInterface()) {
if (cha.implementsInterface(typeKlass, T)) {
if (type.getClassHierarchy().implementsInterface(typeKlass, T)) {
return other;
}
}
// if we get here, we need to do cha-based superclass and return a cone.
// TODO: avoid the allocation
return other.meet(new ConeType(other.getType(), cha));
return other.meet(new ConeType(other.getType()));
} else {
Assertions.UNREACHABLE("Unexpected type: " + rhs.getClass());
return null;
@ -104,8 +101,8 @@ public class PointType extends TypeAbstraction {
}
PointType other = (PointType) obj;
if (Assertions.verifyAssertions) {
if (!cha.equals(other.cha)) {
Assertions._assert(cha.equals(other.cha), "different chas " + this + " " + other);
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
Assertions.UNREACHABLE("different chas " + this + " " + other);
}
}
return type.equals(other.type);

View File

@ -91,7 +91,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
this.cha = ir.getMethod().getClassHierarchy();
this.ir = ir;
this.doPrimitives = doPrimitives;
this.BOTTOM = new ConeType(cha.getRootClass(), cha);
this.BOTTOM = new ConeType(cha.getRootClass());
initialize();
}
@ -112,7 +112,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
if (t.isReferenceType()) {
IClass klass = cha.lookupClass(t);
if (klass != null) {
v.setType(new ConeType(klass, cha));
v.setType(new ConeType(klass));
} else {
v.setType(ConeType.TOP);
// v.setType(BOTTOM);
@ -147,7 +147,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
if (Assertions.verifyAssertions) {
Assertions._assert(klass != null);
}
v.setType(new PointType(klass, cha));
v.setType(new PointType(klass));
IMethod m = cha.resolveMethod(call.getDeclaredTarget());
if (m != null) {
@ -163,7 +163,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
TypeReference tx = x[i];
IClass tc = cha.lookupClass(tx);
if (tc != null) {
v.setType(v.getType().meet(new ConeType(tc, cha)));
v.setType(v.getType().meet(new ConeType(tc)));
}
}
}
@ -451,7 +451,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
if (Assertions.verifyAssertions) {
Assertions._assert(klass != null);
}
t.setType(new ConeType(klass, cha));
t.setType(new ConeType(klass));
return CHANGED;
}
} else {
@ -460,7 +460,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
// Assertions._assert(klass != null);
// }
if (klass != null) {
t.setType(new ConeType(klass, cha));
t.setType(new ConeType(klass));
} else {
t.setType(ConeType.TOP);
}
@ -535,7 +535,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
// be pessimistic
result = new DeclaredTypeOperator(BOTTOM);
} else {
result = new DeclaredTypeOperator(new ConeType(klass, cha));
result = new DeclaredTypeOperator(new ConeType(klass));
}
}
}
@ -549,7 +549,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
// be pessimistic
result = new DeclaredTypeOperator(BOTTOM);
} else {
result = new DeclaredTypeOperator(new ConeType(klass, cha));
result = new DeclaredTypeOperator(new ConeType(klass));
}
} else if (doPrimitives && type.isPrimitiveType()) {
result = new DeclaredTypeOperator(PrimitiveType.getPrimitive(type));
@ -566,7 +566,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
// be pessimistic
result = new DeclaredTypeOperator(BOTTOM);
} else {
result = new DeclaredTypeOperator(new PointType(klass, cha));
result = new DeclaredTypeOperator(new PointType(klass));
}
}
@ -578,7 +578,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
// be pessimistic
result = new DeclaredTypeOperator(BOTTOM);
} else {
result = new DeclaredTypeOperator(new ConeType(klass, cha));
result = new DeclaredTypeOperator(new ConeType(klass));
}
}
@ -631,7 +631,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
// be pessimistic
result = BOTTOM;
} else {
result = new ConeType(klass, cha);
result = new ConeType(klass);
}
while (it.hasNext()) {
t = (TypeReference) it.next();
@ -639,7 +639,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
if (tClass == null) {
result = BOTTOM;
} else {
result = result.meet(new ConeType(tClass, cha));
result = result.meet(new ConeType(tClass));
}
}
return result;
@ -749,7 +749,7 @@ public class TypeInference extends SSAInference implements FixedPointConstants {
public TypeAbstraction getConstantType(int valueNumber) {
if (ir.getSymbolTable().isStringConstant(valueNumber)) {
return new PointType(cha.lookupClass(TypeReference.JavaLangString), cha);
return new PointType(cha.lookupClass(TypeReference.JavaLangString));
} else {
return getConstantPrimitiveType(valueNumber);
}

View File

@ -399,10 +399,7 @@ public class JdtUtil {
}
}
/**
* @param sigs
* @return
*/
private static String[] toArray(ArrayList<String> sigs) {
int size = sigs.size();
if (size == 0) {

View File

@ -249,7 +249,7 @@ public class DefaultFixedPointSystem implements IFixedPointSystem {
checkGraph();
}
Iterator<INodeWithNumber> order = reverseSCCTopOrder(graph);
Iterator<INodeWithNumber> order = makeSCCTopOrder(graph);
int number = 0;
while (order.hasNext()) {
Object elt = order.next();
@ -262,16 +262,16 @@ public class DefaultFixedPointSystem implements IFixedPointSystem {
/**
* Build an Iterator over all the nodes in the graph, in an order
* such that SCCs are visited in reverse topological order.
* such that SCCs are visited in topological order.
*/
public static <T> Iterator<T> reverseSCCTopOrder(Graph<T> graph) {
public static <T> Iterator<T> makeSCCTopOrder(Graph<T> graph) {
// the following code ensures a topological order over SCCs.
// note that the first two lines of the following give a topological
// order for dags, but that can get screwed up by cycles. so
// instead, we use Tarjan's SCC algorithm, which happens to
// visit nodes in an order consistent with a top. order over SCCs.
// finish time is post-orderat
// finish time is post-order
// note that if you pay attention only to the first representative
// of each SCC discovered, we have a top. order of these SCC
// representatives

View File

@ -504,7 +504,7 @@ public class PropagationGraph implements IFixedPointSystem {
public void reorder() {
VariableGraphView graph = new VariableGraphView();
Iterator<IVariable> order = DefaultFixedPointSystem.reverseSCCTopOrder(graph);
Iterator<IVariable> order = DefaultFixedPointSystem.makeSCCTopOrder(graph);
int number = 0;
while (order.hasNext()) {

View File

@ -47,7 +47,7 @@ public class ReceiverTypeContextSelector implements ContextSelector {
if (receiver == null) {
throw new IllegalArgumentException("receiver is null");
}
PointType P = new PointType(receiver.getConcreteType(), cha);
PointType P = new PointType(receiver.getConcreteType());
return new JavaTypeContext(P);
}

View File

@ -71,7 +71,7 @@ public class ReflectionSummary {
Assertions._assert(klass != null, "null type for " + T);
}
}
p[i] = new PointType(klass, cha);
p[i] = new PointType(klass);
}
return new SetType(p);
}

View File

@ -60,4 +60,8 @@ public class ReverseIterator<T> implements Iterator<T> {
throw new UnsupportedOperationException();
}
public static <T> Iterator<T> reverse(Iterator<T> it) {
return new ReverseIterator<T>(it);
}
}