From a78f356ed9804ad2f0ba404d8272aa1209bb0087 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Wed, 4 Mar 2026 16:41:39 -0500 Subject: [PATCH] Diagnostics: Shorten type names Add type aliases for diagnostic types that are shorted (and somewhat less redundant) than the canonical type names. --- Source/cmCMakeDiagnosticCommand.cxx | 13 ++++---- Source/cmDiagnostics.cxx | 13 ++++---- Source/cmDiagnostics.h | 3 ++ Source/cmMakefile.cxx | 24 ++++++------- Source/cmMakefile.h | 16 ++++----- Source/cmStateSnapshot.cxx | 52 ++++++++++++++--------------- Source/cmStateSnapshot.h | 31 ++++++++--------- 7 files changed, 69 insertions(+), 83 deletions(-) diff --git a/Source/cmCMakeDiagnosticCommand.cxx b/Source/cmCMakeDiagnosticCommand.cxx index 3f094b1e3b..d05a4899ab 100644 --- a/Source/cmCMakeDiagnosticCommand.cxx +++ b/Source/cmCMakeDiagnosticCommand.cxx @@ -11,9 +11,8 @@ #include "cmStringAlgorithms.h" namespace { -using AlterFunction = bool (cmMakefile::*)(cmDiagnostics::DiagnosticCategory, - cmDiagnostics::DiagnosticAction, - bool); +using AlterFunction = bool (cmMakefile::*)(cmDiagnosticCategory, + cmDiagnosticAction, bool); bool HandleAlterMode(std::vector const& args, cmExecutionStatus& status, AlterFunction function, @@ -37,7 +36,7 @@ bool HandleAlterMode(std::vector const& args, } } - cm::optional const action = + cm::optional const action = cmDiagnostics::GetDiagnosticAction(args[2]); if (!action) { status.SetError(cmStrCat( @@ -45,7 +44,7 @@ bool HandleAlterMode(std::vector const& args, return false; } - cm::optional const category = + cm::optional const category = cmDiagnostics::GetDiagnosticCategory(args[1]); if (!category) { status.SetError(cmStrCat(args[0], @@ -69,7 +68,7 @@ bool HandleGetMode(std::vector const& args, return false; } - cm::optional const category = + cm::optional const category = cmDiagnostics::GetDiagnosticCategory(args[1]); if (!category) { status.SetError(cmStrCat(args[0], @@ -78,7 +77,7 @@ bool HandleGetMode(std::vector const& args, return false; } - cmDiagnostics::DiagnosticAction const action = + cmDiagnosticAction const action = status.GetMakefile().GetDiagnosticAction(*category); status.GetMakefile().AddDefinition(args[2], diff --git a/Source/cmDiagnostics.cxx b/Source/cmDiagnostics.cxx index 5cb1011230..60d3ec4067 100644 --- a/Source/cmDiagnostics.cxx +++ b/Source/cmDiagnostics.cxx @@ -12,10 +12,9 @@ #include "cmStringAlgorithms.h" namespace { -cm::optional stringToCategory( - cm::string_view input) +cm::optional stringToCategory(cm::string_view input) { - using Map = std::map; + using Map = std::map; static Map const mapping = { #define CATEGORY_MAP(C) { #C ""_s, cmDiagnostics::C }, CM_FOR_EACH_DIAGNOSTIC_CATEGORY(CATEGORY_MAP) @@ -73,8 +72,8 @@ cm::string_view cmDiagnostics::GetCategoryString(DiagnosticCategory category) return {}; } -cm::optional -cmDiagnostics::GetDiagnosticAction(cm::string_view name) +cm::optional cmDiagnostics::GetDiagnosticAction( + cm::string_view name) { if (name == "IGNORE"_s) { return DiagnosticAction::Ignore; @@ -92,8 +91,8 @@ cmDiagnostics::GetDiagnosticAction(cm::string_view name) return cm::nullopt; } -cm::optional -cmDiagnostics::GetDiagnosticCategory(cm::string_view name) +cm::optional cmDiagnostics::GetDiagnosticCategory( + cm::string_view name) { return stringToCategory(name); } diff --git a/Source/cmDiagnostics.h b/Source/cmDiagnostics.h index 8f44eaa361..5b3d56685e 100644 --- a/Source/cmDiagnostics.h +++ b/Source/cmDiagnostics.h @@ -94,3 +94,6 @@ public: /** Represent a set of diagnostic category actions. */ using DiagnosticMap = std::array; }; + +using cmDiagnosticCategory = cmDiagnostics::DiagnosticCategory; +using cmDiagnosticAction = cmDiagnostics::DiagnosticAction; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 54742eab06..a45d8c0bd8 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4165,31 +4165,28 @@ void cmMakefile::PopPolicy() } } -cmDiagnostics::DiagnosticAction cmMakefile::GetDiagnosticAction( - cmDiagnostics::DiagnosticCategory category) const +cmDiagnosticAction cmMakefile::GetDiagnosticAction( + cmDiagnosticCategory category) const { return this->StateSnapshot.GetDiagnostic(category); } -bool cmMakefile::SetDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive) +bool cmMakefile::SetDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive) { this->StateSnapshot.SetDiagnostic(category, action, recursive); return true; } -bool cmMakefile::PromoteDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive) +bool cmMakefile::PromoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive) { this->StateSnapshot.PromoteDiagnostic(category, action, recursive); return true; } -bool cmMakefile::DemoteDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive) +bool cmMakefile::DemoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive) { this->StateSnapshot.DemoteDiagnostic(category, action, recursive); return true; @@ -4296,9 +4293,8 @@ void cmMakefile::RecordPolicies(cmPolicies::PolicyMap& pm) const void cmMakefile::RecordDiagnostics(cmDiagnostics::DiagnosticMap& dm) const { /* Record the setting of every diagnostic category. */ - using DiagnosticCategory = cmDiagnostics::DiagnosticCategory; - for (size_t n = 0; n < cmDiagnostics::CategoryCount; ++n) { - DiagnosticCategory dc = static_cast(n); + for (unsigned n = 0; n < cmDiagnostics::CategoryCount; ++n) { + cmDiagnosticCategory const dc = static_cast(n); dm[dc] = this->GetDiagnosticAction(dc); } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index dae1afbd5a..706fe0184e 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -412,17 +412,13 @@ public: /** * Set, Push, Pop diagnostics for CMake. */ - bool SetDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, + bool SetDiagnostic(cmDiagnosticCategory category, cmDiagnosticAction action, bool recursive = false); - bool PromoteDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive = false); - bool DemoteDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive = false); - cmDiagnostics::DiagnosticAction GetDiagnosticAction( - cmDiagnostics::DiagnosticCategory category) const; + bool PromoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive = false); + bool DemoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive = false); + cmDiagnosticAction GetDiagnosticAction(cmDiagnosticCategory category) const; void RecordDiagnostics(cmDiagnostics::DiagnosticMap& dm) const; //@} diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 90c45bab7d..e56817714a 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -248,56 +248,56 @@ bool cmStateSnapshot::CanPopDiagnosticScope() const return this->Position->Diagnostics != this->Position->DiagnosticScope; } -void cmStateSnapshot::SetDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive) +void cmStateSnapshot::SetDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive) { assert(action != cmDiagnostics::Undefined); - auto function = [](cmDiagnostics::DiagnosticAction, - cmDiagnostics::DiagnosticAction) -> bool { return true; }; + auto function = [](cmDiagnosticAction, cmDiagnosticAction) -> bool { + return true; + }; this->AlterDiagnostic(category, action, function, recursive); } -void cmStateSnapshot::PromoteDiagnostic( - cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, bool recursive) +void cmStateSnapshot::PromoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, + bool recursive) { assert(action != cmDiagnostics::Undefined); - auto function = [](cmDiagnostics::DiagnosticAction current, - cmDiagnostics::DiagnosticAction desired) -> bool { + auto function = [](cmDiagnosticAction current, + cmDiagnosticAction desired) -> bool { return (current < desired); }; this->AlterDiagnostic(category, action, function, recursive); } -void cmStateSnapshot::DemoteDiagnostic( - cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, bool recursive) +void cmStateSnapshot::DemoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, + bool recursive) { assert(action != cmDiagnostics::Undefined); - auto function = [](cmDiagnostics::DiagnosticAction current, - cmDiagnostics::DiagnosticAction desired) -> bool { + auto function = [](cmDiagnosticAction current, + cmDiagnosticAction desired) -> bool { return (current > desired); }; this->AlterDiagnostic(category, action, function, recursive); } -void cmStateSnapshot::AlterDiagnostic( - cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, AlterDiagnosticFunction function, - bool recursive) +void cmStateSnapshot::AlterDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, + AlterDiagnosticFunction function, + bool recursive) { if (recursive) { unsigned i = category; for (;;) { - this->AlterDiagnostic(static_cast(i), - action, function, false); + this->AlterDiagnostic(static_cast(i), action, + function, false); if (++i >= cmDiagnostics::CategoryCount) { break; } @@ -306,8 +306,7 @@ void cmStateSnapshot::AlterDiagnostic( } } } else { - cmDiagnostics::DiagnosticAction const oldAction = - this->GetDiagnostic(category); + cmDiagnosticAction const oldAction = this->GetDiagnostic(category); if (function(oldAction, action)) { // Update the policy stack from the top to the top-most strong entry. bool previous_was_weak = true; @@ -321,9 +320,8 @@ void cmStateSnapshot::AlterDiagnostic( } } -cmDiagnostics::DiagnosticAction cmStateSnapshot::GetDiagnostic( - cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction defaultAction) const +cmDiagnosticAction cmStateSnapshot::GetDiagnostic( + cmDiagnosticCategory category, cmDiagnosticAction defaultAction) const { cmLinkedTree::iterator dir = this->Position->BuildSystemDirectory; @@ -335,7 +333,7 @@ cmDiagnostics::DiagnosticAction cmStateSnapshot::GetDiagnostic( cmLinkedTree::iterator root = dir->CurrentScope->DiagnosticRoot; for (; leaf != root; ++leaf) { - cmDiagnostics::DiagnosticAction const action = (*leaf)[category]; + cmDiagnosticAction const action = (*leaf)[category]; if (action != cmDiagnostics::Undefined) { return action; } diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index da4e905b72..f72712346e 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -58,19 +58,15 @@ public: bool PopPolicy(); bool CanPopPolicyScope() const; - void SetDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, bool recursive); - void PromoteDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive); - void DemoteDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, - bool recursive); - cmDiagnostics::DiagnosticAction GetDiagnostic( - cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction defaultAction) const; - cmDiagnostics::DiagnosticAction GetDiagnostic( - cmDiagnostics::DiagnosticCategory category) const + void SetDiagnostic(cmDiagnosticCategory category, cmDiagnosticAction action, + bool recursive); + void PromoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive); + void DemoteDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, bool recursive); + cmDiagnosticAction GetDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction defaultAction) const; + cmDiagnosticAction GetDiagnostic(cmDiagnosticCategory category) const { return this->GetDiagnostic( category, cmDiagnostics::CategoryInfo[category].DefaultAction); @@ -111,11 +107,10 @@ private: void InitializeFromParent(); - using AlterDiagnosticFunction = - bool (*)(cmDiagnostics::DiagnosticAction current, - cmDiagnostics::DiagnosticAction desired); - void AlterDiagnostic(cmDiagnostics::DiagnosticCategory category, - cmDiagnostics::DiagnosticAction action, + using AlterDiagnosticFunction = bool (*)(cmDiagnosticAction current, + cmDiagnosticAction desired); + void AlterDiagnostic(cmDiagnosticCategory category, + cmDiagnosticAction action, AlterDiagnosticFunction function, bool recursive); cmState* State;