mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Avoid using std::get except in holds_alternative-asserting accessors
This commit is contained in:
@@ -33,6 +33,9 @@ struct Symbol {
|
||||
int32_t, // Constants just have a numeric value
|
||||
Label // Label values refer to an offset within a specific section
|
||||
> data;
|
||||
|
||||
Label &label();
|
||||
Label const &label() const;
|
||||
};
|
||||
|
||||
void sym_AddSymbol(Symbol &symbol);
|
||||
|
||||
@@ -340,11 +340,11 @@ static void readSection(FILE *file, Section §ion, char const *fileName,
|
||||
static void linkSymToSect(Symbol &symbol, Section §ion)
|
||||
{
|
||||
uint32_t a = 0, b = section.symbols.size();
|
||||
int32_t symbolOffset = std::get<Label>(symbol.data).offset;
|
||||
int32_t symbolOffset = symbol.label().offset;
|
||||
|
||||
while (a != b) {
|
||||
uint32_t c = (a + b) / 2;
|
||||
int32_t otherOffset = std::get<Label>(section.symbols[c]->data).offset;
|
||||
int32_t otherOffset = section.symbols[c]->label().offset;
|
||||
|
||||
if (otherOffset > symbolOffset)
|
||||
b = c;
|
||||
|
||||
@@ -347,7 +347,7 @@ static void writeSymBank(SortedSections const &bankSections, enum SectionType ty
|
||||
if (!sym->name.empty() && canStartSymName(sym->name[0]))
|
||||
symList.push_back({
|
||||
.sym = sym,
|
||||
.addr = (uint16_t)(std::get<Label>(sym->data).offset + sect->org)
|
||||
.addr = (uint16_t)(sym->label().offset + sect->org)
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -417,7 +417,7 @@ static void writeMapBank(SortedSections const §List, enum SectionType type,
|
||||
for (Symbol *sym : sect->symbols)
|
||||
// Space matches "\tSECTION: $xxxx ..."
|
||||
fprintf(mapFile, "\t $%04" PRIx32 " = %s\n",
|
||||
std::get<Label>(sym->data).offset + org,
|
||||
sym->label().offset + org,
|
||||
sym->name.c_str());
|
||||
|
||||
if (sect->nextu) {
|
||||
|
||||
@@ -228,14 +228,14 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
||||
fileSymbols[value].name.c_str());
|
||||
isError = true;
|
||||
value = 1;
|
||||
} else if (!std::holds_alternative<Label>(symbol->data)) {
|
||||
} else if (Label const *label = std::get_if<Label>(&symbol->data); label) {
|
||||
value = label->section->bank;
|
||||
} else {
|
||||
error(patch.src, patch.lineNo,
|
||||
"Requested BANK() of non-label symbol \"%s\"",
|
||||
fileSymbols[value].name.c_str());
|
||||
isError = true;
|
||||
value = 1;
|
||||
} else {
|
||||
value = std::get<Label>(symbol->data).section->bank;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -715,7 +715,7 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector<Symbol>
|
||||
if (section->modifier == SECTION_FRAGMENT) {
|
||||
// Add the fragment's offset to all of its symbols
|
||||
for (Symbol *symbol : section->symbols)
|
||||
std::get<Label>(symbol->data).offset += section->offset;
|
||||
symbol->label().offset += section->offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,18 @@
|
||||
|
||||
std::map<std::string, Symbol *> symbols;
|
||||
|
||||
Label &Symbol::label()
|
||||
{
|
||||
assert(std::holds_alternative<Label>(data));
|
||||
return std::get<Label>(data);
|
||||
}
|
||||
|
||||
Label const &Symbol::label() const
|
||||
{
|
||||
assert(std::holds_alternative<Label>(data));
|
||||
return std::get<Label>(data);
|
||||
}
|
||||
|
||||
void sym_AddSymbol(Symbol &symbol)
|
||||
{
|
||||
// Check if the symbol already exists
|
||||
|
||||
Reference in New Issue
Block a user