|
|
@ -25,9 +25,9 @@ import java.util.Vector; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Jochen Hoenicke |
|
|
|
* @author Jochen Hoenicke |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ArrayType extends Type { |
|
|
|
public class ArrayType extends ClassInterfacesType { |
|
|
|
// The interfaces that an array implements:
|
|
|
|
// The interfaces that an array implements:
|
|
|
|
final static ClassInfo[] ifaces = { |
|
|
|
final static ClassInfo[] arrayIfaces = { |
|
|
|
// Make sure to list all interfaces, even if some interface
|
|
|
|
// Make sure to list all interfaces, even if some interface
|
|
|
|
// implements another (or change code in getGeneralizedType().
|
|
|
|
// implements another (or change code in getGeneralizedType().
|
|
|
|
ClassInfo.forName("java.lang.Cloneable"), |
|
|
|
ClassInfo.forName("java.lang.Cloneable"), |
|
|
@ -37,7 +37,8 @@ public class ArrayType extends Type { |
|
|
|
Type elementType; |
|
|
|
Type elementType; |
|
|
|
|
|
|
|
|
|
|
|
public ArrayType(Type elementType) { |
|
|
|
public ArrayType(Type elementType) { |
|
|
|
super(TC_ARRAY); |
|
|
|
super(null, arrayIfaces); |
|
|
|
|
|
|
|
typecode = TC_ARRAY; |
|
|
|
this.elementType = elementType; |
|
|
|
this.elementType = elementType; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -45,56 +46,48 @@ public class ArrayType extends Type { |
|
|
|
return elementType; |
|
|
|
return elementType; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Type getBottom() { |
|
|
|
public Type getSuperType() { |
|
|
|
return tArray(elementType.getBottom()); |
|
|
|
return tRange(tObject, (ClassInterfacesType) |
|
|
|
|
|
|
|
tArray(elementType.getSuperType())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Type getTop() { |
|
|
|
public Type getSubType() { |
|
|
|
return tArray(elementType.getTop()); |
|
|
|
return tArray(elementType.getSubType()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public Type getBottom() {
|
|
|
|
|
|
|
|
// return tArray(elementType.getBottom());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public Type getTop() {
|
|
|
|
|
|
|
|
// return tArray(elementType.getTop());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public Type getHint() { |
|
|
|
public Type getHint() { |
|
|
|
return tArray(elementType.getHint()); |
|
|
|
return tArray(elementType.getHint()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static boolean implementsAllIfaces(ClassInfo[] otherIfaces) { |
|
|
|
|
|
|
|
big: |
|
|
|
|
|
|
|
for (int i=0; i < otherIfaces.length; i++) { |
|
|
|
|
|
|
|
ClassInfo iface = otherIfaces[i]; |
|
|
|
|
|
|
|
for (int j=0; j < ifaces.length; j++) { |
|
|
|
|
|
|
|
if (iface.implementedBy(ifaces[j])) |
|
|
|
|
|
|
|
continue big; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create the type corresponding to the range from bottomType to this. |
|
|
|
* Create the type corresponding to the range from bottomType to this. |
|
|
|
* @param bottomType the start point of the range |
|
|
|
* @param bottomType the start point of the range |
|
|
|
* @return the range type, or tError if not possible. |
|
|
|
* @return the range type, or tError if not possible. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Type createRangeType(Type bottomType) { |
|
|
|
public Type createRangeType(ClassInterfacesType bottom) { |
|
|
|
/* tUnknown , tArray(x) -> <tObject, tArray(x)> |
|
|
|
/* |
|
|
|
|
|
|
|
* tArray(y), tArray(x) -> tArray( y.intersection(x) ) |
|
|
|
* obj , tArray(x) -> <obj, tArray(x)> |
|
|
|
* obj , tArray(x) -> <obj, tArray(x)> |
|
|
|
* iff tArray extends and implements obj |
|
|
|
* iff tArray extends and implements obj |
|
|
|
* tArray(y), tArray(x) -> tArray( <y,x> ) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (bottomType == tUnknown || bottomType == tObject) |
|
|
|
if (bottom.getTypeCode() == TC_ARRAY) |
|
|
|
return tRange(tObject, this); |
|
|
|
return tArray(elementType.intersection |
|
|
|
|
|
|
|
(((ArrayType)bottom).elementType)); |
|
|
|
|
|
|
|
|
|
|
|
if (bottomType instanceof ClassInterfacesType) { |
|
|
|
if (bottom.getTypeCode() == TC_CLASS) { |
|
|
|
ClassInterfacesType bottom = (ClassInterfacesType) bottomType; |
|
|
|
|
|
|
|
if (bottom.clazz == null |
|
|
|
if (bottom.clazz == null |
|
|
|
&& implementsAllIfaces(bottom.ifaces)) |
|
|
|
&& implementsAllIfaces(bottom.ifaces)) |
|
|
|
return tRange(bottom, this); |
|
|
|
return tRange(bottom, this); |
|
|
|
return tError; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return (bottomType.typecode == TC_ARRAY) |
|
|
|
return tError; |
|
|
|
? tArray(elementType.createRangeType |
|
|
|
|
|
|
|
(((ArrayType)bottomType).elementType)) |
|
|
|
|
|
|
|
: tError; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -103,25 +96,27 @@ public class ArrayType extends Type { |
|
|
|
* @return the common sub type. |
|
|
|
* @return the common sub type. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Type getSpecializedType(Type type) { |
|
|
|
public Type getSpecializedType(Type type) { |
|
|
|
/* tArray(x), tUnknown -> tArray(x) |
|
|
|
/* |
|
|
|
* tArray(x), tObject -> tArray(x) |
|
|
|
* tArray(x), object -> tArray(x) iff tArray implements object |
|
|
|
* tArray(x), tArray(y) -> tArray(x.getSpecialized(y)) |
|
|
|
* tArray(x), tArray(y) -> tArray(x.intersection(y)) |
|
|
|
* tArray(x), other -> tError |
|
|
|
* tArray(x), other -> tError |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (type == tUnknown || type == tObject) |
|
|
|
if (type.getTypeCode() == TC_RANGE) { |
|
|
|
|
|
|
|
type = ((RangeType) type).getBottom(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (type == tNull) |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
|
|
|
|
if (type.getTypeCode() == TC_ARRAY) { |
|
|
|
if (type instanceof ClassInterfacesType) { |
|
|
|
return tArray(elementType.intersection |
|
|
|
|
|
|
|
(((ArrayType)type).elementType)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (type.getTypeCode() == TC_CLASS) { |
|
|
|
ClassInterfacesType other = (ClassInterfacesType) type; |
|
|
|
ClassInterfacesType other = (ClassInterfacesType) type; |
|
|
|
if (other.clazz == null |
|
|
|
if (other.clazz == null |
|
|
|
&& implementsAllIfaces(other.ifaces)) |
|
|
|
&& implementsAllIfaces(other.ifaces)) |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
return tError; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return (type.getTypeCode() == TC_ARRAY) |
|
|
|
return tError; |
|
|
|
? tArray(elementType.getSpecializedType |
|
|
|
|
|
|
|
(((ArrayType)type).elementType)) |
|
|
|
|
|
|
|
: tError; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -130,28 +125,25 @@ public class ArrayType extends Type { |
|
|
|
* @return the common super type. |
|
|
|
* @return the common super type. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Type getGeneralizedType(Type type) { |
|
|
|
public Type getGeneralizedType(Type type) { |
|
|
|
/* tArray(x), tUnknown -> tArray(x) |
|
|
|
/* tArray(x), tNull -> tArray(x) |
|
|
|
* tArray(x), tClass(y) -> tObject |
|
|
|
* tArray(x), tClass(y) -> tObject, ifaces of tArray and tClass |
|
|
|
* tArray(x), tArray(y) -> tArray(x.getGeneralized(y)) |
|
|
|
* tArray(x), tArray(y) -> tArray(x.intersection(y)) |
|
|
|
* tArray(x), other -> tError |
|
|
|
* tArray(x), other -> tError |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (type == tUnknown) |
|
|
|
if (type.getTypeCode() == TC_RANGE) { |
|
|
|
|
|
|
|
type = ((RangeType) type).getTop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (type == tNull) |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
if (type.getTypeCode() == TC_ARRAY) |
|
|
|
if (type.getTypeCode() == TC_ARRAY) |
|
|
|
return tArray(elementType.getGeneralizedType |
|
|
|
return tArray(elementType.intersection |
|
|
|
(((ArrayType)type).elementType)); |
|
|
|
(((ArrayType)type).elementType)); |
|
|
|
|
|
|
|
|
|
|
|
if (type.getTypeCode() == TC_CLASS) { |
|
|
|
if (type.getTypeCode() == TC_CLASS) { |
|
|
|
ClassInterfacesType other = (ClassInterfacesType) type; |
|
|
|
ClassInterfacesType other = (ClassInterfacesType) type; |
|
|
|
if (implementsAllIfaces(other.ifaces)) { |
|
|
|
|
|
|
|
if (other.clazz == null) |
|
|
|
|
|
|
|
return other; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return ClassInterfacesType.create(null, other.ifaces); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (other.implementsAllIfaces(ifaces)) |
|
|
|
if (other.implementsAllIfaces(ifaces)) |
|
|
|
return ClassInterfacesType.create(null, ifaces); |
|
|
|
return ClassInterfacesType.create(null, ifaces); |
|
|
|
|
|
|
|
if (other.clazz == null && implementsAllIfaces(other.ifaces)) |
|
|
|
|
|
|
|
return other; |
|
|
|
|
|
|
|
|
|
|
|
/* Now the more complicated part: find all interfaces, that are |
|
|
|
/* Now the more complicated part: find all interfaces, that are |
|
|
|
* implemented by one interface or class in each group. |
|
|
|
* implemented by one interface or class in each group. |
|
|
@ -183,34 +175,34 @@ public class ArrayType extends Type { |
|
|
|
return tError; |
|
|
|
return tError; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
// /**
|
|
|
|
* Checks if we need to cast to a middle type, before we can cast from |
|
|
|
// * Checks if we need to cast to a middle type, before we can cast from
|
|
|
|
* fromType to this type. |
|
|
|
// * fromType to this type.
|
|
|
|
* @return the middle type, or null if it is not necessary. |
|
|
|
// * @return the middle type, or null if it is not necessary.
|
|
|
|
*/ |
|
|
|
// */
|
|
|
|
public Type getCastHelper(Type fromType) { |
|
|
|
// public Type getCastHelper(Type fromType) {
|
|
|
|
Type topType = fromType.getTop(); |
|
|
|
// Type topType = fromType.getTop();
|
|
|
|
switch (topType.getTypeCode()) { |
|
|
|
// switch (topType.getTypeCode()) {
|
|
|
|
case TC_ARRAY: |
|
|
|
// case TC_ARRAY:
|
|
|
|
if (!elementType.isClassType() |
|
|
|
// if (!elementType.isClassType()
|
|
|
|
|| !((ArrayType)topType).elementType.isClassType()) |
|
|
|
// || !((ArrayType)topType).elementType.isClassType())
|
|
|
|
return tObject; |
|
|
|
// return tObject;
|
|
|
|
Type middleType = elementType.getCastHelper |
|
|
|
// Type middleType = elementType.getCastHelper
|
|
|
|
(((ArrayType)topType).elementType); |
|
|
|
// (((ArrayType)topType).elementType);
|
|
|
|
if (middleType != null) |
|
|
|
// if (middleType != null)
|
|
|
|
return tArray(middleType); |
|
|
|
// return tArray(middleType);
|
|
|
|
return null; |
|
|
|
// return null;
|
|
|
|
case TC_CLASS: |
|
|
|
// case TC_CLASS:
|
|
|
|
ClassInterfacesType top = (ClassInterfacesType) topType; |
|
|
|
// ClassInterfacesType top = (ClassInterfacesType) topType;
|
|
|
|
if (top.clazz == null |
|
|
|
// if (top.clazz == null
|
|
|
|
&& implementsAllIfaces(top.ifaces)) |
|
|
|
// && implementsAllIfaces(top.ifaces))
|
|
|
|
return null; |
|
|
|
// return null;
|
|
|
|
return tObject; |
|
|
|
// return tObject;
|
|
|
|
case TC_UNKNOWN: |
|
|
|
// case TC_UNKNOWN:
|
|
|
|
return null; |
|
|
|
// return null;
|
|
|
|
} |
|
|
|
// }
|
|
|
|
return tObject; |
|
|
|
// return tObject;
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Checks if this type represents a valid type instead of a list |
|
|
|
* Checks if this type represents a valid type instead of a list |
|
|
|