mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add more rules to .clang-format
This commit is contained in:
@@ -24,6 +24,7 @@ AttributeMacros:
|
|||||||
BinPackArguments: false
|
BinPackArguments: false
|
||||||
BinPackParameters: false
|
BinPackParameters: false
|
||||||
BitFieldColonSpacing: Both
|
BitFieldColonSpacing: Both
|
||||||
|
BreakAfterAttributes: Always
|
||||||
BreakBeforeBinaryOperators: NonAssignment
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
BreakBeforeBraces: Attach
|
BreakBeforeBraces: Attach
|
||||||
BreakBeforeConceptDeclarations: true
|
BreakBeforeConceptDeclarations: true
|
||||||
@@ -60,6 +61,7 @@ IndentPPDirectives: BeforeHash
|
|||||||
IndentRequires: true
|
IndentRequires: true
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
IndentWrappedFunctionNames: true
|
IndentWrappedFunctionNames: true
|
||||||
|
InsertNewlineAtEOF: true
|
||||||
# Only support for Javascript as of clang-format 14...
|
# Only support for Javascript as of clang-format 14...
|
||||||
# InsertTrailingCommas: Wrapped
|
# InsertTrailingCommas: Wrapped
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
@@ -71,6 +73,8 @@ PPIndentWidth: -1
|
|||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
QualifierAlignment: Right
|
QualifierAlignment: Right
|
||||||
ReflowComments: true
|
ReflowComments: true
|
||||||
|
RemoveParentheses: ReturnStatement
|
||||||
|
RemoveSemicolon: true
|
||||||
SortIncludes: CaseSensitive
|
SortIncludes: CaseSensitive
|
||||||
SortUsingDeclarations: true
|
SortUsingDeclarations: true
|
||||||
SpaceAfterCStyleCast: false
|
SpaceAfterCStyleCast: false
|
||||||
|
|||||||
@@ -64,19 +64,22 @@ void processWarningFlag(char const *flag);
|
|||||||
|
|
||||||
// Used to warn the user about problems that don't prevent the generation of
|
// Used to warn the user about problems that don't prevent the generation of
|
||||||
// valid code.
|
// valid code.
|
||||||
[[gnu::format(printf, 2, 3)]] void warning(WarningID id, char const *fmt, ...);
|
[[gnu::format(printf, 2, 3)]]
|
||||||
|
void warning(WarningID id, char const *fmt, ...);
|
||||||
|
|
||||||
// Used for errors that compromise the whole assembly process by affecting the
|
// Used for errors that compromise the whole assembly process by affecting the
|
||||||
// following code, potencially making the assembler generate errors caused by
|
// following code, potencially making the assembler generate errors caused by
|
||||||
// the first one and unrelated to the code that the assembler complains about.
|
// the first one and unrelated to the code that the assembler complains about.
|
||||||
// It is also used when the assembler goes into an invalid state (for example,
|
// It is also used when the assembler goes into an invalid state (for example,
|
||||||
// when it fails to allocate memory).
|
// when it fails to allocate memory).
|
||||||
[[gnu::format(printf, 1, 2), noreturn]] void fatalerror(char const *fmt, ...);
|
[[gnu::format(printf, 1, 2), noreturn]]
|
||||||
|
void fatalerror(char const *fmt, ...);
|
||||||
|
|
||||||
// Used for errors that make it impossible to assemble correctly, but don't
|
// 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
|
// 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
|
// get a list of all errors at the end, making it easier to fix all of them at
|
||||||
// once.
|
// once.
|
||||||
[[gnu::format(printf, 1, 2)]] void error(char const *fmt, ...);
|
[[gnu::format(printf, 1, 2)]]
|
||||||
|
void error(char const *fmt, ...);
|
||||||
|
|
||||||
#endif // RGBDS_ASM_WARNING_HPP
|
#endif // RGBDS_ASM_WARNING_HPP
|
||||||
|
|||||||
@@ -4,11 +4,15 @@
|
|||||||
#define RGBDS_ERROR_HPP
|
#define RGBDS_ERROR_HPP
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
[[gnu::format(printf, 1, 2)]] void warn(char const *fmt...);
|
[[gnu::format(printf, 1, 2)]]
|
||||||
[[gnu::format(printf, 1, 2)]] void warnx(char const *fmt, ...);
|
void warn(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]]
|
||||||
[[gnu::format(printf, 1, 2), noreturn]] void errx(char const *fmt, ...);
|
void err(char const *fmt, ...);
|
||||||
|
[[gnu::format(printf, 1, 2), noreturn]]
|
||||||
|
void errx(char const *fmt, ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // RGBDS_ERROR_HPP
|
#endif // RGBDS_ERROR_HPP
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ struct Options {
|
|||||||
static constexpr uint8_t VERB_TRACE = 5; // Step-by-step algorithm details
|
static constexpr uint8_t VERB_TRACE = 5; // Step-by-step algorithm details
|
||||||
static constexpr uint8_t VERB_VVVVVV = 6; // What, can't I have a little fun?
|
static constexpr uint8_t VERB_VVVVVV = 6; // What, can't I have a little fun?
|
||||||
// clang-format on
|
// clang-format on
|
||||||
[[gnu::format(printf, 3, 4)]] void verbosePrint(uint8_t level, char const *fmt, ...) const;
|
[[gnu::format(printf, 3, 4)]]
|
||||||
|
void verbosePrint(uint8_t level, char const *fmt, ...) const;
|
||||||
|
|
||||||
mutable bool hasTransparentPixels = false;
|
mutable bool hasTransparentPixels = false;
|
||||||
uint8_t maxOpaqueColors() const { return nbColorsPerPal - hasTransparentPixels; }
|
uint8_t maxOpaqueColors() const { return nbColorsPerPal - hasTransparentPixels; }
|
||||||
@@ -66,19 +67,23 @@ struct Options {
|
|||||||
extern Options options;
|
extern Options options;
|
||||||
|
|
||||||
// Prints the error count, and exits with failure
|
// Prints the error count, and exits with failure
|
||||||
[[noreturn]] void giveUp();
|
[[noreturn]]
|
||||||
|
void giveUp();
|
||||||
// If any error has been emitted thus far, calls `giveUp()`.
|
// If any error has been emitted thus far, calls `giveUp()`.
|
||||||
void requireZeroErrors();
|
void requireZeroErrors();
|
||||||
// Prints a warning, and does not change the error count
|
// Prints a warning, and does not change the error count
|
||||||
[[gnu::format(printf, 1, 2)]] void warning(char const *fmt, ...);
|
[[gnu::format(printf, 1, 2)]]
|
||||||
|
void warning(char const *fmt, ...);
|
||||||
// Prints an error, and increments the error count
|
// Prints an error, and increments the error count
|
||||||
[[gnu::format(printf, 1, 2)]] void error(char const *fmt, ...);
|
[[gnu::format(printf, 1, 2)]]
|
||||||
|
void error(char const *fmt, ...);
|
||||||
// Prints an error, and increments the error count
|
// Prints an error, and increments the error count
|
||||||
// Does not take format arguments so `format_` and `-Wformat-security` won't complain about
|
// Does not take format arguments so `format_` and `-Wformat-security` won't complain about
|
||||||
// calling `errorMessage(msg)`.
|
// calling `errorMessage(msg)`.
|
||||||
void errorMessage(char const *msg);
|
void errorMessage(char const *msg);
|
||||||
// Prints a fatal error, increments the error count, and gives up
|
// Prints a fatal error, increments the error count, and gives up
|
||||||
[[gnu::format(printf, 1, 2), noreturn]] void fatal(char const *fmt, ...);
|
[[gnu::format(printf, 1, 2), noreturn]]
|
||||||
|
void fatal(char const *fmt, ...);
|
||||||
|
|
||||||
struct Palette {
|
struct Palette {
|
||||||
// An array of 4 GBC-native (RGB555) colors
|
// An array of 4 GBC-native (RGB555) colors
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
#else
|
#else
|
||||||
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
// This seems to generate similar code to __builtin_unreachable, despite different semantics
|
||||||
// Note that executing this is undefined behavior (declared [[noreturn]], but does return)
|
// Note that executing this is undefined behavior (declared [[noreturn]], but does return)
|
||||||
[[noreturn]] static inline void unreachable_() {
|
[[noreturn]]
|
||||||
|
static inline void unreachable_() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -58,11 +58,11 @@ struct FileStackNode {
|
|||||||
std::string const &dump(uint32_t curLineNo) const;
|
std::string const &dump(uint32_t curLineNo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[gnu::format(printf, 3, 4)]] void
|
[[gnu::format(printf, 3, 4)]]
|
||||||
warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
void warning(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
||||||
[[gnu::format(printf, 3, 4)]] void
|
[[gnu::format(printf, 3, 4)]]
|
||||||
error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
void error(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
||||||
[[gnu::format(printf, 3, 4), noreturn]] void
|
[[gnu::format(printf, 3, 4), noreturn]]
|
||||||
fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...);
|
||||||
|
|
||||||
#endif // RGBDS_LINK_MAIN_HPP
|
#endif // RGBDS_LINK_MAIN_HPP
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ static std::pair<Symbol const *, Symbol const *> currentLoadLabelScopes = {nullp
|
|||||||
int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset)
|
int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutputOffset)
|
||||||
|
|
||||||
// A quick check to see if we have an initialized section
|
// A quick check to see if we have an initialized section
|
||||||
[[nodiscard]] static bool requireSection() {
|
[[nodiscard]]
|
||||||
|
static bool requireSection() {
|
||||||
if (currentSection)
|
if (currentSection)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -59,7 +60,8 @@ int32_t loadOffset; // Offset into the LOAD section's parent (see sect_GetOutput
|
|||||||
|
|
||||||
// A quick check to see if we have an initialized section that can contain
|
// A quick check to see if we have an initialized section that can contain
|
||||||
// this much initialized data
|
// this much initialized data
|
||||||
[[nodiscard]] static bool requireCodeSection() {
|
[[nodiscard]]
|
||||||
|
static bool requireCodeSection() {
|
||||||
if (!requireSection())
|
if (!requireSection())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ int32_t Symbol::getOutputValue() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContentSpan const &Symbol::getMacro() const {
|
ContentSpan const &Symbol::getMacro() const {
|
||||||
assume((std::holds_alternative<ContentSpan>(data)));
|
assume(std::holds_alternative<ContentSpan>(data));
|
||||||
return std::get<ContentSpan>(data);
|
return std::get<ContentSpan>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,8 @@ void error(char const *fmt, ...) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void fatalerror(char const *fmt, ...) {
|
[[noreturn]]
|
||||||
|
void fatalerror(char const *fmt, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ static void vwarnx(char const *fmt, va_list ap) {
|
|||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] static void verr(char const *fmt, va_list ap) {
|
[[noreturn]]
|
||||||
|
static void verr(char const *fmt, va_list ap) {
|
||||||
char const *error = strerror(errno);
|
char const *error = strerror(errno);
|
||||||
|
|
||||||
fprintf(stderr, "error: ");
|
fprintf(stderr, "error: ");
|
||||||
@@ -32,7 +33,8 @@ static void vwarnx(char const *fmt, va_list ap) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] static void verrx(char const *fmt, va_list ap) {
|
[[noreturn]]
|
||||||
|
static void verrx(char const *fmt, va_list ap) {
|
||||||
fprintf(stderr, "error: ");
|
fprintf(stderr, "error: ");
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
@@ -56,14 +58,16 @@ void warnx(char const *fmt, ...) {
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void err(char const *fmt, ...) {
|
[[noreturn]]
|
||||||
|
void err(char const *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
verr(fmt, ap);
|
verr(fmt, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void errx(char const *fmt, ...) {
|
[[noreturn]]
|
||||||
|
void errx(char const *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ static void printUsage() {
|
|||||||
|
|
||||||
static uint8_t nbErrors;
|
static uint8_t nbErrors;
|
||||||
|
|
||||||
[[gnu::format(printf, 1, 2)]] static void report(char const *fmt, ...) {
|
[[gnu::format(printf, 1, 2)]]
|
||||||
|
static void report(char const *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ static struct LocalOptions {
|
|||||||
|
|
||||||
static uintmax_t nbErrors;
|
static uintmax_t nbErrors;
|
||||||
|
|
||||||
[[noreturn]] void giveUp() {
|
[[noreturn]]
|
||||||
|
void giveUp() {
|
||||||
fprintf(stderr, "Conversion aborted after %ju error%s\n", nbErrors, nbErrors == 1 ? "" : "s");
|
fprintf(stderr, "Conversion aborted after %ju error%s\n", nbErrors, nbErrors == 1 ? "" : "s");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -82,7 +83,8 @@ void errorMessage(char const *msg) {
|
|||||||
nbErrors++;
|
nbErrors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void fatal(char const *fmt, ...) {
|
[[noreturn]]
|
||||||
|
void fatal(char const *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
fputs("FATAL: ", stderr);
|
fputs("FATAL: ", stderr);
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ static T readLE(U const *bytes) {
|
|||||||
|
|
||||||
// **Appends** the first line read from `file` to the end of the provided `buffer`.
|
// **Appends** the first line read from `file` to the end of the provided `buffer`.
|
||||||
// @return true if a line was read.
|
// @return true if a line was read.
|
||||||
[[gnu::warn_unused_result]] static bool readLine(std::filebuf &file, std::string &buffer) {
|
[[gnu::warn_unused_result]]
|
||||||
|
static bool readLine(std::filebuf &file, std::string &buffer) {
|
||||||
assume(buffer.empty());
|
assume(buffer.empty());
|
||||||
// TODO: maybe this can be optimized to bulk reads?
|
// TODO: maybe this can be optimized to bulk reads?
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ public:
|
|||||||
// Registers a color in the palette.
|
// Registers a color in the palette.
|
||||||
// If the newly inserted color "conflicts" with another one (different color, but same CGB
|
// If the newly inserted color "conflicts" with another one (different color, but same CGB
|
||||||
// color), then the other color is returned. Otherwise, `nullptr` is returned.
|
// color), then the other color is returned. Otherwise, `nullptr` is returned.
|
||||||
[[nodiscard]] Rgba const *registerColor(Rgba const &rgba) {
|
[[nodiscard]]
|
||||||
|
Rgba const *registerColor(Rgba const &rgba) {
|
||||||
decltype(_colors)::value_type &slot = _colors[rgba.cgbColor()];
|
decltype(_colors)::value_type &slot = _colors[rgba.cgbColor()];
|
||||||
|
|
||||||
if (rgba.cgbColor() == Rgba::transparent) {
|
if (rgba.cgbColor() == Rgba::transparent) {
|
||||||
@@ -77,7 +78,8 @@ class Png {
|
|||||||
int nbTransparentEntries;
|
int nbTransparentEntries;
|
||||||
png_bytep transparencyPal = nullptr;
|
png_bytep transparencyPal = nullptr;
|
||||||
|
|
||||||
[[noreturn]] static void handleError(png_structp png, char const *msg) {
|
[[noreturn]]
|
||||||
|
static void handleError(png_structp png, char const *msg) {
|
||||||
Png *self = reinterpret_cast<Png *>(png_get_error_ptr(png));
|
Png *self = reinterpret_cast<Png *>(png_get_error_ptr(png));
|
||||||
|
|
||||||
fatal("Error reading input image (\"%s\"): %s", self->c_str(), msg);
|
fatal("Error reading input image (\"%s\"): %s", self->c_str(), msg);
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ static DefaultInitVec<uint8_t> readInto(std::string const &path) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] static void pngError(png_structp png, char const *msg) {
|
[[noreturn]]
|
||||||
|
static void pngError(png_structp png, char const *msg) {
|
||||||
fatal(
|
fatal(
|
||||||
"Error writing reversed image (\"%s\"): %s",
|
"Error writing reversed image (\"%s\"): %s",
|
||||||
static_cast<char const *>(png_get_error_ptr(png)),
|
static_cast<char const *>(png_get_error_ptr(png)),
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ void argErr(char flag, char const *fmt, ...) {
|
|||||||
nbErrors++;
|
nbErrors++;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
[[noreturn]]
|
||||||
|
void fatal(FileStackNode const *where, uint32_t lineNo, char const *fmt, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -308,7 +309,8 @@ next: // Can't `continue` a `for` loop with this nontrivial iteration logic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void reportErrors() {
|
[[noreturn]]
|
||||||
|
void reportErrors() {
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr, "Linking failed with %" PRIu32 " error%s\n", nbErrors, nbErrors == 1 ? "" : "s"
|
stderr, "Linking failed with %" PRIu32 " error%s\n", nbErrors, nbErrors == 1 ? "" : "s"
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ static void error(char const *fmt, ...) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] static void fatal(char const *fmt, ...) {
|
[[noreturn]]
|
||||||
|
static void fatal(char const *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
fputs("FATAL: ", stderr);
|
fputs("FATAL: ", stderr);
|
||||||
@@ -96,7 +97,8 @@ class Png {
|
|||||||
int nbTransparentEntries;
|
int nbTransparentEntries;
|
||||||
png_bytep transparencyPal = nullptr;
|
png_bytep transparencyPal = nullptr;
|
||||||
|
|
||||||
[[noreturn]] static void handleError(png_structp png, char const *msg) {
|
[[noreturn]]
|
||||||
|
static void handleError(png_structp png, char const *msg) {
|
||||||
Png *self = reinterpret_cast<Png *>(png_get_error_ptr(png));
|
Png *self = reinterpret_cast<Png *>(png_get_error_ptr(png));
|
||||||
|
|
||||||
fatal("Error reading input image (\"%s\"): %s", self->path.c_str(), msg);
|
fatal("Error reading input image (\"%s\"): %s", self->path.c_str(), msg);
|
||||||
@@ -314,12 +316,7 @@ static char *execProg(char const *name, char * const *argv) {
|
|||||||
if (int info; waitpid(pid, &info, 0) == -1 || !WIFEXITED(info)) {
|
if (int info; waitpid(pid, &info, 0) == -1 || !WIFEXITED(info)) {
|
||||||
fatal("Error waiting for %s: %s", name, strerror(errno));
|
fatal("Error waiting for %s: %s", name, strerror(errno));
|
||||||
} else if (int status = WEXITSTATUS(info); status != 0) {
|
} else if (int status = WEXITSTATUS(info); status != 0) {
|
||||||
fatal(
|
fatal("%s returned with status %d\n\tThe command was: [%s]", name, status, formatArgv());
|
||||||
"%s returned with status %d\n\tThe command was: [%s]",
|
|
||||||
name,
|
|
||||||
status,
|
|
||||||
formatArgv()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // defined(_MSC_VER) || defined(__MINGW32__)
|
#else // defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
|||||||
Reference in New Issue
Block a user