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;
|
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) {
|
||||||
// If making the warning an error but param is 0, set to the maximum
|
continue;
|
||||||
// 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 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
|
// 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) {
|
||||||
// Set each of the warning flags that meets this level
|
continue;
|
||||||
for (W id : EnumSeq(W::NB_WARNINGS)) {
|
|
||||||
if (metaWarning.level >= warningFlags[id].level) {
|
|
||||||
state.metaStates[id].update(flagState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rootFlag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// 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);
|
fprintf(stderr, " as %s", asType);
|
||||||
}
|
}
|
||||||
dumpFilename(sym);
|
dumpFilename(sym);
|
||||||
if (sym.type == SYM_EQUS) {
|
if (sym.type != SYM_EQUS) {
|
||||||
if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) {
|
return;
|
||||||
fprintf(
|
}
|
||||||
stderr,
|
if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) {
|
||||||
"\n (should it be {interpolated} to define its contents \"%s\"?)",
|
fprintf(
|
||||||
contents.c_str()
|
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);
|
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});
|
||||||
|
|||||||
@@ -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;
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user