More support for rewriting ObjC intefaces. Still some edge cases to handle...

llvm-svn: 43493
diff --git a/clang/Parse/MinimalAction.cpp b/clang/Parse/MinimalAction.cpp
index b0dad93..d439141 100644
--- a/clang/Parse/MinimalAction.cpp
+++ b/clang/Parse/MinimalAction.cpp
@@ -72,7 +72,7 @@
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *SuperName, SourceLocation SuperLoc,
                     IdentifierInfo **ProtocolNames, unsigned NumProtocols,
-                    AttributeList *AttrList) {
+                    SourceLocation EndProtoLoc, AttributeList *AttrList) {
   TypeNameInfo *TI =
     new TypeNameInfo(1, ClassName->getFETokenInfo<TypeNameInfo>());
 
diff --git a/clang/Parse/ParseDecl.cpp b/clang/Parse/ParseDecl.cpp
index 1e786da..aeecdb7 100644
--- a/clang/Parse/ParseDecl.cpp
+++ b/clang/Parse/ParseDecl.cpp
@@ -407,8 +407,9 @@
           DS.Range.setEnd(Tok.getLocation());
           ConsumeToken(); // The identifier
           if (Tok.is(tok::less)) {
+            SourceLocation endProtoLoc;
             llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
-            ParseObjCProtocolReferences(ProtocolRefs);
+            ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
             llvm::SmallVector<DeclTy *, 8> *ProtocolDecl = 
                     new llvm::SmallVector<DeclTy *, 8>;
             DS.setProtocolQualifiers(ProtocolDecl);
diff --git a/clang/Parse/ParseObjc.cpp b/clang/Parse/ParseObjc.cpp
index 0d44dcd..0c0c165 100644
--- a/clang/Parse/ParseObjc.cpp
+++ b/clang/Parse/ParseObjc.cpp
@@ -146,9 +146,10 @@
       return 0;
     }
     rparenLoc = ConsumeParen();
+    SourceLocation endProtoLoc;
     // Next, we need to check for any protocol references.
     if (Tok.is(tok::less)) {
-      if (ParseObjCProtocolReferences(ProtocolRefs))
+      if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
         return 0;
     }
     if (attrList) // categories don't support attributes.
@@ -183,14 +184,15 @@
   }
   // Next, we need to check for any protocol references.
   llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
+  SourceLocation endProtoLoc;
   if (Tok.is(tok::less)) {
-    if (ParseObjCProtocolReferences(ProtocolRefs))
+    if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
       return 0;
   }
   DeclTy *ClsType = Actions.ActOnStartClassInterface(
 		      atLoc, nameId, nameLoc, 
                       superClassId, superClassLoc, &ProtocolRefs[0], 
-                      ProtocolRefs.size(), attrList);
+                      ProtocolRefs.size(), endProtoLoc, attrList);
             
   if (Tok.is(tok::l_brace))
     ParseObjCClassInstanceVariables(ClsType, atLoc);
@@ -635,7 +637,8 @@
 ///     '<' identifier-list '>'
 ///
 bool Parser::ParseObjCProtocolReferences(
-  llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs) {
+  llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc) 
+{
   assert(Tok.is(tok::less) && "expected <");
   
   ConsumeToken(); // the "<"
@@ -661,9 +664,13 @@
   // Make protocol names unique.
   ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()), 
                      ProtocolRefs.end());
-
   // Consume the '>'.
-  return ExpectAndConsume(tok::greater, diag::err_expected_greater);
+  if (Tok.is(tok::greater)) {
+    endLoc = ConsumeAnyToken();
+    return false;
+  }
+  Diag(Tok, diag::err_expected_greater);
+  return true;
 }
 
 ///   objc-class-instance-variables:
@@ -811,15 +818,16 @@
                                                    &ProtocolRefs[0], 
                                                    ProtocolRefs.size());
   // Last, and definitely not least, parse a protocol declaration.
+  SourceLocation endProtoLoc;
   if (Tok.is(tok::less)) {
-    if (ParseObjCProtocolReferences(ProtocolRefs))
+    if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc))
       return 0;
   }
   
   DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, 
                                 protocolName, nameLoc,
                                 &ProtocolRefs[0],
-                                ProtocolRefs.size());
+                                ProtocolRefs.size(), endProtoLoc);
   ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol);
 
   // The @ sign was already consumed by ParseObjCInterfaceDeclList().
diff --git a/clang/Parse/ParseStmt.cpp b/clang/Parse/ParseStmt.cpp
index 9e18bba..5e05f9a 100644
--- a/clang/Parse/ParseStmt.cpp
+++ b/clang/Parse/ParseStmt.cpp
@@ -235,9 +235,10 @@
                                        IdentTok.getLocation(), PrevSpec,
                                        TypeRep);
     assert(!isInvalid && "First declspec can't be invalid!");
+    SourceLocation endProtoLoc;
     if (Tok.is(tok::less)) {
       llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
-      ParseObjCProtocolReferences(ProtocolRefs);
+      ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc);
       llvm::SmallVector<DeclTy *, 8> *ProtocolDecl = 
               new llvm::SmallVector<DeclTy *, 8>;
       DS.setProtocolQualifiers(ProtocolDecl);