ref: a47da5f71f1b755b3a2fa03736cda60534dfb639
parent: 68ad926279b783fe1a20947946cf903e60dc4f01
author: Rangi <35663410+Rangi42@users.noreply.github.com>
date: Fri Sep 30 09:48:30 EDT 2022
Deprecate `__FILE__` and `__LINE__` (#1072) Unlike C, these constants are not convenient for logging in macros, since they always report the same data (their location in the macro). Fixes #1068
--- a/man/rgbasm.5
+++ b/man/rgbasm.5
@@ -1346,8 +1346,6 @@
.It Dv @ Ta Ic EQU Ta PC value (essentially, the current memory address)
.It Dv _RS Ta Ic = Ta _RS Counter
.It Dv _NARG Ta Ic EQU Ta Number of arguments passed to macro, updated by Ic SHIFT
-.It Dv __LINE__ Ta Ic EQU Ta The current line number
-.It Dv __FILE__ Ta Ic EQUS Ta The current filename
.It Dv __DATE__ Ta Ic EQUS Ta Today's date
.It Dv __TIME__ Ta Ic EQUS Ta The current time
.It Dv __ISO_8601_LOCAL__ Ta Ic EQUS Ta ISO 8601 timestamp (local)
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -78,12 +78,15 @@
static int32_t Callback__LINE__(void)
{
+ warning(WARNING_OBSOLETE, "`__LINE__` is deprecated\n");
+
return lexer_GetLineNo();
}
static char const *Callback__FILE__(void)
{
- // FIXME: this is dangerous, and here's why this is CURRENTLY okay. It's still bad, fix it.
+ warning(WARNING_OBSOLETE, "`__FILE__` is deprecated\n");
+
// There are only two call sites for this; one copies the contents directly, the other is
// EQUS expansions, which cannot straddle file boundaries. So this should be fine.
static char *buf = NULL;
@@ -680,7 +683,9 @@
{
PCSymbol = createBuiltinSymbol("@");
struct Symbol *_NARGSymbol = createBuiltinSymbol("_NARG");
+ // __LINE__ is deprecated
struct Symbol *__LINE__Symbol = createBuiltinSymbol("__LINE__");
+ // __FILE__ is deprecated
struct Symbol *__FILE__Symbol = createBuiltinSymbol("__FILE__");
PCSymbol->type = SYM_LABEL;
--- a/test/asm/builtin-overwrite.asm
+++ b/test/asm/builtin-overwrite.asm
@@ -39,5 +39,6 @@
endm
; Representative numeric and string builtins
- tickle __LINE__, 1
- tickle __FILE__, 0
+ ; (SOURCE_DATE_EPOCH in test.sh makes this reproducible)
+ tickle __UTC_YEAR__, 1
+ tickle __ISO_8601_UTC__, 0
--- a/test/asm/builtin-overwrite.err
+++ b/test/asm/builtin-overwrite.err
@@ -1,57 +1,57 @@
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(7):
- '__LINE__' already defined as constant at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(8):
- '__LINE__' already defined as constant at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(11):
- '__LINE__' already defined at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(12):
- '__LINE__' already defined at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(16):
- Built-in symbol '__LINE__' cannot be purged
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(17):
- Built-in symbol '__LINE__' cannot be purged
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(20):
- '__LINE__' already defined at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(21):
- '__LINE__' already defined at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(24):
- '__LINE__' already defined as constant at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(25):
- '__LINE__' already defined as constant at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(28):
- '__LINE__' already defined at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(29):
- '__LINE__' already defined at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(32):
- '__LINE__' already defined as constant at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(33):
- '__LINE__' already defined as constant at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(36):
- '__LINE__' already defined as non-EQUS at <builtin>
-error: builtin-overwrite.asm(42) -> builtin-overwrite.asm::tickle(37):
- '__LINE__' already defined as non-EQUS at <builtin>
+error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(7):
+ '__UTC_YEAR__' already defined as constant at <command-line>
+error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(8):
+ '__UTC_YEAR__' already defined as constant at <command-line>
+error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(11):
+ '__UTC_YEAR__' already defined at <command-line>
+error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(12):
+ '__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(16):
- Built-in symbol '__FILE__' cannot be purged
+ Built-in symbol '__UTC_YEAR__' cannot be purged
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(17):
- Built-in symbol '__FILE__' cannot be purged
+ Built-in symbol '__UTC_YEAR__' cannot be purged
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(20):
- '__FILE__' already defined at <builtin>
+ '__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(21):
- '__FILE__' already defined at <builtin>
+ '__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(24):
- '__FILE__' already defined as constant at <builtin>
+ '__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(25):
- '__FILE__' already defined as constant at <builtin>
+ '__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(28):
- '__FILE__' already defined at <builtin>
+ '__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(29):
- '__FILE__' already defined at <builtin>
+ '__UTC_YEAR__' already defined at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(32):
- '__FILE__' already defined as constant at <builtin>
+ '__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(33):
- '__FILE__' already defined as constant at <builtin>
+ '__UTC_YEAR__' already defined as constant at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(36):
- Built-in symbol '__FILE__' cannot be redefined
+ '__UTC_YEAR__' already defined as non-EQUS at <command-line>
error: builtin-overwrite.asm(43) -> builtin-overwrite.asm::tickle(37):
- Built-in symbol '__FILE__' cannot be redefined
+ '__UTC_YEAR__' already defined as non-EQUS at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(16):
+ Built-in symbol '__ISO_8601_UTC__' cannot be purged
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(17):
+ Built-in symbol '__ISO_8601_UTC__' cannot be purged
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(20):
+ '__ISO_8601_UTC__' already defined at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(21):
+ '__ISO_8601_UTC__' already defined at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(24):
+ '__ISO_8601_UTC__' already defined as constant at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(25):
+ '__ISO_8601_UTC__' already defined as constant at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(28):
+ '__ISO_8601_UTC__' already defined at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(29):
+ '__ISO_8601_UTC__' already defined at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(32):
+ '__ISO_8601_UTC__' already defined as constant at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(33):
+ '__ISO_8601_UTC__' already defined as constant at <command-line>
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(36):
+ Built-in symbol '__ISO_8601_UTC__' cannot be redefined
+error: builtin-overwrite.asm(44) -> builtin-overwrite.asm::tickle(37):
+ Built-in symbol '__ISO_8601_UTC__' cannot be redefined
error: Assembly aborted (28 errors)!
--- a/test/asm/builtin-overwrite.out
+++ b/test/asm/builtin-overwrite.out
@@ -1,14 +1,14 @@
-$9
-$D
-$12
-$16
-$1A
-$1E
-$22
-$26
-builtin-overwrite.asm
-builtin-overwrite.asm
-builtin-overwrite.asm
-builtin-overwrite.asm
-builtin-overwrite.asm
-builtin-overwrite.asm
+$7C5
+$7C5
+$7C5
+$7C5
+$7C5
+$7C5
+$7C5
+$7C5
+1989-04-21T12:34:56Z
+1989-04-21T12:34:56Z
+1989-04-21T12:34:56Z
+1989-04-21T12:34:56Z
+1989-04-21T12:34:56Z
+1989-04-21T12:34:56Z
--- a/test/asm/compound-assignment.asm
+++ b/test/asm/compound-assignment.asm
@@ -33,8 +33,5 @@
_RS += 100
println _RS
-__LINE__ *= 200
-println __LINE__
-
UnDeFiNeD ^= 300
println UnDeFiNeD
--- a/test/asm/compound-assignment.err
+++ b/test/asm/compound-assignment.err
@@ -1,5 +1,3 @@
error: compound-assignment.asm(36):
- '__LINE__' already defined as constant at <builtin>
-error: compound-assignment.asm(39):
Expected constant expression: 'UnDeFiNeD' is not constant at assembly time
-error: Assembly aborted (2 errors)!
+error: Assembly aborted (1 error)!
--- a/test/asm/compound-assignment.out
+++ b/test/asm/compound-assignment.out
@@ -35,5 +35,4 @@
$14
$A
$64
-$25
$0
--- a/test/asm/file-sym.err
+++ b/test/asm/file-sym.err
@@ -1,0 +1,2 @@
+warning: file-sym.asm(1): [-Wobsolete]
+ `__FILE__` is deprecated
--- a/test/asm/preinclude.asm
+++ b/test/asm/preinclude.asm
@@ -1,3 +1,3 @@
-warn "main {__FILE__}"
+warn "main file"
def v3 = v1 + v2
println "{d:v1} + {d:v2} = {d:v3}"
--- a/test/asm/preinclude.err
+++ b/test/asm/preinclude.err
@@ -1,4 +1,4 @@
warning: preinclude.asm(0) -> preinclude.inc(1): [-Wuser]
- pre-include "preinclude.inc"
+ pre-included file
warning: preinclude.asm(1): [-Wuser]
- main "preinclude.asm"
+ main file
--- a/test/asm/preinclude.inc
+++ b/test/asm/preinclude.inc
@@ -1,4 +1,4 @@
-warn "pre-include {__FILE__}"
+warn "pre-included file"
def v1 = 12
rept 3
--- a/test/asm/test.sh
+++ b/test/asm/test.sh
@@ -2,6 +2,9 @@
export LC_ALL=C
+# Game Boy release date, 1989-04-21T12:34:56Z (for reproducible test results)
+export SOURCE_DATE_EPOCH=609165296
+
o="$(mktemp)"
gb="$(mktemp)"
input="$(mktemp)"
@@ -50,20 +53,6 @@
else
echo "${bold}${orange}Warning: cannot run version test!${rescolors}${resbold}"
rm -f version.asm
-fi
-
-# Add the quote test, except on Windows
-if uname | grep -viq mingw; then
- cat > quote\"file.asm <<EOF
-WARN __FILE__
-EOF
- cat > quote\"file.out <<EOF
-EOF
- cat > quote\"file.err <<EOF
-warning: quote"file.asm(1): [-Wuser]
- quote"file.asm
-while expanding symbol "__FILE__"
-EOF
fi
# Check whether to use '.simple.err' files if they exist