* Method::getType should return type cast as MethodType, eliminate getMethodType

* Make Type::*Ty not be const types
* Add a new Type.def file to provide info about types
* Add a full complement of casting methods to the Type class


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@533 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2001-09-10 20:06:17 +00:00
parent 746e0014a6
commit be07811cd0
3 changed files with 102 additions and 29 deletions

View File

@@ -51,7 +51,9 @@ public:
virtual void setName(const string &name, SymbolTable *ST = 0); virtual void setName(const string &name, SymbolTable *ST = 0);
const Type *getReturnType() const; const Type *getReturnType() const;
const MethodType *getMethodType() const; const MethodType *getType() const {
return (const MethodType*)Value::getType();
}
// Is the body of this method unknown? (the basic block list is empty if so) // Is the body of this method unknown? (the basic block list is empty if so)
// this is true for external methods, defined as forward "declare"ations // this is true for external methods, defined as forward "declare"ations

58
include/llvm/Type.def Normal file
View File

@@ -0,0 +1,58 @@
//===-- 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

View File

@@ -54,13 +54,12 @@ public:
TypeTyID, // 12 : Type definitions TypeTyID, // 12 : Type definitions
LabelTyID , // 13 : Labels... LabelTyID , // 13 : Labels...
/*LockTyID , */ // 14 : mutex - TODO
// Derived types... see DerivedTypes.h file... // Derived types... see DerivedTypes.h file...
// Make sure FirstDerivedTyID stays up to date!!! // Make sure FirstDerivedTyID stays up to date!!!
MethodTyID , ModuleTyID, // Methods... Modules... MethodTyID , StructTyID, // Methods... Structs...
ArrayTyID , PointerTyID, // Array... pointer... ArrayTyID , PointerTyID, // Array... pointer...
StructTyID , OpaqueTyID, // Structure... Opaque type instances... OpaqueTyID, // Opaque type instances...
//PackedTyID , // SIMD 'packed' format... TODO //PackedTyID , // SIMD 'packed' format... TODO
//... //...
@@ -172,23 +171,21 @@ public:
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// These are the builtin types that are always available... // These are the builtin types that are always available...
// //
static const Type *VoidTy , *BoolTy; static Type *VoidTy , *BoolTy;
static const Type *SByteTy, *UByteTy, static Type *SByteTy, *UByteTy,
*ShortTy, *UShortTy, *ShortTy, *UShortTy,
*IntTy , *UIntTy, *IntTy , *UIntTy,
*LongTy , *ULongTy; *LongTy , *ULongTy;
static const Type *FloatTy, *DoubleTy; 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 // 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; // 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 isPrimitiveType() const { return ID < FirstDerivedTyID; }
inline bool isLabelType() const { return this == LabelTy; } inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
inline const DerivedType *castDerivedType() const { inline const DerivedType *castDerivedType() const {
return isDerivedType() ? (const DerivedType*)this : 0; return isDerivedType() ? (const DerivedType*)this : 0;
} }
@@ -197,22 +194,38 @@ public:
return (const DerivedType*)this; return (const DerivedType*)this;
} }
inline const MethodType *isMethodType() const { // Methods for determining the subtype of this Type. The cast*() methods are
return ID == MethodTyID ? (const MethodType*)this : 0; // equilivent to using dynamic_cast<>... if the cast is successful, this is
} // returned, otherwise you get a null pointer, allowing expressions like this:
inline bool isModuleType() const { return ID == ModuleTyID; } //
inline const ArrayType *isArrayType() const { // if (MethodType *MTy = Ty->dyncastMethodType()) { ... }
return ID == ArrayTyID ? (const ArrayType*)this : 0; //
} // This section also defines a family of isArrayType(), isLabelType(),
inline const PointerType *isPointerType() const { // etc functions...
return ID == PointerTyID ? (const PointerType*)this : 0; //
} // The family of functions Ty->cast<type>() is used in the same way as the
inline const StructType *isStructType() const { // Ty->dyncast<type>() instructions, but they assert the expected type instead
return ID == StructTyID ? (const StructType*)this : 0; // of checking it at runtime.
} //
inline const OpaqueType *isOpaqueType() const { #define HANDLE_PRIM_TYPE(NAME, SIZE) \
return ID == OpaqueTyID ? (const OpaqueType*)this : 0; 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: private:
class TypeIterator : public std::bidirectional_iterator<const Type, class TypeIterator : public std::bidirectional_iterator<const Type,