Diagnostics: Shorten type names

Add type aliases for diagnostic types that are shorted (and somewhat
less redundant) than the canonical type names.
This commit is contained in:
Matthew Woehlke
2026-03-04 16:41:39 -05:00
parent 2b7ee7137b
commit a78f356ed9
7 changed files with 69 additions and 83 deletions

View File

@@ -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<std::string> const& args,
cmExecutionStatus& status, AlterFunction function,
@@ -37,7 +36,7 @@ bool HandleAlterMode(std::vector<std::string> const& args,
}
}
cm::optional<cmDiagnostics::DiagnosticAction> const action =
cm::optional<cmDiagnosticAction> const action =
cmDiagnostics::GetDiagnosticAction(args[2]);
if (!action) {
status.SetError(cmStrCat(
@@ -45,7 +44,7 @@ bool HandleAlterMode(std::vector<std::string> const& args,
return false;
}
cm::optional<cmDiagnostics::DiagnosticCategory> const category =
cm::optional<cmDiagnosticCategory> const category =
cmDiagnostics::GetDiagnosticCategory(args[1]);
if (!category) {
status.SetError(cmStrCat(args[0],
@@ -69,7 +68,7 @@ bool HandleGetMode(std::vector<std::string> const& args,
return false;
}
cm::optional<cmDiagnostics::DiagnosticCategory> const category =
cm::optional<cmDiagnosticCategory> const category =
cmDiagnostics::GetDiagnosticCategory(args[1]);
if (!category) {
status.SetError(cmStrCat(args[0],
@@ -78,7 +77,7 @@ bool HandleGetMode(std::vector<std::string> const& args,
return false;
}
cmDiagnostics::DiagnosticAction const action =
cmDiagnosticAction const action =
status.GetMakefile().GetDiagnosticAction(*category);
status.GetMakefile().AddDefinition(args[2],

View File

@@ -12,10 +12,9 @@
#include "cmStringAlgorithms.h"
namespace {
cm::optional<cmDiagnostics::DiagnosticCategory> stringToCategory(
cm::string_view input)
cm::optional<cmDiagnosticCategory> stringToCategory(cm::string_view input)
{
using Map = std::map<cm::string_view, cmDiagnostics::DiagnosticCategory>;
using Map = std::map<cm::string_view, cmDiagnosticCategory>;
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::DiagnosticAction>
cmDiagnostics::GetDiagnosticAction(cm::string_view name)
cm::optional<cmDiagnosticAction> 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::DiagnosticCategory>
cmDiagnostics::GetDiagnosticCategory(cm::string_view name)
cm::optional<cmDiagnosticCategory> cmDiagnostics::GetDiagnosticCategory(
cm::string_view name)
{
return stringToCategory(name);
}

View File

@@ -94,3 +94,6 @@ public:
/** Represent a set of diagnostic category actions. */
using DiagnosticMap = std::array<DiagnosticAction, CategoryCount>;
};
using cmDiagnosticCategory = cmDiagnostics::DiagnosticCategory;
using cmDiagnosticAction = cmDiagnostics::DiagnosticAction;

View File

@@ -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<DiagnosticCategory>(n);
for (unsigned n = 0; n < cmDiagnostics::CategoryCount; ++n) {
cmDiagnosticCategory const dc = static_cast<cmDiagnosticCategory>(n);
dm[dc] = this->GetDiagnosticAction(dc);
}
}

View File

@@ -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;
//@}

View File

@@ -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<cmDiagnostics::DiagnosticCategory>(i),
action, function, false);
this->AlterDiagnostic(static_cast<cmDiagnosticCategory>(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<cmStateDetail::BuildsystemDirectoryStateType>::iterator dir =
this->Position->BuildSystemDirectory;
@@ -335,7 +333,7 @@ cmDiagnostics::DiagnosticAction cmStateSnapshot::GetDiagnostic(
cmLinkedTree<cmStateDetail::DiagnosticStackEntry>::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;
}

View File

@@ -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;