mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 18:52:07 +00:00
Refactor warnings and errors (#1728)
* Remove `err` and `warn`, keep `errx` and `warnx`, using them in RGBGFX too * Separate RGBGFX and RGBLINK warnings/errors from main options * Separate `report` function into `error` and `fatal` messages * Implicit newlines for most RGBASM errors
This commit is contained in:
92
src/link/warning.cpp
Normal file
92
src/link/warning.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "link/warning.hpp"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "link/main.hpp"
|
||||
|
||||
static uint32_t nbErrors = 0;
|
||||
|
||||
static void printDiag(
|
||||
char const *fmt, va_list args, char const *type, FileStackNode const *where, uint32_t lineNo
|
||||
) {
|
||||
fputs(type, stderr);
|
||||
fputs(": ", stderr);
|
||||
if (where) {
|
||||
where->dump(lineNo);
|
||||
fputs(": ", stderr);
|
||||
}
|
||||
vfprintf(stderr, fmt, args);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "warning", where, lineNo);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "error", where, lineNo);
|
||||
va_end(args);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
void errorNoDump(char const *fmt, ...) {
|
||||
va_list args;
|
||||
fputs("error: ", stderr);
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
void argErr(char flag, char const *fmt, ...) {
|
||||
va_list args;
|
||||
fprintf(stderr, "error: Invalid argument for option '%c': ", flag);
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
putc('\n', stderr);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
printDiag(fmt, args, "FATAL", where, lineNo);
|
||||
va_end(args);
|
||||
|
||||
if (nbErrors != UINT32_MAX) {
|
||||
nbErrors++;
|
||||
}
|
||||
|
||||
fprintf(
|
||||
stderr, "Linking aborted after %" PRIu32 " error%s\n", nbErrors, nbErrors == 1 ? "" : "s"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void requireZeroErrors() {
|
||||
if (nbErrors != 0) {
|
||||
fprintf(
|
||||
stderr, "Linking failed with %" PRIu32 " error%s\n", nbErrors, nbErrors == 1 ? "" : "s"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user