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 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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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:

View File

@@ -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

View File

@@ -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<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());
prefixes.pop();
CharmapNode const &node = charmap.nodes[nodeIdx];

View File

@@ -190,7 +190,7 @@ static std::unordered_map<std::string, int, CaseInsensitive, CaseInsensitive> 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<std::string, int, CaseInsensitive, CaseInsensitive> 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<ViewedContent>();
return {
.lineNo = lineNo, .span = {.ptr = view.makeSharedContentPtr(), .size = 0}
};
};
} else {
assume(lexerState->captureBuf == nullptr);
lexerState->captureBuf = std::make_shared<std::vector<char>>();
// `.span.ptr == nullptr`; indicates to retrieve the capture buffer when done capturing
return {
.lineNo = lineNo, .span = {.ptr = nullptr, .size = 0}
};
};
}
}

View File

@@ -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<int32_t>(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!

View File

@@ -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) {

View File

@@ -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 },

View File

@@ -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<uint8_t>(globalSum >> 8),
static_cast<uint8_t>(globalSum & 0xFF)
static_cast<uint8_t>(globalSum >> 8), static_cast<uint8_t>(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

View File

@@ -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 (;;) {

View File

@@ -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<uint8_t, 16> _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

View File

@@ -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<uint8_t, 256> 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()) {

View File

@@ -183,7 +183,8 @@ static ssize_t getPlacement(Section const &section, 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 &section) {
);
}
// 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<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
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], ",=");
}