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:
Rangi
2025-07-08 12:58:23 -04:00
committed by GitHub
parent 991b74dd0d
commit 35962dedc4
39 changed files with 753 additions and 757 deletions

View File

@@ -74,4 +74,11 @@ void fatalerror(char const *fmt, ...);
[[gnu::format(printf, 1, 2)]]
void error(char const *fmt, ...);
// Used for errors that make it impossible to assemble correctly, but don't
// affect the following code. The code will fail to assemble but the user will
// get a list of all errors at the end, making it easier to fix all of them at
// once.
[[gnu::format(printf, 1, 2)]]
void errorNoNewline(char const *fmt, ...);
#endif // RGBDS_ASM_WARNING_HPP

View File

@@ -3,16 +3,10 @@
#ifndef RGBDS_ERROR_HPP
#define RGBDS_ERROR_HPP
extern "C" {
[[gnu::format(printf, 1, 2)]]
void warn(char const *fmt...);
[[gnu::format(printf, 1, 2)]]
void warnx(char const *fmt, ...);
[[gnu::format(printf, 1, 2)]]
void warnx(char const *fmt, ...);
[[gnu::format(printf, 1, 2), noreturn]]
void err(char const *fmt, ...);
[[gnu::format(printf, 1, 2), noreturn]]
void errx(char const *fmt, ...);
}
[[gnu::format(printf, 1, 2), noreturn]]
void errx(char const *fmt, ...);
#endif // RGBDS_ERROR_HPP

View File

@@ -85,16 +85,9 @@ extern Options options;
void giveUp();
// If any error has been emitted thus far, calls `giveUp()`.
void requireZeroErrors();
// Prints a warning, and does not change the error count
[[gnu::format(printf, 1, 2)]]
void warning(char const *fmt, ...);
// Prints an error, and increments the error count
[[gnu::format(printf, 1, 2)]]
void error(char const *fmt, ...);
// Prints an error, and increments the error count
// Does not take format arguments so `format_` and `-Wformat-security` won't complain about
// calling `errorMessage(msg)`.
void errorMessage(char const *msg);
// Prints a fatal error, increments the error count, and gives up
[[gnu::format(printf, 1, 2), noreturn]]
void fatal(char const *fmt, ...);

21
include/gfx/warning.hpp Normal file
View File

@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
#ifndef RGBDS_GFX_WARNING_HPP
#define RGBDS_GFX_WARNING_HPP
// Prints the error count, and exits with failure
[[noreturn]]
void giveUp();
// If any error has been emitted thus far, calls `giveUp()`
void requireZeroErrors();
// Prints an error, and increments the error count
[[gnu::format(printf, 1, 2)]]
void error(char const *fmt, ...);
// Prints a fatal error, increments the error count, and gives up
[[gnu::format(printf, 1, 2), noreturn]]
void fatal(char const *fmt, ...);
#endif // RGBDS_GFX_WARNING_HPP

View File

@@ -59,11 +59,4 @@ struct FileStackNode {
std::string const &dump(uint32_t curLineNo) const;
};
[[gnu::format(printf, 3, 4)]]
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
[[gnu::format(printf, 3, 4)]]
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
[[gnu::format(printf, 3, 4), noreturn]]
void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
#endif // RGBDS_LINK_MAIN_HPP

23
include/link/warning.hpp Normal file
View File

@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
#ifndef RGBDS_LINK_WARNING_HPP
#define RGBDS_LINK_WARNING_HPP
#include <stdint.h>
struct FileStackNode;
[[gnu::format(printf, 3, 4)]]
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
[[gnu::format(printf, 3, 4)]]
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
[[gnu::format(printf, 1, 2)]]
void errorNoDump(char const *fmt, ...);
[[gnu::format(printf, 2, 3)]]
void argErr(char flag, char const *fmt, ...);
[[gnu::format(printf, 3, 4), noreturn]]
void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
void requireZeroErrors();
#endif // RGBDS_LINK_WARNING_HPP