use of com.android.dx.rop.type.Type in project buck by facebook.
the class Rops method opNewArray.
/**
* Returns the appropriate {@code new-array} rop for the given
* type. The result is a shared instance.
*
* @param arrayType {@code non-null;} array type of array being created
* @return {@code non-null;} an appropriate instance
*/
public static Rop opNewArray(TypeBearer arrayType) {
Type type = arrayType.getType();
Type elementType = type.getComponentType();
switch(elementType.getBasicType()) {
case Type.BT_INT:
return NEW_ARRAY_INT;
case Type.BT_LONG:
return NEW_ARRAY_LONG;
case Type.BT_FLOAT:
return NEW_ARRAY_FLOAT;
case Type.BT_DOUBLE:
return NEW_ARRAY_DOUBLE;
case Type.BT_BOOLEAN:
return NEW_ARRAY_BOOLEAN;
case Type.BT_BYTE:
return NEW_ARRAY_BYTE;
case Type.BT_CHAR:
return NEW_ARRAY_CHAR;
case Type.BT_SHORT:
return NEW_ARRAY_SHORT;
case Type.BT_OBJECT:
{
return new Rop(RegOps.NEW_ARRAY, type, StdTypeList.INT, Exceptions.LIST_Error_NegativeArraySizeException, "new-array-object");
}
}
return throwBadType(type);
}
use of com.android.dx.rop.type.Type in project buck by facebook.
the class Rops method opFilledNewArray.
/**
* Returns the appropriate {@code filled-new-array} rop for the given
* type. The result may be a shared instance.
*
* @param arrayType {@code non-null;} type of array being created
* @param count {@code >= 0;} number of elements that the array should have
* @return {@code non-null;} an appropriate instance
*/
public static Rop opFilledNewArray(TypeBearer arrayType, int count) {
Type type = arrayType.getType();
Type elementType = type.getComponentType();
if (elementType.isCategory2()) {
return throwBadType(arrayType);
}
if (count < 0) {
throw new IllegalArgumentException("count < 0");
}
StdTypeList sourceTypes = new StdTypeList(count);
for (int i = 0; i < count; i++) {
sourceTypes.set(i, elementType);
}
// Note: The resulting rop is considered call-like.
return new Rop(RegOps.FILLED_NEW_ARRAY, sourceTypes, Exceptions.LIST_Error);
}
use of com.android.dx.rop.type.Type in project buck by facebook.
the class OneLocalsArray method makeInitialized.
/** {@inheritDoc} */
public void makeInitialized(Type type) {
int len = locals.length;
if (len == 0) {
// We have to check for this before checking for immutability.
return;
}
throwIfImmutable();
Type initializedType = type.getInitializedType();
for (int i = 0; i < len; i++) {
if (locals[i] == type) {
locals[i] = initializedType;
}
}
}
use of com.android.dx.rop.type.Type in project buck by facebook.
the class OneLocalsArray method getCategory1.
/** {@inheritDoc} */
public TypeBearer getCategory1(int idx) {
TypeBearer result = get(idx);
Type type = result.getType();
if (type.isUninitialized()) {
return throwSimException(idx, "uninitialized instance");
}
if (type.isCategory2()) {
return throwSimException(idx, "category-2");
}
return result;
}
use of com.android.dx.rop.type.Type in project buck by facebook.
the class Merger method isPossiblyAssignableFrom.
/**
* Returns whether the given supertype is possibly assignable from
* the given subtype. This takes into account primitiveness,
* int-likeness, known-nullness, and array dimensions, but does
* not assume anything about class hierarchy other than that the
* type {@code Object} is the supertype of all reference
* types and all arrays are assignable to
* {@code Serializable} and {@code Cloneable}.
*
* @param supertypeBearer {@code non-null;} the supertype
* @param subtypeBearer {@code non-null;} the subtype
*/
public static boolean isPossiblyAssignableFrom(TypeBearer supertypeBearer, TypeBearer subtypeBearer) {
Type supertype = supertypeBearer.getType();
Type subtype = subtypeBearer.getType();
if (supertype.equals(subtype)) {
// Easy out.
return true;
}
int superBt = supertype.getBasicType();
int subBt = subtype.getBasicType();
if (superBt == Type.BT_ADDR) {
supertype = Type.OBJECT;
superBt = Type.BT_OBJECT;
}
if (subBt == Type.BT_ADDR) {
subtype = Type.OBJECT;
subBt = Type.BT_OBJECT;
}
if ((superBt != Type.BT_OBJECT) || (subBt != Type.BT_OBJECT)) {
/*
* No two distinct primitive types are assignable in this sense,
* unless they are both int-like.
*/
return supertype.isIntlike() && subtype.isIntlike();
}
if (supertype == Type.KNOWN_NULL) {
/*
* A known-null supertype is only assignable from another
* known-null (handled in the easy out at the top of the
* method).
*/
return false;
} else if (subtype == Type.KNOWN_NULL) {
/*
* A known-null subtype is in fact assignable to any
* reference type.
*/
return true;
} else if (supertype == Type.OBJECT) {
/*
* Object is assignable from any reference type.
*/
return true;
} else if (supertype.isArray()) {
// The supertype is an array type.
if (!subtype.isArray()) {
// The subtype isn't an array, and so can't be assignable.
return false;
}
/*
* Strip off as many matched component types from both
* types as possible, and check the assignability of the
* results.
*/
do {
supertype = supertype.getComponentType();
subtype = subtype.getComponentType();
} while (supertype.isArray() && subtype.isArray());
return isPossiblyAssignableFrom(supertype, subtype);
} else if (subtype.isArray()) {
/*
* Other than Object (handled above), array types are
* assignable only to Serializable and Cloneable.
*/
return (supertype == Type.SERIALIZABLE) || (supertype == Type.CLONEABLE);
} else {
/*
* All other unequal reference types are considered at
* least possibly assignable.
*/
return true;
}
}
Aggregations