gnu.bytecode

Class Type

public abstract class Type extends Object

Field Summary
static MethodbooleanValue_method
static ClassTypeboolean_ctype
static PrimTypeboolean_type
static PrimTypebyte_type
static PrimTypechar_type
static Methodclone_method
static MethoddoubleValue_method
static PrimTypedouble_type
static MethodfloatValue_method
static PrimTypefloat_type
static MethodintValue_method
static PrimTypeint_type
static ClassTypejava_lang_Class_type
static MethodlongValue_method
static PrimTypelong_type
static PrimTypeneverReturnsType
The "return type" of an expression that never returns, such as a throw.
static ObjectTypenullType
The magic type of null.
static ClassTypenumber_type
static ClassTypepointer_type
protected ClassreflectClass
static PrimTypeshort_type
static ClassTypestring_type
static ClassTypethrowable_type
static ClassTypetostring_type
static MethodtoString_method
static Type[]typeArray0
static PrimTypevoid_type
Constructor Summary
protected Type()
Type(Type type)
Method Summary
abstract ObjectcoerceFromObject(Object obj)
Convert an object to a value of this Type.
ObjectcoerceToObject(Object obj)
abstract intcompare(Type other)
Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common.
voidemitCoerceFromObject(CodeAttr code)
Compile code to coerce/convert from Object to this type.
voidemitCoerceToObject(CodeAttr code)
Compile code to convert a object of this type on the stack to Object.
voidemitIsInstance(CodeAttr code)
TypegetImplementationType()
The type used to implement types not natively understood by the JVM.
StringgetName()
ClassgetReflectClass()
Get the java.lang.Class object for the representation type.
StringgetSignature()
intgetSize()
intgetSizeInWords()
static TypegetType(String name)
Find an Type with the given name, or create a new one.
inthashCode()
booleanisInstance(Object obj)
static booleanisMoreSpecific(Type[] t1, Type[] t2)
Return true iff t1[i].isSubtype(t2[i]) for all i.
booleanisSubtype(Type other)
Return true if this is a "subtype" of other.
static booleanisValidJavaTypeName(String name)
booleanisVoid()
static TypelookupType(String name)
static TypelowestCommonSuperType(Type t1, Type t2)
Computes the common supertype Interfaces are not taken into account.
static Typemake(Class reflectClass)
Typepromote()
static voidregisterTypeForClass(Class clas, Type type)
Register that the Type for class is type.
protected voidsetName(String name)
voidsetReflectClass(Class rclass)
protected voidsetSignature(String sig)
static intsignatureLength(String sig, int pos)
Return the length of the signature starting at a given string position.
static intsignatureLength(String sig)
static StringsignatureToName(String sig)
Returns the Java-level type name from a given signature.
static PrimTypesignatureToPrimitive(char sig)
Returns the primitive type corresponding to a signature character.
static TypesignatureToType(String sig, int off, int len)
Get a Type corresponding to the given signature string.
static TypesignatureToType(String sig)
Get a Type corresponding to the given signature string.
protected static intswappedCompareResult(int code)
Change result from compare to compensate for argument swapping.
StringtoString()

Field Detail

booleanValue_method

public static final Method booleanValue_method

boolean_ctype

public static final ClassType boolean_ctype

boolean_type

public static final PrimType boolean_type

byte_type

public static final PrimType byte_type

char_type

public static final PrimType char_type

clone_method

public static final Method clone_method

doubleValue_method

public static final Method doubleValue_method

double_type

public static final PrimType double_type

floatValue_method

public static final Method floatValue_method

float_type

public static final PrimType float_type

intValue_method

public static final Method intValue_method

int_type

public static final PrimType int_type

java_lang_Class_type

public static final ClassType java_lang_Class_type

longValue_method

public static final Method longValue_method

long_type

public static final PrimType long_type

neverReturnsType

public static final PrimType neverReturnsType
The "return type" of an expression that never returns, such as a throw.

nullType

public static final ObjectType nullType
The magic type of null.

number_type

public static final ClassType number_type

pointer_type

public static final ClassType pointer_type

reflectClass

protected Class reflectClass

short_type

public static final PrimType short_type

string_type

