[clang] [clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use enum_select (PR #147120)
https://github.com/erichkeane closed https://github.com/llvm/llvm-project/pull/147120 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use enum_select (PR #147120)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/147120 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use enum_select (PR #147120)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/147120 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use enum_select (PR #147120)
github-actions[bot] wrote: ⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. See [LLVM Developer Policy](https://llvm.org/docs/DeveloperPolicy.html#email-addresses) and [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information. https://github.com/llvm/llvm-project/pull/147120 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use enum_select (PR #147120)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Ayokunle Amodu (ayokunle321)
Changes
Related: https://github.com/llvm/llvm-project/issues/123121
This patch refactors the `warn_doc_container_decl_mismatch` diagnostic to use
`enum_select` instead of `select`. This gets rid of magic numbers and improves
readability in the caller site.
@cor3ntin @erichkeane
---
Full diff: https://github.com/llvm/llvm-project/pull/147120.diff
2 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticCommentKinds.td (+4-2)
- (modified) clang/lib/AST/CommentSema.cpp (+15-16)
``diff
diff --git a/clang/include/clang/Basic/DiagnosticCommentKinds.td
b/clang/include/clang/Basic/DiagnosticCommentKinds.td
index 1122ace3027d8..0ce53b395ecee 100644
--- a/clang/include/clang/Basic/DiagnosticCommentKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommentKinds.td
@@ -90,8 +90,10 @@ def warn_doc_api_container_decl_mismatch : Warning<
InGroup, DefaultIgnore;
def warn_doc_container_decl_mismatch : Warning<
- "'%select{\\|@}0%select{classdesign|coclass|dependency|helper"
-
"|helperclass|helps|instancesize|ownership|performance|security|superclass}1' "
+ "'%select{\\|@}0%enum_select{%ClassDesign{classdesign}|"
+
"%CoClass{coclass}|%Dependency{dependency}|%Helper{helper}|%HelperClass{helperclass}|"
+ "%Helps{helps}|%InstanceSize{instancesize}|%Ownership{ownership}|"
+ "%Performance{performance}|%Security{security}|%Superclass{superclass}}1' "
"command should not be used in a comment attached to a non-container
declaration">,
InGroup, DefaultIgnore;
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index fb745fc560d2f..28e52e618a329 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -171,50 +171,49 @@ void Sema::checkContainerDecl(const BlockCommandComment
*Comment) {
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
if (!Info->IsRecordLikeDetailCommand || isRecordLikeDecl())
return;
- unsigned DiagSelect;
+ std::optional DiagSelect;
switch (Comment->getCommandID()) {
case CommandTraits::KCI_classdesign:
- DiagSelect = 1;
+ DiagSelect = diag::DocCommandKind::ClassDesign;
break;
case CommandTraits::KCI_coclass:
- DiagSelect = 2;
+ DiagSelect = diag::DocCommandKind::CoClass;
break;
case CommandTraits::KCI_dependency:
- DiagSelect = 3;
+ DiagSelect = diag::DocCommandKind::Dependency;
break;
case CommandTraits::KCI_helper:
- DiagSelect = 4;
+ DiagSelect = diag::DocCommandKind::Helper;
break;
case CommandTraits::KCI_helperclass:
- DiagSelect = 5;
+ DiagSelect = diag::DocCommandKind::HelperClass;
break;
case CommandTraits::KCI_helps:
- DiagSelect = 6;
+ DiagSelect = diag::DocCommandKind::Helps;
break;
case CommandTraits::KCI_instancesize:
- DiagSelect = 7;
+ DiagSelect = diag::DocCommandKind::InstanceSize;
break;
case CommandTraits::KCI_ownership:
- DiagSelect = 8;
+ DiagSelect = diag::DocCommandKind::Ownership;
break;
case CommandTraits::KCI_performance:
- DiagSelect = 9;
+ DiagSelect = diag::DocCommandKind::Performance;
break;
case CommandTraits::KCI_security:
- DiagSelect = 10;
+ DiagSelect = diag::DocCommandKind::Security;
break;
case CommandTraits::KCI_superclass:
- DiagSelect = 11;
+ DiagSelect = diag::DocCommandKind::Superclass;
break;
default:
- DiagSelect = 0;
+ DiagSelect = std::nullopt;
break;
}
if (DiagSelect)
Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch)
-<< Comment->getCommandMarker()
-<< (DiagSelect-1)
-<< Comment->getSourceRange();
+<< Comment->getCommandMarker() << (*DiagSelect)
+<< Comment->getSourceRange();
}
/// Turn a string into the corresponding PassDirection or -1 if it's not
``
https://github.com/llvm/llvm-project/pull/147120
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][diagnostics] Refactor "warn_doc_container_decl_mismatch" to use enum_select (PR #147120)
https://github.com/ayokunle321 created https://github.com/llvm/llvm-project/pull/147120 Related: https://github.com/llvm/llvm-project/issues/123121 This patch refactors the `warn_doc_container_decl_mismatch` diagnostic to use `enum_select` instead of `select`. This gets rid of magic numbers and improves readability in the caller site. @cor3ntin @erichkeane >From ca1ba33f9ef07c8fa3a8314adb1cec4a7da1f5d5 Mon Sep 17 00:00:00 2001 From: Ayokunle Amodu <[email protected]> Date: Fri, 4 Jul 2025 17:36:17 -0600 Subject: [PATCH] refactor warn_doc_container_decl_mismatch diag --- .../clang/Basic/DiagnosticCommentKinds.td | 6 ++-- clang/lib/AST/CommentSema.cpp | 31 +-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticCommentKinds.td b/clang/include/clang/Basic/DiagnosticCommentKinds.td index 1122ace3027d8..0ce53b395ecee 100644 --- a/clang/include/clang/Basic/DiagnosticCommentKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommentKinds.td @@ -90,8 +90,10 @@ def warn_doc_api_container_decl_mismatch : Warning< InGroup, DefaultIgnore; def warn_doc_container_decl_mismatch : Warning< - "'%select{\\|@}0%select{classdesign|coclass|dependency|helper" - "|helperclass|helps|instancesize|ownership|performance|security|superclass}1' " + "'%select{\\|@}0%enum_select{%ClassDesign{classdesign}|" + "%CoClass{coclass}|%Dependency{dependency}|%Helper{helper}|%HelperClass{helperclass}|" + "%Helps{helps}|%InstanceSize{instancesize}|%Ownership{ownership}|" + "%Performance{performance}|%Security{security}|%Superclass{superclass}}1' " "command should not be used in a comment attached to a non-container declaration">, InGroup, DefaultIgnore; diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index fb745fc560d2f..28e52e618a329 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -171,50 +171,49 @@ void Sema::checkContainerDecl(const BlockCommandComment *Comment) { const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID()); if (!Info->IsRecordLikeDetailCommand || isRecordLikeDecl()) return; - unsigned DiagSelect; + std::optional DiagSelect; switch (Comment->getCommandID()) { case CommandTraits::KCI_classdesign: - DiagSelect = 1; + DiagSelect = diag::DocCommandKind::ClassDesign; break; case CommandTraits::KCI_coclass: - DiagSelect = 2; + DiagSelect = diag::DocCommandKind::CoClass; break; case CommandTraits::KCI_dependency: - DiagSelect = 3; + DiagSelect = diag::DocCommandKind::Dependency; break; case CommandTraits::KCI_helper: - DiagSelect = 4; + DiagSelect = diag::DocCommandKind::Helper; break; case CommandTraits::KCI_helperclass: - DiagSelect = 5; + DiagSelect = diag::DocCommandKind::HelperClass; break; case CommandTraits::KCI_helps: - DiagSelect = 6; + DiagSelect = diag::DocCommandKind::Helps; break; case CommandTraits::KCI_instancesize: - DiagSelect = 7; + DiagSelect = diag::DocCommandKind::InstanceSize; break; case CommandTraits::KCI_ownership: - DiagSelect = 8; + DiagSelect = diag::DocCommandKind::Ownership; break; case CommandTraits::KCI_performance: - DiagSelect = 9; + DiagSelect = diag::DocCommandKind::Performance; break; case CommandTraits::KCI_security: - DiagSelect = 10; + DiagSelect = diag::DocCommandKind::Security; break; case CommandTraits::KCI_superclass: - DiagSelect = 11; + DiagSelect = diag::DocCommandKind::Superclass; break; default: - DiagSelect = 0; + DiagSelect = std::nullopt; break; } if (DiagSelect) Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch) -<< Comment->getCommandMarker() -<< (DiagSelect-1) -<< Comment->getSourceRange(); +<< Comment->getCommandMarker() << (*DiagSelect) +<< Comment->getSourceRange(); } /// Turn a string into the corresponding PassDirection or -1 if it's not ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
