First step toward fixing <rdar://problem/6613046> refactor clang objc type representation.

Add a type (ObjCObjectPointerType) and remove a type (ObjCQualifiedIdType).

This large/tedious patch is just a first step. Next step is to remove ObjCQualifiedInterfaceType. After that, I will remove the magic TypedefType for 'id' (installed by Sema). This work will enable various simplifications throughout clang (when dealing with ObjC types). 

No functionality change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73649 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 254080a..60d8e5f 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -164,7 +164,7 @@
   // Synthesize "typedef struct objc_object { Class isa; } *id;"
   if (Context.getObjCIdType().isNull()) {
     RecordDecl *ObjectTag = CreateStructDecl(Context, "objc_object");
-    
+
     QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag));
     PushOnScopeChains(ObjectTag, TUScope);
     TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext,
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index ab12cff..672e487 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1969,13 +1969,13 @@
   return 0;
 }
 
-static Decl *FindGetterNameDecl(const ObjCQualifiedIdType *QIdTy,
+static Decl *FindGetterNameDecl(const ObjCObjectPointerType *QIdTy,
                                 IdentifierInfo &Member,
                                 const Selector &Sel,
                                 ASTContext &Context) {
   // Check protocols on qualified interfaces.
   Decl *GDecl = 0;
-  for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
+  for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
        E = QIdTy->qual_end(); I != E; ++I) {
     if (ObjCPropertyDecl *PD = (*I)->FindPropertyDeclaration(Context, &Member)) {
       GDecl = PD;
@@ -1988,7 +1988,7 @@
     }
   }
   if (!GDecl) {
-    for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
+    for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
          E = QIdTy->qual_end(); I != E; ++I) {
       // Search in the protocol-qualifier list of current protocol.
       GDecl = FindGetterNameDeclFromProtocolList(*I, Member, Sel, Context);
@@ -2313,7 +2313,7 @@
       << &Member << BaseType);
   }
   // Handle properties on qualified "id" protocols.
