Package gnu.bytecode
Class Type
java.lang.Object
gnu.bytecode.Type
- All Implemented Interfaces:
Type
- Direct Known Subclasses:
InlineCalls.LenientExpectedType,ObjectType,OccurrenceType,PrimType,XDataType
An abstract type as used by both gnu.bytecode and gnu.expr.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA marker class, used forType.neverReturnsType. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ClassTypeDeprecated.static final PrimTypestatic final PrimTypestatic final Methodstatic final PrimTypestatic final PrimTypestatic final PrimTypestatic final PrimTypestatic final Methodstatic final PrimTypestatic final PrimTypestatic final Methodstatic final ObjectTypestatic final PrimTypestatic final PrimTypestatic final Methodstatic final PrimTypestatic final PrimTypestatic final Methodstatic final ClassTypeDeprecated.static final ClassTypestatic final ClassTypestatic final ClassTypestatic final ClassTypestatic final ClassTypestatic final ClassTypestatic final ClassTypestatic ClassTypestatic final ClassTypestatic final PrimTypestatic final PrimTypestatic final Methodstatic final TypeThe return type of an expression that never returns, such as a throw.static final ObjectTypeThe magic type of null.static final ClassTypeDeprecated.static final ClassTypestatic final ClassTypeDeprecated.protected Classstatic final PrimTypestatic final PrimTypestatic final ClassTypeDeprecated.static final ClassTypestatic final Methodstatic final ObjectTypeDeprecated.static final ObjectTypestatic final Type[]static final PrimTypestatic final PrimType -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ObjectcoerceFromObject(Object obj) Convert an object to a value of this Type.coerceToObject(Object obj) Given a raw JVM value convert it to an object of this type.abstract intReturn 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.voidemitConvertFromPrimitive(Type stackType, CodeAttr code) Convert from stackType (usually PrimType) to this type.voidemitIsInstance(CodeAttr code) Return Java-level implementation type.getName()Return JVM-level implementation type.If this is a type alias, get the aliased type.Get the java.lang.Class object for the representation type.final intgetSize()intstatic TypeFind an Type with the given name, or create a new one.inthashCode()intisCompatibleWithValue(Type valueType) If this is the target type, is a given source type compatible?static intisCompatibleWithValue(Type targetType, Type valueType) booleanbooleanisInstance(Object obj) booleanstatic booleanisMoreSpecific(Type[] t1, Type[] t2) Return true iff t1[i].isSubtype(t2[i]) for all i.static booleanfinal booleanReturn true if this is a "subtype" of other.static booleanisValidJavaTypeName(String name) final booleanisVoid()static TypelookupType(String name) static TypelowestCommonSharedType(Type t1, Type t2) static TypelowestCommonSuperType(Type t1, Type t2) Computes the common supertype Interfaces are not taken into account.static Typestatic TypeTry to map java.lang.reflect.Type to gnu.bytecode.Type.static voidprintSignature(String sig, int off, int len, PrintWriter out) promote()static voidregisterTypeForClass(Class clas, Type type) Register that the Type for class is type.protected voidprotected voidvoidsetReflectClass(Class rclass) protected voidsetSignature(String sig) static intsignatureLength(String sig) static intsignatureLength(String sig, int pos) Return the length of the signature starting at a given string position.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) Get a Type corresponding to the given signature string.static TypesignatureToType(String sig, int off, int len) Get a Type corresponding to the given signature string.protected static intswappedCompareResult(int code) Change result from compare to compensate for argument swapping.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.reflect.Type
getTypeName
-
Field Details
-
byteType
-
shortType
-
intType
-
longType
-
floatType
-
doubleType
-
booleanType
-
charType
-
voidType
-
byte_type
-
short_type
-
int_type
-
long_type
-
float_type
-
double_type
-
boolean_type
-
char_type
-
void_type
-
neverReturnsType
The return type of an expression that never returns, such as a throw. -
javalangObjectType
-
objectType
-
javalangBooleanType
-
javalangCharacterType
-
javalangThrowableType
-
javalangannotationAnnotationType
-
typeArray0
-
toString_method
-
javalangNumberType
-
clone_method
-
intValue_method
-
longValue_method
-
floatValue_method
-
doubleValue_method
-
booleanValue_method
-
javalangClassType
-
javalanginvokeMethodHandleType
-
nullType
The magic type of null. -
errorType
-
javalangStringType
-
toStringType
-
pointer_type
Deprecated. -
string_type
Deprecated. -
tostring_type
Deprecated. -
java_lang_Class_type
Deprecated. -
boolean_ctype
Deprecated. -
throwable_type
-
number_type
Deprecated. -
reflectClass
-
-
Constructor Details
-
Type
protected Type() -
Type
-
-
Method Details
-
getImplementationType
Return Java-level implementation type. The type used to implement types not natively understood by the JVM or the Java language. 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 Java level, and known at compile time. -
getRawType
Return JVM-level implementation type. -
getRealType
If this is a type alias, get the aliased type. This is semi-deprecated. -
isInterface
public boolean isInterface() -
isExisting
public boolean isExisting() -
lookupType
-
getType
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
Register that the Type for class is type. -
make
Try to map java.lang.reflect.Type to gnu.bytecode.Type. If we can't handle that, resolve the Class instead. -
make
-
getSignature
-
setSignature
-
getGenericSignature
-
setGenericSignature
-
getMaybeGenericSignature
-
promote
-
promoteIfUnsigned
-
getSize
public final int getSize() -
getSizeInWords
public int getSizeInWords() -
isVoid
public final boolean isVoid() -
signatureToPrimitive
Returns the primitive type corresponding to a signature character.- Returns:
- a primitive type, or null if there is no such type.
-
signatureToType
Get a Type corresponding to the given signature string. -
signatureToType
Get a Type corresponding to the given signature string. -
printSignature
-
signatureLength
Return the length of the signature starting at a given string position. Returns -1 for an invalid signature. -
signatureLength
-
signatureToName
Returns the Java-level type name from a given signature. Returns null for an invalid signature. -
getName
-
setName
-
isValidJavaTypeName
-
isInstance
-
isSubtype
Return true if this is a "subtype" of other. -
isCompatibleWithValue
If this is the target type, is a given source type compatible?- Returns:
- -1 if not compatible; 0 if need to check at run-time; 1 if compatible; 2 if compatible and no conversion or cast needed. We also return 0 for some "narrowing" conversions even if we know they will always succeed, so as to make such conversions less preferred when doing method overloading.
-
isCompatibleWithValue
-
lowestCommonSuperType
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
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 values" 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 but 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
Return true iff t1[i].isSubtype(t2[i]) for all i. -
isSame
-
emitIsInstance
-
coerceFromObject
Convert an object to a value of this Type. The result is actually of the implementation type, boxed as appropriate, so it is suitable for standard reflective operations, like the arguments to Field#set or Method#invoke. Throw a ClassCastException when this is not possible. -
coerceToObject
Given a raw JVM value convert it to an object of this type. I.e. the argument is an object of the type returned bygetRawType(), boxed as needed. The result may be a language-specific (boxed) value. Generally a no-op. -
emitConvertFromPrimitive
Convert from stackType (usually PrimType) to this type. However, we might only convert part-way, to some object type. If converting to this type might fail at run-time, only convert to Object (as by emitCoerceToObject); a caller can usestackType.emitConvertFromObjectto convert the rest, but that might throw an exception. (This is a bit of a kludge.) -
emitCoerceToObject
Compile code to convert a object of this type on the stack to Object. -
emitCoerceFromObject
Compile code to coerce/convert from Object to this type. -
getReflectClass
Get the java.lang.Class object for the representation type. -
setReflectClass
-
toString
-
hashCode
public int hashCode()
-