--- /dev/null
+//===-- llvm/Type.def - File that describes various LLVM types ---*- C++ -*--=//
+//
+// This file contains descriptions of the various LLVM types and derived types.
+// This file serves as a source of in source documentation and a can be
+// #included to do something on all of the type definitions.
+//
+//===----------------------------------------------------------------------===//
+
+// NOTE: NO INCLUDE GUARD DESIRED!
+
+
+// If the user didn't specify one of the macros, give a default noop defn.
+//
+#ifndef HANDLE_PRIM_TYPE
+#define HANDLE_PRIM_TYPE(x,y)
+#endif
+#ifndef HANDLE_DERV_TYPE
+#define HANDLE_DERV_TYPE(x,y)
+#endif
+
+
+// HANDLE_PRIM_TYPE - Parameterized #define that takes the following fields to
+// declare a primitive type:
+//
+// Type Name: This is the symbolic name of the type, without the trailing Ty.
+// Type Size: This is the size or precision of the type.
+//
+HANDLE_PRIM_TYPE(Void , 1)
+HANDLE_PRIM_TYPE(Bool , 1)
+HANDLE_PRIM_TYPE(SByte , 1)
+HANDLE_PRIM_TYPE(UByte , 1)
+HANDLE_PRIM_TYPE(Short , 2)
+HANDLE_PRIM_TYPE(UShort, 2)
+HANDLE_PRIM_TYPE(Int , 4)
+HANDLE_PRIM_TYPE(UInt , 4)
+HANDLE_PRIM_TYPE(Long , 8)
+HANDLE_PRIM_TYPE(ULong , 8)
+HANDLE_PRIM_TYPE(Float , 4)
+HANDLE_PRIM_TYPE(Double, 8)
+HANDLE_PRIM_TYPE(Type , 0)
+HANDLE_PRIM_TYPE(Label , 8)
+
+
+// HANDLE_DERV_TYPE - Parameterized #define that takes the following fields to
+// declare a derived type:
+//
+// Type Name: This is the symbolic name of the type, without the trailing Ty.
+// Class Name: This is the subclass that implements the derived type.
+//
+HANDLE_DERV_TYPE(Method , MethodType)
+HANDLE_DERV_TYPE(Array , ArrayType)
+HANDLE_DERV_TYPE(Pointer, PointerType)
+HANDLE_DERV_TYPE(Struct , StructType)
+HANDLE_DERV_TYPE(Opaque , OpaqueType)
+
+// Kill the macros on exit...
+#undef HANDLE_PRIM_TYPE
+#undef HANDLE_DERV_TYPE
TypeTyID, // 12 : Type definitions
LabelTyID , // 13 : Labels...
- /*LockTyID , */ // 14 : mutex - TODO
// Derived types... see DerivedTypes.h file...
// Make sure FirstDerivedTyID stays up to date!!!
- MethodTyID , ModuleTyID, // Methods... Modules...
+ MethodTyID , StructTyID, // Methods... Structs...
ArrayTyID , PointerTyID, // Array... pointer...
- StructTyID , OpaqueTyID, // Structure... Opaque type instances...
+ OpaqueTyID, // Opaque type instances...
//PackedTyID , // SIMD 'packed' format... TODO
//...
//===--------------------------------------------------------------------===//
// These are the builtin types that are always available...
//
- static const Type *VoidTy , *BoolTy;
- static const Type *SByteTy, *UByteTy,
- *ShortTy, *UShortTy,
- *IntTy , *UIntTy,
- *LongTy , *ULongTy;
- static const Type *FloatTy, *DoubleTy;
+ static Type *VoidTy , *BoolTy;
+ static Type *SByteTy, *UByteTy,
+ *ShortTy, *UShortTy,
+ *IntTy , *UIntTy,
+ *LongTy , *ULongTy;
+ static Type *FloatTy, *DoubleTy;
- static const Type *TypeTy , *LabelTy; //, *LockTy;
+ static Type *TypeTy , *LabelTy;
// Here are some useful little methods to query what type derived types are
// Note that all other types can just compare to see if this == Type::xxxTy;
//
- inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; }
- inline bool isLabelType() const { return this == LabelTy; }
-
+ inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
inline const DerivedType *castDerivedType() const {
return isDerivedType() ? (const DerivedType*)this : 0;
}
return (const DerivedType*)this;
}
- inline const MethodType *isMethodType() const {
- return ID == MethodTyID ? (const MethodType*)this : 0;
- }
- inline bool isModuleType() const { return ID == ModuleTyID; }
- inline const ArrayType *isArrayType() const {
- return ID == ArrayTyID ? (const ArrayType*)this : 0;
- }
- inline const PointerType *isPointerType() const {
- return ID == PointerTyID ? (const PointerType*)this : 0;
- }
- inline const StructType *isStructType() const {
- return ID == StructTyID ? (const StructType*)this : 0;
- }
- inline const OpaqueType *isOpaqueType() const {
- return ID == OpaqueTyID ? (const OpaqueType*)this : 0;
+ // Methods for determining the subtype of this Type. The cast*() methods are
+ // equilivent to using dynamic_cast<>... if the cast is successful, this is
+ // returned, otherwise you get a null pointer, allowing expressions like this:
+ //
+ // if (MethodType *MTy = Ty->dyncastMethodType()) { ... }
+ //
+ // This section also defines a family of isArrayType(), isLabelType(),
+ // etc functions...
+ //
+ // The family of functions Ty->cast<type>() is used in the same way as the
+ // Ty->dyncast<type>() instructions, but they assert the expected type instead
+ // of checking it at runtime.
+ //
+#define HANDLE_PRIM_TYPE(NAME, SIZE) \
+ inline bool is##NAME##Type() const { return ID == NAME##TyID; }
+#define HANDLE_DERV_TYPE(NAME, CLASS) \
+ inline bool is##NAME##Type() const { return ID == NAME##TyID; } \
+ inline const CLASS *dyncast##NAME##Type() const { /*const version */ \
+ return is##NAME##Type() ? (const CLASS*)this : 0; \
+ } \
+ inline CLASS *dyncast##NAME##Type() { /* nonconst version */ \
+ return is##NAME##Type() ? (CLASS*)this : 0; \
+ } \
+ inline const CLASS *cast##NAME##Type() const { /*const version */ \
+ assert(is##NAME##Type() && "Expected TypeTy: " #NAME); \
+ return (const CLASS*)this; \
+ } \
+ inline CLASS *cast##NAME##Type() { /* nonconst version */ \
+ assert(is##NAME##Type() && "Expected TypeTy: " #NAME); \
+ return (CLASS*)this; \
}
+#include "llvm/Type.def"
private:
class TypeIterator : public std::bidirectional_iterator<const Type,