]> granicus.if.org Git - clang/commitdiff
doc parsing. Add @method and @callback for
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Mar 2013 19:40:47 +0000 (19:40 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 5 Mar 2013 19:40:47 +0000 (19:40 +0000)
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

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

index 50abc5948ce360ab5f50baeb1d008354e3482c47..f3d9baab437c2cb444e4ab854df5a4aab170784e 100644 (file)
@@ -187,8 +187,8 @@ def Protocol  : DeclarationVerbatimLineCommand<"protocol">;
 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">;
index 6df48dcce1ab13fbac128c7286c5cc55f34df8ca..7b81077b506a9254d0170f3a8d587486b1d3d36f 100644 (file)
@@ -206,6 +206,7 @@ public:
   void resolveParamCommandIndexes(const FullComment *FC);
 
   bool isFunctionDecl();
+  bool isCallbackDecl();
   bool isObjCPropertyDecl();
   bool isTemplateOrSpecialization();
 
index 5f286251513af15c1ba4341b74f6afccc3bb6528..2ee932781624abf7e9f929fc11cfb4fc38d5e509 100644 (file)
@@ -74,8 +74,8 @@ 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<
-  "'@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<
index c361679e90567232871c5b76511e4230039bd60d..09912c6188645742acadd825718dfc4d89c40b4b 100644 (file)
@@ -706,8 +706,6 @@ VerbatimLineComment *Parser::parseVerbatimLine() {
                                                 TextBegin,
                                                 Text);
   consumeToken();
-  S.checkFunctionDeclVerbatimLine(VL);
-  
   return VL;
 }
 
index 0cf7b5fd50d2e7969ad33a0d2e14f555171efa13..8adaa9526f40ae72e02bfbf5ad1572ca37731b93 100644 (file)
@@ -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 @@ ParamCommandComment *Sema::actOnParamCommandStart(
 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 @@ VerbatimLineComment *Sema::actOnVerbatimLine(SourceLocation LocBegin,
                                              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 @@ bool Sema::isFunctionDecl() {
   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;
index 8b38ddd81a96e813244657514c815fef17bccfab..0e5fef823e552957e5ffaff48917b11d7708a023 100644 (file)
@@ -548,6 +548,18 @@ namespace test_returns_wrong_decl_10 { };
 /// @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 @@ int test_nocrash12();
 // 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);
index 8a894dca7003405400d0675cdc17ba61d9089779..cfa84870e82ea09ecd4a112fb1e3f454e2f9707a 100644 (file)
@@ -97,3 +97,11 @@ int b;
 /// \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