]> granicus.if.org Git - clang/commitdiff
Move ObjCProtocolDecl::EndLoc into its DefinitionData, and give
authorDouglas Gregor <dgregor@apple.com>
Mon, 2 Jan 2012 01:18:16 +0000 (01:18 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 2 Jan 2012 01:18:16 +0000 (01:18 +0000)
ObjCProtocolDecl proper source-range information.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147420 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/Sema/SemaDeclObjC.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 5f6bdec1cff2c5f2f0b985aed0e316b851c36129..9d9b9b1d7d8a534d005adbf7341dfb67fa395825 100644 (file)
@@ -1071,14 +1071,15 @@ class ObjCProtocolDecl : public ObjCContainerDecl,
     // \brief The declaration that defines this protocol.
     ObjCProtocolDecl *Definition;
 
-    /// Referenced protocols
+    /// \brief Referenced protocols
     ObjCProtocolList ReferencedProtocols;    
+
+    /// \brief Marks the '>' or identifier.
+    SourceLocation EndLoc; 
   };
   
   DefinitionData *Data;
 
-  SourceLocation EndLoc; // marks the '>' or identifier.
-
   DefinitionData &data() const {
     assert(Data && "Objective-C protocol has no definition!");
     return *Data;
@@ -1181,10 +1182,21 @@ public:
   /// \brief Starts the definition of this Objective-C protocol.
   void startDefinition();
 
-  // Location information, modeled after the Stmt API.
-  SourceLocation getLocStart() const { return getAtStartLoc(); } // '@'protocol
-  SourceLocation getLocEnd() const { return EndLoc; }
-  void setLocEnd(SourceLocation LE) { EndLoc = LE; }
+  virtual SourceRange getSourceRange() const {
+    if (isThisDeclarationADefinition())
+      return ObjCContainerDecl::getSourceRange();
+   
+    return SourceRange(getAtStartLoc(), getLocation());
+  }
+                           
+  SourceLocation getEndOfDefinitionLoc() const { 
+    if (!hasDefinition())
+      return getLocation();
+   
+    return data().EndLoc; 
+  }
+   
+  void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
 
   typedef redeclarable_base::redecl_iterator redecl_iterator;
   redecl_iterator redecls_begin() const {
index e76971188ff9f06236789cc2de573b9b608392ce..9658174f97d12c7940f82f9df748fb1336287a4f 100644 (file)
@@ -615,7 +615,7 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
     /// Check then save referenced protocols.
     PDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,
                            ProtoLocs, Context);
-    PDecl->setLocEnd(EndProtoLoc);
+    PDecl->setEndOfDefinitionLoc(EndProtoLoc);
   }
 
   CheckObjCDeclScope(PDecl);
index 46dcc8757d90a5053bebc434fe60ecc1bdb4760e..75a2aad5e47cd1f1d0cbe1bf58d97ea8a79c5fb6 100644 (file)
@@ -764,7 +764,6 @@ void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
   
   RedeclarableResult Redecl = VisitRedeclarable(PD);
   VisitObjCContainerDecl(PD);
-  PD->setLocEnd(ReadSourceLocation(Record, Idx));
   
   // Determine whether we need to merge this declaration with another @protocol
   // with the same name.
@@ -822,6 +821,8 @@ void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
     PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
                         Reader.getContext());
     
+    PD->setEndOfDefinitionLoc(ReadSourceLocation(Record, Idx));
+
     // Note that we have deserialized a definition.
     Reader.PendingDefinitions.insert(PD);
   } else if (Def && Def->Data) {
index 4701b8fc386ab8e190b29eb8ae3830973520d654..8510feca5e5639e83248355ab61c071e67c9032f 100644 (file)
@@ -518,7 +518,6 @@ void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
 void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
   VisitRedeclarable(D);
   VisitObjCContainerDecl(D);
-  Writer.AddSourceLocation(D->getLocEnd(), Record);
   
   ObjCProtocolDecl *Def = D->getDefinition();
   Writer.AddDeclRef(Def, Record);
@@ -532,6 +531,7 @@ void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
            PLEnd = D->protocol_loc_end();
          PL != PLEnd; ++PL)
       Writer.AddSourceLocation(*PL, Record);
+    Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
   }
   
   Code = serialization::DECL_OBJC_PROTOCOL;