2006-11-22 17:38:46 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 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.analysis.typeInference;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import com.ibm.wala.classLoader.IClass;
|
2007-06-01 03:26:18 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2007-07-06 22:08:13 +00:00
|
|
|
import com.ibm.wala.types.TypeReference;
|
2006-11-22 17:38:46 +00:00
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2009-05-01 17:42:28 +00:00
|
|
|
* Represents a type and its subtypes.
|
2006-11-22 17:38:46 +00:00
|
|
|
*
|
|
|
|
* @author sfink
|
|
|
|
*/
|
|
|
|
public class ConeType extends TypeAbstraction {
|
|
|
|
|
|
|
|
private final IClass type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* default constructor
|
2007-05-23 13:43:11 +00:00
|
|
|
*
|
2009-05-01 17:42:28 +00:00
|
|
|
* @throws IllegalArgumentException if type is null
|
2006-11-22 17:38:46 +00:00
|
|
|
*/
|
2007-05-23 13:43:11 +00:00
|
|
|
public ConeType(IClass type) {
|
2007-05-16 18:58:43 +00:00
|
|
|
if (type == null) {
|
|
|
|
throw new IllegalArgumentException("type is null");
|
|
|
|
}
|
2009-05-01 17:42:28 +00:00
|
|
|
assert type.getReference().isReferenceType();
|
2006-11-22 17:38:46 +00:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public TypeAbstraction meet(TypeAbstraction rhs) {
|
|
|
|
if (rhs == TOP) {
|
|
|
|
return this;
|
|
|
|
} else if (rhs instanceof ConeType) {
|
|
|
|
ConeType other = (ConeType) rhs;
|
|
|
|
if (type.equals(other.type)) {
|
|
|
|
return this;
|
|
|
|
} else if (type.isArrayClass() || other.type.isArrayClass()) {
|
2007-05-23 13:43:11 +00:00
|
|
|
// give up on arrays. We don't care anyway.
|
2007-07-16 14:49:20 +00:00
|
|
|
return new ConeType(type.getClassHierarchy().getRootClass());
|
2006-11-22 17:38:46 +00:00
|
|
|
} else {
|
2007-05-23 13:43:11 +00:00
|
|
|
return new ConeType(type.getClassHierarchy().getLeastCommonSuperclass(this.type, other.type));
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
} else if (rhs instanceof PointType) {
|
|
|
|
return rhs.meet(this);
|
|
|
|
} else if (rhs instanceof PrimitiveType) {
|
|
|
|
return TOP;
|
|
|
|
} else {
|
|
|
|
Assertions.UNREACHABLE("unexpected type " + rhs.getClass());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public String toString() {
|
|
|
|
return "cone:" + type.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method getType.
|
2007-05-23 13:43:11 +00:00
|
|
|
*
|
2006-11-22 17:38:46 +00:00
|
|
|
* @return TypeReference
|
|
|
|
*/
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public IClass getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2007-06-01 14:06:13 +00:00
|
|
|
@Override
|
2007-06-01 03:26:18 +00:00
|
|
|
public TypeReference getTypeReference() {
|
|
|
|
return type.getReference();
|
|
|
|
}
|
|
|
|
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public boolean equals(Object obj) {
|
2007-07-16 14:49:20 +00:00
|
|
|
if (!(obj instanceof ConeType)) {
|
2006-11-22 17:38:46 +00:00
|
|
|
return false;
|
2007-07-16 14:49:20 +00:00
|
|
|
}
|
2006-11-22 17:38:46 +00:00
|
|
|
ConeType other = (ConeType) obj;
|
2007-07-16 14:49:20 +00:00
|
|
|
if (other == TOP) {
|
2006-11-22 17:38:46 +00:00
|
|
|
return false;
|
2007-07-16 14:49:20 +00:00
|
|
|
}
|
2009-05-01 17:42:28 +00:00
|
|
|
if (!type.getClassHierarchy().equals(other.type.getClassHierarchy())) {
|
|
|
|
Assertions.UNREACHABLE("different chas " + this + " " + other);
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
return type.equals(other.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see java.lang.Object#hashCode()
|
|
|
|
*/
|
2007-05-30 15:16:05 +00:00
|
|
|
@Override
|
2006-11-22 17:38:46 +00:00
|
|
|
public int hashCode() {
|
|
|
|
return 39 * type.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isArrayType() {
|
|
|
|
return getType().isArrayClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInterface() {
|
|
|
|
return getType().isInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return an Iteration of IClass that implement this interface
|
|
|
|
*/
|
|
|
|
public Iterator iterateImplementors() {
|
2007-05-23 13:43:11 +00:00
|
|
|
return type.getClassHierarchy().getImplementors(getType().getReference()).iterator();
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
|
2007-06-01 03:26:18 +00:00
|
|
|
public IClassHierarchy getClassHierarchy() {
|
2007-05-23 13:43:11 +00:00
|
|
|
return type.getClassHierarchy();
|
2006-11-22 17:38:46 +00:00
|
|
|
}
|
|
|
|
}
|