r176509 - doc parsing. Add @method and @callback for

Fariborz Jahanian fjahanian at apple.com
Tue Mar 5 11:40:47 PST 2013


Author: fjahanian
Date: Tue Mar  5 13:40:47 2013
New Revision: 176509

URL: http://llvm.org/viewvc/llvm-project?rev=176509&view=rev
Log:
doc parsing. Add @method and @callback for
checkings and few other refactoring/cleanup.
// rdar://13094352.

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

Modified: cfe/trunk/include/clang/AST/CommentCommands.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentCommands.td?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentCommands.td (original)
+++ cfe/trunk/include/clang/AST/CommentCommands.td Tue Mar  5 13:40:47 2013
@@ -187,8 +187,8 @@ def Protocol  : DeclarationVerbatimLineC
 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">;

Modified: cfe/trunk/include/clang/AST/CommentSema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentSema.h?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentSema.h (original)
+++ cfe/trunk/include/clang/AST/CommentSema.h Tue Mar  5 13:40:47 2013
@@ -206,6 +206,7 @@ public:
   void resolveParamCommandIndexes(const FullComment *FC);
 
   bool isFunctionDecl();
+  bool isCallbackDecl();
   bool isObjCPropertyDecl();
   bool isTemplateOrSpecialization();
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td Tue Mar  5 13:40:47 2013
@@ -74,8 +74,8 @@ def warn_doc_param_not_attached_to_a_fun
   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<

Modified: cfe/trunk/lib/AST/CommentParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentParser.cpp?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentParser.cpp (original)
+++ cfe/trunk/lib/AST/CommentParser.cpp Tue Mar  5 13:40:47 2013
@@ -706,8 +706,6 @@ VerbatimLineComment *Parser::parseVerbat
                                                 TextBegin,
                                                 Text);
   consumeToken();
-  S.checkFunctionDeclVerbatimLine(VL);
-  
   return VL;
 }
 

Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Tue Mar  5 13:40:47 2013
@@ -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::actOnParamCom
 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::actOnVerbatim
                                              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;

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Tue Mar  5 13:40:47 2013
@@ -548,6 +548,18 @@ namespace test_returns_wrong_decl_10 { }
 /// @returns Aaa
 typedef unsigned int test_returns_wrong_decl_11;
 
+// rdar://13094352
+// expected-warning at +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 at +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 at +1 {{'\endverbatim' command does not terminate a verbatim text block}}
 /// \endverbatim
@@ -910,13 +922,3 @@ int test_nocrash12();
 // expected-warning at +1 {{empty paragraph passed to '@param' command}}
 ///@param x at param y
 int test_nocrash13(int x, int y);
-
-// expected-warning at +3 {{'@function' command used in a comment that is attached to a non-function declaration immediately following it}}
-// expected-warning at +3 {{'@param' command used in a comment that is not attached to a function declaration}}
-// expected-warning at +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);

Modified: cfe/trunk/test/Sema/warn-documentation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.m?rev=176509&r1=176508&r2=176509&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.m (original)
+++ cfe/trunk/test/Sema/warn-documentation.m Tue Mar  5 13:40:47 2013
@@ -97,3 +97,11 @@ int b;
 /// \returns aaa.
 typedef int (^test_param1)(int aaa, int ccc);
 
+// rdar://13094352
+// expected-warning at +2 {{'@method' command used in a comment that is attached to a non-method declaration immediately following it}}
+ at interface I
+/*!	@method Base64EncodeEx
+*/
+typedef id ID;
+- (unsigned) Base64EncodeEx : (ID)Arg;
+ at end





More information about the cfe-commits mailing list