doc. parsing. Improve on diagnostics on my last patch.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Mar 2013 22:46:07 +0000 (22:46 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Mar 2013 22:46:07 +0000 (22:46 +0000)
// rdar://13094352.

llvm-svn: 176525

clang/include/clang/AST/CommentSema.h
clang/include/clang/Basic/DiagnosticCommentKinds.td
clang/lib/AST/CommentSema.cpp
clang/test/Sema/warn-documentation.cpp
clang/test/Sema/warn-documentation.m

index 7b81077..8eb49f6 100644 (file)
@@ -206,7 +206,8 @@ public:
   void resolveParamCommandIndexes(const FullComment *FC);
 
   bool isFunctionDecl();
-  bool isCallbackDecl();
+  bool isFunctionPointerVarDecl();
+  bool isObjCMethodDecl();
   bool isObjCPropertyDecl();
   bool isTemplateOrSpecialization();
 
index 2ee9327..b0aece5 100644 (file)
@@ -74,8 +74,18 @@ def warn_doc_param_not_attached_to_a_function_decl : Warning<
   InGroup<Documentation>, DefaultIgnore;
 
 def warn_doc_function_not_attached_to_a_function_decl : Warning<
-  "'%select{\\|@}0%1' command used in a comment that is attached to a non-%2 "
-  "declaration immediately following it">,
+  "'%select{\\|@}0function' command should be used in a comment attached to a "
+  "function declaration">,
+  InGroup<Documentation>, DefaultIgnore;
+  
+def warn_doc_callback_not_attached_to_a_function_ptr_decl : Warning<
+  "'%select{\\|@}0callback' command should be used in a comment attached to a "
+  "pointer to function declaration">,
+  InGroup<Documentation>, DefaultIgnore;
+
+def warn_doc_method_not_attached_to_a_objc_method_decl : Warning<
+  "'%select{\\|@}0method' command should be used in a comment attached to an "
+  "objective-c method declaration">,
   InGroup<Documentation>, DefaultIgnore;
   
 def warn_doc_param_duplicate : Warning<
index bd32da6..23e27a3 100644 (file)
@@ -90,12 +90,17 @@ ParamCommandComment *Sema::actOnParamCommandStart(
 
 void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
   const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
-  if (Info->IsFunctionDeclarationCommand &&
-      !isFunctionDecl() && !isCallbackDecl())
-    Diag(Comment->getLocation(),
-         diag::warn_doc_function_not_attached_to_a_function_decl)
-    << Comment->getCommandMarker()
-    << Info->Name << Info->Name
+  if (!Info->IsFunctionDeclarationCommand)
+    return;
+  StringRef Name = Info->Name;
+  unsigned DiagKind = llvm::StringSwitch<unsigned>(Name)
+  .Case("function", diag::warn_doc_function_not_attached_to_a_function_decl)
+  .Case("method", diag::warn_doc_method_not_attached_to_a_objc_method_decl)
+  .Case("callback", diag::warn_doc_callback_not_attached_to_a_function_ptr_decl)
+  .Default(0);
+  
+  if (DiagKind)
+    Diag(Comment->getLocation(), DiagKind) << Comment->getCommandMarker()
     << Comment->getSourceRange();
 }
 
@@ -685,8 +690,15 @@ bool Sema::isFunctionDecl() {
     inspectThisDecl();
   return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
 }
+
+bool Sema::isObjCMethodDecl() {
+  return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
+         isa<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl);
+}
   
-bool Sema::isCallbackDecl() {
+/// isFunctionPointerVarDecl - returns 'true' if declaration is a pointer to
+/// function decl.
+bool Sema::isFunctionPointerVarDecl() {
   if (!ThisDeclInfo)
     return false;
   if (!ThisDeclInfo->IsFilled)
index 0e5fef8..32e43a7 100644 (file)
@@ -549,13 +549,13 @@ namespace test_returns_wrong_decl_10 { };
 typedef unsigned int test_returns_wrong_decl_11;
 
 // rdar://13094352
-// expected-warning@+1 {{'@function' command used in a comment that is attached to a non-function declaration immediately following it}}
+// expected-warning@+1 {{'@function' command should be used in a comment attached to a function declaration}}
 /*!    @function test_function
 */
 typedef unsigned int Base64Flags;
 unsigned test_function(Base64Flags inFlags);
 
-// expected-warning@+1 {{'@callback' command used in a comment that is attached to a non-callback declaration immediately following it}}
+// expected-warning@+1 {{'@callback' command should be used in a comment attached to a pointer to function declaration}}
 /*! @callback test_callback
 */
 typedef unsigned int BaseFlags;
index cfa8487..a0ea47e 100644 (file)
@@ -98,7 +98,7 @@ int b;
 typedef int (^test_param1)(int aaa, int ccc);
 
 // rdar://13094352
-// expected-warning@+2 {{'@method' command used in a comment that is attached to a non-method declaration immediately following it}}
+// expected-warning@+2 {{'@method' command should be used in a comment attached to an objective-c method declaration}}
 @interface I
 /*!    @method Base64EncodeEx
 */