Reduce some more deep nesting

This commit is contained in:
Rangi42
2025-07-15 17:41:32 -04:00
parent 5aec36350b
commit ee29579d3e
4 changed files with 69 additions and 60 deletions

View File

@@ -138,7 +138,10 @@ std::string Diagnostics<L, W>::processWarningFlag(char const *flag) {
uint8_t maxParam = paramWarning.lastID - baseID + 1; uint8_t maxParam = paramWarning.lastID - baseID + 1;
assume(paramWarning.defaultLevel <= maxParam); assume(paramWarning.defaultLevel <= maxParam);
if (rootFlag == warningFlags[baseID].name) { // Match! if (rootFlag != warningFlags[baseID].name) {
continue;
}
// If making the warning an error but param is 0, set to the maximum // If making the warning an error but param is 0, set to the maximum
// This accommodates `-Werror=<flag>`, but also `-Werror=<flag>=0`, which is // This accommodates `-Werror=<flag>`, but also `-Werror=<flag>=0`, which is
// thus filtered out by the caller. // thus filtered out by the caller.
@@ -161,8 +164,7 @@ std::string Diagnostics<L, W>::processWarningFlag(char const *flag) {
// Set the first <param> to enabled/error, and disable the rest // Set the first <param> to enabled/error, and disable the rest
for (uint8_t ofs = 0; ofs < maxParam; ofs++) { for (uint8_t ofs = 0; ofs < maxParam; ofs++) {
WarningState &warning = state.flagStates[baseID + ofs]; if (WarningState &warning = state.flagStates[baseID + ofs]; ofs < *param) {
if (ofs < *param) {
warning.update(flagState); warning.update(flagState);
} else { } else {
warning.state = WARNING_DISABLED; warning.state = WARNING_DISABLED;
@@ -170,13 +172,15 @@ std::string Diagnostics<L, W>::processWarningFlag(char const *flag) {
} }
return rootFlag; return rootFlag;
} }
}
// Try to match against a non-parametric warning, unless there was an equals sign // Try to match against a non-parametric warning, unless there was an equals sign
if (!param.has_value()) { if (!param.has_value()) {
// Try to match against a "meta" warning // Try to match against a "meta" warning
for (WarningFlag<L> const &metaWarning : metaWarnings) { for (WarningFlag<L> const &metaWarning : metaWarnings) {
if (rootFlag == metaWarning.name) { if (rootFlag != metaWarning.name) {
continue;
}
// Set each of the warning flags that meets this level // Set each of the warning flags that meets this level
for (W id : EnumSeq(W::NB_WARNINGS)) { for (W id : EnumSeq(W::NB_WARNINGS)) {
if (metaWarning.level >= warningFlags[id].level) { if (metaWarning.level >= warningFlags[id].level) {
@@ -185,7 +189,6 @@ std::string Diagnostics<L, W>::processWarningFlag(char const *flag) {
} }
return rootFlag; return rootFlag;
} }
}
// Try to match the flag against a "normal" flag // Try to match the flag against a "normal" flag
for (W id : EnumSeq(W::NB_PLAIN_WARNINGS)) { for (W id : EnumSeq(W::NB_PLAIN_WARNINGS)) {

View File

@@ -149,7 +149,9 @@ static void alreadyDefinedError(Symbol const &sym, char const *asType) {
fprintf(stderr, " as %s", asType); fprintf(stderr, " as %s", asType);
} }
dumpFilename(sym); dumpFilename(sym);
if (sym.type == SYM_EQUS) { if (sym.type != SYM_EQUS) {
return;
}
if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) { if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) {
fprintf( fprintf(
stderr, stderr,
@@ -157,7 +159,6 @@ static void alreadyDefinedError(Symbol const &sym, char const *asType) {
contents.c_str() contents.c_str()
); );
} }
}
}); });
} }
} }

View File

@@ -348,9 +348,8 @@ static void writeSymBank(SortedSections const &bankSections, SectionType type, u
if (Symbol const *parentSym = sym_GetSymbol(parentName); if (Symbol const *parentSym = sym_GetSymbol(parentName);
parentSym && std::holds_alternative<Label>(parentSym->data)) { parentSym && std::holds_alternative<Label>(parentSym->data)) {
auto const &parentLabel = parentSym->label(); auto const &parentLabel = parentSym->label();
assume(parentLabel.section != nullptr); Section const &parentSection = *parentLabel.section;
parentAddr = parentAddr = static_cast<uint16_t>(parentLabel.offset + parentSection.org);
static_cast<uint16_t>(parentLabel.offset + parentLabel.section->org);
} }
} }
symList.push_back({.sym = sym, .addr = addr, .parentAddr = parentAddr}); symList.push_back({.sym = sym, .addr = addr, .parentAddr = parentAddr});

View File

@@ -58,13 +58,24 @@
%token YYEOF 0 "end of file" %token YYEOF 0 "end of file"
%token newline "end of line" %token newline "end of line"
%token COMMA "," %token COMMA ","
// Keywords
%token ORG "ORG" %token ORG "ORG"
FLOATING "FLOATING" %token FLOATING "FLOATING"
INCLUDE "INCLUDE" %token INCLUDE "INCLUDE"
ALIGN "ALIGN" %token ALIGN "ALIGN"
DS "DS" %token DS "DS"
OPTIONAL "OPTIONAL" %token OPTIONAL "OPTIONAL"
// Literals
%token <std::string> string;
%token <uint32_t> number;
%token <SectionType> sect_type;
%type <bool> optional;
%code { %code {
static std::array keywords{ static std::array keywords{
Keyword{"ORG"sv, yy::parser::make_ORG}, Keyword{"ORG"sv, yy::parser::make_ORG},
@@ -75,11 +86,6 @@
Keyword{"OPTIONAL"sv, yy::parser::make_OPTIONAL}, Keyword{"OPTIONAL"sv, yy::parser::make_OPTIONAL},
}; };
} }
%token <std::string> string;
%token <uint32_t> number;
%token <SectionType> sect_type;
%type <bool> optional;
%% %%