- Add location info to category/protocol AST's
- Rewrite categories.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43501 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 8d3887a..e125ce5 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1081,16 +1081,18 @@
     ObjcProtocols[ProtocolName] = PDecl;
   }    
   
-  /// Check then save referenced protocols
-  for (unsigned int i = 0; i != NumProtoRefs; i++) {
-    ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
-    if (!RefPDecl || RefPDecl->isForwardDecl())
-      Diag(ProtocolLoc, diag::err_undef_protocolref,
-           ProtoRefNames[i]->getName(),
-           ProtocolName->getName());
-    PDecl->setReferencedProtocols((int)i, RefPDecl);
+  if (NumProtoRefs) {
+    /// Check then save referenced protocols
+    for (unsigned int i = 0; i != NumProtoRefs; i++) {
+      ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
+      if (!RefPDecl || RefPDecl->isForwardDecl())
+        Diag(ProtocolLoc, diag::err_undef_protocolref,
+             ProtoRefNames[i]->getName(),
+             ProtocolName->getName());
+      PDecl->setReferencedProtocols((int)i, RefPDecl);
+    }
+    PDecl->setLocEnd(EndProtoLoc);
   }
-
   return PDecl;
 }
 
@@ -1137,7 +1139,8 @@
                       SourceLocation AtInterfaceLoc,
                       IdentifierInfo *ClassName, SourceLocation ClassLoc,
                       IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
-                      IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
+                      IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs,
+                      SourceLocation EndProtoLoc) {
   ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
   
   /// Check that class of this category is already completely declared.
@@ -1161,17 +1164,19 @@
   if (!CDeclChain)
     CDecl->insertNextClassCategory();
 
-  /// Check then save referenced protocols
-  for (unsigned int i = 0; i != NumProtoRefs; i++) {
-    ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
-    if (!RefPDecl || RefPDecl->isForwardDecl()) {
-      Diag(CategoryLoc, diag::err_undef_protocolref,
-           ProtoRefNames[i]->getName(),
-           CategoryName->getName());
+  if (NumProtoRefs) {
+    /// Check then save referenced protocols
+    for (unsigned int i = 0; i != NumProtoRefs; i++) {
+      ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
+      if (!RefPDecl || RefPDecl->isForwardDecl()) {
+        Diag(CategoryLoc, diag::err_undef_protocolref,
+             ProtoRefNames[i]->getName(),
+             CategoryName->getName());
+      }
+      CDecl->setCatReferencedProtocols((int)i, RefPDecl);
     }
-    CDecl->setCatReferencedProtocols((int)i, RefPDecl);
+    CDecl->setLocEnd(EndProtoLoc);
   }
-  
   return CDecl;
 }