Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clang-format rules #1629

Merged
merged 11 commits into from
Jan 28, 2025
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AttributeMacros:
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BreakAfterAttributes: Always
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: true
Expand Down Expand Up @@ -60,6 +61,8 @@ IndentPPDirectives: BeforeHash
IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertBraces: true
InsertNewlineAtEOF: true
# Only support for Javascript as of clang-format 14...
# InsertTrailingCommas: Wrapped
KeepEmptyLinesAtTheStartOfBlocks: false
Expand All @@ -71,6 +74,8 @@ PPIndentWidth: -1
PointerAlignment: Right
QualifierAlignment: Right
ReflowComments: true
RemoveParentheses: ReturnStatement
RemoveSemicolon: true
SortIncludes: CaseSensitive
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
Expand Down
2 changes: 1 addition & 1 deletion include/asm/charmap.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_CHARMAP_HPP
#define RGBDS_ASM_CHARMAP_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/fixpoint.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_FIXPOINT_HPP
#define RGBDS_ASM_FIXPOINT_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/format.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_FORMAT_HPP
#define RGBDS_ASM_FORMAT_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/fstack.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

// Contains some assembler-wide defines and externs

Expand Down
2 changes: 1 addition & 1 deletion include/asm/lexer.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_LEXER_HPP
#define RGBDS_ASM_LEXER_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/macro.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_MACRO_HPP
#define RGBDS_ASM_MACRO_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/main.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_MAIN_HPP
#define RGBDS_ASM_MAIN_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/opt.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_OPT_HPP
#define RGBDS_ASM_OPT_HPP
Expand Down
11 changes: 2 additions & 9 deletions include/asm/output.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_OUTPUT_HPP
#define RGBDS_ASM_OUTPUT_HPP
Expand All @@ -14,14 +14,7 @@
struct Expression;
struct FileStackNode;

enum StateFeature {
STATE_EQU,
STATE_VAR,
STATE_EQUS,
STATE_CHAR,
STATE_MACRO,
NB_STATE_FEATURES
};
enum StateFeature { STATE_EQU, STATE_VAR, STATE_EQUS, STATE_CHAR, STATE_MACRO, NB_STATE_FEATURES };

extern std::string objectFileName;

