doc parsing. Add @method and @callback for
checkings and few other refactoring/cleanup.
// rdar://13094352.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176509 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/CommentCommands.td b/include/clang/AST/CommentCommands.td
index 50abc59..f3d9baa 100644
--- a/include/clang/AST/CommentCommands.td
+++ b/include/clang/AST/CommentCommands.td
@@ -187,8 +187,8 @@
 def Category  : DeclarationVerbatimLineCommand<"category">;
 def Template  : DeclarationVerbatimLineCommand<"template">;
 def Function  : FunctionDeclarationVerbatimLineCommand<"function">;
-def Method    : DeclarationVerbatimLineCommand<"method">;
-def Callback  : DeclarationVerbatimLineCommand<"callback">;
+def Method    : FunctionDeclarationVerbatimLineCommand<"method">;
+def Callback  : FunctionDeclarationVerbatimLineCommand<"callback">;
 def Const     : DeclarationVerbatimLineCommand<"const">;
 def Constant  : DeclarationVerbatimLineCommand<"constant">;
 def Struct    : DeclarationVerbatimLineCommand<"struct">;
diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h
index 6df48dc..7b81077 100644
--- a/include/clang/AST/CommentSema.h
+++ b/include/clang/AST/CommentSema.h
@@ -206,6 +206,7 @@
   void resolveParamCommandIndexes(const FullComment *FC);
 
   bool isFunctionDecl();
+  bool isCallbackDecl();
   bool isObjCPropertyDecl();
   bool isTemplateOrSpecialization();
 
diff --git a/include/clang/Basic/DiagnosticCommentKinds.td b/include/clang/Basic/DiagnosticCommentKinds.td
index 5f28625..2ee9327 100644
--- a/include/clang/Basic/DiagnosticCommentKinds.td
+++ b/include/clang/Basic/DiagnosticCommentKinds.td
@@ -74,8 +74,8 @@
   InGroup<Documentation>, DefaultIgnore;
 
 def warn_doc_function_not_attached_to_a_function_decl : Warning<
-  "'@function' command used in a comment that is attached to "
-  "a non-function declaration immediately following it">,
+  "'%select{\\|@}0%1' command used in a comment that is attached to a non-%2 "
+  "declaration immediately following it">,
   InGroup<Documentation>, DefaultIgnore;
   
 def warn_doc_param_duplicate : Warning<
diff --git a/lib/AST/CommentParser.cpp b/lib/AST/CommentParser.cpp
index c361679..09912c6 100644
--- a/lib/AST/CommentParser.cpp
+++ b/lib/AST/CommentParser.cpp
@@ -706,8 +706,6 @@
                                                 TextBegin,
                                                 Text);
   consumeToken();
-  S.checkFunctionDeclVerbatimLine(VL);
-  
   return VL;
 }
 
diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp
index 0cf7b5f..8adaa95 100644
--- a/lib/AST/CommentSema.cpp
+++ b/lib/AST/CommentSema.cpp
@@ -1,4 +1,4 @@
-//===--- CommentSema.cpp - Doxygen comment semantic analysis --------------===//
+class//===--- CommentSema.cpp - Doxygen comment semantic analysis --------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -91,9 +91,11 @@
 void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
   const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
   if (Info->IsFunctionDeclarationCommand &&
-      !isFunctionDecl())
+      !isFunctionDecl() && !isCallbackDecl())
     Diag(Comment->getLocation(),
          diag::warn_doc_function_not_attached_to_a_function_decl)
+    << Comment->getCommandMarker()
+    << Info->Name << Info->Name
     << Comment->getSourceRange();
 }
 
@@ -346,12 +348,14 @@
                                              unsigned CommandID,
                                              SourceLocation TextBegin,
                                              StringRef Text) {
-  return new (Allocator) VerbatimLineComment(
+  VerbatimLineComment *VL = new (Allocator) VerbatimLineComment(
                               LocBegin,
                               TextBegin.getLocWithOffset(Text.size()),
                               CommandID,
                               TextBegin,
                               Text);
+  checkFunctionDeclVerbatimLine(VL);
+  return VL;
 }
 
 HTMLStartTagComment *Sema::actOnHTMLStartTagStart(SourceLocation LocBegin,
@@ -682,6 +686,20 @@
   return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
 }
   
+bool Sema::isCallbackDecl() {
+  if (!ThisDeclInfo)
+    return false;
+  if (!ThisDeclInfo->IsFilled)
+    inspectThisDecl();
+  if (ThisDeclInfo->getKind() == DeclInfo::VariableKind) {
+    if (const VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDeclInfo->CurrentDecl)) {
+      QualType QT = VD->getType();
+      return QT->isFunctionPointerType();
+    }
+  }
+  return false;
+}
+  
 bool Sema::isObjCPropertyDecl() {
   if (!ThisDeclInfo)
     return false;
diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp
index 8b38ddd..0e5fef8 100644
--- a/test/Sema/warn-documentation.cpp
+++ b/test/Sema/warn-documentation.cpp
@@ -548,6 +548,18 @@
 /// @returns Aaa
 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}}
+/*!	@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}}
+/*! @callback test_callback
+*/
+typedef unsigned int BaseFlags;
+unsigned (*test_callback)(BaseFlags inFlags);
 
 // expected-warning@+1 {{'\endverbatim' command does not terminate a verbatim text block}}
 /// \endverbatim
@@ -910,13 +922,3 @@
 // expected-warning@+1 {{empty paragraph passed to '@param' command}}
 ///@param x@param y
 int test_nocrash13(int x, int y);
-
-// expected-warning@+3 {{'@function' command used in a comment that is attached to a non-function declaration immediately following it}}
-// expected-warning@+3 {{'@param' command used in a comment that is not attached to a function declaration}}
-// expected-warning@+3 {{'@result' command used in a comment that is not attached to a function or method declaration}}
-/*!	@function Base64EncodeEx
-	@param	inFlags  This is error flag
-	@result	Error
-*/
-typedef unsigned int Base64Flags;
-unsigned Base64EncodeEx(Base64Flags	inFlags);
diff --git a/test/Sema/warn-documentation.m b/test/Sema/warn-documentation.m
index 8a894dc..cfa8487 100644
--- a/test/Sema/warn-documentation.m
+++ b/test/Sema/warn-documentation.m
@@ -97,3 +97,11 @@
 /// \returns aaa.
 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}}
+@interface I
+/*!	@method Base64EncodeEx
+*/
+typedef id ID;
+- (unsigned) Base64EncodeEx : (ID)Arg;
+@end