mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-28 05:47:48 +00:00
RGBLINK lists local symbols when encountering an unknown symbol reference (#1496)
This commit is contained in:
@@ -564,8 +564,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
||||
|
||||
readSymbol(file, symbol, fileName, nodes[fileID]);
|
||||
|
||||
if (symbol.type == SYMTYPE_EXPORT)
|
||||
sym_AddSymbol(symbol);
|
||||
sym_AddSymbol(symbol);
|
||||
if (symbol.data.holds<Label>())
|
||||
nbSymPerSect[symbol.data.get<Label>().sectionID]++;
|
||||
}
|
||||
|
||||
@@ -388,6 +388,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
||||
"Unknown symbol \"%s\"",
|
||||
fileSymbols[value].name.c_str()
|
||||
);
|
||||
sym_DumpLocalAliasedSymbols(fileSymbols[value].name);
|
||||
isError = true;
|
||||
} else if (symbol->data.holds<Label>()) {
|
||||
Label const &label = symbol->data.get<Label>();
|
||||
|
||||
@@ -382,6 +382,7 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector<Symbol>
|
||||
// Expected format: /[DR]ef[0-9A-F]+/i
|
||||
if (token[0] == 'R' || token[0] == 'r') {
|
||||
symbol.type = SYMTYPE_IMPORT;
|
||||
sym_AddSymbol(symbol);
|
||||
// TODO: hard error if the rest is not zero
|
||||
} else if (token[0] != 'D' && token[0] != 'd') {
|
||||
fatal(&where, lineNo, "'S' line is neither \"Def\" nor \"Ref\"");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers.hpp" // assume
|
||||
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "link/section.hpp"
|
||||
|
||||
std::unordered_map<std::string, Symbol *> symbols;
|
||||
std::unordered_map<std::string, std::vector<Symbol *>> localSymbols;
|
||||
|
||||
void sym_ForEach(void (*callback)(Symbol &)) {
|
||||
for (auto &it : symbols)
|
||||
@@ -18,6 +20,12 @@ void sym_ForEach(void (*callback)(Symbol &)) {
|
||||
}
|
||||
|
||||
void sym_AddSymbol(Symbol &symbol) {
|
||||
if (symbol.type != SYMTYPE_EXPORT) {
|
||||
if (symbol.type != SYMTYPE_IMPORT)
|
||||
localSymbols[symbol.name].push_back(&symbol);
|
||||
return;
|
||||
}
|
||||
|
||||
Symbol *other = sym_GetSymbol(symbol.name);
|
||||
int32_t *symValue = symbol.data.holds<int32_t>() ? &symbol.data.get<int32_t>() : nullptr;
|
||||
int32_t *otherValue =
|
||||
@@ -41,3 +49,30 @@ Symbol *sym_GetSymbol(std::string const &name) {
|
||||
auto search = symbols.find(name);
|
||||
return search != symbols.end() ? search->second : nullptr;
|
||||
}
|
||||
|
||||
void sym_DumpLocalAliasedSymbols(std::string const &name) {
|
||||
std::vector<Symbol *> const &locals = localSymbols[name];
|
||||
int count = 0;
|
||||
for (Symbol *local : locals) {
|
||||
if (count++ == 3) {
|
||||
size_t remaining = locals.size() - 3;
|
||||
bool plural = remaining != 1;
|
||||
fprintf(
|
||||
stderr,
|
||||
" ...and %zu more symbol%s with that name %s defined but not exported\n",
|
||||
remaining,
|
||||
plural ? "s" : "",
|
||||
plural ? "are" : "is"
|
||||
);
|
||||
break;
|
||||
}
|
||||
fprintf(
|
||||
stderr,
|
||||
" A %s with that name is defined but not exported at ",
|
||||
local->data.holds<Label>() ? "label" : "constant"
|
||||
);
|
||||
assume(local->src);
|
||||
local->src->dump(local->lineNo);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user