]> granicus.if.org Git - clang/commitdiff
Keep protocol source locations when parsing protocol references.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 29 Sep 2009 19:41:44 +0000 (19:41 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 29 Sep 2009 19:41:44 +0000 (19:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83091 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/DeclSpec.h
include/clang/Parse/Parser.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseObjc.cpp

index 7ecbf7db7bc81f31a16c58070a0cd5165e1a28a0..7d316c43fd6a75beb5cb1b71812d83fa5f9bd82e 100644 (file)
@@ -144,6 +144,8 @@ private:
   // "id<foo>".
   const ActionBase::DeclPtrTy *ProtocolQualifiers;
   unsigned NumProtocolQualifiers;
+  SourceLocation ProtocolLAngleLoc;
+  SourceLocation *ProtocolLocs;
 
   // SourceLocation info.  These are null if the item wasn't specified or if
   // the setting was synthesized.
@@ -175,11 +177,13 @@ public:
       TypeRep(0),
       AttrList(0),
       ProtocolQualifiers(0),
-      NumProtocolQualifiers(0) {
+      NumProtocolQualifiers(0),
+      ProtocolLocs(0) {
   }
   ~DeclSpec() {
     delete AttrList;
     delete [] ProtocolQualifiers;
+    delete [] ProtocolLocs;
   }
   // storage-class-specifier
   SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
@@ -339,14 +343,21 @@ public:
   ProtocolQualifierListTy getProtocolQualifiers() const {
     return ProtocolQualifiers;
   }
+  SourceLocation *getProtocolLocs() const { return ProtocolLocs; }
   unsigned getNumProtocolQualifiers() const {
     return NumProtocolQualifiers;
   }
-  void setProtocolQualifiers(const ActionBase::DeclPtrTy *Protos, unsigned NP) {
+  SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; }
+  void setProtocolQualifiers(const ActionBase::DeclPtrTy *Protos, unsigned NP,
+                             SourceLocation *ProtoLocs,
+                             SourceLocation LAngleLoc) {
     if (NP == 0) return;
     ProtocolQualifiers = new ActionBase::DeclPtrTy[NP];
+    ProtocolLocs = new SourceLocation[NP];
     memcpy((void*)ProtocolQualifiers, Protos, sizeof(ActionBase::DeclPtrTy)*NP);
+    memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP);
     NumProtocolQualifiers = NP;
+    ProtocolLAngleLoc = LAngleLoc;
   }
 
   /// Finish - This does final analysis of the declspec, issuing diagnostics for
index e11ca0ce6b17a5e08609189ea61081b498991d16..9cb4677f66370daee579b5c81d09becd7fec533f 100644 (file)
@@ -674,7 +674,9 @@ private:
   void ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
                                        SourceLocation atLoc);
   bool ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &P,
+                                   llvm::SmallVectorImpl<SourceLocation> &PLocs,
                                    bool WarnOnDeclarations,
+                                   SourceLocation &LAngleLoc,
                                    SourceLocation &EndProtoLoc);
   void ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl,
                                   tok::ObjCKeywordKind contextKey);
index d885558e1f383ed1b142d7886a6cf4b67ef0ace7..e15a4cd6880513ab71207afd095c6d31d8b7ebf1 100644 (file)
@@ -848,10 +848,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
       if (!Tok.is(tok::less) || !getLang().ObjC1)
         continue;
 
-      SourceLocation EndProtoLoc;
+      SourceLocation LAngleLoc, EndProtoLoc;
       llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
-      ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
-      DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size());
+      llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
+      ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false,
+                                  LAngleLoc, EndProtoLoc);
+      DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(),
+                               ProtocolLocs.data(), LAngleLoc);
 
       DS.SetRangeEnd(EndProtoLoc);
       continue;
@@ -908,10 +911,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
       if (!Tok.is(tok::less) || !getLang().ObjC1)
         continue;
 
-      SourceLocation EndProtoLoc;
+      SourceLocation LAngleLoc, EndProtoLoc;
       llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
