From ee29579d3e08d7e3091479ea3180ee1b11d621a1 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Tue, 15 Jul 2025 17:41:32 -0400 Subject: [PATCH] Reduce some more deep nesting --- include/diagnostics.hpp | 81 +++++++++++++++++++++-------------------- src/asm/symbol.cpp | 17 +++++---- src/link/output.cpp | 5 +-- src/link/script.y | 26 ++++++++----- 4 files changed, 69 insertions(+), 60 deletions(-) diff --git a/include/diagnostics.hpp b/include/diagnostics.hpp index d96bac68..2ca67953 100644 --- a/include/diagnostics.hpp +++ b/include/diagnostics.hpp @@ -138,53 +138,56 @@ std::string Diagnostics::processWarningFlag(char const *flag) { uint8_t maxParam = paramWarning.lastID - baseID + 1; assume(paramWarning.defaultLevel <= maxParam); - if (rootFlag == warningFlags[baseID].name) { // Match! - // If making the warning an error but param is 0, set to the maximum - // This accommodates `-Werror=`, but also `-Werror==0`, which is - // thus filtered out by the caller. - // A param of 0 makes sense for disabling everything, but neither for - // enabling nor "erroring". Use the default for those. - if (!param.has_value() || *param == 0) { - param = paramWarning.defaultLevel; - } else if (*param > maxParam) { - if (*param != 255) { // Don't warn if already capped - warnx( - "Invalid parameter %" PRIu8 - " for warning flag \"%s\"; capping at maximum %" PRIu8, - *param, - rootFlag.c_str(), - maxParam - ); - } - *param = maxParam; - } - - // Set the first to enabled/error, and disable the rest - for (uint8_t ofs = 0; ofs < maxParam; ofs++) { - WarningState &warning = state.flagStates[baseID + ofs]; - if (ofs < *param) { - warning.update(flagState); - } else { - warning.state = WARNING_DISABLED; - } - } - return rootFlag; + if (rootFlag != warningFlags[baseID].name) { + continue; } + + // If making the warning an error but param is 0, set to the maximum + // This accommodates `-Werror=`, but also `-Werror==0`, which is + // thus filtered out by the caller. + // A param of 0 makes sense for disabling everything, but neither for + // enabling nor "erroring". Use the default for those. + if (!param.has_value() || *param == 0) { + param = paramWarning.defaultLevel; + } else if (*param > maxParam) { + if (*param != 255) { // Don't warn if already capped + warnx( + "Invalid parameter %" PRIu8 + " for warning flag \"%s\"; capping at maximum %" PRIu8, + *param, + rootFlag.c_str(), + maxParam + ); + } + *param = maxParam; + } + + // Set the first to enabled/error, and disable the rest + for (uint8_t ofs = 0; ofs < maxParam; ofs++) { + if (WarningState &warning = state.flagStates[baseID + ofs]; ofs < *param) { + warning.update(flagState); + } else { + warning.state = WARNING_DISABLED; + } + } + return rootFlag; } // Try to match against a non-parametric warning, unless there was an equals sign if (!param.has_value()) { // Try to match against a "meta" warning for (WarningFlag const &metaWarning : metaWarnings) { - if (rootFlag == metaWarning.name) { - // Set each of the warning flags that meets this level - for (W id : EnumSeq(W::NB_WARNINGS)) { - if (metaWarning.level >= warningFlags[id].level) { - state.metaStates[id].update(flagState); - } - } - return rootFlag; + if (rootFlag != metaWarning.name) { + continue; } + + // Set each of the warning flags that meets this level + for (W id : EnumSeq(W::NB_WARNINGS)) { + if (metaWarning.level >= warningFlags[id].level) { + state.metaStates[id].update(flagState); + } + } + return rootFlag; } // Try to match the flag against a "normal" flag diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index d0d10d6a..1314c0e2 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -149,14 +149,15 @@ static void alreadyDefinedError(Symbol const &sym, char const *asType) { fprintf(stderr, " as %s", asType); } dumpFilename(sym); - if (sym.type == SYM_EQUS) { - if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) { - fprintf( - stderr, - "\n (should it be {interpolated} to define its contents \"%s\"?)", - contents.c_str() - ); - } + if (sym.type != SYM_EQUS) { + return; + } + if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) { + fprintf( + stderr, + "\n (should it be {interpolated} to define its contents \"%s\"?)", + contents.c_str() + ); } }); } diff --git a/src/link/output.cpp b/src/link/output.cpp index 6e453b67..65250f25 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -348,9 +348,8 @@ static void writeSymBank(SortedSections const &bankSections, SectionType type, u if (Symbol const *parentSym = sym_GetSymbol(parentName); parentSym && std::holds_alternative