Handle missing newline at EOF for linkerscript INCLUDEd files (#1691)

This commit is contained in:
Rangi
2025-05-22 04:55:58 -04:00
committed by GitHub
parent 5d998ef483
commit 804db4e073
9 changed files with 32 additions and 3 deletions

View File

@@ -251,10 +251,16 @@ yy::parser::symbol_type yylex() {
if (c == EOF) { if (c == EOF) {
// Basically yywrap(). // Basically yywrap().
if (lexerStack.size() != 1) { if (lexerStack.size() != 1) {
lexerStack.pop_back(); if (!atEof) {
return yylex(); // Inject a newline at EOF to simplify parsing.
atEof = true;
return yy::parser::make_newline();
} else {
lexerStack.pop_back();
return yylex();
}
} else if (!atEof) { } else if (!atEof) {
// Inject a newline at EOF, to avoid errors for files that don't end with one. // Inject a newline at EOF to simplify parsing.
atEof = true; atEof = true;
return yy::parser::make_newline(); return yy::parser::make_newline();
} else { } else {

View File

@@ -0,0 +1,2 @@
section "a", rom0
db $11

View File

@@ -0,0 +1,3 @@
rom0
org 0
"a" ; no newline

View File

@@ -0,0 +1,2 @@
section "b", rom0
db $22

View File

@@ -0,0 +1,3 @@
rom0
org 1
"b" ; yes newline

View File

View File

@@ -0,0 +1 @@
"

View File

@@ -0,0 +1,2 @@
include "script-include/a.inc"
include "script-include/b.inc"

View File

@@ -262,6 +262,16 @@ tryDiff "$test"/out.err "$outtemp"
tryCmpRomSize "$gbtemp" 65536 tryCmpRomSize "$gbtemp" 65536
evaluateTest evaluateTest
test="script-include"
startTest
"$RGBASM" -o "$otemp" "$test"/a.asm
"$RGBASM" -o "$gbtemp2" "$test"/b.asm
continueTest
rgblinkQuiet -o "$gbtemp" -l "$test"/script.link "$otemp" "$gbtemp2" 2>"$outtemp"
tryDiff "$test"/out.err "$outtemp"
tryCmpRom "$test"/ref.out.bin
evaluateTest
test="sdcc/good" test="sdcc/good"
startTest startTest
"$RGBASM" -o "$otemp" "$test"/a.asm "$RGBASM" -o "$otemp" "$test"/a.asm