diff --git a/.clang-format b/.clang-format index cd82ea10..7380e7d4 100644 --- a/.clang-format +++ b/.clang-format @@ -69,6 +69,7 @@ MaxEmptyLinesToKeep: 1 NamespaceIndentation: None PPIndentWidth: -1 PointerAlignment: Right +QualifierAlignment: Right ReflowComments: true SortIncludes: CaseSensitive SortUsingDeclarations: true diff --git a/include/asm/fstack.hpp b/include/asm/fstack.hpp index 268ffe52..81011242 100644 --- a/include/asm/fstack.hpp +++ b/include/asm/fstack.hpp @@ -40,7 +40,7 @@ struct FileStackNode { std::string const &name() const; FileStackNode(FileStackNodeType type_, std::variant, std::string> data_) - : type(type_), data(data_) {}; + : type(type_), data(data_){}; void dump(uint32_t curLineNo) const; }; diff --git a/include/asm/output.hpp b/include/asm/output.hpp index 43fc244e..32f2bc22 100644 --- a/include/asm/output.hpp +++ b/include/asm/output.hpp @@ -10,7 +10,7 @@ struct Expression; struct FileStackNode; -extern const char *objectName; +extern char const *objectName; void out_RegisterNode(FileStackNode *node); void out_ReplaceNode(FileStackNode *node); diff --git a/include/asm/rpn.hpp b/include/asm/rpn.hpp index 435efa11..42c539d0 100644 --- a/include/asm/rpn.hpp +++ b/include/asm/rpn.hpp @@ -27,7 +27,7 @@ struct Expression { Expression(Expression &&) = default; #ifdef _MSC_VER // MSVC and WinFlexBison won't build without this... - Expression(const Expression &) = default; + Expression(Expression const &) = default; #endif Expression &operator=(Expression &&) = default; @@ -36,10 +36,10 @@ struct Expression { void rpn_Number(Expression &expr, uint32_t val); void rpn_Symbol(Expression &expr, char const *symName); void rpn_LOGNOT(Expression &expr, Expression &&src); -void rpn_BinaryOp(RPNCommand op, Expression &expr, Expression &&src1, const Expression &src2); +void rpn_BinaryOp(RPNCommand op, Expression &expr, Expression &&src1, Expression const &src2); void rpn_HIGH(Expression &expr, Expression &&src); void rpn_LOW(Expression &expr, Expression &&src); -void rpn_ISCONST(Expression &expr, const Expression &src); +void rpn_ISCONST(Expression &expr, Expression const &src); void rpn_NEG(Expression &expr, Expression &&src); void rpn_NOT(Expression &expr, Expression &&src); void rpn_BankSymbol(Expression &expr, char const *symName); @@ -52,6 +52,6 @@ void rpn_StartOfSectionType(Expression &expr, SectionType type); void rpn_CheckHRAM(Expression &expr); void rpn_CheckRST(Expression &expr); -void rpn_CheckNBit(const Expression &expr, uint8_t n); +void rpn_CheckNBit(Expression const &expr, uint8_t n); #endif // RGBDS_ASM_RPN_H diff --git a/include/extern/getopt.hpp b/include/extern/getopt.hpp index fc6a892b..b5d56ee5 100644 --- a/include/extern/getopt.hpp +++ b/include/extern/getopt.hpp @@ -18,7 +18,7 @@ struct option { }; int musl_getopt_long_only( - int argc, char **argv, char const *optstring, const option *longopts, int *idx + int argc, char **argv, char const *optstring, option const *longopts, int *idx ); #define no_argument 0 diff --git a/include/platform.hpp b/include/platform.hpp index 3937279a..7118d300 100644 --- a/include/platform.hpp +++ b/include/platform.hpp @@ -19,7 +19,7 @@ #ifdef _MSC_VER #define S_IFMT _S_IFMT #define S_IFDIR _S_IFDIR - #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) + #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) #endif // MSVC doesn't use POSIX types or defines for `read` @@ -40,7 +40,7 @@ #ifdef _MSC_VER #include #define O_RDWR _O_RDWR - #define S_ISREG(field) ((field) & _S_IFREG) + #define S_ISREG(field) ((field)&_S_IFREG) #define O_BINARY _O_BINARY #define O_TEXT _O_TEXT #elif !defined(O_BINARY) // Cross-compilers define O_BINARY diff --git a/src/asm/fstack.cpp b/src/asm/fstack.cpp index 6ccc1720..04d69ede 100644 --- a/src/asm/fstack.cpp +++ b/src/asm/fstack.cpp @@ -38,7 +38,7 @@ size_t maxRecursionDepth; // The first include path for `fstk_FindFile` to try is none at all static std::vector includePaths = {""}; -static const char *preIncludeName; +static char const *preIncludeName; std::vector &FileStackNode::iters() { assert(std::holds_alternative>(data)); @@ -60,7 +60,7 @@ std::string const &FileStackNode::name() const { return std::get(data); } -static const char *dumpNodeAndParents(FileStackNode const &node) { +static char const *dumpNodeAndParents(FileStackNode const &node) { char const *name; if (node.type == NODE_REPT) { diff --git a/src/asm/main.cpp b/src/asm/main.cpp index 01eca30b..13e6270f 100644 --- a/src/asm/main.cpp +++ b/src/asm/main.cpp @@ -77,7 +77,7 @@ static std::string make_escape(std::string &str) { } // Short options -static const char *optstring = "b:D:Eg:Hhi:I:LlM:o:P:p:Q:r:VvW:wX:"; +static char const *optstring = "b:D:Eg:Hhi:I:LlM:o:P:p:Q:r:VvW:wX:"; // Variables for the long-only options static int depType; // Variants of `-M` @@ -279,7 +279,7 @@ int main(int argc, char *argv[]) { break; unsigned long precision; - const char *precisionArg; + char const *precisionArg; case 'Q': precisionArg = musl_optarg; if (precisionArg[0] == '.') diff --git a/src/asm/opt.cpp b/src/asm/opt.cpp index fd604b19..5cadfada 100644 --- a/src/asm/opt.cpp +++ b/src/asm/opt.cpp @@ -106,7 +106,7 @@ void opt_Parse(char const *s) { } break; - const char *precisionArg; + char const *precisionArg; case 'Q': precisionArg = &s[1]; if (precisionArg[0] == '.') diff --git a/src/asm/output.cpp b/src/asm/output.cpp index 53dbd775..1641ed34 100644 --- a/src/asm/output.cpp +++ b/src/asm/output.cpp @@ -29,7 +29,7 @@ struct Assertion { std::string message; }; -const char *objectName; +char const *objectName; // List of symbols to put in the object file static std::vector objectSymbols; @@ -159,7 +159,7 @@ static uint32_t getSymbolID(Symbol &sym) { return sym.ID; } -static void writerpn(std::vector &rpnexpr, const std::vector &rpn) { +static void writerpn(std::vector &rpnexpr, std::vector const &rpn) { std::string symName; size_t rpnptr = 0; diff --git a/src/asm/parser.y b/src/asm/parser.y index af867dce..2b0a553c 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -38,7 +38,7 @@ StrFmtArgList(StrFmtArgList &&) = default; #ifdef _MSC_VER // MSVC and WinFlexBison won't build without this... - StrFmtArgList(const StrFmtArgList &) = default; + StrFmtArgList(StrFmtArgList const &) = default; #endif StrFmtArgList &operator=(StrFmtArgList &&) = default; @@ -73,7 +73,7 @@ static void upperstring(char *dest, char const *src); static void lowerstring(char *dest, char const *src); static uint32_t str2int2(std::vector const &s); - static const char *strrstr(char const *s1, char const *s2); + static char const *strrstr(char const *s1, char const *s2); static void errorInvalidUTF8Byte(uint8_t byte, char const *functionName); static size_t strlenUTF8(char const *s); static void strsubUTF8(char *dest, size_t destLen, char const *src, uint32_t pos, uint32_t len); @@ -84,10 +84,12 @@ char *dest, size_t destLen, char const *src, char const *old, char const *rep ); static void strfmt( - char *dest, size_t destLen, char const *spec, + char *dest, + size_t destLen, + char const *spec, std::vector> &args ); - static void compoundAssignment(const char *symName, RPNCommand op, int32_t constValue); + static void compoundAssignment(char const *symName, RPNCommand op, int32_t constValue); static void failAssert(AssertionType type); static void failAssertMsg(AssertionType type, char const *msg); @@ -628,7 +630,7 @@ assignment: sym_AddVar($1.c_str(), $3); } | LABEL compoundeq const { - const char *compoundEqOperator = nullptr; + char const *compoundEqOperator = nullptr; switch ($2) { case RPN_ADD: compoundEqOperator = "+="; break; case RPN_SUB: compoundEqOperator = "-="; break; @@ -2471,7 +2473,8 @@ static uint32_t str2int2(std::vector const &s) { if (length > 4) warning( WARNING_NUMERIC_STRING_1, - "Treating string as a number ignores first %" PRIu32 " character%s\n", length - 4, + "Treating string as a number ignores first %" PRIu32 " character%s\n", + length - 4, length == 5 ? "" : "s" ); else if (length > 1) @@ -2489,7 +2492,7 @@ static uint32_t str2int2(std::vector const &s) { return r; } -static const char *strrstr(char const *s1, char const *s2) { +static char const *strrstr(char const *s1, char const *s2) { size_t len1 = strlen(s1); size_t len2 = strlen(s2); @@ -2605,7 +2608,8 @@ static void charsubUTF8(char *dest, char const *src, uint32_t pos) { if (!charmap_ConvertNext(src, nullptr)) warning( - WARNING_BUILTIN_ARG, "CHARSUB: Position %" PRIu32 " is past the end of the string\n", + WARNING_BUILTIN_ARG, + "CHARSUB: Position %" PRIu32 " is past the end of the string\n", pos ); @@ -2672,7 +2676,9 @@ static void strrpl(char *dest, size_t destLen, char const *src, char const *old, } static void strfmt( - char *dest, size_t destLen, char const *spec, + char *dest, + size_t destLen, + char const *spec, std::vector> &args ) { size_t a = 0; @@ -2748,7 +2754,7 @@ static void strfmt( dest[i] = '\0'; } -static void compoundAssignment(const char *symName, RPNCommand op, int32_t constValue) { +static void compoundAssignment(char const *symName, RPNCommand op, int32_t constValue) { Expression oldExpr, constExpr, newExpr; int32_t newValue; diff --git a/src/asm/rpn.cpp b/src/asm/rpn.cpp index 2f884929..7c987c2f 100644 --- a/src/asm/rpn.cpp +++ b/src/asm/rpn.cpp @@ -232,7 +232,7 @@ void rpn_CheckRST(Expression &expr) { } // Checks that an RPN expression's value fits within N bits (signed or unsigned) -void rpn_CheckNBit(const Expression &expr, uint8_t n) { +void rpn_CheckNBit(Expression const &expr, uint8_t n) { assert(n != 0); // That doesn't make sense assert(n < CHAR_BIT * sizeof(int)); // Otherwise `1 << n` is UB @@ -324,7 +324,7 @@ static int32_t tryConstMask(Expression const &lhs, Expression const &rhs) { return (symbolOfs + sect.alignOfs) & ~unknownBits; } -void rpn_BinaryOp(RPNCommand op, Expression &expr, Expression &&src1, const Expression &src2) { +void rpn_BinaryOp(RPNCommand op, Expression &expr, Expression &&src1, Expression const &src2) { initExpression(expr); expr.isSymbol = false; int32_t constMaskVal; @@ -570,7 +570,7 @@ void rpn_LOW(Expression &expr, Expression &&src) { } } -void rpn_ISCONST(Expression &expr, const Expression &src) { +void rpn_ISCONST(Expression &expr, Expression const &src) { initExpression(expr); expr.val = src.isKnown; expr.isKnown = true; diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp index 70e7f7d2..e2debec7 100644 --- a/src/asm/symbol.cpp +++ b/src/asm/symbol.cpp @@ -589,7 +589,7 @@ void sym_Init(time_t now) { now = 0; } - const tm *time_local = localtime(&now); + tm const *time_local = localtime(&now); strftime(savedTIME, sizeof(savedTIME), "\"%H:%M:%S\"", time_local); strftime(savedDATE, sizeof(savedDATE), "\"%d %B %Y\"", time_local); @@ -600,7 +600,7 @@ void sym_Init(time_t now) { time_local ); - const tm *time_utc = gmtime(&now); + tm const *time_utc = gmtime(&now); strftime( savedTIMESTAMP_ISO8601_UTC, diff --git a/src/asm/warning.cpp b/src/asm/warning.cpp index 946f9ac9..f40a1d76 100644 --- a/src/asm/warning.cpp +++ b/src/asm/warning.cpp @@ -67,7 +67,7 @@ static WarningState warningState(WarningID id) { return state; } -static const char * const warningFlags[NB_WARNINGS] = { +static char const * const warningFlags[NB_WARNINGS] = { "assert", "backwards-for", "builtin-args", diff --git a/src/error.cpp b/src/error.cpp index 64c6e1dc..1550d3c1 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -9,7 +9,7 @@ #include static void vwarn(char const *fmt, va_list ap) { - const char *error = strerror(errno); + char const *error = strerror(errno); fprintf(stderr, "warning: "); vfprintf(stderr, fmt, ap); @@ -23,7 +23,7 @@ static void vwarnx(char const *fmt, va_list ap) { } [[noreturn]] static void verr(char const *fmt, va_list ap) { - const char *error = strerror(errno); + char const *error = strerror(errno); fprintf(stderr, "error: "); vfprintf(stderr, fmt, ap); diff --git a/src/extern/getopt.cpp b/src/extern/getopt.cpp index d9b3c856..db798d51 100644 --- a/src/extern/getopt.cpp +++ b/src/extern/getopt.cpp @@ -114,11 +114,11 @@ static void permute(char **argv, int dest, int src) { } static int musl_getopt_long_core( - int argc, char **argv, char const *optstring, const option *longopts, int *idx, int longonly + int argc, char **argv, char const *optstring, option const *longopts, int *idx, int longonly ); static int musl_getopt_long( - int argc, char **argv, char const *optstring, const option *longopts, int *idx, int longonly + int argc, char **argv, char const *optstring, option const *longopts, int *idx, int longonly ) { int ret, skipped, resumed; @@ -155,7 +155,7 @@ static int musl_getopt_long( } static int musl_getopt_long_core( - int argc, char **argv, char const *optstring, const option *longopts, int *idx, int longonly + int argc, char **argv, char const *optstring, option const *longopts, int *idx, int longonly ) { musl_optarg = 0; if (longopts && argv[musl_optind][0] == '-' @@ -260,7 +260,7 @@ static int musl_getopt_long_core( } int musl_getopt_long_only( - int argc, char **argv, char const *optstring, const option *longopts, int *idx + int argc, char **argv, char const *optstring, option const *longopts, int *idx ) { return musl_getopt_long(argc, argv, optstring, longopts, idx, 1); } diff --git a/src/fix/main.cpp b/src/fix/main.cpp index 8b1489af..90162d6d 100644 --- a/src/fix/main.cpp +++ b/src/fix/main.cpp @@ -24,7 +24,7 @@ #define BANK_SIZE 0x4000 // Short options -static const char *optstring = "Ccf:i:jk:l:m:n:Op:r:st:Vv"; +static char const *optstring = "Ccf:i:jk:l:m:n:Op:r:st:Vv"; /* * Equivalent long options @@ -754,10 +754,10 @@ static enum { DMG, BOTH, CGB } model = DMG; // If DMG, byte is left alone #define FIX_GLOBAL_SUM 0x08 #define TRASH_GLOBAL_SUM 0x04 static uint8_t fixSpec = 0; -static const char *gameID = nullptr; +static char const *gameID = nullptr; static uint8_t gameIDLen; static bool japanese = true; -static const char *newLicensee = nullptr; +static char const *newLicensee = nullptr; static uint8_t newLicenseeLen; static uint16_t oldLicensee = UNSPECIFIED; static MbcType cartridgeType = MBC_NONE; @@ -766,7 +766,7 @@ static bool overwriteRom = false; // If false, warn when overwriting non-zero no static uint16_t padValue = UNSPECIFIED; static uint16_t ramSize = UNSPECIFIED; static bool sgb = false; // If false, SGB flags are left alone -static const char *title = nullptr; +static char const *title = nullptr; static uint8_t titleLen; static uint8_t maxTitleLen() { diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index 46224ac4..64c2f377 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -789,7 +789,7 @@ int main(int argc, char *argv[]) { }()); if (options.palSpecType == Options::EXPLICIT) { fputs("\t[\n", stderr); - for (const auto &pal : options.palSpec) { + for (auto const &pal : options.palSpec) { fputs("\t\t", stderr); for (auto &color : pal) { if (color) { diff --git a/src/gfx/pal_spec.cpp b/src/gfx/pal_spec.cpp index 909617c4..3b685dfe 100644 --- a/src/gfx/pal_spec.cpp +++ b/src/gfx/pal_spec.cpp @@ -14,8 +14,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index c1ebd540..721ea095 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -21,7 +21,7 @@ #include "gfx/main.hpp" -static DefaultInitVec readInto(const std::string &path) { +static DefaultInitVec readInto(std::string const &path) { File file; if (!file.open(path, std::ios::in | std::ios::binary)) { fatal("Failed to open \"%s\": %s", file.c_str(path), strerror(errno)); diff --git a/src/link/main.cpp b/src/link/main.cpp index 81a79086..c46f4992 100644 --- a/src/link/main.cpp +++ b/src/link/main.cpp @@ -150,7 +150,7 @@ void argErr(char flag, char const *fmt, ...) { } // Short options -static const char *optstring = "dl:m:Mn:O:o:p:S:s:tVvWwx"; +static char const *optstring = "dl:m:Mn:O:o:p:S:s:tVvWwx"; /* * Equivalent long options diff --git a/src/link/script.y b/src/link/script.y index d6bcb77a..f48d44a0 100644 --- a/src/link/script.y +++ b/src/link/script.y @@ -33,7 +33,7 @@ using namespace std::literals; - static void includeFile(std::string &&path); + static void includeFile(std::string && path); static void incLineNo(); static void setSectionType(SectionType type); @@ -145,8 +145,7 @@ optional: 0, \ "%s(%" PRIu32 "): " fmt, \ context.path.c_str(), \ - context.lineNo __VA_OPT__(, ) \ - __VA_ARGS__ \ + context.lineNo __VA_OPT__(, ) __VA_ARGS__ \ ) // Lexer. @@ -406,14 +405,20 @@ static void setSectionType(SectionType type, uint32_t bank) { if (bank < typeInfo.firstBank) { scriptError( - context, "%s bank %" PRIu32 " doesn't exist (the minimum is %" PRIu32 ")", - typeInfo.name.c_str(), bank, typeInfo.firstBank + context, + "%s bank %" PRIu32 " doesn't exist (the minimum is %" PRIu32 ")", + typeInfo.name.c_str(), + bank, + typeInfo.firstBank ); bank = typeInfo.firstBank; } else if (bank > typeInfo.lastBank) { scriptError( - context, "%s bank %" PRIu32 " doesn't exist (the maximum is %" PRIu32 ")", - typeInfo.name.c_str(), bank, typeInfo.lastBank + context, + "%s bank %" PRIu32 " doesn't exist (the maximum is %" PRIu32 ")", + typeInfo.name.c_str(), + bank, + typeInfo.lastBank ); } @@ -434,8 +439,11 @@ static void setAddr(uint32_t addr) { scriptError(context, "Cannot decrease the current address (from $%04x to $%04x)", pc, addr); } else if (addr > endaddr(activeType)) { // Allow "one past the end" sections. scriptError( - context, "Cannot set the current address to $%04" PRIx32 ": %s ends at $%04" PRIx16 "", - addr, typeInfo.name.c_str(), endaddr(activeType) + context, + "Cannot set the current address to $%04" PRIx32 ": %s ends at $%04" PRIx16 "", + addr, + typeInfo.name.c_str(), + endaddr(activeType) ); pc = endaddr(activeType); } else { @@ -476,7 +484,8 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) { context, "Cannot align: The alignment offset (%" PRIu32 ") must be less than alignment size (%" PRIu32 ")", - alignOfs, alignSize + alignOfs, + alignSize ); return; } @@ -508,7 +517,8 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) { context, "Cannot align: The alignment offset (%" PRIu32 ") must be less than alignment size (%" PRIu32 ")", - alignOfs, alignSize + alignOfs, + alignSize ); return; } @@ -522,7 +532,9 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) { context, "Cannot align: the next suitable address after $%04" PRIx16 " is $%04" PRIx16 ", past $%04" PRIx16, - pc, (uint16_t)(pc + length), (uint16_t)(endaddr(activeType) + 1) + pc, + (uint16_t)(pc + length), + (uint16_t)(endaddr(activeType) + 1) ); return; } @@ -549,8 +561,10 @@ static void pad(uint32_t length) { if (uint16_t offset = pc - typeInfo.startAddr; length + offset > typeInfo.size) { scriptError( context, - "Cannot increase the current address by %u bytes: only %u bytes to $%04" PRIx16, length, - typeInfo.size - offset, (uint16_t)(endaddr(activeType) + 1) + "Cannot increase the current address by %u bytes: only %u bytes to $%04" PRIx16, + length, + typeInfo.size - offset, + (uint16_t)(endaddr(activeType) + 1) ); } else { pc += length; @@ -584,8 +598,11 @@ static void placeSection(std::string const &name, bool isOptional) { } } else if (section->type != activeType) { scriptError( - context, "\"%s\" is specified to be a %s section, but it is already a %s section", - name.c_str(), typeInfo.name.c_str(), sectionTypeInfo[section->type].name.c_str() + context, + "\"%s\" is specified to be a %s section, but it is already a %s section", + name.c_str(), + typeInfo.name.c_str(), + sectionTypeInfo[section->type].name.c_str() ); } @@ -595,7 +612,10 @@ static void placeSection(std::string const &name, bool isOptional) { context, "The linker script places section \"%s\" in %s bank %" PRIu32 ", but it was already defined in bank %" PRIu32, - name.c_str(), sectionTypeInfo[section->type].name.c_str(), bank, section->bank + name.c_str(), + sectionTypeInfo[section->type].name.c_str(), + bank, + section->bank ); } section->isBankFixed = true; @@ -608,7 +628,9 @@ static void placeSection(std::string const &name, bool isOptional) { context, "The linker script assigns section \"%s\" to address $%04" PRIx16 ", but it was already at $%04" PRIx16, - name.c_str(), org, section->org + name.c_str(), + org, + section->org ); } else if (section->isAlignFixed && (org & section->alignMask) != section->alignOfs) { uint8_t alignment = std::countr_one(section->alignMask); @@ -617,7 +639,11 @@ static void placeSection(std::string const &name, bool isOptional) { "The linker script assigns section \"%s\" to address $%04" PRIx16 ", but that would be ALIGN[%" PRIu8 ", %" PRIu16 "] instead of the requested ALIGN[%" PRIu8 ", %" PRIu16 "]", - name.c_str(), org, alignment, (uint16_t)(org & section->alignMask), alignment, + name.c_str(), + org, + alignment, + (uint16_t)(org & section->alignMask), + alignment, section->alignOfs ); } @@ -632,7 +658,11 @@ static void placeSection(std::string const &name, bool isOptional) { context, "The linker script assigns section \"%s\" to address $%04" PRIx16 ", but then it would overflow %s by %" PRIu16 " byte%s", - name.c_str(), org, typeInfo.name.c_str(), overflowSize, overflowSize == 1 ? "" : "s" + name.c_str(), + org, + typeInfo.name.c_str(), + overflowSize, + overflowSize == 1 ? "" : "s" ); // Fill as much as possible without going out of bounds. org = typeInfo.startAddr + typeInfo.size;