Miscellaneous updates

This commit is contained in:
Rangi42
2025-07-08 17:37:23 -04:00
parent 6736d2ec66
commit 8c50839109
16 changed files with 85 additions and 62 deletions

View File

@@ -552,7 +552,7 @@ void out_WriteState(std::string name, std::vector<StateFeature> const &features)
for (StateFeature feature : features) {
fprintf(file, "\n; %s\n", dumpHeadings[feature]);
if (!dumpFuncs[feature](file)) {
fprintf(file, "; No values\n");
fputs("; No values\n", file);
}
}
}

View File

@@ -256,10 +256,10 @@ static void mergeSections(
break;
case SECTION_NORMAL:
errorNoNewline("Section already defined previously at ");
sect.src->dump(sect.fileLine);
putc('\n', stderr);
nbSectErrors++;
sectError([&]() {
fputs("Section already defined previously at ", stderr);
sect.src->dump(sect.fileLine);
});
break;
}
}

View File

@@ -115,11 +115,10 @@ static void dumpFilename(Symbol const &sym) {
fputs(" at ", stderr);
if (sym.src) {
sym.src->dump(sym.fileLine);
putc('\n', stderr);
} else if (sym.isBuiltin) {
fputs("<builtin>\n", stderr);
fputs("<builtin>", stderr);
} else {
fputs("<command-line>\n", stderr);
fputs("<command-line>", stderr);
}
}
@@ -144,20 +143,22 @@ static void alreadyDefinedError(Symbol const &sym, char const *asType) {
// `DEF()` would return false, so we should not claim the symbol is already defined
error("'%s' is reserved for a built-in symbol", sym.name.c_str());
} else {
errorNoNewline("'%s' already defined", sym.name.c_str());
if (asType) {
fprintf(stderr, " as %s", asType);
}
dumpFilename(sym);
if (sym.type == SYM_EQUS) {
if (std::string const &contents = *sym.getEqus(); isValidIdentifier(contents)) {
fprintf(
stderr,
" (should it be {interpolated} to define its contents \"%s\"?)\n",
contents.c_str()
);
error([&]() {
fprintf(stderr, "'%s' already defined", sym.name.c_str());
if (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()
);
}
}
});
}
}
@@ -372,8 +373,10 @@ static Symbol *createNonrelocSymbol(std::string const &symName, bool numeric) {
return nullptr; // Don't allow overriding the symbol, that'd be bad!
} else if (!numeric) {
// The symbol has already been referenced, but it's not allowed
errorNoNewline("'%s' already referenced", symName.c_str());
dumpFilename(*sym);
error([&]() {
fprintf(stderr, "'%s' already referenced", symName.c_str());
dumpFilename(*sym);
});
return nullptr; // Don't allow overriding the symbol, that'd be bad!
}
@@ -438,8 +441,10 @@ Symbol *sym_RedefString(std::string const &symName, std::shared_ptr<std::string>
if (sym->isDefined()) {
alreadyDefinedError(*sym, "non-EQUS");
} else {
errorNoNewline("'%s' already referenced", symName.c_str());
dumpFilename(*sym);
error([&]() {
fprintf(stderr, "'%s' already referenced", symName.c_str());
dumpFilename(*sym);
});
}
return nullptr;
} else if (sym->isBuiltin) {

View File

@@ -78,13 +78,7 @@ static void printDiag(
lexer_DumpStringExpansions();
}
void error(char const *fmt, ...) {
va_list args;
va_start(args, fmt);
printDiag(fmt, args, "error", ":", nullptr);
va_end(args);
static void incrementErrors() {
// This intentionally makes 0 act as "unlimited" (or at least "limited to sizeof(unsigned)")
nbErrors++;
if (nbErrors == maxErrors) {
@@ -97,26 +91,25 @@ void error(char const *fmt, ...) {
}
}
void errorNoNewline(char const *fmt, ...) {
void error(char const *fmt, ...) {
va_list args;
va_start(args, fmt);
printDiag(fmt, args, "error", ":", nullptr);
va_end(args);
incrementErrors();
}
void error(std::function<void()> callback) {
fputs("error: ", stderr);
fstk_DumpCurrent();
fputs(":\n ", stderr);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
callback();
putc('\n', stderr);
lexer_DumpStringExpansions();
// This intentionally makes 0 act as "unlimited" (or at least "limited to sizeof(unsigned)")
nbErrors++;
if (nbErrors == maxErrors) {
errx(
"The maximum of %u error%s was reached (configure with \"-X/--max-errors\"); assembly "
"aborted!",
maxErrors,
maxErrors == 1 ? "" : "s"
);
}
incrementErrors();
}
[[noreturn]]