]> granicus.if.org Git - clang/commitdiff
Attaching comments to declarations during parsing: handle more Objective-C declarations.
authorDmitri Gribenko <gribozavr@gmail.com>
Fri, 13 Jul 2012 01:06:46 +0000 (01:06 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Fri, 13 Jul 2012 01:06:46 +0000 (01:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160156 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaObjCProperty.cpp
test/Sema/warn-documentation.m

index 2a1521e21e8a15fb411ea9f0b54982a7f6939cba..a9681d86697e65cc69bcad5e2f1c77f4a3d16290 100644 (file)
@@ -78,9 +78,21 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
   if (RawComments.empty())
     return NULL;
 
+  // Find declaration location.
+  // For Objective-C declarations we generally don't expect to have multiple
+  // declarators, thus use declaration starting location as the "declaration
+  // location".
+  // For all other declarations multiple declarators are used quite frequently,
+  // so we use the location of the identifier as the "declaration location".
+  SourceLocation DeclLoc;
+  if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) ||
+      isa<ObjCPropertyDecl>(D))
+    DeclLoc = D->getLocStart();
+  else
+    DeclLoc = D->getLocation();
+
   // If the declaration doesn't map directly to a location in a file, we
   // can't find the comment.
-  SourceLocation DeclLoc = D->getLocation();
   if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
     return NULL;
 
@@ -144,7 +156,7 @@ RawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const {
 
   // There should be no other declarations or preprocessor directives between
   // comment and declaration.
-  if (Text.find_first_of(",;{}#") != StringRef::npos)
+  if (Text.find_first_of(",;{}#@") != StringRef::npos)
     return NULL;
 
   return *Comment;
index 47453762d9d2c2f2238ea5a04b623f76d6160edb..f00ed8279be4ec1e8f92f963347969fe859115a0 100644 (file)
@@ -8932,7 +8932,6 @@ Decl *Sema::ActOnObjCContainerStartDefinition(Decl *IDecl) {
   assert(getContainingDC(OCD) == CurContext &&
       "The next DeclContext should be lexically contained in the current one.");
   CurContext = OCD;
-  ActOnDocumentableDecl(IDecl);
   return IDecl;
 }
 
index 8d4694662d5e89dba28fa6b8d6eaae03d178374e..17c34a239d5cf44a2b5ec424acd1af10a2aa8b38 100644 (file)
@@ -2429,6 +2429,7 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd,
     Consumer.HandleTopLevelDeclInObjCContainer(DG);
   }
 
+  ActOnDocumentableDecl(ClassDecl);
   return ClassDecl;
 }
 
index 34dd068945eaac41214a4d899ef9ee576d5272f7..335dad18dd989791867f01776e3002b7f8211196 100644 (file)
@@ -149,6 +149,7 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
         if (getLangOpts().ObjCAutoRefCount)
           checkARCPropertyDecl(*this, cast<ObjCPropertyDecl>(Res));
       }
+      ActOnDocumentableDecl(Res);
       return Res;
     }
   
@@ -169,6 +170,7 @@ Decl *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
   if (getLangOpts().ObjCAutoRefCount)
     checkARCPropertyDecl(*this, Res);
 
+  ActOnDocumentableDecl(Res);
   return Res;
 }
 
index 0a02f7bb26c1b774538f2b31bc69b37992217329..3a661c5ef4078c6058806e209a166a1ae2eeca81 100644 (file)
@@ -2,11 +2,9 @@
 
 @class NSString;
 
-// expected-warning@+2 {{empty paragraph passed to '\brief' command}}
-/**
- * \brief\brief Aaa
- */
-@interface A
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@interface Test1
 // expected-warning@+2 {{empty paragraph passed to '\brief' command}}
 /**
  * \brief\brief Aaa
  * \param aab Aaa
  */
 + (NSString *)test2:(NSString *)aaa;
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@property int test3; // a property: ObjCPropertyDecl
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@property int test4; // a property: ObjCPropertyDecl
 @end
 
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@interface Test1()
+@end
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@implementation Test1 // a class implementation : ObjCImplementationDecl
++ (NSString *)test1:(NSString *)aaa suffix:(NSString *)bbb {
+  return 0;
+}
+
++ (NSString *)test2:(NSString *)aaa {
+  return 0;
+}
+
+@synthesize test3; // a property implementation: ObjCPropertyImplDecl
+@dynamic test4; // a property implementation: ObjCPropertyImplDecl
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+NSString *_test5;
+@end
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@interface Test1(Test1Category) // a category: ObjCCategoryDecl
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
++ (NSString *)test3:(NSString *)aaa;
+@end
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@implementation Test1(Test1Category) // a category implementation: ObjCCategoryImplDecl
++ (NSString *)test3:(NSString *)aaa {
+  return 0;
+}
+@end
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@protocol TestProto1 // a protocol: ObjCProtocolDecl
+@end
+
+int a;
+
+// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
+/// \brief\brief Aaa
+@interface Test4
+@end
+
+int b;
+