-      ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
-      DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size());
+      llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
+      ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false,
+                                  LAngleLoc, EndProtoLoc);
+      DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(),
+                               ProtocolLocs.data(), LAngleLoc);
 
       DS.SetRangeEnd(EndProtoLoc);
 
@@ -1154,10 +1160,13 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
         goto DoneWithDeclSpec;
 
       {
-        SourceLocation EndProtoLoc;
+        SourceLocation LAngleLoc, EndProtoLoc;
         llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
-        ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
-        DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size());
+        llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
+        ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false,
+                                    LAngleLoc, EndProtoLoc);
+        DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(),
+                                 ProtocolLocs.data(), LAngleLoc);
         DS.SetRangeEnd(EndProtoLoc);
 
         Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id)
@@ -1268,10 +1277,13 @@ bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, bool& isInvalid,
     if (!Tok.is(tok::less) || !getLang().ObjC1)
       return true;
 
-    SourceLocation EndProtoLoc;
+    SourceLocation LAngleLoc, EndProtoLoc;
     llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
-    ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
-    DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size());
+    llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
+    ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false,
+                                LAngleLoc, EndProtoLoc);
+    DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(),
+                             ProtocolLocs.data(), LAngleLoc);
 
     DS.SetRangeEnd(EndProtoLoc);
     return true;
index fdd031c66de1d0974e48b975720cbee50f12898a..014f10edd40f1433f383ebeb99243be147ae163d 100644 (file)
@@ -148,10 +148,12 @@ Parser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration(
     rparenLoc = ConsumeParen();
 
     // Next, we need to check for any protocol references.
-    SourceLocation EndProtoLoc;
+    SourceLocation LAngleLoc, EndProtoLoc;
     llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
+    llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
     if (Tok.is(tok::less) &&
-        ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc))
+        ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
+                                    LAngleLoc, EndProtoLoc))
       return DeclPtrTy();
 
     if (attrList) // categories don't support attributes.
@@ -183,9 +185,11 @@ Parser::DeclPtrTy Parser::ParseObjCAtInterfaceDeclaration(
   }
   // Next, we need to check for any protocol references.
   llvm::SmallVector<Action::DeclPtrTy, 8> ProtocolRefs;
-  SourceLocation EndProtoLoc;
+  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
+  SourceLocation LAngleLoc, EndProtoLoc;
   if (Tok.is(tok::less) &&
-      ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc))
+      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true,
+                                  LAngleLoc, EndProtoLoc))
     return DeclPtrTy();
 
   DeclPtrTy ClsType =
@@ -786,10 +790,12 @@ Parser::DeclPtrTy Parser::ParseObjCMethodDecl(SourceLocation mLoc,
 ///
 bool Parser::
 ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols,
-                            bool WarnOnDeclarations, SourceLocation &EndLoc) {
+                            llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs,
+                            bool WarnOnDeclarations,
+                            SourceLocation &LAngleLoc, SourceLocation &EndLoc) {
   assert(Tok.is(tok::less) && "expected <");
 
-  ConsumeToken(); // the "<"
+  LAngleLoc = ConsumeToken(); // the "<"
 
   llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents;
 
@@ -801,6 +807,7 @@ ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclPtrTy> &Protocols,
     }
     ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
                                        Tok.getLocation()));
+    ProtocolLocs.push_back(Tok.getLocation());
     ConsumeToken();
 
     if (Tok.isNot(tok::comma))
@@ -982,11 +989,13 @@ Parser::DeclPtrTy Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
   }
 
   // Last, and definitely not least, parse a protocol declaration.
-  SourceLocation EndProtoLoc;
+  SourceLocation LAngleLoc, EndProtoLoc;
 
   llvm::SmallVector<DeclPtrTy, 8> ProtocolRefs;
+  llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
   if (Tok.is(tok::less) &&
-      ParseObjCProtocolReferences(ProtocolRefs, false, EndProtoLoc))
+      ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false,
+                                  LAngleLoc, EndProtoLoc))
     return DeclPtrTy();
 
   DeclPtrTy ProtoType =