mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Implement a single nbErrors counter inside generic diagnostic code
This commit is contained in:
@@ -2,14 +2,11 @@
|
||||
|
||||
#include "gfx/warning.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static uintmax_t nbErrors;
|
||||
|
||||
// clang-format off: nested initializers
|
||||
Diagnostics<WarningLevel, WarningID> warnings = {
|
||||
.metaWarnings = {
|
||||
@@ -22,27 +19,27 @@ Diagnostics<WarningLevel, WarningID> warnings = {
|
||||
},
|
||||
.paramWarnings = {},
|
||||
.state = DiagnosticsState<WarningID>(),
|
||||
.nbErrors = 0,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
[[noreturn]]
|
||||
void giveUp() {
|
||||
fprintf(stderr, "Conversion aborted after %ju error%s\n", nbErrors, nbErrors == 1 ? "" : "s");
|
||||
fprintf(
|
||||
stderr,
|
||||
"Conversion aborted after %" PRIu64 " error%s\n",
|
||||
warnings.nbErrors,
|
||||
warnings.nbErrors == 1 ? "" : "s"
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void requireZeroErrors() {
|
||||
if (nbErrors != 0) {
|
||||
if (warnings.nbErrors != 0) {
|
||||
giveUp();
|
||||
}
|
||||
}
|
||||
|
||||
static void incrementErrors() {
|
||||
if (nbErrors != std::numeric_limits<decltype(nbErrors)>::max()) {
|
||||
++nbErrors;
|
||||
}
|
||||
}
|
||||
|
||||
void error(char const *fmt, ...) {
|
||||
va_list ap;
|
||||
fputs("error: ", stderr);
|
||||
@@ -51,7 +48,7 @@ void error(char const *fmt, ...) {
|
||||
va_end(ap);
|
||||
putc('\n', stderr);
|
||||
|
||||
incrementErrors();
|
||||
warnings.incrementErrors();
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
@@ -63,7 +60,7 @@ void fatal(char const *fmt, ...) {
|
||||
va_end(ap);
|
||||
putc('\n', stderr);
|
||||
|
||||
incrementErrors();
|
||||
warnings.incrementErrors();
|
||||
giveUp();
|
||||
}
|
||||
|
||||
@@ -90,7 +87,7 @@ void warning(WarningID id, char const *fmt, ...) {
|
||||
va_end(ap);
|
||||
putc('\n', stderr);
|
||||
|
||||
incrementErrors();
|
||||
warnings.incrementErrors();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user