[cfe-commits] r49308 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/ASTContext.cpp

Chris Lattner sabre at nondot.org
Sun Apr 6 21:44:08 PDT 2008


Author: lattner
Date: Sun Apr  6 23:44:08 2008
New Revision: 49308

URL: http://llvm.org/viewvc/llvm-project?rev=49308&view=rev
Log:
eliminate getReferencedProtocols from 
ObjCQualifiedIdType/ObjCQualifiedInterfaceType, adding an interator 
interface instead.

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=49308&r1=49307&r2=49308&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Apr  6 23:44:08 2008
@@ -1087,7 +1087,7 @@
   llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols;
 
   ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D,
-                             ObjCProtocolDecl **Protos,  unsigned NumP) : 
+                             ObjCProtocolDecl **Protos, unsigned NumP) : 
     ObjCInterfaceType(ObjCQualifiedInterface, D), 
     Protocols(Protos, Protos+NumP) { }
   friend class ASTContext;  // ASTContext creates these.
@@ -1099,9 +1099,11 @@
   unsigned getNumProtocols() const {
     return Protocols.size();
   }
-  ObjCProtocolDecl **getReferencedProtocols() {
-    return &Protocols[0];
-  }  
+
+  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
+  qual_iterator qual_begin() const { return Protocols.begin(); }
+  qual_iterator qual_end() const   { return Protocols.end(); }
+                                     
   virtual void getAsStringInternal(std::string &InnerString) const;
   
   void Profile(llvm::FoldingSetNodeID &ID);
@@ -1135,7 +1137,11 @@
   }
   ObjCProtocolDecl **getReferencedProtocols() {
     return &Protocols[0];
-  } 
+  }
+                              
+  typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator;
+  qual_iterator qual_begin() const { return Protocols.begin(); }
+  qual_iterator qual_end() const   { return Protocols.end(); }
     
   virtual void getAsStringInternal(std::string &InnerString) const;
     

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49308&r1=49307&r2=49308&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Apr  6 23:44:08 2008
@@ -811,9 +811,8 @@
   return QualType(Decl->TypeForDecl, 0);
 }
 
-/// getObjCQualifiedInterfaceType - Return a 
-/// ObjCQualifiedInterfaceType type for the given interface decl and
-/// the conforming protocol list.
+/// getObjCQualifiedInterfaceType - Return a ObjCQualifiedInterfaceType type for
+/// the given interface decl and the conforming protocol list.
 QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
                        ObjCProtocolDecl **Protocols, unsigned NumProtocols) {
   llvm::FoldingSetNodeID ID;
@@ -1443,6 +1442,9 @@
   return false;
 }
 
+/// areCompatObjCQualInterfaces - Return true if the two qualified interface
+/// types are compatible for assignment from RHS to LHS.
+///
 static bool 
 areCompatObjCQualInterfaces(const ObjCQualifiedInterfaceType *LHS, 
                             const ObjCQualifiedInterfaceType *RHS) {
@@ -1525,13 +1527,10 @@
     QualType PointeeTy = PT->getPointeeType();
     if (isObjCIdType(PointeeTy) || PointeeTy->isVoidType())
       return true;
-        
-  }
-  else if (const PointerType *PT = rhs->getAsPointerType()) {
+  } else if (const PointerType *PT = rhs->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
     if (isObjCIdType(PointeeTy) || PointeeTy->isVoidType())
       return true;
-    
   }
   
   ObjCQualifiedInterfaceType *lhsQI = 0;
@@ -1558,15 +1557,13 @@
     if (!rhsQI && !rhsQID && !rhsID)
       return false;
     
-    unsigned numRhsProtocols = 0;
-    ObjCProtocolDecl **rhsProtoList = 0;
+    ObjCQualifiedIdType::qual_iterator RHSProtoI, RHSProtoE;
     if (rhsQI) {
-      numRhsProtocols = rhsQI->getNumProtocols();
-      rhsProtoList = rhsQI->getReferencedProtocols();
-    }
-    else if (rhsQID) {
-      numRhsProtocols = rhsQID->getNumProtocols();
-      rhsProtoList = rhsQID->getReferencedProtocols();
+      RHSProtoI = rhsQI->qual_begin();
+      RHSProtoE = rhsQI->qual_end();
+    } else if (rhsQID) {
+      RHSProtoI = rhsQID->qual_begin();
+      RHSProtoE = rhsQID->qual_end();
     }
     
     for (unsigned i =0; i < lhsQID->getNumProtocols(); i++) {
@@ -1579,13 +1576,14 @@
       if (rhsID) {
         if (ClassImplementsProtocol(lhsProto, rhsID, true))
           match = true;
-      }
-      else for (unsigned j = 0; j < numRhsProtocols; j++) {
-        ObjCProtocolDecl *rhsProto = rhsProtoList[j];
-        if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
-            compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
-          match = true;
-          break;
+      } else {
+        for (; RHSProtoI != RHSProtoE; ++RHSProtoI) {
+          ObjCProtocolDecl *rhsProto = *RHSProtoI;
+          if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
+              compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
+            match = true;
+            break;
+          }
         }
       }
       if (!match)
@@ -1609,16 +1607,15 @@
     if (!lhsQI && !lhsQID && !lhsID)
       return false;
     
-    unsigned numLhsProtocols = 0;
-    ObjCProtocolDecl **lhsProtoList = 0;
+    ObjCQualifiedIdType::qual_iterator LHSProtoI, LHSProtoE;
     if (lhsQI) {
-      numLhsProtocols = lhsQI->getNumProtocols();
-      lhsProtoList = lhsQI->getReferencedProtocols();
+      LHSProtoI = lhsQI->qual_begin();
+      LHSProtoE = lhsQI->qual_end();
+    } else if (lhsQID) {
+      LHSProtoI = lhsQID->qual_begin();
+      LHSProtoE = lhsQID->qual_end();
     }
-    else if (lhsQID) {
-      numLhsProtocols = lhsQID->getNumProtocols();
-      lhsProtoList = lhsQID->getReferencedProtocols();
-    }    
+    
     bool match = false;
     // for static type vs. qualified 'id' type, check that class implements
     // one of 'id's protocols.
@@ -1630,16 +1627,17 @@
           break;
         }
       }
-    }    
-    else for (unsigned i =0; i < numLhsProtocols; i++) {
-      match = false;
-      ObjCProtocolDecl *lhsProto = lhsProtoList[i];
-      for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) {
-        ObjCProtocolDecl *rhsProto = rhsQID->getProtocols(j);
-        if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
-          compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
-          match = true;
-          break;
+    } else {
+      for (; LHSProtoI != LHSProtoE; ++LHSProtoI) {
+        match = false;
+        ObjCProtocolDecl *lhsProto = *LHSProtoI;
+        for (unsigned j = 0; j < rhsQID->getNumProtocols(); j++) {
+          ObjCProtocolDecl *rhsProto = rhsQID->getProtocols(j);
+          if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
+            compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto)) {
+            match = true;
+            break;
+          }
         }
       }
     }





More information about the cfe-commits mailing list