gnu.bytecode
Class Type

java.lang.Object
  |
  +--gnu.bytecode.Type
Direct Known Subclasses:
ObjectType, PrimType

public abstract class Type
extends java.lang.Object


Field Summary
static ClassType boolean_ctype
           
static PrimType boolean_type
           
static Method booleanValue_method
           
static PrimType byte_type
           
static PrimType char_type
           
static PrimType double_type
           
static Method doubleValue_method
           
static PrimType float_type
           
static Method floatValue_method
           
static PrimType int_type
           
static Method intValue_method
           
static PrimType long_type
           
static Method longValue_method
           
static ClassType number_type
           
static ClassType pointer_type
           
protected  java.lang.Class reflectClass
           
static PrimType short_type
           
static ClassType string_type
           
static ClassType throwable_type
           
static Method toString_method
           
static Type[] typeArray0
           
static PrimType void_type
           
 
Method Summary
abstract  java.lang.Object coerceFromObject(java.lang.Object obj)
          Convert an object to a value of this Type.
 java.lang.Object coerceToObject(java.lang.Object obj)
           
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 members; -1: if this is a pure subtype of other; -2: if both a member in common but neither is a subtype of the other; -3: if the types have no values in common.
 void emitCoerceFromObject(CodeAttr code)
          Compile code to coerce/convert from Object to this type.
 void emitCoerceToObject(CodeAttr code)
          Compile code to convert an object (on the stack) to this Type.
 void emitIsInstance(CodeAttr code)
           
 java.lang.String getName()
           
 java.lang.Class getReflectClass()
          Get the java.lang.Class object for the representation type.
 java.lang.String getSignature()
           
 int getSize()
           
static Type getType(java.lang.String name)
          Find an Type with the given name, or create a new one.
 boolean isInstance(java.lang.Object obj)
           
static boolean isMoreSpecific(Type[] t1, Type[] t2)
          Return true iff t1[i].isSubtype(t2[i]) for all i.
 boolean isSubtype(Type other)
          Return true if this is a "subtype" of other.
static boolean isValidJavaTypeName(java.lang.String name)
           
 boolean isVoid()
           
static Type lookupType(java.lang.String name)
           
static Type lowestCommonSuperType(Type t1, Type t2)
          Computes the common supertype Interfaces are not taken into account.
static Type make(java.lang.Class reflectClass)
           
 Type promote()
           
static void registerTypeForClass(java.lang.Class clas, Type type)
          Register that the Type for class is type.
protected  void setSignature(java.lang.String sig)
           
static int signatureLength(java.lang.String sig)
           
static int signatureLength(java.lang.String sig, int pos)
          Return the length of the signature starting at a given string position.
static java.lang.String signatureToName(java.lang.String sig)
          Returns the Java-level type name from a given signature.
static Type signatureToPrimitive(char sig)
          Returns the primitive type corresponding to a signature character.
static Type signatureToType(java.lang.String sig)
          Get a Type corresponding to the given signature string.
static Type signatureToType(java.lang.String sig, int off, int len)
          Get a Type corresponding to the given signature string.
protected static int swappedCompareResult(int code)
          Change result from compare to compensate for argument swapping.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

byte_type

public static final PrimType byte_type

short_type

public static final PrimType short_type

int_type

public static final PrimType int_type

long_type

public static final PrimType long_type

float_type

public static final PrimType float_type

double_type

public static final PrimType double_type

boolean_type

public static final PrimType boolean_type

char_type

public static final PrimType char_type

void_type

public static final PrimType void_type

pointer_type

public static ClassType pointer_type

string_type

public static ClassType string_type

boolean_ctype

public static ClassType boolean_ctype

throwable_type

public static ClassType throwable_type

typeArray0

public static Type[] typeArray0

toString_method

public static Method toString_method

number_type

public static ClassType number_type

intValue_method

public static Method intValue_method

longValue_method

public static Method longValue_method

floatValue_method

public static Method floatValue_method

doubleValue_method

public static Method doubleValue_method

booleanValue_method

public static Method booleanValue_method

reflectClass

protected java.lang.Class reflectClass
Method Detail

lookupType

public static Type lookupType(java.lang.String name)

getType

public static Type getType(java.lang.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").

registerTypeForClass

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

make

public static Type make(java.lang.Class reflectClass)

getSignature

public final java.lang.String getSignature()

setSignature

protected void setSignature(java.lang.String sig)

promote

public Type promote()

getSize

public final int getSize()

isVoid

public final boolean isVoid()

signatureToPrimitive

public static Type 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(java.lang.String sig,
                                   int off,
                                   int len)
Get a Type corresponding to the given signature string.

signatureToType

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

signatureLength

public static int signatureLength(java.lang.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(java.lang.String sig)

signatureToName

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

getName

public final java.lang.String getName()

isValidJavaTypeName

public static boolean isValidJavaTypeName(java.lang.String name)

isInstance

public boolean isInstance(java.lang.Object obj)

isSubtype

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

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.

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 members; -1: if this is a pure subtype of other; -2: if both a member 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), 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.

swappedCompareResult

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

isMoreSpecific

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

emitIsInstance

public void emitIsInstance(CodeAttr code)

coerceFromObject

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

coerceToObject

public java.lang.Object coerceToObject(java.lang.Object obj)

emitCoerceToObject

public void emitCoerceToObject(CodeAttr code)
Compile code to convert an object (on the stack) to this Type.

emitCoerceFromObject

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

getReflectClass

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object