Error messages refer to "undefined" symbols and sections

This commit is contained in:
Rangi42
2025-08-08 19:22:13 -04:00
parent 9fc83efe06
commit 2130a5ba1f
38 changed files with 86 additions and 79 deletions

View File

@@ -14,6 +14,7 @@
bool isWhitespace(int c);
bool isNewline(int c);
bool isPrintable(int c);
bool startsIdentifier(int c);
bool continuesIdentifier(int c);

View File

@@ -594,9 +594,9 @@ std::string act_SectionName(std::string const &symName) {
Symbol *sym = sym_FindScopedValidSymbol(symName);
if (!sym) {
if (sym_IsPurgedScoped(symName)) {
fatal("Unknown symbol \"%s\"; it was purged", symName.c_str());
fatal("Undefined symbol \"%s\"; it was purged", symName.c_str());
} else {
fatal("Unknown symbol \"%s\"", symName.c_str());
fatal("Undefined symbol \"%s\"", symName.c_str());
}
}

View File

@@ -370,9 +370,9 @@ void fstk_RunMacro(std::string const &macroName, std::shared_ptr<MacroArgs> macr
if (!macro) {
if (sym_IsPurgedExact(macroName)) {
error("Macro \"%s\" not defined; it was purged", macroName.c_str());
error("Undefined macro \"%s\"; it was purged", macroName.c_str());
} else {
error("Macro \"%s\" not defined", macroName.c_str());
error("Undefined macro \"%s\"", macroName.c_str());
}
return;
}

View File

@@ -579,7 +579,7 @@ static uint32_t readBracketedMacroArgNum() {
c = bumpChar();
if (c != '>') {
error("Invalid character in bracketed macro argument %s", printChar(c));
error("Invalid character %s in bracketed macro argument", printChar(c));
return 0;
} else if (empty) {
error("Empty bracketed macro argument");
@@ -911,7 +911,7 @@ static void discardLineContinuation() {
error("Invalid line continuation at end of file");
break;
} else {
error("Invalid character after line continuation %s", printChar(c));
error("Invalid character %s after line continuation", printChar(c));
break;
}
}
@@ -1568,17 +1568,19 @@ static bool isGarbageCharacter(int c) {
static void reportGarbageCharacters(int c) {
// '#' can be garbage if it doesn't start a raw string or identifier
assume(isGarbageCharacter(c) || c == '#');
bool isAscii = isPrintable(c);
if (isGarbageCharacter(peek())) {
// At least two characters are garbage; group them into one error report
std::string garbage = printChar(c);
while (isGarbageCharacter(peek())) {
c = bumpChar();
isAscii &= isPrintable(c);
garbage += ", ";
garbage += printChar(c);
}
error("Unknown characters %s", garbage.c_str());
error("Invalid characters %s%s", garbage.c_str(), isAscii ? "" : " (is the file UTF-8?)");
} else {
error("Unknown character %s", printChar(c));
error("Invalid character %s%s", printChar(c), isAscii ? "" : " (is the file UTF-8?)");
}
}

View File

@@ -284,9 +284,9 @@ void sym_Purge(std::string const &symName) {
if (!sym) {
if (sym_IsPurgedScoped(symName)) {
error("'%s' was already purged", symName.c_str());
error("Undefined symbol '%s' was already purged", symName.c_str());
} else {
error("'%s' not defined", symName.c_str());
error("Undefined symbol '%s'", symName.c_str());
}
} else if (sym->isBuiltin) {
error("Built-in symbol '%s' cannot be purged", symName.c_str());

View File

@@ -223,7 +223,7 @@ void layout_PlaceSection(std::string const &name, bool isOptional) {
Section *section = sect_GetSection(name.c_str());
if (!section) {
if (!isOptional) {
lexer_Error("Unknown section \"%s\"", name.c_str());
lexer_Error("Undefined section \"%s\"", name.c_str());
}
return;
}

View File

@@ -277,7 +277,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
if (Symbol const *symbol = getSymbol(fileSymbols, value); !symbol) {
errorAt(
patch,
"Requested BANK() of symbol \"%s\", which was not found",
"Requested BANK() of undefined symbol \"%s\"",
fileSymbols[value].name.c_str()
);
isError = true;
@@ -302,7 +302,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
while (getRPNByte(expression, size, patch)) {}
if (Section const *sect = sect_GetSection(name); !sect) {
errorAt(patch, "Requested BANK() of section \"%s\", which was not found", name);
errorAt(patch, "Requested BANK() of undefined section \"%s\"", name);
isError = true;
value = 1;
} else {
@@ -327,7 +327,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
while (getRPNByte(expression, size, patch)) {}
if (Section const *sect = sect_GetSection(name); !sect) {
errorAt(patch, "Requested SIZEOF() of section \"%s\", which was not found", name);
errorAt(patch, "Requested SIZEOF() of undefined section \"%s\"", name);
isError = true;
value = 1;
} else {
@@ -342,7 +342,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
while (getRPNByte(expression, size, patch)) {}
if (Section const *sect = sect_GetSection(name); !sect) {
errorAt(patch, "Requested STARTOF() of section \"%s\", which was not found", name);
errorAt(patch, "Requested STARTOF() of undefined section \"%s\"", name);
isError = true;
value = 1;
} else {
@@ -427,7 +427,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
isError = true;
}
} else if (Symbol const *symbol = getSymbol(fileSymbols, value); !symbol) {
errorAt(patch, "Unknown symbol \"%s\"", fileSymbols[value].name.c_str());
errorAt(patch, "Undefined symbol \"%s\"", fileSymbols[value].name.c_str());
sym_DumpLocalAliasedSymbols(fileSymbols[value].name);
isError = true;
} else if (std::holds_alternative<Label>(symbol->data)) {

View File

@@ -13,6 +13,10 @@ bool isNewline(int c) {
return c == '\r' || c == '\n';
}
bool isPrintable(int c) {
return c >= ' ' && c <= '~';
}
bool startsIdentifier(int c) {
// This returns false for anonymous labels, which internally start with a '!',
// and for section fragment literal labels, which internally start with a '$'.
@@ -34,7 +38,7 @@ char const *printChar(int c) {
}
// Handle printable ASCII characters
if (c >= ' ' && c <= '~') {
if (isPrintable(c)) {
buf[0] = '\'';
buf[1] = c;
buf[2] = '\'';

View File

@@ -1,15 +1,15 @@
error: blue-paint.asm(9) -> blue-paint.asm::arg_to_arg(7):
Invalid character after line continuation '3'
Invalid character '3' after line continuation
error: blue-paint.asm(9) -> blue-paint.asm::arg_to_arg(7):
syntax error, unexpected number
error: blue-paint.asm(9) -> blue-paint.asm::arg_to_arg(7):
Unknown character '}'
Invalid character '}'
error: blue-paint.asm(15) -> blue-paint.asm::arg_to_interp(13):
Unknown character '{'
Invalid character '{'
error: blue-paint.asm(15) -> blue-paint.asm::arg_to_interp(13):
Unknown character '}'
Invalid character '}'
error: blue-paint.asm(26) -> blue-paint.asm::endless(24):
Invalid character after line continuation '1'
Invalid character '1' after line continuation
error: blue-paint.asm(26) -> blue-paint.asm::endless(24):
syntax error, unexpected number
FATAL: blue-paint.asm(30):

View File

@@ -1,5 +1,5 @@
error: builtin-reserved.asm(3):
'_NARG' not defined
Undefined symbol '_NARG'
error: builtin-reserved.asm(5):
'_NARG' is reserved for a built-in symbol
error: builtin-reserved.asm(6):
@@ -15,7 +15,7 @@ error: builtin-reserved.asm(12):
error: builtin-reserved.asm(15):
'_NARG' is reserved for a built-in symbol
error: builtin-reserved.asm(20):
'.' not defined
Undefined symbol '.'
error: builtin-reserved.asm(22):
'.' is reserved for a built-in symbol
error: builtin-reserved.asm(23):

View File

@@ -1,7 +1,7 @@
error: character-escapes.asm(10) -> character-escapes.asm::m(6):
Illegal character escape 'z'
error: character-escapes.asm(10) -> character-escapes.asm::m(7):
Invalid character in bracketed macro argument '\'
Invalid character '\' in bracketed macro argument
error: character-escapes.asm(10) -> character-escapes.asm::m(8):
Invalid character in bracketed macro argument '\t'
Invalid character '\t' in bracketed macro argument
Assembly aborted with 3 errors!

View File

@@ -1,7 +1,7 @@
error: code-after-endm-endr-endc.asm(6):
syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
error: code-after-endm-endr-endc.asm(7):
Macro "mac" not defined
Undefined macro "mac"
error: code-after-endm-endr-endc.asm(12):
syntax error, unexpected PRINTLN, expecting end of line or end of buffer or end of fragment literal
error: code-after-endm-endr-endc.asm(17):

View File

@@ -1,3 +1,3 @@
error: double-purge.asm(3):
'n' was already purged
Undefined symbol 'n' was already purged
Assembly aborted with 1 error!

View File

@@ -1,5 +1,5 @@
error: empty-raw-identifier.asm(5) -> empty-raw-identifier.asm::macro(3):
Invalid character in bracketed macro argument '?'
Invalid character '?' in bracketed macro argument
error: empty-raw-identifier.asm(5) -> empty-raw-identifier.asm::macro(3):
Empty raw symbol in bracketed macro argument
Assembly aborted with 2 errors!

View File

@@ -1,3 +1,3 @@
error: garbage_char.asm(1):
Unknown character 0xFF
Invalid character 0xFF (is the file UTF-8?)
Assembly aborted with 1 error!

View File

@@ -1,11 +1,11 @@
error: garbage_sequence.asm(1):
Unknown character '#'
Invalid character '#'
error: garbage_sequence.asm(2):
Unknown characters '?', 0xFF
Invalid characters '?', 0xFF (is the file UTF-8?)
error: garbage_sequence.asm(3):
Unknown characters '?', 0xFF, '?'
Invalid characters '?', 0xFF, '?' (is the file UTF-8?)
error: garbage_sequence.asm(3):
Unknown character '#'
Invalid character '#'
error: garbage_sequence.asm(3):
Unknown characters '#', '?', '?'
Invalid characters '#', '?', '?'
Assembly aborted with 5 errors!

View File

@@ -1,5 +1,5 @@
error: invalid-macro-arg-character.asm(1):
Invalid character in bracketed macro argument '!'
Invalid character '!' in bracketed macro argument
error: invalid-macro-arg-character.asm(1):
syntax error, unexpected >
Assembly aborted with 2 errors!

View File

@@ -1,3 +1,3 @@
error: invalid-utf-8.asm(6) -> invalid-utf-8.asm::m(4):
Unknown characters 0xCF, 0xD3
Invalid characters 0xCF, 0xD3 (is the file UTF-8?)
Assembly aborted with 1 error!

View File

@@ -1,9 +1,9 @@
error: label-scope.asm(3):
'@' not defined
Undefined symbol '@'
error: label-scope.asm(3):
'.' not defined
Undefined symbol '.'
error: label-scope.asm(3):
'..' not defined
Undefined symbol '..'
error: label-scope.asm(12):
Built-in symbol '@' cannot be purged
error: label-scope.asm(12):

View File

@@ -3,7 +3,7 @@ error: lexer-hack.asm(22):
error: lexer-hack.asm(24):
'mac' already defined at lexer-hack.asm(1)
error: lexer-hack.asm(27):
Macro "undef" not defined
Undefined macro "undef"
error: lexer-hack.asm(28):
Macro "undef" not defined
Undefined macro "undef"
Assembly aborted with 4 errors!

View File

@@ -1,13 +1,13 @@
error: line-continuation-block-comment.asm(6):
Invalid character after line continuation '/'
Invalid character '/' after line continuation
error: line-continuation-block-comment.asm(6):
syntax error, unexpected end of line
error: line-continuation-block-comment.asm(7):
syntax error, unexpected number
error: line-continuation-block-comment.asm(12):
Invalid character after line continuation '/'
Invalid character '/' after line continuation
error: line-continuation-block-comment.asm(14):
Invalid character after line continuation '/'
Invalid character '/' after line continuation
error: line-continuation-block-comment.asm(17):
Invalid character after line continuation '/'
Invalid character '/' after line continuation
Assembly aborted with 6 errors!

View File

@@ -1,5 +1,5 @@
error: line-continuation.asm(3):
Invalid character after line continuation 's'
Invalid character 's' after line continuation
warning: line-continuation.asm(6) -> line-continuation.asm::spam(4): [-Wuser]
spam
error: line-continuation.asm(14):

View File

@@ -1,5 +1,5 @@
error: macro-arg-0.asm(5) -> macro-arg-0.asm::m(2):
Invalid character after line continuation '0'
Invalid character '0' after line continuation
error: macro-arg-0.asm(5) -> macro-arg-0.asm::m(3):
Invalid bracketed macro argument '\<0>'
Assembly aborted with 2 errors!

View File

@@ -1,3 +1,3 @@
error: macro-arg-recursion.asm(6) -> macro-arg-recursion.asm::m(2):
Invalid character after line continuation '2'
Invalid character '2' after line continuation
Assembly aborted with 1 error!

View File

@@ -1,3 +1,3 @@
error: nested-expansions.asm(6) -> nested-expansions.asm::test(4):
Macro "qux" not defined
Undefined macro "qux"
Assembly aborted with 1 error!

View File

@@ -3,5 +3,5 @@ warning: nested-macrodef.asm(26) -> nested-macrodef.asm::outer(22): [-Wuser]
error: nested-macrodef.asm(26) -> nested-macrodef.asm::outer(24):
Unterminated macro definition
error: nested-macrodef.asm(27):
Macro "inner" not defined
Undefined macro "inner"
Assembly aborted with 2 errors!

View File

@@ -1,3 +1,3 @@
error: null-in-macro.asm(4) -> null-in-macro.asm::foo(2):
Unknown character '\0'
Invalid character '\0' (is the file UTF-8?)
Assembly aborted with 1 error!

View File

@@ -1,17 +1,17 @@
error: null-outside-string.asm(3):
Invalid character after line continuation '0'
Invalid character '0' after line continuation
error: null-outside-string.asm(3):
syntax error, unexpected number
error: null-outside-string.asm(4):
Invalid character after line continuation '0'
Invalid character '0' after line continuation
error: null-outside-string.asm(4):
syntax error, unexpected number
error: null-outside-string.asm(6):
Invalid character after line continuation 'X'
Invalid character 'X' after line continuation
error: null-outside-string.asm(6):
syntax error, unexpected symbol
error: null-outside-string.asm(7):
Invalid character after line continuation 'X'
Invalid character 'X' after line continuation
error: null-outside-string.asm(7):
syntax error, unexpected symbol
Assembly aborted with 8 errors!

View File

@@ -5,5 +5,5 @@ error: purge.asm(9):
warning: purge.asm(12): [-Wpurge]
Purging an exported symbol "Exported"
error: purge.asm(15):
'Undefined' not defined
Undefined symbol 'Undefined'
Assembly aborted with 2 errors!

View File

@@ -25,7 +25,7 @@ error: raw-string-symbol-errors.asm(23):
error: raw-string-symbol-errors.asm(24):
'u' is not a string symbol
error: raw-string-symbol-errors.asm(27):
's' was already purged
Undefined symbol 's' was already purged
error: raw-string-symbol-errors.asm(29):
's' is not a string symbol
Assembly aborted with 13 errors!

View File

@@ -1,2 +1,2 @@
FATAL: section-name-undefined.asm(1):
Unknown symbol "Undefined"
Undefined symbol "Undefined"

View File

@@ -1,5 +1,5 @@
error: use-purged-symbol.asm(6):
Macro "m" not defined; it was purged
Undefined macro "m"; it was purged
error: use-purged-symbol.asm(13) -> use-purged-symbol.asm::m2(10):
Bracketed symbol "argi" does not exist; it was purged
error: use-purged-symbol.asm(15):
@@ -15,4 +15,4 @@ error: use-purged-symbol.asm(22):
warning: use-purged-symbol.asm(25): [-Wpurge]
Purging an exported symbol "Label2"
FATAL: use-purged-symbol.asm(26):
Unknown symbol "Label2"; it was purged
Undefined symbol "Label2"; it was purged

View File

@@ -1,3 +1,3 @@
error: cascading-errors-fatal-assert.asm(1): Unknown symbol "UnknownSymbol"
error: cascading-errors-fatal-assert.asm(1): Undefined symbol "UnknownSymbol"
FATAL: cascading-errors-fatal-assert.asm(1): Failed to evaluate assertion
Linking aborted with 2 errors

View File

@@ -1,11 +1,11 @@
error: cascading-errors.asm(18): Unknown symbol "Foo"
error: cascading-errors.asm(19): Unknown symbol "Bar"
error: cascading-errors.asm(16): Unknown symbol "hNonExist"
error: cascading-errors.asm(14): Unknown symbol "NonExist"
error: cascading-errors.asm(12): Unknown symbol "Foo"
error: cascading-errors.asm(10): Unknown symbol "Foo"
error: cascading-errors.asm(18): Undefined symbol "Foo"
error: cascading-errors.asm(19): Undefined symbol "Bar"
error: cascading-errors.asm(16): Undefined symbol "hNonExist"
error: cascading-errors.asm(14): Undefined symbol "NonExist"
error: cascading-errors.asm(12): Undefined symbol "Foo"
error: cascading-errors.asm(10): Undefined symbol "Foo"
error: cascading-errors.asm(10): Division by 0
error: cascading-errors.asm(9): Unknown symbol "Foo"
error: cascading-errors.asm(9): Unknown symbol "Bar"
error: cascading-errors.asm(8): Unknown symbol "Bar"
error: cascading-errors.asm(9): Undefined symbol "Foo"
error: cascading-errors.asm(9): Undefined symbol "Bar"
error: cascading-errors.asm(8): Undefined symbol "Bar"
Linking failed with 10 errors

View File

@@ -1,9 +1,9 @@
error: invalid-patches.asm(10): JR target must be between -128 and 127 bytes away, not 190; use JP instead
error: invalid-patches.asm(9): Address $0 for LDH is not in HRAM range
error: invalid-patches.asm(8): Requested SIZEOF() of section "NonexistentSection", which was not found
error: invalid-patches.asm(7): Requested STARTOF() of section "NonexistentSection", which was not found
error: invalid-patches.asm(6): Requested BANK() of section "NonexistentSection", which was not found
error: invalid-patches.asm(5): Requested BANK() of symbol "NonexistentSymbol", which was not found
error: invalid-patches.asm(8): Requested SIZEOF() of undefined section "NonexistentSection"
error: invalid-patches.asm(7): Requested STARTOF() of undefined section "NonexistentSection"
error: invalid-patches.asm(6): Requested BANK() of undefined section "NonexistentSection"
error: invalid-patches.asm(5): Requested BANK() of undefined symbol "NonexistentSymbol"
error: invalid-patches.asm(4): Exponent by negative value -1
error: invalid-patches.asm(3): Modulo by 0
Linking failed with 8 errors

View File

@@ -1,2 +1,2 @@
error: script-unknown-section.link(2): Unknown section "Wheeee"
error: script-unknown-section.link(2): Undefined section "Wheeee"
Linking failed with 1 error

View File

@@ -1,3 +1,3 @@
error: sym-noexist.asm(3): Unknown symbol "nothing"
error: sym-noexist.asm(2): Unknown symbol "where"
error: sym-noexist.asm(3): Undefined symbol "nothing"
error: sym-noexist.asm(2): Undefined symbol "where"
Linking failed with 2 errors

View File

@@ -1,4 +1,4 @@
error: symbols/unknown/a.asm(2): Unknown symbol "Label"
error: symbols/unknown/a.asm(2): Undefined symbol "Label"
A label with that name is defined but not exported at symbols/unknown/b.asm(2)
A constant with that name is defined but not exported at symbols/unknown/c.asm(1)
A constant with that name is defined but not exported at symbols/unknown/d.asm(1)