r176525 - doc. parsing. Improve on diagnostics on my last patch.
Jordan Rose
jordan_rose at apple.com
Tue Mar 5 15:37:55 PST 2013
I hate to continue bikeshedding here, but why is this not just a single warning with a %select and associated enum { Function, Callback, Method }?
Also, "Objective-C" should not be lowercase.
On Mar 5, 2013, at 14:46 , Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Tue Mar 5 16:46:07 2013
> New Revision: 176525
>
> URL: http://llvm.org/viewvc/llvm-project?rev=176525&view=rev
> Log:
> doc. parsing. Improve on diagnostics on my last patch.
> // rdar://13094352.
>
> Modified:
> cfe/trunk/include/clang/AST/CommentSema.h
> cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td
> 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/CommentSema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentSema.h?rev=176525&r1=176524&r2=176525&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/CommentSema.h (original)
> +++ cfe/trunk/include/clang/AST/CommentSema.h Tue Mar 5 16:46:07 2013
> @@ -206,7 +206,8 @@ public:
> void resolveParamCommandIndexes(const FullComment *FC);
>
> bool isFunctionDecl();
> - bool isCallbackDecl();
> + bool isFunctionPointerVarDecl();
> + bool isObjCMethodDecl();
> 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=176525&r1=176524&r2=176525&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticCommentKinds.td Tue Mar 5 16:46:07 2013
> @@ -74,8 +74,18 @@ def warn_doc_param_not_attached_to_a_fun
> 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<
>
> Modified: cfe/trunk/lib/AST/CommentSema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=176525&r1=176524&r2=176525&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/CommentSema.cpp (original)
> +++ cfe/trunk/lib/AST/CommentSema.cpp Tue Mar 5 16:46:07 2013
> @@ -90,12 +90,17 @@ ParamCommandComment *Sema::actOnParamCom
>
> 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)
>
> Modified: cfe/trunk/test/Sema/warn-documentation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=176525&r1=176524&r2=176525&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-documentation.cpp (original)
> +++ cfe/trunk/test/Sema/warn-documentation.cpp Tue Mar 5 16:46:07 2013
> @@ -549,13 +549,13 @@ namespace test_returns_wrong_decl_10 { }
> 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}}
> +// expected-warning at +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 at +1 {{'@callback' command used in a comment that is attached to a non-callback declaration immediately following it}}
> +// expected-warning at +1 {{'@callback' command should be used in a comment attached to a pointer to function declaration}}
> /*! @callback test_callback
> */
> typedef unsigned int BaseFlags;
>
> Modified: cfe/trunk/test/Sema/warn-documentation.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.m?rev=176525&r1=176524&r2=176525&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-documentation.m (original)
> +++ cfe/trunk/test/Sema/warn-documentation.m Tue Mar 5 16:46:07 2013
> @@ -98,7 +98,7 @@ int b;
> 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}}
> +// expected-warning at +2 {{'@method' command should be used in a comment attached to an objective-c method declaration}}
> @interface I
> /*! @method Base64EncodeEx
> */
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130305/6a6ef4cb/attachment.html>
More information about the cfe-commits
mailing list