mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix incorrect line numbers with some IF blocks
If a line ended with a string's closing quote, or a newline escape, then
skipping over that line via IF/ELIF/ELSE would fail to count that line,
offsetting the rest of the file.
I have no idea why but for some reason 9829be1 changed *specifically*
`if_skip_to_else` to have incorrect behavior on string endings. The incorrect
behavior on newline escapes seems to have been here since the beginning.
Also added a test to check for both of those behaviors in both functions.
Honestly, it baffles me that nobody ever noticed. I didn't until I started
working on #395.
This commit is contained in:
@@ -354,20 +354,14 @@ static void if_skip_to_else(void)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (*src) {
|
if (*src == '\"') {
|
||||||
case '\\':
|
|
||||||
src += 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\"':
|
|
||||||
src += 2;
|
|
||||||
inString = false;
|
inString = false;
|
||||||
break;
|
} else if (*src == '\\') {
|
||||||
|
/* Escaped quotes don't end the string */
|
||||||
default:
|
if (*++src != '\"')
|
||||||
src++;
|
src--;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
src++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,21 +399,14 @@ static void if_skip_to_endc(void)
|
|||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (*src) {
|
if (*src == '\"') {
|
||||||
|
|
||||||
case '\\':
|
|
||||||
src += 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\"':
|
|
||||||
src++;
|
|
||||||
inString = false;
|
inString = false;
|
||||||
break;
|
} else if (*src == '\\') {
|
||||||
|
/* Escaped quotes don't end the string */
|
||||||
default:
|
if (*++src != '\"')
|
||||||
src++;
|
src--;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
src++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
test/asm/correct-line-number.asm
Normal file
11
test/asm/correct-line-number.asm
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
IF 0
|
||||||
|
"\
|
||||||
|
"
|
||||||
|
ELIF 1
|
||||||
|
WARN "Am I geting ahead of myself?"
|
||||||
|
ELSE
|
||||||
|
"\
|
||||||
|
"
|
||||||
|
ENDC
|
||||||
|
|
||||||
|
WARN "Hopefully not."
|
||||||
4
test/asm/correct-line-number.out
Normal file
4
test/asm/correct-line-number.out
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
warning: correct-line-number.asm(5):
|
||||||
|
Am I geting ahead of myself?
|
||||||
|
warning: correct-line-number.asm(11):
|
||||||
|
Hopefully not.
|
||||||
4
test/asm/correct-line-number.out.pipe
Normal file
4
test/asm/correct-line-number.out.pipe
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
warning: -(5):
|
||||||
|
Am I geting ahead of myself?
|
||||||
|
warning: -(11):
|
||||||
|
Hopefully not.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
warning: multiple-charmaps.asm(75):
|
warning: multiple-charmaps.asm(75):
|
||||||
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
||||||
ERROR: multiple-charmaps.asm(100) -> new_(5):
|
ERROR: multiple-charmaps.asm(100) -> new_(6):
|
||||||
Charmap 'map1' already exists
|
Charmap 'map1' already exists
|
||||||
ERROR: multiple-charmaps.asm(102) -> set_(2):
|
ERROR: multiple-charmaps.asm(102) -> set_(2):
|
||||||
Charmap 'map5' doesn't exist
|
Charmap 'map5' doesn't exist
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
warning: -(75):
|
warning: -(75):
|
||||||
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
Using 'charmap' within a section when the current charmap is 'main' is deprecated
|
||||||
ERROR: -(100) -> new_(5):
|
ERROR: -(100) -> new_(6):
|
||||||
Charmap 'map1' already exists
|
Charmap 'map1' already exists
|
||||||
ERROR: -(102) -> set_(2):
|
ERROR: -(102) -> set_(2):
|
||||||
Charmap 'map5' doesn't exist
|
Charmap 'map5' doesn't exist
|
||||||
|
|||||||
Reference in New Issue
Block a user