public static ClassType string_type

throwable_type

public static final ClassType throwable_type

tostring_type

public static final ClassType tostring_type

toString_method

public static final Method toString_method

typeArray0

public static final Type[] typeArray0

void_type

public static final PrimType void_type

Constructor Detail

Type

protected Type()

Type

public Type(Type type)

Method Detail

coerceFromObject

public abstract Object coerceFromObject(Object obj)
Convert an object to a value of this Type. Throw a ClassCastException when this is not possible.

coerceToObject

public Object coerceToObject(Object obj)

compare

public abstract int compare(Type other)
Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common. "Same member" is rather loose; by "A is a subtype of B" we mean that all instance of A can be "widened" to B. More formally, A.compare(B) returns: 1: all B values can be converted to A without a coercion failure (i.e. a ClassCastException or overflow or major loss of information), but not vice versa. 0: all A values can be converted to B without a coercion failure and vice versa; -1: all A values can be converted to B without a coercion failure not not vice versa; -2: there are (potentially) some A values that can be converted to B, and some B values can be converted to A; -3: there are no A values that can be converted to B, and neither are there any B values that can be converted to A.

emitCoerceFromObject

public void emitCoerceFromObject(CodeAttr code)
Compile code to coerce/convert from Object to this type.

emitCoerceToObject

public void emitCoerceToObject(CodeAttr code)
Compile code to convert a object of this type on the stack to Object.

emitIsInstance

public void emitIsInstance(CodeAttr code)

getImplementationType

public Type getImplementationType()
The type used to implement types not natively understood by the JVM. Usually, the identity function. However, a language might handle union types or template types or type expressions calculated at run time. In that case return the type used at the JVM level, and known at compile time.

getName

public final String getName()

getReflectClass

public Class getReflectClass()
Get the java.lang.Class object for the representation type.

getSignature

public final String getSignature()

getSize

public final int getSize()

getSizeInWords

public int getSizeInWords()

getType

public static Type getType(String name)
Find an Type with the given name, or create a new one. Use this for "library classes", where you need the field/method types, but not one where you are about to generate code for.

Parameters: name the name of the class (e..g. "java.lang.String").

hashCode

public int hashCode()

isInstance

public boolean isInstance(Object obj)

isMoreSpecific

public static boolean isMoreSpecific(Type[] t1, Type[] t2)
Return true iff t1[i].isSubtype(t2[i]) for all i.

isSubtype

public final boolean isSubtype(Type other)
Return true if this is a "subtype" of other.

isValidJavaTypeName

public static boolean isValidJavaTypeName(String name)

isVoid

public final boolean isVoid()

lookupType

public static Type lookupType(String name)

lowestCommonSuperType

public static Type lowestCommonSuperType(Type t1, Type t2)
Computes the common supertype Interfaces are not taken into account. This would be difficult, since interfaces allow multiple-inheritance. This means that there may exists multiple common supertypes to t1 and t2 that are not comparable.

Returns: the lowest type that is both above t1 and t2, or null if t1 and t2 have no common supertype.

make

public static Type make(Class reflectClass)

promote

public Type promote()

registerTypeForClass

public static void registerTypeForClass(Class clas, Type type)
Register that the Type for class is type.

setName

protected void setName(String name)

setReflectClass

public void setReflectClass(Class rclass)

setSignature

protected void setSignature(String sig)

signatureLength

public static int signatureLength(String sig, int pos)
Return the length of the signature starting at a given string position. Returns -1 for an invalid signature.

signatureLength

public static int signatureLength(String sig)

signatureToName

public static String signatureToName(String sig)
Returns the Java-level type name from a given signature. Returns null for an invalid signature.

signatureToPrimitive

public static PrimType signatureToPrimitive(char sig)
Returns the primitive type corresponding to a signature character.

Returns: a primitive type, or null if there is no such type.

signatureToType

public static Type signatureToType(String sig, int off, int len)
Get a Type corresponding to the given signature string.

signatureToType

public static Type signatureToType(String sig)
Get a Type corresponding to the given signature string.

swappedCompareResult

protected static int swappedCompareResult(int code)
Change result from compare to compensate for argument swapping.

toString

public String toString()