Reformat source files with clang-format 19.1.7

This commit is contained in:
Rangi42
2025-01-27 17:27:52 -05:00
committed by Rangi
parent 20c18256ed
commit a354af3d08
18 changed files with 75 additions and 81 deletions

View File

@@ -14,14 +14,7 @@
struct Expression; struct Expression;
struct FileStackNode; struct FileStackNode;
enum StateFeature { enum StateFeature { STATE_EQU, STATE_VAR, STATE_EQUS, STATE_CHAR, STATE_MACRO, NB_STATE_FEATURES };
STATE_EQU,
STATE_VAR,
STATE_EQUS,
STATE_CHAR,
STATE_MACRO,
NB_STATE_FEATURES
};
extern std::string objectFileName; extern std::string objectFileName;

View File

@@ -31,12 +31,8 @@ struct Expression {
Expression &operator=(Expression &&) = default; Expression &operator=(Expression &&) = default;
bool isKnown() const { bool isKnown() const { return data.holds<int32_t>(); }
return data.holds<int32_t>(); int32_t value() const { return data.get<int32_t>(); }
}
int32_t value() const {
return data.get<int32_t>();
}
int32_t getConstVal() const; int32_t getConstVal() const;
Symbol const *symbolOf() const; Symbol const *symbolOf() const;

View File

@@ -4,12 +4,11 @@
#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)]] void warnx(char const *fmt, ...);
[[gnu::format(printf, 1, 2)]] void warn(char const *fmt...); [[gnu::format(printf, 1, 2), noreturn]] void err(char const *fmt, ...);
[[gnu::format(printf, 1, 2)]] void warnx(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 #endif // RGBDS_ERROR_HPP

View File

@@ -6,25 +6,23 @@
#define RGBDS_EXTERN_GETOPT_HPP #define RGBDS_EXTERN_GETOPT_HPP
extern "C" { extern "C" {
extern char *musl_optarg;
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
extern char *musl_optarg; struct option {
extern int musl_optind, musl_opterr, musl_optopt, musl_optreset;
struct option {
char const *name; char const *name;
int has_arg; int has_arg;
int *flag; int *flag;
int val; int val;
}; };
int musl_getopt_long_only( int musl_getopt_long_only(
int argc, char **argv, char const *optstring, option const *longopts, int *idx int argc, char **argv, char const *optstring, option const *longopts, int *idx
); );
#define no_argument 0 #define no_argument 0
#define required_argument 1 #define required_argument 1
#define optional_argument 2 #define optional_argument 2
}
} // extern "C"
#endif // RGBDS_EXTERN_GETOPT_HPP #endif // RGBDS_EXTERN_GETOPT_HPP

View File

@@ -48,6 +48,7 @@ struct Options {
std::string input{}; // positional arg 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_NONE = 0; // Normal, no extra output
static constexpr uint8_t VERB_CFG = 1; // Print configuration after parsing options 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_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_DEBUG = 4; // Internals are logged
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
[[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;

View File

@@ -3,13 +3,12 @@
#ifndef RGBDS_VERSION_HPP #ifndef RGBDS_VERSION_HPP
#define RGBDS_VERSION_HPP #define RGBDS_VERSION_HPP
extern "C" {
#define PACKAGE_VERSION_MAJOR 0 #define PACKAGE_VERSION_MAJOR 0
#define PACKAGE_VERSION_MINOR 9 #define PACKAGE_VERSION_MINOR 9
#define PACKAGE_VERSION_PATCH 0 #define PACKAGE_VERSION_PATCH 0
char const *get_package_version_string(); extern "C" {
char const *get_package_version_string();
} }
#endif // RGBDS_VERSION_H #endif // RGBDS_VERSION_H

View File

@@ -45,7 +45,10 @@ bool charmap_ForEach(
for (Charmap const &charmap : charmapList) { for (Charmap const &charmap : charmapList) {
// Traverse the trie depth-first to derive the character mappings in definition order // Traverse the trie depth-first to derive the character mappings in definition order
std::map<size_t, std::string> mappings; std::map<size_t, std::string> mappings;
for (std::stack<std::pair<size_t, std::string>> prefixes({{0, ""}}); !prefixes.empty();) { // clang-format off: nested initializers
for (std::stack<std::pair<size_t, std::string>> prefixes({{0, ""}});
!prefixes.empty();) {
// clang-format on
auto [nodeIdx, mapping] = std::move(prefixes.top()); auto [nodeIdx, mapping] = std::move(prefixes.top());
prefixes.pop(); prefixes.pop();
CharmapNode const &node = charmap.nodes[nodeIdx]; CharmapNode const &node = charmap.nodes[nodeIdx];

View File

@@ -477,9 +477,7 @@ void sect_SetLoadSection(
void sect_EndLoadSection(char const *cause) { void sect_EndLoadSection(char const *cause) {
if (cause) if (cause)
warning( warning(
WARNING_UNTERMINATED_LOAD, WARNING_UNTERMINATED_LOAD, "`LOAD` block without `ENDL` terminated by `%s`\n", cause
"`LOAD` block without `ENDL` terminated by `%s`\n",
cause
); );
if (!currentLoadSection) { if (!currentLoadSection) {

View File

@@ -35,13 +35,13 @@ struct WarningFlag {
WarningLevel level; WarningLevel level;
}; };
static const WarningFlag metaWarnings[] = { static WarningFlag const metaWarnings[] = {
{"all", LEVEL_ALL }, {"all", LEVEL_ALL },
{"extra", LEVEL_EXTRA }, {"extra", LEVEL_EXTRA },
{"everything", LEVEL_EVERYTHING}, {"everything", LEVEL_EVERYTHING},
}; };
static const WarningFlag warningFlags[NB_WARNINGS] = { static WarningFlag const warningFlags[NB_WARNINGS] = {
{"assert", LEVEL_DEFAULT }, {"assert", LEVEL_DEFAULT },
{"backwards-for", LEVEL_ALL }, {"backwards-for", LEVEL_ALL },
{"builtin-args", LEVEL_ALL }, {"builtin-args", LEVEL_ALL },

View File

@@ -385,12 +385,14 @@ static MbcType parseMBC(char const *name) {
// Read "additional features" // Read "additional features"
uint8_t features = 0; uint8_t features = 0;
// clang-format off: vertically align values
static constexpr uint8_t RAM = 1 << 7; static constexpr uint8_t RAM = 1 << 7;
static constexpr uint8_t BATTERY = 1 << 6; static constexpr uint8_t BATTERY = 1 << 6;
static constexpr uint8_t TIMER = 1 << 5; static constexpr uint8_t TIMER = 1 << 5;
static constexpr uint8_t RUMBLE = 1 << 4; static constexpr uint8_t RUMBLE = 1 << 4;
static constexpr uint8_t SENSOR = 1 << 3; static constexpr uint8_t SENSOR = 1 << 3;
static constexpr uint8_t MULTIRUMBLE = 1 << 2; static constexpr uint8_t MULTIRUMBLE = 1 << 2;
// clang-format on
for (;;) { for (;;) {
// Trim off trailing whitespace // Trim off trailing whitespace
@@ -742,12 +744,14 @@ static uint8_t const nintendoLogo[] = {
}; };
static uint8_t fixSpec = 0; static uint8_t fixSpec = 0;
// clang-format off: vertically align values
static constexpr uint8_t FIX_LOGO = 1 << 7; static constexpr uint8_t FIX_LOGO = 1 << 7;
static constexpr uint8_t TRASH_LOGO = 1 << 6; static constexpr uint8_t TRASH_LOGO = 1 << 6;
static constexpr uint8_t FIX_HEADER_SUM = 1 << 5; static constexpr uint8_t FIX_HEADER_SUM = 1 << 5;
static constexpr uint8_t TRASH_HEADER_SUM = 1 << 4; static constexpr uint8_t TRASH_HEADER_SUM = 1 << 4;
static constexpr uint8_t FIX_GLOBAL_SUM = 1 << 3; static constexpr uint8_t FIX_GLOBAL_SUM = 1 << 3;
static constexpr uint8_t TRASH_GLOBAL_SUM = 1 << 2; 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 enum { DMG, BOTH, CGB } model = DMG; // If DMG, byte is left alone
static char const *gameID = nullptr; static char const *gameID = nullptr;
@@ -1083,8 +1087,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize)
globalSum = ~globalSum; globalSum = ~globalSum;
uint8_t bytes[2] = { uint8_t bytes[2] = {
static_cast<uint8_t>(globalSum >> 8), static_cast<uint8_t>(globalSum >> 8), static_cast<uint8_t>(globalSum & 0xFF)
static_cast<uint8_t>(globalSum & 0xFF)
}; };
overwriteBytes(rom0, 0x14E, bytes, sizeof(bytes), "global checksum"); overwriteBytes(rom0, 0x14E, bytes, sizeof(bytes), "global checksum");

View File

@@ -194,8 +194,7 @@ static T readLE(U const *bytes) {
* *
* @return true if a line was read. * @return true if a line was read.
*/ */
[[gnu::warn_unused_result]] // Ignoring EOF is a bad idea. [[gnu::warn_unused_result]] static bool readLine(std::filebuf &file, std::string &buffer) {
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 (;;) {

View File

@@ -712,8 +712,9 @@ static void hashBitplanes(uint16_t bitplanes, uint16_t &hash) {
class TileData { class TileData {
// Importantly, `TileData` is **always** 2bpp. // Importantly, `TileData` is **always** 2bpp.
// If the active bit depth is 1bpp, all tiles are processed as 2bpp nonetheless, but emitted as 1bpp. // If the active bit depth is 1bpp, all tiles are processed as 2bpp nonetheless, but emitted as
// This massively simplifies internal processing, since bit depth is always identical outside of I/O / serialization boundaries. // 1bpp. This massively simplifies internal processing, since bit depth is always identical
// outside of I/O / serialization boundaries.
std::array<uint8_t, 16> _data; std::array<uint8_t, 16> _data;
// The hash is a bit lax: it's the XOR of all lines, and every other nibble is identical // 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 // if horizontal mirroring is in effect. It should still be a reasonable tie-breaker in

View File

@@ -15,24 +15,26 @@
* since commit b5a611c5db46d6a0649d04d24d8d6339200f9ca1 (Dec 2020), * since commit b5a611c5db46d6a0649d04d24d8d6339200f9ca1 (Dec 2020),
* with gaps in the scale curve filled by polynomial interpolation. * with gaps in the scale curve filled by polynomial interpolation.
*/ */
// clang-format off: vertically align columns of values
static std::array<uint8_t, 256> reverse_curve{ static std::array<uint8_t, 256> reverse_curve{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, // These 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, // comments 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, // prevent 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, // clang-format 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, // from 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, // reflowing 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, // these 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, // sixteen 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, // 16-item 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, // lines, 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, // which, 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, // in 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, // my 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, // opinion, 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, // help 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, // visualization! 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
}; };
// clang-format on
uint16_t Rgba::cgbColor() const { uint16_t Rgba::cgbColor() const {
if (isTransparent()) { if (isTransparent()) {

View File

@@ -183,7 +183,8 @@ static ssize_t getPlacement(Section const &section, MemoryLocation &location) {
location.bank = scrambleROMX + 1; location.bank = scrambleROMX + 1;
else else
return -1; 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) if (location.bank > typeInfo.firstBank)
location.bank--; location.bank--;
else if (scrambleWRAMX < typeInfo.lastBank) else if (scrambleWRAMX < typeInfo.lastBank)
@@ -328,9 +329,11 @@ static void placeSection(Section &section) {
); );
} }
// clang-format off: vertically align values
static constexpr uint8_t BANK_CONSTRAINED = 1 << 2; static constexpr uint8_t BANK_CONSTRAINED = 1 << 2;
static constexpr uint8_t ORG_CONSTRAINED = 1 << 1; static constexpr uint8_t ORG_CONSTRAINED = 1 << 1;
static constexpr uint8_t ALIGN_CONSTRAINED = 1 << 0; static constexpr uint8_t ALIGN_CONSTRAINED = 1 << 0;
// clang-format on
static std::deque<Section *> unassignedSections[1 << 3]; static std::deque<Section *> unassignedSections[1 << 3];
/* /*

View File

@@ -228,9 +228,7 @@ static void parseScrambleSpec(char const *spec) {
// Find the next non-blank char after the region name's end // Find the next non-blank char after the region name's end
spec += regionNameLen + strspn(&spec[regionNameLen], " \t"); spec += regionNameLen + strspn(&spec[regionNameLen], " \t");
if (*spec != '\0' && *spec != ',' && *spec != '=') { if (*spec != '\0' && *spec != ',' && *spec != '=') {
argErr( argErr('S', "Unexpected '%c' after region name \"%.*s\"", regionNameFmtLen, regionName);
'S', "Unexpected '%c' after region name \"%.*s\"", regionNameFmtLen, regionName
);
// Skip to next ',' or '=' (or NUL) and keep parsing // Skip to next ',' or '=' (or NUL) and keep parsing
spec += 1 + strcspn(&spec[1], ",="); spec += 1 + strcspn(&spec[1], ",=");
} }