diff --git a/include/asm/output.hpp b/include/asm/output.hpp index 490f4448..fd7dfc50 100644 --- a/include/asm/output.hpp +++ b/include/asm/output.hpp @@ -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; diff --git a/include/asm/rpn.hpp b/include/asm/rpn.hpp index 69d7700c..75e101e6 100644 --- a/include/asm/rpn.hpp +++ b/include/asm/rpn.hpp @@ -31,12 +31,8 @@ struct Expression { Expression &operator=(Expression &&) = default; - bool isKnown() const { - return data.holds(); - } - int32_t value() const { - return data.get(); - } + bool isKnown() const { return data.holds(); } + int32_t value() const { return data.get(); } int32_t getConstVal() const; Symbol const *symbolOf() const; diff --git a/include/error.hpp b/include/error.hpp index 5f8476d8..2fb259e2 100644 --- a/include/error.hpp +++ b/include/error.hpp @@ -4,12 +4,11 @@ #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 diff --git a/include/extern/getopt.hpp b/include/extern/getopt.hpp index 68bda496..68e12491 100644 --- a/include/extern/getopt.hpp +++ b/include/extern/getopt.hpp @@ -6,25 +6,23 @@ #define RGBDS_EXTERN_GETOPT_HPP extern "C" { + extern char *musl_optarg; + extern int musl_optind, musl_opterr, musl_optopt, musl_optreset; -extern char *musl_optarg; -extern int musl_optind, musl_opterr, musl_optopt, musl_optreset; + struct option { + char const *name; + int has_arg; + int *flag; + int val; + }; -struct option { - char const *name; - int has_arg; - int *flag; - int val; -}; - -int musl_getopt_long_only( - int argc, char **argv, char const *optstring, option const *longopts, int *idx -); + 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 diff --git a/include/gfx/main.hpp b/include/gfx/main.hpp index c3c7af6f..be278a90 100644 --- a/include/gfx/main.hpp +++ b/include/gfx/main.hpp @@ -48,6 +48,7 @@ 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 @@ -55,6 +56,7 @@ struct Options { 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? + // clang-format on [[gnu::format(printf, 3, 4)]] void verbosePrint(uint8_t level, char const *fmt, ...) const; mutable bool hasTransparentPixels = false; diff --git a/include/itertools.hpp b/include/itertools.hpp index 09e2cba6..039574df 100644 --- a/include/itertools.hpp +++ b/include/itertools.hpp @@ -25,7 +25,7 @@ class EnumSeq { auto operator*() const { return _value; } bool operator==(Iterator const &rhs) const { return _value == rhs._value; } - bool operator!=(Iterator const &rhs) const { return _value != rhs._value; } + bool operator!=(Iterator const &rhs) const { return _value != rhs._value; } }; public: diff --git a/include/version.hpp b/include/version.hpp index f27d46af..ee2792f6 100644 --- a/include/version.hpp +++ b/include/version.hpp @@ -3,13 +3,12 @@ #ifndef RGBDS_VERSION_HPP #define RGBDS_VERSION_HPP -extern "C" { - #define PACKAGE_VERSION_MAJOR 0 #define PACKAGE_VERSION_MINOR 9 #define PACKAGE_VERSION_PATCH 0 -char const *get_package_version_string(); +extern "C" { + char const *get_package_version_string(); } #endif // RGBDS_VERSION_H diff --git a/src/asm/charmap.cpp b/src/asm/charmap.cpp index 84678b87..ccea0b64 100644 --- a/src/asm/charmap.cpp +++ b/src/asm/charmap.cpp @@ -45,7 +45,10 @@ bool charmap_ForEach( for (Charmap const &charmap : charmapList) { // Traverse the trie depth-first to derive the character mappings in definition order std::map mappings; - for (std::stack> prefixes({{0, ""}}); !prefixes.empty();) { + // clang-format off: nested initializers + for (std::stack> prefixes({{0, ""}}); + !prefixes.empty();) { + // clang-format on auto [nodeIdx, mapping] = std::move(prefixes.top()); prefixes.pop(); CharmapNode const &node = charmap.nodes[nodeIdx]; diff --git a/src/asm/lexer.cpp b/src/asm/lexer.cpp index 9bcbcd1c..95582081 100644 --- a/src/asm/lexer.cpp +++ b/src/asm/lexer.cpp @@ -190,7 +190,7 @@ static std::unordered_map ke {"NZ", T_(CC_NZ) }, {"Z", T_(CC_Z) }, {"NC", T_(CC_NC) }, - // There is no `T_(CC_C)`; it's handled before as `T_(TOKEN_C)` + // There is no `T_(CC_C)`; it's handled before as `T_(TOKEN_C)` {"AF", T_(MODE_AF) }, {"BC", T_(MODE_BC) }, @@ -315,7 +315,7 @@ static std::unordered_map ke {"RB", T_(POP_RB) }, {"RW", T_(POP_RW) }, - // There is no `T_(POP_RL)`; it's handled before as `T_(SM83_RL)` + // There is no `T_(POP_RL)`; it's handled before as `T_(SM83_RL)` {"EQU", T_(POP_EQU) }, {"EQUS", T_(POP_EQUS) }, @@ -2286,14 +2286,14 @@ static Capture startCapture() { auto &view = lexerState->content.get(); return { .lineNo = lineNo, .span = {.ptr = view.makeSharedContentPtr(), .size = 0} - }; + }; } else { assume(lexerState->captureBuf == nullptr); lexerState->captureBuf = std::make_shared>(); // `.span.ptr == nullptr`; indicates to retrieve the capture buffer when done capturing return { .lineNo = lineNo, .span = {.ptr = nullptr, .size = 0} - }; + }; } } diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index fb71cec6..0ee2c209 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -77,9 +77,9 @@ void Expression::makeSymbol(std::string const &symName) { isSymbol = true; data = sym_IsPC(sym) ? "PC is not constant at assembly time" - : sym_IsPurgedScoped(symName) - ? "'"s + symName + "' is not constant at assembly time; it was purged" - : "'"s + symName + "' is not constant at assembly time"; + : sym_IsPurgedScoped(symName) + ? "'"s + symName + "' is not constant at assembly time; it was purged" + : "'"s + symName + "' is not constant at assembly time"; sym = sym_Ref(symName); size_t nameLen = sym->name.length() + 1; // Don't forget NUL! @@ -120,8 +120,8 @@ void Expression::makeBankSymbol(std::string const &symName) { data = static_cast(sym->getSection()->bank); } else { data = sym_IsPurgedScoped(symName) - ? "\""s + symName + "\"'s bank is not known; it was purged" - : "\""s + symName + "\"'s bank is not known"; + ? "\""s + symName + "\"'s bank is not known; it was purged" + : "\""s + symName + "\"'s bank is not known"; size_t nameLen = sym->name.length() + 1; // Room for NUL! diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 25553888..4af1a407 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -477,9 +477,7 @@ void sect_SetLoadSection( void sect_EndLoadSection(char const *cause) { if (cause) warning( - WARNING_UNTERMINATED_LOAD, - "`LOAD` block without `ENDL` terminated by `%s`\n", - cause + WARNING_UNTERMINATED_LOAD, "`LOAD` block without `ENDL` terminated by `%s`\n", cause ); if (!currentLoadSection) { diff --git a/src/asm/warning.cpp b/src/asm/warning.cpp index 2288c106..ae0ef1da 100644 --- a/src/asm/warning.cpp +++ b/src/asm/warning.cpp @@ -35,13 +35,13 @@ struct WarningFlag { WarningLevel level; }; -static const WarningFlag metaWarnings[] = { +static WarningFlag const metaWarnings[] = { {"all", LEVEL_ALL }, {"extra", LEVEL_EXTRA }, {"everything", LEVEL_EVERYTHING}, }; -static const WarningFlag warningFlags[NB_WARNINGS] = { +static WarningFlag const warningFlags[NB_WARNINGS] = { {"assert", LEVEL_DEFAULT }, {"backwards-for", LEVEL_ALL }, {"builtin-args", LEVEL_ALL }, diff --git a/src/fix/main.cpp b/src/fix/main.cpp index 7849672a..dfaae9af 100644 --- a/src/fix/main.cpp +++ b/src/fix/main.cpp @@ -385,12 +385,14 @@ static MbcType parseMBC(char const *name) { // Read "additional features" uint8_t features = 0; + // clang-format off: vertically align values static constexpr uint8_t RAM = 1 << 7; static constexpr uint8_t BATTERY = 1 << 6; static constexpr uint8_t TIMER = 1 << 5; static constexpr uint8_t RUMBLE = 1 << 4; static constexpr uint8_t SENSOR = 1 << 3; static constexpr uint8_t MULTIRUMBLE = 1 << 2; + // clang-format on for (;;) { // Trim off trailing whitespace @@ -742,12 +744,14 @@ static uint8_t const nintendoLogo[] = { }; static uint8_t fixSpec = 0; +// clang-format off: vertically align values static constexpr uint8_t FIX_LOGO = 1 << 7; static constexpr uint8_t TRASH_LOGO = 1 << 6; static constexpr uint8_t FIX_HEADER_SUM = 1 << 5; static constexpr uint8_t TRASH_HEADER_SUM = 1 << 4; static constexpr uint8_t FIX_GLOBAL_SUM = 1 << 3; static constexpr uint8_t TRASH_GLOBAL_SUM = 1 << 2; +// clang-format on static enum { DMG, BOTH, CGB } model = DMG; // If DMG, byte is left alone static char const *gameID = nullptr; @@ -1083,8 +1087,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize) globalSum = ~globalSum; uint8_t bytes[2] = { - static_cast(globalSum >> 8), - static_cast(globalSum & 0xFF) + static_cast(globalSum >> 8), static_cast(globalSum & 0xFF) }; overwriteBytes(rom0, 0x14E, bytes, sizeof(bytes), "global checksum"); @@ -1269,9 +1272,9 @@ int main(int argc, char *argv[]) { #define overrideSpecs(fix, fixFlag, trash, trashFlag) \ OVERRIDE_SPEC(fix, trash, fixFlag, trashFlag); \ OVERRIDE_SPEC(trash, fix, trashFlag, fixFlag) - overrideSpecs(l, FIX_LOGO, L, TRASH_LOGO); - overrideSpecs(h, FIX_HEADER_SUM, H, TRASH_HEADER_SUM); - overrideSpecs(g, FIX_GLOBAL_SUM, G, TRASH_GLOBAL_SUM); + overrideSpecs(l, FIX_LOGO, L, TRASH_LOGO); + overrideSpecs(h, FIX_HEADER_SUM, H, TRASH_HEADER_SUM); + overrideSpecs(g, FIX_GLOBAL_SUM, G, TRASH_GLOBAL_SUM); #undef OVERRIDE_SPEC #undef overrideSpecs diff --git a/src/gfx/pal_spec.cpp b/src/gfx/pal_spec.cpp index f1e1400d..ab587a84 100644 --- a/src/gfx/pal_spec.cpp +++ b/src/gfx/pal_spec.cpp @@ -194,8 +194,7 @@ static T readLE(U const *bytes) { * * @return true if a line was read. */ -[[gnu::warn_unused_result]] // Ignoring EOF is a bad idea. -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()); // TODO: maybe this can be optimized to bulk reads? for (;;) { diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index 9aeeb6e6..f55ec71b 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -712,8 +712,9 @@ static void hashBitplanes(uint16_t bitplanes, uint16_t &hash) { class TileData { // Importantly, `TileData` is **always** 2bpp. - // If the active bit depth is 1bpp, all tiles are processed as 2bpp nonetheless, but emitted as 1bpp. - // This massively simplifies internal processing, since bit depth is always identical outside of I/O / serialization boundaries. + // If the active bit depth is 1bpp, all tiles are processed as 2bpp nonetheless, but emitted as + // 1bpp. This massively simplifies internal processing, since bit depth is always identical + // outside of I/O / serialization boundaries. std::array _data; // The hash is a bit lax: it's the XOR of all lines, and every other nibble is identical // if horizontal mirroring is in effect. It should still be a reasonable tie-breaker in diff --git a/src/gfx/rgba.cpp b/src/gfx/rgba.cpp index e2ae941d..cbf8bf10 100644 --- a/src/gfx/rgba.cpp +++ b/src/gfx/rgba.cpp @@ -15,24 +15,26 @@ * since commit b5a611c5db46d6a0649d04d24d8d6339200f9ca1 (Dec 2020), * with gaps in the scale curve filled by polynomial interpolation. */ +// clang-format off: vertically align columns of values static std::array reverse_curve{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, // These - 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, // comments - 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, // prevent - 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, // clang-format - 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, // from - 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, // reflowing - 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, // these - 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, // sixteen - 19, 19, 19, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 22, // 16-item - 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, // lines, - 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, // which, - 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, // in - 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, // my - 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, // opinion, - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, // help - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, // visualization! + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, + 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, + 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, + 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, + 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, + 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 16, 16, + 16, 16, 16, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, + 19, 19, 19, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 22, + 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, + 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, + 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, }; +// clang-format on uint16_t Rgba::cgbColor() const { if (isTransparent()) { diff --git a/src/link/assign.cpp b/src/link/assign.cpp index 35810c24..08be7ac0 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -183,7 +183,8 @@ static ssize_t getPlacement(Section const §ion, MemoryLocation &location) { location.bank = scrambleROMX + 1; else return -1; - } else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX && location.bank <= scrambleWRAMX) { + } else if (scrambleWRAMX && section.type == SECTTYPE_WRAMX + && location.bank <= scrambleWRAMX) { if (location.bank > typeInfo.firstBank) location.bank--; else if (scrambleWRAMX < typeInfo.lastBank) @@ -328,9 +329,11 @@ static void placeSection(Section §ion) { ); } +// clang-format off: vertically align values static constexpr uint8_t BANK_CONSTRAINED = 1 << 2; static constexpr uint8_t ORG_CONSTRAINED = 1 << 1; static constexpr uint8_t ALIGN_CONSTRAINED = 1 << 0; +// clang-format on static std::deque
unassignedSections[1 << 3]; /* diff --git a/src/link/main.cpp b/src/link/main.cpp index 7e4c1d0d..61e7938f 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -228,9 +228,7 @@ static void parseScrambleSpec(char const *spec) { // Find the next non-blank char after the region name's end spec += regionNameLen + strspn(&spec[regionNameLen], " \t"); if (*spec != '\0' && *spec != ',' && *spec != '=') { - argErr( - 'S', "Unexpected '%c' after region name \"%.*s\"", regionNameFmtLen, regionName - ); + argErr('S', "Unexpected '%c' after region name \"%.*s\"", regionNameFmtLen, regionName); // Skip to next ',' or '=' (or NUL) and keep parsing spec += 1 + strcspn(&spec[1], ",="); }