-  const ObjCQualifiedIdType *QIdTy;
+  const ObjCObjectPointerType *QIdTy;
   if (OpKind == tok::period && (QIdTy = BaseType->getAsObjCQualifiedIdType())) {
     // Check protocols on qualified interfaces.
     Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 71033b4..f1869f9 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -590,9 +590,10 @@
   
   // We allow sending a message to a qualified ID ("id<foo>"), which is ok as 
   // long as one of the protocols implements the selector (if not, warn).
-  if (ObjCQualifiedIdType *QIdTy = dyn_cast<ObjCQualifiedIdType>(ReceiverCType)) {
+  if (const ObjCObjectPointerType *QIdTy = 
+        ReceiverCType->getAsObjCQualifiedIdType()) {
     // Search protocols for instance methods.
-    for (ObjCQualifiedIdType::qual_iterator I = QIdTy->qual_begin(),
+    for (ObjCObjectPointerType::qual_iterator I = QIdTy->qual_begin(),
          E = QIdTy->qual_end(); I != E; ++I) {
       ObjCProtocolDecl *PDecl = *I;
       if (PDecl && (Method = PDecl->lookupInstanceMethod(Context, Sel)))
@@ -754,8 +755,8 @@
       return true;
   }
   
-  if (const ObjCQualifiedIdType *lhsQID = lhs->getAsObjCQualifiedIdType()) {
-    const ObjCQualifiedIdType *rhsQID = rhs->getAsObjCQualifiedIdType();
+  if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) {
+    const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType();
     const ObjCQualifiedInterfaceType *rhsQI = 0;
     QualType rtype;
     
@@ -770,7 +771,7 @@
         // make sure we check the class hierarchy.
         if (const ObjCInterfaceType *IT = rtype->getAsObjCInterfaceType()) {
           ObjCInterfaceDecl *rhsID = IT->getDecl();
-          for (ObjCQualifiedIdType::qual_iterator I = lhsQID->qual_begin(),
+          for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(),
                E = lhsQID->qual_end(); I != E; ++I) {
             // when comparing an id<P> on lhs with a static type on rhs,
             // see if static class implements all of id's protocols, directly or
@@ -783,7 +784,7 @@
       }      
     }
     
-    ObjCQualifiedIdType::qual_iterator RHSProtoI, RHSProtoE;
+    ObjCObjectPointerType::qual_iterator RHSProtoI, RHSProtoE;
     if (rhsQI) { // We have a qualified interface (e.g. "NSObject<Proto> *").
       RHSProtoI = rhsQI->qual_begin();
       RHSProtoE = rhsQI->qual_end();
@@ -794,7 +795,7 @@
       return false;
     }
     
-    for (ObjCQualifiedIdType::qual_iterator I = lhsQID->qual_begin(),
+    for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(),
          E = lhsQID->qual_end(); I != E; ++I) {
       ObjCProtocolDecl *lhsProto = *I;
       bool match = false;
@@ -815,7 +816,7 @@
         // make sure we check the class hierarchy.
         if (const ObjCInterfaceType *IT = rtype->getAsObjCInterfaceType()) {
           ObjCInterfaceDecl *rhsID = IT->getDecl();
-          for (ObjCQualifiedIdType::qual_iterator I = lhsQID->qual_begin(),
+          for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(),
                E = lhsQID->qual_end(); I != E; ++I) {
             // when comparing an id<P> on lhs with a static type on rhs,
             // see if static class implements all of id's protocols, directly or
@@ -834,7 +835,7 @@
     return true;
   }
   
-  const ObjCQualifiedIdType *rhsQID = rhs->getAsObjCQualifiedIdType();
+  const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType();
   assert(rhsQID && "One of the LHS/RHS should be id<x>");
     
   if (!lhs->isPointerType())
@@ -843,12 +844,12 @@
   QualType ltype = lhs->getAsPointerType()->getPointeeType();
   if (const ObjCQualifiedInterfaceType *lhsQI =
          ltype->getAsObjCQualifiedInterfaceType()) {
-    ObjCQualifiedIdType::qual_iterator LHSProtoI = lhsQI->qual_begin();
-    ObjCQualifiedIdType::qual_iterator LHSProtoE = lhsQI->qual_end();
+    ObjCObjectPointerType::qual_iterator LHSProtoI = lhsQI->qual_begin();
+    ObjCObjectPointerType::qual_iterator LHSProtoE = lhsQI->qual_end();
     for (; LHSProtoI != LHSProtoE; ++LHSProtoI) {
       bool match = false;
       ObjCProtocolDecl *lhsProto = *LHSProtoI;
-      for (ObjCQualifiedIdType::qual_iterator I = rhsQID->qual_begin(),
+      for (ObjCObjectPointerType::qual_iterator I = rhsQID->qual_begin(),
            E = rhsQID->qual_end(); I != E; ++I) {
         ObjCProtocolDecl *rhsProto = *I;
         if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) ||
@@ -867,7 +868,7 @@
     // for static type vs. qualified 'id' type, check that class implements
     // all of 'id's protocols.
     ObjCInterfaceDecl *lhsID = IT->getDecl();
-    for (ObjCQualifiedIdType::qual_iterator I = rhsQID->qual_begin(),
+    for (ObjCObjectPointerType::qual_iterator I = rhsQID->qual_begin(),
          E = rhsQID->qual_end(); I != E; ++I) {
       if (!ClassImplementsProtocol(*I, lhsID, compare, true))
         return false;
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index dd955fe..9358833 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -847,7 +847,7 @@
   case Type::Typename:
   case Type::ObjCInterface:
   case Type::ObjCQualifiedInterface:
-  case Type::ObjCQualifiedId:
+  case Type::ObjCObjectPointer:
 #define TYPE(Class, Base)
 #define ABSTRACT_TYPE(Class, Base)
 #define DEPENDENT_TYPE(Class, Base)
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index fd5a460..72f9511 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -657,6 +657,14 @@
 
 QualType 
 TemplateTypeInstantiator::
+InstantiateObjCObjectPointerType(const ObjCObjectPointerType *T,
+                                 unsigned Quals) const {
+  assert(false && "Objective-C types cannot be dependent");
+  return QualType();
+}
+
+QualType
+TemplateTypeInstantiator::
 InstantiateObjCInterfaceType(const ObjCInterfaceType *T,
                              unsigned Quals) const {
   assert(false && "Objective-C types cannot be dependent");
@@ -671,14 +679,6 @@
   return QualType();
 }
 
-QualType 
-TemplateTypeInstantiator::
-InstantiateObjCQualifiedIdType(const ObjCQualifiedIdType *T,
-                               unsigned Quals) const {
-  assert(false && "Objective-C types cannot be dependent");
-  return QualType();
-}
-
 /// \brief The actual implementation of Sema::InstantiateType().
 QualType TemplateTypeInstantiator::Instantiate(QualType T) const {
   // If T is not a dependent type, there is nothing to do.