#define LLVM_TYPE_H
#include "llvm/Value.h"
-#include "llvm/Support/GraphTraits.h"
+#include "Support/GraphTraits.h"
class DerivedType;
class MethodType;
private:
PrimitiveID ID; // The current base type of this type...
unsigned UID; // The unique ID number for this class
- string Desc; // The printed name of the string...
+ std::string Desc; // The printed name of the string...
bool Abstract; // True if type contains an OpaqueType
bool Recursive; // True if the type is recursive
protected:
// ctor is protected, so only subclasses can create Type objects...
- Type(const string &Name, PrimitiveID id);
+ Type(const std::string &Name, PrimitiveID id);
virtual ~Type() {}
// When types are refined, they update their description to be more concrete.
//
- inline void setDescription(const string &D) { Desc = D; }
+ inline void setDescription(const std::string &D) { Desc = D; }
// setName - Associate the name with this type in the symbol table, but don't
// set the local name to be equal specified name.
//
- virtual void setName(const string &Name, SymbolTable *ST = 0);
+ virtual void setName(const std::string &Name, SymbolTable *ST = 0);
// Types can become nonabstract later, if they are refined.
//
inline unsigned getUniqueID() const { return UID; }
// getDescription - Return the string representation of the type...
- inline const string &getDescription() const { return Desc; }
+ inline const std::string &getDescription() const { return Desc; }
// isSigned - Return whether a numeric type is signed.
virtual bool isSigned() const { return 0; }
//
inline bool isRecursive() const { return Recursive; }
+ // isLosslesslyConvertableTo - Return true if this type can be converted to
+ // 'Ty' without any reinterpretation of bits. For example, uint to int.
+ //
+ bool isLosslesslyConvertableTo(const Type *Ty) const;
+
+ // isSized - Return true if it makes sense to take the size of this type. To
+ // get the actual size for a particular target, it is reasonable to use the
+ // TargetData subsystem to do this.
+ //
+ bool isSized() const {
+ return ID != TypeTyID && ID != MethodTyID && ID != OpaqueTyID;
+ }
+
//===--------------------------------------------------------------------===//
// Type Iteration support
//
// Note that all other types can just compare to see if this == Type::xxxTy;
//
inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; }
-
inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
- inline const DerivedType *castDerivedType() const {
- return isDerivedType() ? (const DerivedType*)this : 0;
+
+ // isFirstClassType - Return true if the value is holdable in a register.
+ inline bool isFirstClassType() const {
+ return isPrimitiveType() || ID == PointerTyID;
}
- inline const DerivedType *castDerivedTypeAsserting() const {
- assert(isDerivedType());
- return (const DerivedType*)this;
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const Type *T) { return true; }
+ static inline bool classof(const Value *V) {
+ return V->getValueType() == Value::TypeVal;
}
- // 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.
+ // Methods for determining the subtype of this Type. This section defines a
+ // family of isArrayType(), isLabelType(), etc functions...
//
#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; \
- }
+ inline bool is##NAME##Type() const { return ID == NAME##TyID; }
+
#include "llvm/Type.def"
private: