Add support for casting operators
[oota-llvm.git] / lib / VMCore / Type.cpp
index cf16309ccb44820a6224631c955e7a89760db8c4..2e0bee55e55f6d9b599fc0d42a6ad5bbc569bfe8 100644 (file)
@@ -70,6 +70,9 @@ public:
 
   // isSigned - Return whether a numeric type is signed.
   virtual bool isSigned() const { return 1; }
+  
+  // isIntegral - Return whether this is one of the integer types
+  virtual bool isIntegral() const { return 1; }
 };
 
 class UnsignedIntType : public Type {
@@ -81,6 +84,9 @@ public:
 
   // isUnsigned - Return whether a numeric type is signed.
   virtual bool isUnsigned() const { return 1; }
+  
+  // isIntegral - Return whether this is one of the integer types
+  virtual bool isIntegral() const { return 1; }
 };
 
 static struct TypeType : public Type {
@@ -143,7 +149,11 @@ ArrayType::ArrayType(const Type *ElType, int NumEl, const string &Name)
 }
 
 StructType::StructType(const vector<const Type*> &Types, const string &Name) 
-  : Type(Name, StructTyID), ETypes(Types) {
+  : Type(Name, StructTyID),
+    ETypes(Types),
+    layoutCache(new StructSizeAndOffsetInfo) 
+{
+  ResetCachedInfo();
 }
 
 PointerType::PointerType(const Type *E) 
@@ -157,13 +167,13 @@ PointerType::PointerType(const Type *E)
 const MethodType *MethodType::getMethodType(const Type *ReturnType, 
                                             const vector<const Type*> &Params) {
   static vector<const MethodType*> ExistingMethodTypesCache;
-  for (unsigned i = 0; i < ExistingMethodTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingMethodTypesCache.size(); ++i) {
     const MethodType *T = ExistingMethodTypesCache[i];
     if (T->getReturnType() == ReturnType) {
       const ParamTypes &EParams = T->getParamTypes();
       ParamTypes::const_iterator I = Params.begin(); 
       ParamTypes::const_iterator J = EParams.begin(); 
-      for (; I != Params.end() && J != EParams.end(); I++, J++)
+      for (; I != Params.end() && J != EParams.end(); ++I, ++J)
         if (*I != *J) break;  // These types aren't equal!
 
       if (I == Params.end() && J == EParams.end()) {
@@ -189,7 +199,7 @@ const MethodType *MethodType::getMethodType(const Type *ReturnType,
   // Calculate the string name for the new type...
   string Name = ReturnType->getName() + " (";
   for (ParamTypes::const_iterator I = Params.begin();  
-       I != Params.end(); I++) {
+       I != Params.end(); ++I) {
     if (I != Params.begin())
       Name += ", ";
     Name += (*I)->getName();
@@ -208,10 +218,11 @@ const MethodType *MethodType::getMethodType(const Type *ReturnType,
 
 const ArrayType *ArrayType::getArrayType(const Type *ElementType, 
                                         int NumElements = -1) {
+  assert(ElementType && "Can't get array of null types!");
   static vector<const ArrayType*> ExistingTypesCache;
 
   // Search cache for value...
-  for (unsigned i = 0; i < ExistingTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) {
     const ArrayType *T = ExistingTypesCache[i];
 
     if (T->getElementType() == ElementType && 
@@ -237,13 +248,13 @@ const ArrayType *ArrayType::getArrayType(const Type *ElementType,
 const StructType *StructType::getStructType(const ElementTypes &ETypes) {
   static vector<const StructType*> ExistingStructTypesCache;
 
-  for (unsigned i = 0; i < ExistingStructTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingStructTypesCache.size(); ++i) {
     const StructType *T = ExistingStructTypesCache[i];
 
     const ElementTypes &Elements = T->getElementTypes();
     ElementTypes::const_iterator I = ETypes.begin(); 
     ElementTypes::const_iterator J = Elements.begin(); 
-    for (; I != ETypes.end() && J != Elements.end(); I++, J++)
+    for (; I != ETypes.end() && J != Elements.end(); ++I, ++J)
       if (*I != *J) break;  // These types aren't equal!
     
     if (I == ETypes.end() && J == Elements.end()) {
@@ -269,7 +280,7 @@ const StructType *StructType::getStructType(const ElementTypes &ETypes) {
   // Calculate the string name for the new type...
   string Name = "{ ";
   for (ElementTypes::const_iterator I = ETypes.begin();  
-       I != ETypes.end(); I++) {
+       I != ETypes.end(); ++I) {
     if (I != ETypes.begin())
       Name += ", ";
     Name += (*I)->getName();
@@ -287,10 +298,11 @@ const StructType *StructType::getStructType(const ElementTypes &ETypes) {
 
 
 const PointerType *PointerType::getPointerType(const Type *ValueType) {
+  assert(ValueType && "Can't get a pointer to <null> type!");
   static vector<const PointerType*> ExistingTypesCache;
 
   // Search cache for value...
-  for (unsigned i = 0; i < ExistingTypesCache.size(); i++) {
+  for (unsigned i = 0; i < ExistingTypesCache.size(); ++i) {
     const PointerType *T = ExistingTypesCache[i];
 
     if (T->getValueType() == ValueType)