From 88f070f99f7f352e294eed212fdf7a23c0815fe2 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 6 Mar 2013 17:36:51 +0000 Subject: [PATCH] say objective-C in the warning and streamline several diagnostics into one. // rdar://13094352 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176560 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticCommentKinds.td | 17 ++++------------- lib/AST/CommentSema.cpp | 17 ++++++++--------- test/Sema/warn-documentation.m | 2 +- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/include/clang/Basic/DiagnosticCommentKinds.td b/include/clang/Basic/DiagnosticCommentKinds.td index b0aece5640..1bf290edf6 100644 --- a/include/clang/Basic/DiagnosticCommentKinds.td +++ b/include/clang/Basic/DiagnosticCommentKinds.td @@ -73,19 +73,10 @@ def warn_doc_param_not_attached_to_a_function_decl : Warning< "a function declaration">, InGroup, DefaultIgnore; -def warn_doc_function_not_attached_to_a_function_decl : Warning< - "'%select{\\|@}0function' command should be used in a comment attached to a " - "function declaration">, - InGroup, 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, 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">, +def warn_doc_function_method_decl_mismatch : Warning< + "'%select{\\|@}0%select{function|method|callback}1' command should be " + "used in a comment attached to " + "%select{a function|an objective-C method|a pointer to function}2 declaration">, InGroup, DefaultIgnore; def warn_doc_param_duplicate : Warning< diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index a834bb4b03..68a9ebbd5a 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -93,17 +93,16 @@ void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) { if (!Info->IsFunctionDeclarationCommand) return; StringRef Name = Info->Name; - unsigned DiagKind = llvm::StringSwitch(Name) - .Case("function", !isAnyFunctionDecl() ? - diag::warn_doc_function_not_attached_to_a_function_decl : 0) - .Case("method", !isObjCMethodDecl() ? - diag::warn_doc_method_not_attached_to_a_objc_method_decl : 0) - .Case("callback", !isFunctionPointerVarDecl() ? - diag::warn_doc_callback_not_attached_to_a_function_ptr_decl : 0) + unsigned DiagSelect = llvm::StringSwitch(Name) + .Case("function", !isAnyFunctionDecl() ? 1 : 0) + .Case("method", !isObjCMethodDecl() ? 2 : 0) + .Case("callback", !isFunctionPointerVarDecl() ? 3 : 0) .Default(0); - if (DiagKind) - Diag(Comment->getLocation(), DiagKind) << Comment->getCommandMarker() + if (DiagSelect) + Diag(Comment->getLocation(), diag::warn_doc_function_method_decl_mismatch) + << Comment->getCommandMarker() + << (DiagSelect-1) << (DiagSelect-1) << Comment->getSourceRange(); } diff --git a/test/Sema/warn-documentation.m b/test/Sema/warn-documentation.m index a0ea47ec5a..81919cfe77 100644 --- a/test/Sema/warn-documentation.m +++ b/test/Sema/warn-documentation.m @@ -98,7 +98,7 @@ int b; typedef int (^test_param1)(int aaa, int ccc); // rdar://13094352 -// expected-warning@+2 {{'@method' command should be used in a comment attached to an objective-c method declaration}} +// expected-warning@+2 {{'@method' command should be used in a comment attached to an objective-C method declaration}} @interface I /*! @method Base64EncodeEx */ -- 2.40.0