Expand Down
10 changes: 3 additions & 7 deletions include/asm/rpn.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_RPN_HPP
#define RGBDS_ASM_RPN_HPP
Expand Down Expand Up @@ -31,12 +31,8 @@ struct Expression {

Expression &operator=(Expression &&) = default;

bool isKnown() const {
return data.holds<int32_t>();
}
int32_t value() const {
return data.get<int32_t>();
}
bool isKnown() const { return data.holds<int32_t>(); }
int32_t value() const { return data.get<int32_t>(); }

int32_t getConstVal() const;
Symbol const *symbolOf() const;
Expand Down
2 changes: 1 addition & 1 deletion include/asm/section.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_SECTION_HPP
#define RGBDS_ASM_SECTION_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/asm/symbol.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_SYMBOL_HPP
#define RGBDS_ASM_SYMBOL_HPP
Expand Down
43 changes: 20 additions & 23 deletions include/asm/warning.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_ASM_WARNING_HPP
#define RGBDS_ASM_WARNING_HPP
Expand Down Expand Up @@ -62,27 +62,24 @@ extern bool warningsAreErrors;

void processWarningFlag(char const *flag);

/*
* Used to warn the user about problems that don't prevent the generation of
* valid code.
*/
[[gnu::format(printf, 2, 3)]] void warning(WarningID id, char const *fmt, ...);

/*
* Used for errors that compromise the whole assembly process by affecting the
* following code, potencially making the assembler generate errors caused by
* 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,
* when it fails to allocate memory).
*/
[[gnu::format(printf, 1, 2), noreturn]] void fatalerror(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 error(char const *fmt, ...);
// Used to warn the user about problems that don't prevent the generation of
// valid code.
[[gnu::format(printf, 2, 3)]]
void warning(WarningID id, char const *fmt, ...);

// Used for errors that compromise the whole assembly process by affecting the
// following code, potencially making the assembler generate errors caused by
// 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,
// when it fails to allocate memory).
[[gnu::format(printf, 1, 2), noreturn]]
void fatalerror(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 error(char const *fmt, ...);

#endif // RGBDS_ASM_WARNING_HPP
15 changes: 6 additions & 9 deletions include/defaultinitvec.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_DEFAULT_INIT_ALLOC_HPP
#define RGBDS_DEFAULT_INIT_ALLOC_HPP

#include <memory>
#include <vector>

/*
* Allocator adaptor that interposes construct() calls to convert value-initialization
* (which is what you get with e.g. `vector::resize`) into default-initialization (which does not
* zero out non-class types).
* From
* https://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container/21028912#21028912
*/

// Allocator adaptor that interposes construct() calls to convert value-initialization
// (which is what you get with e.g. `vector::resize`) into default-initialization (which does not
// zero out non-class types).
// From
// https://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container/21028912#21028912
template<typename T, typename A = std::allocator<T>>
class default_init_allocator : public A {
using a_t = std::allocator_traits<A>;
Expand Down
2 changes: 1 addition & 1 deletion include/either.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_EITHER_HPP
#define RGBDS_EITHER_HPP
Expand Down
15 changes: 9 additions & 6 deletions include/error.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#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 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]] void errx(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, ...);
}

#endif // RGBDS_ERROR_HPP
16 changes: 7 additions & 9 deletions include/extern/getopt.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

/* This implementation was taken from musl and modified for RGBDS */
// This implementation was taken from musl and modified for RGBDS

#ifndef RGBDS_EXTERN_GETOPT_HPP
#define RGBDS_EXTERN_GETOPT_HPP

extern "C" {
// clang-format off: vertically align values
static constexpr int no_argument = 0;
static constexpr int required_argument = 1;
static constexpr int optional_argument = 2;
// clang-format on

extern char *musl_optarg;
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
Expand All @@ -21,10 +25,4 @@ int musl_getopt_long_only(
int argc, char **argv, char const *optstring, option const *longopts, int *idx
);

#define no_argument 0
#define required_argument 1
#define optional_argument 2

} // extern "C"

#endif // RGBDS_EXTERN_GETOPT_HPP
2 changes: 1 addition & 1 deletion include/extern/utf8decoder.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_EXTERN_UTF8DECODER_HPP
#define RGBDS_EXTERN_UTF8DECODER_HPP
Expand Down
8 changes: 3 additions & 5 deletions include/file.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_FILE_HPP
#define RGBDS_FILE_HPP
Expand All @@ -25,10 +25,8 @@ class File {
File() {}
~File() { close(); }

/**
* This should only be called once, and before doing any `->` operations.
* Returns `nullptr` on error, and a non-null pointer otherwise.
*/
// This should only be called once, and before doing any `->` operations.
// Returns `nullptr` on error, and a non-null pointer otherwise.
File *open(std::string const &path, std::ios_base::openmode mode) {
if (path != "-") {
_file.emplace<std::filebuf>();
Expand Down
47 changes: 21 additions & 26 deletions include/gfx/main.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_GFX_MAIN_HPP
#define RGBDS_GFX_MAIN_HPP
Expand Down Expand Up @@ -48,47 +48,42 @@ struct Options {

std::string input{}; // positional arg

// clang-format off: vertically align values
static constexpr uint8_t VERB_NONE = 0; // Normal, no extra output
static constexpr uint8_t VERB_CFG = 1; // Print configuration after parsing options
static constexpr uint8_t VERB_LOG_ACT = 2; // Log actions before doing them
static constexpr uint8_t VERB_INTERM = 3; // Print some intermediate results
static constexpr uint8_t VERB_DEBUG = 4; // Internals are logged
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?
[[gnu::format(printf, 3, 4)]] void verbosePrint(uint8_t level, char const *fmt, ...) const;
// clang-format on
[[gnu::format(printf, 3, 4)]]
void verbosePrint(uint8_t level, char const *fmt, ...) const;

mutable bool hasTransparentPixels = false;
uint8_t maxOpaqueColors() const { return nbColorsPerPal - hasTransparentPixels; }
};

extern Options options;

/*
* Prints the error count, and exits with failure
*/
[[noreturn]] void giveUp();
/*
* If any error has been emitted thus far, calls `giveUp()`.
*/
// Prints the error count, and exits with failure
[[noreturn]]
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)`.
*/
// 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, ...);
// Prints a fatal error, increments the error count, and gives up
[[gnu::format(printf, 1, 2), noreturn]]
void fatal(char const *fmt, ...);

struct Palette {
// An array of 4 GBC-native (RGB555) colors
Expand Down
6 changes: 2 additions & 4 deletions include/gfx/pal_packing.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_GFX_PAL_PACKING_HPP
#define RGBDS_GFX_PAL_PACKING_HPP
Expand All @@ -11,9 +11,7 @@
struct Palette;
class ProtoPalette;

/*
* Returns which palette each proto-palette maps to, and how many palettes are necessary
*/
// Returns which palette each proto-palette maps to, and how many palettes are necessary
std::tuple<DefaultInitVec<size_t>, size_t>
overloadAndRemove(std::vector<ProtoPalette> const &protoPalettes);

Expand Down
2 changes: 1 addition & 1 deletion include/gfx/pal_sorting.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_GFX_PAL_SORTING_HPP
#define RGBDS_GFX_PAL_SORTING_HPP
Expand Down
2 changes: 1 addition & 1 deletion include/gfx/pal_spec.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */
// SPDX-License-Identifier: MIT

#ifndef RGBDS_GFX_PAL_SPEC_HPP
#define RGBDS_GFX_PAL_SPEC_HPP
Expand Down
Loading
Loading