Use the Support/iterator file to abstract out compiler differences
[oota-llvm.git] / include / llvm / Type.h
index 07d9615ba95a0e40eebdbd1074c13446fbd13318..8cb4b581fcfb322a1d95a32af495ba3328796548 100644 (file)
@@ -1,7 +1,7 @@
 //===-- llvm/Type.h - Classes for handling data types ------------*- C++ -*--=//
 //
 // This file contains the declaration of the Type class.  For more "Type" type
-// stuff, look in DerivedTypes.h and Opt/ConstantHandling.h
+// stuff, look in DerivedTypes.h.
 //
 // Note that instances of the Type class are immutable: once they are created,
 // they are never changed.  Also note that only one instance of a particular 
@@ -28,6 +28,7 @@
 
 #include "llvm/Value.h"
 #include "Support/GraphTraits.h"
+#include "Support/iterator"
 
 class DerivedType;
 class FunctionType;
@@ -98,6 +99,7 @@ protected:
   inline void setRecursive(bool Val) { Recursive = Val; }
 
 public:
+  virtual void print(std::ostream &O) const;
 
   //===--------------------------------------------------------------------===//
   // Property accessors for dealing with types...
@@ -132,6 +134,10 @@ public:
   //
   virtual bool isIntegral() const { return 0; }
 
+  // isFloatingPoint - Return true if this is one of the two floating point
+  // types
+  bool isFloatingPoint() const { return ID == FloatTyID || ID == DoubleTyID; }
+
   // isAbstract - True if the type is either an Opaque type, or is a derived
   // type that includes an opaque type somewhere in it.  
   //
@@ -146,14 +152,34 @@ public:
   //
   bool isLosslesslyConvertableTo(const Type *Ty) const;
 
+
+  // 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 isPrimitiveType() const { return ID < FirstDerivedTyID;  }
+  inline bool isDerivedType()   const { return ID >= FirstDerivedTyID; }
+
+  // isFirstClassType - Return true if the value is holdable in a register.
+  inline bool isFirstClassType() const {
+    return isPrimitiveType() || ID == PointerTyID;
+  }
+
   // 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 != FunctionTyID && ID != OpaqueTyID;
+    return ID != VoidTyID && ID != TypeTyID &&
+           ID != FunctionTyID && ID != LabelTyID && ID != OpaqueTyID;
   }
 
+  // getPrimitiveSize - Return the basic size of this type if it is a primative
+  // type.  These are fixed by LLVM and are not target dependant.  This will
+  // return zero if the type does not have a size or is not a primitive type.
+  //
+  unsigned getPrimitiveSize() const;
+
+
   //===--------------------------------------------------------------------===//
   // Type Iteration support
   //
@@ -194,36 +220,16 @@ public:
 
   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 isPrimitiveType() const { return ID < FirstDerivedTyID;  }
-  inline bool isDerivedType()   const { return ID >= FirstDerivedTyID; }
-
-  // isFirstClassType - Return true if the value is holdable in a register.
-  inline bool isFirstClassType() const {
-    return isPrimitiveType() || ID == PointerTyID;
-  }
-
   // 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. 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; }
-
 #include "llvm/Type.def"
 
 private:
-  class TypeIterator : public std::bidirectional_iterator<const Type,
-                                                         ptrdiff_t> {
+  class TypeIterator : public bidirectional_iterator<const Type, ptrdiff_t> {
     const Type * const Ty;
     unsigned Idx;
 
@@ -288,4 +294,8 @@ template <> struct GraphTraits<const Type*> {
   }
 };
 
+template <> inline bool isa_impl<PointerType, Type>(const Type &Ty) { 
+  return Ty.getPrimitiveID() == Type::PointerTyID;
+}
+
 #endif