planes is not spelled with an O
[oota-llvm.git] / lib / VMCore / Type.cpp
index 7a17d06ff6a1d246665471b2fb94d4e8d87d5506..4990700370f3c873b49d853f78b447778a674145 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "llvm/DerivedTypes.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/Constants.h"
 #include "Support/StringExtras.h"
 #include "Support/STLExtras.h"
 #include <iostream>
@@ -86,8 +87,8 @@ const Type *Type::getPrimitiveType(PrimitiveID IDNumber) {
 //
 bool Type::isLosslesslyConvertableTo(const Type *Ty) const {
   if (this == Ty) return true;
-  if ((!isPrimitiveType()   && !isPointerType()) ||
-      (!Ty->isPointerType() && !Ty->isPrimitiveType())) return false;
+  if ((!isPrimitiveType()    && !isa<PointerType>(this)) ||
+      (!isa<PointerType>(Ty) && !Ty->isPrimitiveType())) return false;
 
   if (getPrimitiveID() == Ty->getPrimitiveID())
     return true;  // Handles identity cast, and cast of differing pointer types
@@ -109,6 +110,18 @@ bool Type::isLosslesslyConvertableTo(const Type *Ty) const {
   }
 }
 
+// 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 Type::getPrimitiveSize() const {
+  switch (getPrimitiveID()) {
+#define HANDLE_PRIM_TYPE(TY,SIZE)  case TY##TyID: return SIZE;
+#include "llvm/Type.def"
+  default: return 0;
+  }
+}
+
 
 bool StructType::indexValid(const Value *V) const {
   if (!isa<Constant>(V)) return false;
@@ -138,36 +151,28 @@ const Type *StructType::getTypeAtIndex(const Value *V) const {
 // These classes are used to implement specialized behavior for each different
 // type.
 //
-class SignedIntType : public Type {
-  int Size;
-public:
-  SignedIntType(const string &Name, PrimitiveID id, int size) : Type(Name, id) {
-    Size = size;
-  }
+struct SignedIntType : public Type {
+  SignedIntType(const string &Name, PrimitiveID id) : Type(Name, id) {}
 
   // isSigned - Return whether a numeric type is signed.
   virtual bool isSigned() const { return 1; }
 
-  // isIntegral - Equivalent to isSigned() || isUnsigned, but with only a single
+  // isInteger - Equivalent to isSigned() || isUnsigned, but with only a single
   // virtual function invocation.
   //
-  virtual bool isIntegral() const { return 1; }
+  virtual bool isInteger() const { return 1; }
 };
 
-class UnsignedIntType : public Type {
-  uint64_t Size;
-public:
-  UnsignedIntType(const string &N, PrimitiveID id, int size) : Type(N, id) {
-    Size = size;
-  }
+struct UnsignedIntType : public Type {
+  UnsignedIntType(const string &N, PrimitiveID id) : Type(N, id) {}
 
   // isUnsigned - Return whether a numeric type is signed.
   virtual bool isUnsigned() const { return 1; }
 
-  // isIntegral - Equivalent to isSigned() || isUnsigned, but with only a single
+  // isInteger - Equivalent to isSigned() || isUnsigned, but with only a single
   // virtual function invocation.
   //
-  virtual bool isIntegral() const { return 1; }
+  virtual bool isInteger() const { return 1; }
 };
 
 static struct TypeType : public Type {
@@ -181,14 +186,14 @@ static struct TypeType : public Type {
 
 Type *Type::VoidTy   = new            Type("void"  , VoidTyID),
      *Type::BoolTy   = new            Type("bool"  , BoolTyID),
-     *Type::SByteTy  = new   SignedIntType("sbyte" , SByteTyID, 1),
-     *Type::UByteTy  = new UnsignedIntType("ubyte" , UByteTyID, 1),
-     *Type::ShortTy  = new   SignedIntType("short" ,  ShortTyID, 2),
-     *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID, 2),
-     *Type::IntTy    = new   SignedIntType("int"   ,  IntTyID, 4), 
-     *Type::UIntTy   = new UnsignedIntType("uint"  , UIntTyID, 4),
-     *Type::LongTy   = new   SignedIntType("long"  ,  LongTyID, 8),
-     *Type::ULongTy  = new UnsignedIntType("ulong" , ULongTyID, 8),
+     *Type::SByteTy  = new   SignedIntType("sbyte" , SByteTyID),
+     *Type::UByteTy  = new UnsignedIntType("ubyte" , UByteTyID),
+     *Type::ShortTy  = new   SignedIntType("short" ,  ShortTyID),
+     *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID),
+     *Type::IntTy    = new   SignedIntType("int"   ,  IntTyID), 
+     *Type::UIntTy   = new UnsignedIntType("uint"  , UIntTyID),
+     *Type::LongTy   = new   SignedIntType("long"  ,  LongTyID),
+     *Type::ULongTy  = new UnsignedIntType("ulong" , ULongTyID),
      *Type::FloatTy  = new            Type("float" , FloatTyID),
      *Type::DoubleTy = new            Type("double", DoubleTyID),
      *Type::TypeTy   =        &TheTypeType,
@@ -418,7 +423,7 @@ public:
   ~TypeMap() { print("ON EXIT"); }
 
   inline TypeClass *get(const ValType &V) {
-    map<ValType, PATypeHandle<TypeClass> >::iterator I = Map.find(V);
+    typename map<ValType, PATypeHandle<TypeClass> >::iterator I = Map.find(V);
     // TODO: FIXME: When Types are not CONST.
     return (I != Map.end()) ? (TypeClass*)I->second.get() : 0;
   }
@@ -432,7 +437,7 @@ public:
   // structurally equivalent to the specified type.
   //
   inline const TypeClass *containsEquivalent(const TypeClass *Ty) {
-    for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
+    for (typename MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
       if (I->second.get() != Ty && TypesEqual(Ty, I->second.get()))
        return (TypeClass*)I->second.get();  // FIXME TODO when types not const
     return 0;
@@ -449,7 +454,7 @@ public:
         << OldTy->getDescription() << "  replacement == " << (void*)NewTy
         << ", " << NewTy->getDescription() << endl;
 #endif
-    for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
+    for (typename MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
       if (I->second == OldTy) {
         // Check to see if the type just became concrete.  If so, remove self
         // from user list.
@@ -459,7 +464,7 @@ public:
   }
 
   void remove(const ValType &OldVal) {
-    MapTy::iterator I = Map.find(OldVal);
+    typename MapTy::iterator I = Map.find(OldVal);
     assert(I != Map.end() && "TypeMap::remove, element not found!");
     Map.erase(I);
   }