use of com.android.dx.rop.type.Type in project buck by facebook.
the class TypeIdsSection method intern.
/**
* Interns an element into this instance.
*
* @param type {@code non-null;} the type to intern
* @return {@code non-null;} the interned reference
*/
public synchronized TypeIdItem intern(CstType type) {
if (type == null) {
throw new NullPointerException("type == null");
}
throwIfPrepared();
Type typePerSe = type.getClassType();
TypeIdItem result = typeIds.get(typePerSe);
if (result == null) {
result = new TypeIdItem(type);
typeIds.put(typePerSe, result);
}
return result;
}
use of com.android.dx.rop.type.Type in project buck by facebook.
the class TypeListItem method writeTo0.
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
TypeIdsSection typeIds = file.getTypeIds();
int sz = list.size();
if (out.annotates()) {
out.annotate(0, offsetString() + " type_list");
out.annotate(HEADER_SIZE, " size: " + Hex.u4(sz));
for (int i = 0; i < sz; i++) {
Type one = list.getType(i);
int idx = typeIds.indexOf(one);
out.annotate(ELEMENT_SIZE, " " + Hex.u2(idx) + " // " + one.toHuman());
}
}
out.writeInt(sz);
for (int i = 0; i < sz; i++) {
out.writeShort(typeIds.indexOf(list.getType(i)));
}
}
use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.
the class ExecutionStack method makeInitialized.
/**
* Replaces all the occurrences of the given uninitialized type in
* this stack with its initialized equivalent.
*
* @param type {@code non-null;} type to replace
*/
public void makeInitialized(Type type) {
if (stackPtr == 0) {
// We have to check for this before checking for immutability.
return;
}
throwIfImmutable();
Type initializedType = type.getInitializedType();
for (int i = 0; i < stackPtr; i++) {
if (stack[i] == type) {
stack[i] = initializedType;
}
}
}
use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.
the class Frame method initializeWithParameters.
/**
* Initialize this frame with the method's parameters. Used for the first
* frame.
*
* @param params Type list of method parameters.
*/
public void initializeWithParameters(StdTypeList params) {
int at = 0;
int sz = params.size();
for (int i = 0; i < sz; i++) {
Type one = params.get(i);
locals.set(at, one);
at += one.getCategory();
}
}
use of com.android.dx.rop.type.Type in project J2ME-Loader by nikita36078.
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