Use more concrete types instead of auto

This commit is contained in:
Rangi42
2025-07-17 23:48:08 -04:00
parent 60cec85638
commit e99ff5ac45
2 changed files with 43 additions and 43 deletions

View File

@@ -144,7 +144,7 @@ public:
return false; return false;
} }
uint8_t bins = 0; uint8_t bins = 0;
for (auto const &color : colors) { for (std::optional<Rgba> const &color : colors) {
if (!color.has_value() || color->isTransparent()) { if (!color.has_value() || color->isTransparent()) {
continue; continue;
} }
@@ -299,7 +299,7 @@ public:
Options::VERB_INTERM, "Embedded palette has %d colors: [", nbColors Options::VERB_INTERM, "Embedded palette has %d colors: [", nbColors
); );
for (int i = 0; i < nbColors; ++i) { for (int i = 0; i < nbColors; ++i) {
auto const &color = embeddedPal[i]; png_color const &color = embeddedPal[i];
options.verbosePrint( options.verbosePrint(
Options::VERB_INTERM, Options::VERB_INTERM,
"#%02x%02x%02x%02x%s", "#%02x%02x%02x%02x%s",
@@ -604,7 +604,7 @@ static std::tuple<std::vector<size_t>, std::vector<Palette>>
} }
// Generate the actual palettes from the mappings // Generate the actual palettes from the mappings
for (size_t protoPalID = 0; protoPalID < mappings.size(); ++protoPalID) { for (size_t protoPalID = 0; protoPalID < mappings.size(); ++protoPalID) {
auto &pal = palettes[mappings[protoPalID]]; Palette &pal = palettes[mappings[protoPalID]];
for (uint16_t color : protoPalettes[protoPalID]) { for (uint16_t color : protoPalettes[protoPalID]) {
pal.addColor(color); pal.addColor(color);
} }
@@ -688,7 +688,7 @@ static std::tuple<std::vector<size_t>, std::vector<Palette>>
static void outputPalettes(std::vector<Palette> const &palettes) { static void outputPalettes(std::vector<Palette> const &palettes) {
// LCOV_EXCL_START // LCOV_EXCL_START
if (options.verbosity >= Options::VERB_INTERM) { if (options.verbosity >= Options::VERB_INTERM) {
for (auto &&palette : palettes) { for (Palette const &palette : palettes) {
fputs("{ ", stderr); fputs("{ ", stderr);
for (uint16_t colorIndex : palette) { for (uint16_t colorIndex : palette) {
fprintf(stderr, "%04" PRIx16 ", ", colorIndex); fprintf(stderr, "%04" PRIx16 ", ", colorIndex);
@@ -790,7 +790,7 @@ public:
} }
} }
auto const &data() const { return _data; } std::array<uint8_t, 16> const &data() const { return _data; }
uint16_t hash() const { return _hash; } uint16_t hash() const { return _hash; }
enum MatchType { enum MatchType {
@@ -933,7 +933,7 @@ static void outputUnoptimizedMaps(
uint8_t tileID = 0; uint8_t tileID = 0;
uint8_t bank = 0; uint8_t bank = 0;
for (auto attr : attrmap) { for (AttrmapEntry const &attr : attrmap) {
if (tileID == options.maxNbTiles[bank]) { if (tileID == options.maxNbTiles[bank]) {
assume(bank == 0); assume(bank == 0);
bank = 1; bank = 1;
@@ -985,7 +985,7 @@ struct UniqueTiles {
return {tileData->tileID, matchType}; return {tileData->tileID, matchType};
} }
auto size() const { return tiles.size(); } size_t size() const { return tiles.size(); }
auto begin() const { return tiles.begin(); } auto begin() const { return tiles.begin(); }
auto end() const { return tiles.end(); } auto end() const { return tiles.end(); }
@@ -1169,7 +1169,7 @@ void process() {
// LCOV_EXCL_START // LCOV_EXCL_START
if (options.verbosity >= Options::VERB_INTERM) { if (options.verbosity >= Options::VERB_INTERM) {
fputs("Image colors: [ ", stderr); fputs("Image colors: [ ", stderr);
for (auto const &slot : colors) { for (std::optional<Rgba> const &slot : colors) {
if (!slot.has_value()) { if (!slot.has_value()) {
continue; continue;
} }
@@ -1287,7 +1287,7 @@ continue_visiting_tiles:;
); );
// LCOV_EXCL_START // LCOV_EXCL_START
if (options.verbosity >= Options::VERB_INTERM) { if (options.verbosity >= Options::VERB_INTERM) {
for (auto const &protoPal : protoPalettes) { for (ProtoPalette const &protoPal : protoPalettes) {
fputs("[ ", stderr); fputs("[ ", stderr);
for (uint16_t color : protoPal) { for (uint16_t color : protoPal) {
fprintf(stderr, "$%04x, ", color); fprintf(stderr, "$%04x, ", color);

View File

@@ -174,15 +174,15 @@ static std::vector<LexerStackEntry> lexerStack;
static bool atEof; static bool atEof;
void yy::parser::error(std::string const &msg) { void yy::parser::error(std::string const &msg) {
auto const &script = lexerStack.back(); LexerStackEntry const &script = lexerStack.back();
scriptError(script, "%s", msg.c_str()); scriptError(script, "%s", msg.c_str());
} }
static void includeFile(std::string &&path) { static void includeFile(std::string &&path) {
// `emplace_back` can invalidate references to the stack's elements! // `emplace_back` can invalidate references to the stack's elements!
// This is why `newContext` must be gotten before `prevContext`. // This is why `newContext` must be gotten before `prevContext`.
auto &newContext = lexerStack.emplace_back(std::move(path)); LexerStackEntry &newContext = lexerStack.emplace_back(std::move(path));
auto &prevContext = lexerStack[lexerStack.size() - 2]; LexerStackEntry &prevContext = lexerStack[lexerStack.size() - 2];
if (!newContext.file.open(newContext.path, std::ios_base::in)) { if (!newContext.file.open(newContext.path, std::ios_base::in)) {
// The order is important: report the error, increment the line number, modify the stack! // The order is important: report the error, increment the line number, modify the stack!
@@ -232,7 +232,7 @@ static bool isIdentChar(int c) {
} }
static std::string readIdent(int c) { static std::string readIdent(int c) {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
std::string ident; std::string ident;
ident.push_back(c); ident.push_back(c);
for (c = context.file.sgetc(); isIdentChar(c); c = context.file.snextc()) { for (c = context.file.sgetc(); isIdentChar(c); c = context.file.snextc()) {
@@ -246,7 +246,7 @@ static bool isDecDigit(int c) {
} }
static yy::parser::symbol_type parseDecNumber(int c) { static yy::parser::symbol_type parseDecNumber(int c) {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
uint32_t number = c - '0'; uint32_t number = c - '0';
for (c = context.file.sgetc(); isDecDigit(c) || c == '_'; c = context.file.sgetc()) { for (c = context.file.sgetc(); isDecDigit(c) || c == '_'; c = context.file.sgetc()) {
if (c != '_') { if (c != '_') {
@@ -262,8 +262,8 @@ static bool isBinDigit(int c) {
} }
static yy::parser::symbol_type parseBinNumber(char const *prefix) { static yy::parser::symbol_type parseBinNumber(char const *prefix) {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
auto c = context.file.sgetc(); int c = context.file.sgetc();
if (!isBinDigit(c)) { if (!isBinDigit(c)) {
scriptError(context, "No binary digits found after '%s'", prefix); scriptError(context, "No binary digits found after '%s'", prefix);
return yy::parser::make_number(0); return yy::parser::make_number(0);
@@ -285,8 +285,8 @@ static bool isOctDigit(int c) {
} }
static yy::parser::symbol_type parseOctNumber(char const *prefix) { static yy::parser::symbol_type parseOctNumber(char const *prefix) {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
auto c = context.file.sgetc(); int c = context.file.sgetc();
if (!isOctDigit(c)) { if (!isOctDigit(c)) {
scriptError(context, "No octal digits found after '%s'", prefix); scriptError(context, "No octal digits found after '%s'", prefix);
return yy::parser::make_number(0); return yy::parser::make_number(0);
@@ -320,8 +320,8 @@ static uint8_t parseHexDigit(int c) {
} }
static yy::parser::symbol_type parseHexNumber(char const *prefix) { static yy::parser::symbol_type parseHexNumber(char const *prefix) {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
auto c = context.file.sgetc(); int c = context.file.sgetc();
if (!isHexDigit(c)) { if (!isHexDigit(c)) {
scriptError(context, "No hexadecimal digits found after '%s'", prefix); scriptError(context, "No hexadecimal digits found after '%s'", prefix);
return yy::parser::make_number(0); return yy::parser::make_number(0);
@@ -339,7 +339,7 @@ static yy::parser::symbol_type parseHexNumber(char const *prefix) {
} }
static yy::parser::symbol_type parseNumber(int c) { static yy::parser::symbol_type parseNumber(int c) {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
if (c == '0') { if (c == '0') {
switch (context.file.sgetc()) { switch (context.file.sgetc()) {
case 'x': case 'x':
@@ -366,8 +366,8 @@ static yy::parser::symbol_type parseNumber(int c) {
} }
static yy::parser::symbol_type parseString() { static yy::parser::symbol_type parseString() {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
auto c = context.file.sgetc(); int c = context.file.sgetc();
std::string str; std::string str;
for (; c != '"'; c = context.file.sgetc()) { for (; c != '"'; c = context.file.sgetc()) {
if (c == EOF || isNewline(c)) { if (c == EOF || isNewline(c)) {
@@ -402,8 +402,8 @@ static yy::parser::symbol_type parseString() {
} }
yy::parser::symbol_type yylex() { yy::parser::symbol_type yylex() {
auto &context = lexerStack.back(); LexerStackEntry &context = lexerStack.back();
auto c = context.file.sbumpc(); int c = context.file.sbumpc();
// First, skip leading whitespace. // First, skip leading whitespace.
while (isWhiteSpace(c)) { while (isWhiteSpace(c)) {
@@ -506,7 +506,7 @@ static void setFloatingSectionType(SectionType type) {
} }
static void setSectionType(SectionType type) { static void setSectionType(SectionType type) {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
if (nbbanks(type) != 1) { if (nbbanks(type) != 1) {
scriptError( scriptError(
@@ -519,8 +519,8 @@ static void setSectionType(SectionType type) {
} }
static void setSectionType(SectionType type, uint32_t bank) { static void setSectionType(SectionType type, uint32_t bank) {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
auto const &typeInfo = sectionTypeInfo[type]; SectionTypeInfo const &typeInfo = sectionTypeInfo[type];
if (bank < typeInfo.firstBank) { if (bank < typeInfo.firstBank) {
scriptError( scriptError(
@@ -545,7 +545,7 @@ static void setSectionType(SectionType type, uint32_t bank) {
} }
static void setAddr(uint32_t addr) { static void setAddr(uint32_t addr) {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
if (activeType == SECTTYPE_INVALID) { if (activeType == SECTTYPE_INVALID) {
scriptError(context, "Cannot set the current address: no memory region is active"); scriptError(context, "Cannot set the current address: no memory region is active");
return; return;
@@ -555,8 +555,8 @@ static void setAddr(uint32_t addr) {
return; return;
} }
auto &pc = curAddr[activeType][activeBankIdx]; uint16_t &pc = curAddr[activeType][activeBankIdx];
auto const &typeInfo = sectionTypeInfo[activeType]; SectionTypeInfo const &typeInfo = sectionTypeInfo[activeType];
if (addr < pc) { if (addr < pc) {
scriptError(context, "Cannot decrease the current address (from $%04x to $%04x)", pc, addr); scriptError(context, "Cannot decrease the current address (from $%04x to $%04x)", pc, addr);
@@ -576,7 +576,7 @@ static void setAddr(uint32_t addr) {
} }
static void makeAddrFloating() { static void makeAddrFloating() {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
if (activeType == SECTTYPE_INVALID) { if (activeType == SECTTYPE_INVALID) {
scriptError( scriptError(
context, "Cannot make the current address floating: no memory region is active" context, "Cannot make the current address floating: no memory region is active"
@@ -590,7 +590,7 @@ static void makeAddrFloating() {
} }
static void alignTo(uint32_t alignment, uint32_t alignOfs) { static void alignTo(uint32_t alignment, uint32_t alignOfs) {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
if (activeType == SECTTYPE_INVALID) { if (activeType == SECTTYPE_INVALID) {
scriptError(context, "Cannot align: no memory region is active"); scriptError(context, "Cannot align: no memory region is active");
return; return;
@@ -619,8 +619,8 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) {
return; return;
} }
auto const &typeInfo = sectionTypeInfo[activeType]; SectionTypeInfo const &typeInfo = sectionTypeInfo[activeType];
auto &pc = curAddr[activeType][activeBankIdx]; uint16_t &pc = curAddr[activeType][activeBankIdx];
if (alignment > 16) { if (alignment > 16) {
scriptError( scriptError(
@@ -666,7 +666,7 @@ static void alignTo(uint32_t alignment, uint32_t alignOfs) {
} }
static void pad(uint32_t length) { static void pad(uint32_t length) {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
if (activeType == SECTTYPE_INVALID) { if (activeType == SECTTYPE_INVALID) {
scriptError(context, "Cannot increase the current address: no memory region is active"); scriptError(context, "Cannot increase the current address: no memory region is active");
return; return;
@@ -677,8 +677,8 @@ static void pad(uint32_t length) {
return; return;
} }
auto const &typeInfo = sectionTypeInfo[activeType]; SectionTypeInfo const &typeInfo = sectionTypeInfo[activeType];
auto &pc = curAddr[activeType][activeBankIdx]; uint16_t &pc = curAddr[activeType][activeBankIdx];
assume(pc >= typeInfo.startAddr); assume(pc >= typeInfo.startAddr);
if (uint16_t offset = pc - typeInfo.startAddr; length + offset > typeInfo.size) { if (uint16_t offset = pc - typeInfo.startAddr; length + offset > typeInfo.size) {
@@ -695,7 +695,7 @@ static void pad(uint32_t length) {
} }
static void placeSection(std::string const &name, bool isOptional) { static void placeSection(std::string const &name, bool isOptional) {
auto const &context = lexerStack.back(); LexerStackEntry const &context = lexerStack.back();
if (activeType == SECTTYPE_INVALID) { if (activeType == SECTTYPE_INVALID) {
scriptError( scriptError(
context, "No memory region has been specified to place section \"%s\" in", name.c_str() context, "No memory region has been specified to place section \"%s\" in", name.c_str()
@@ -703,7 +703,7 @@ static void placeSection(std::string const &name, bool isOptional) {
return; return;
} }
auto *section = sect_GetSection(name.c_str()); Section *section = sect_GetSection(name.c_str());
if (!section) { if (!section) {
if (!isOptional) { if (!isOptional) {
scriptError(context, "Unknown section \"%s\"", name.c_str()); scriptError(context, "Unknown section \"%s\"", name.c_str());
@@ -711,7 +711,7 @@ static void placeSection(std::string const &name, bool isOptional) {
return; return;
} }
auto const &typeInfo = sectionTypeInfo[activeType]; SectionTypeInfo const &typeInfo = sectionTypeInfo[activeType];
assume(section->offset == 0); assume(section->offset == 0);
// Check that the linker script doesn't contradict what the code says. // Check that the linker script doesn't contradict what the code says.
if (section->type == SECTTYPE_INVALID) { if (section->type == SECTTYPE_INVALID) {
@@ -833,7 +833,7 @@ void script_ProcessScript(char const *path) {
lexerStack.clear(); lexerStack.clear();
atEof = false; atEof = false;
auto &newContext = lexerStack.emplace_back(std::string(path)); LexerStackEntry &newContext = lexerStack.emplace_back(std::string(path));
if (!newContext.file.open(newContext.path, std::ios_base::in)) { if (!newContext.file.open(newContext.path, std::ios_base::in)) {
error("Failed to open linker script \"%s\"", newContext.path.c_str()); error("Failed to open linker script \"%s\"", newContext.path.c_str());
@@ -845,7 +845,7 @@ void script_ProcessScript(char const *path) {
(void)linkerScriptParser.parse(); (void)linkerScriptParser.parse();
// Free up working memory. // Free up working memory.
for (auto &region : curAddr) { for (std::vector<uint16_t> &region : curAddr) {
region.clear(); region.clear();
} }
} }