mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-05 13:27:06 +00:00
Fix included linker scripts with no newline at EOF (#2011)
This commit is contained in:
+11
-16
@@ -24,8 +24,9 @@ struct LexerStackEntry {
|
|||||||
std::filebuf file;
|
std::filebuf file;
|
||||||
std::string path;
|
std::string path;
|
||||||
uint32_t lineNo;
|
uint32_t lineNo;
|
||||||
|
bool atEof;
|
||||||
|
|
||||||
explicit LexerStackEntry(std::string &&path_) : file(), path(path_), lineNo(1) {}
|
explicit LexerStackEntry(std::string &&path_) : file(), path(path_), lineNo(1), atEof(false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<LexerStackEntry> lexerStack;
|
static std::vector<LexerStackEntry> lexerStack;
|
||||||
@@ -65,24 +66,18 @@ void lexer_IncLineNo() {
|
|||||||
yy::parser::symbol_type yylex(); // Forward declaration for `yywrap`
|
yy::parser::symbol_type yylex(); // Forward declaration for `yywrap`
|
||||||
|
|
||||||
static yy::parser::symbol_type yywrap() {
|
static yy::parser::symbol_type yywrap() {
|
||||||
static bool atEof = false;
|
if (LexerStackEntry &context = lexerStack.back(); !context.atEof) {
|
||||||
if (lexerStack.size() != 1) {
|
|
||||||
if (!atEof) {
|
|
||||||
// Inject a newline at EOF to simplify parsing.
|
|
||||||
atEof = true;
|
|
||||||
return yy::parser::make_newline();
|
|
||||||
}
|
|
||||||
lexerStack.pop_back();
|
|
||||||
// Increment the line number *after* an INCLUDE has finished.
|
|
||||||
++lexerStack.back().lineNo;
|
|
||||||
return yylex();
|
|
||||||
}
|
|
||||||
if (!atEof) {
|
|
||||||
// Inject a newline at EOF to simplify parsing.
|
// Inject a newline at EOF to simplify parsing.
|
||||||
atEof = true;
|
context.atEof = true;
|
||||||
return yy::parser::make_newline();
|
return yy::parser::make_newline();
|
||||||
}
|
}
|
||||||
return yy::parser::make_YYEOF();
|
if (lexerStack.size() == 1) {
|
||||||
|
return yy::parser::make_YYEOF();
|
||||||
|
}
|
||||||
|
lexerStack.pop_back();
|
||||||
|
// Increment the line number *after* an INCLUDE has finished.
|
||||||
|
++lexerStack.back().lineNo;
|
||||||
|
return yylex();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string readKeyword(int initial) {
|
static std::string readKeyword(int initial) {
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
section "test", rom0[1337]
|
||||||
|
label:: dw label
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
rom0 ; no newline after this
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
include "linkerscript-no-newline-eof.inc"
|
||||||
|
"test" ; no newline after this
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
error: The linker script assigns section "test" to address $0000, but it was already at $0539
|
||||||
|
at linkerscript-no-newline-eof.link(2)
|
||||||
|
Linking failed with 1 error
|
||||||
Reference in New Issue
Block a user