mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Reduce some more deep nesting
This commit is contained in:
@@ -138,53 +138,56 @@ std::string Diagnostics<L, W>::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=<flag>`, but also `-Werror=<flag>=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 <param> 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=<flag>`, but also `-Werror=<flag>=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 <param> 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<L> 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
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -348,9 +348,8 @@ static void writeSymBank(SortedSections const &bankSections, SectionType type, u
|
||||
if (Symbol const *parentSym = sym_GetSymbol(parentName);
|
||||
parentSym && std::holds_alternative<Label>(parentSym->data)) {
|
||||
auto const &parentLabel = parentSym->label();
|
||||
assume(parentLabel.section != nullptr);
|
||||
parentAddr =
|
||||
static_cast<uint16_t>(parentLabel.offset + parentLabel.section->org);
|
||||
Section const &parentSection = *parentLabel.section;
|
||||
parentAddr = static_cast<uint16_t>(parentLabel.offset + parentSection.org);
|
||||
}
|
||||
}
|
||||
symList.push_back({.sym = sym, .addr = addr, .parentAddr = parentAddr});
|
||||
|
||||
@@ -58,13 +58,24 @@
|
||||
|
||||
%token YYEOF 0 "end of file"
|
||||
%token newline "end of line"
|
||||
|
||||
%token COMMA ","
|
||||
|
||||
// Keywords
|
||||
%token ORG "ORG"
|
||||
FLOATING "FLOATING"
|
||||
INCLUDE "INCLUDE"
|
||||
ALIGN "ALIGN"
|
||||
DS "DS"
|
||||
OPTIONAL "OPTIONAL"
|
||||
%token FLOATING "FLOATING"
|
||||
%token INCLUDE "INCLUDE"
|
||||
%token ALIGN "ALIGN"
|
||||
%token DS "DS"
|
||||
%token OPTIONAL "OPTIONAL"
|
||||
|
||||
// Literals
|
||||
%token <std::string> string;
|
||||
%token <uint32_t> number;
|
||||
%token <SectionType> sect_type;
|
||||
|
||||
%type <bool> optional;
|
||||
|
||||
%code {
|
||||
static std::array keywords{
|
||||
Keyword{"ORG"sv, yy::parser::make_ORG},
|
||||
@@ -75,11 +86,6 @@
|
||||
Keyword{"OPTIONAL"sv, yy::parser::make_OPTIONAL},
|
||||
};
|
||||
}
|
||||
%token <std::string> string;
|
||||
%token <uint32_t> number;
|
||||
%token <SectionType> sect_type;
|
||||
|
||||
%type <bool> optional;
|
||||
|
||||
%%
|
||||
|
||||
|
||||
Reference in New Issue
Block a user