Skip to content

Commit b7a4edb

Browse files
authored
Merge pull request #506 from boriel/bugfix/explicit_not_used_in_AT_operator
Bugfix/explicit not used in at operator
2 parents fad4f18 + bf8aa68 commit b7a4edb

6 files changed

Lines changed: 59 additions & 6 deletions

File tree

src/api/check.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def check_type(lineno, type_list, arg):
6666
return False
6767

6868

69-
def check_is_declared_explicit(lineno: int, id_: str, classname: str = 'variable'):
69+
def check_is_declared_explicit(lineno: int, id_: str, classname: str = 'variable') -> bool:
7070
""" Check if the current ID is already declared.
7171
If not, triggers a "undeclared identifier" error,
7272
if the --explicit command line flag is enabled (or #pragma
@@ -77,8 +77,7 @@ def check_is_declared_explicit(lineno: int, id_: str, classname: str = 'variable
7777
if not config.OPTIONS.explicit:
7878
return True
7979

80-
entry = global_.SYMBOL_TABLE.check_is_declared(id_, lineno, classname)
81-
return entry is not None # True if declared
80+
return global_.SYMBOL_TABLE.check_is_declared(id_, lineno, classname)
8281

8382

8483
def check_type_is_explicit(lineno: int, id_: str, type_):

src/api/symboltable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ def update_aliases(entry: SymbolVAR):
408408
for symbol in entry.aliased_by:
409409
symbol.alias = entry
410410

411-
def access_id(self, id_: str, lineno: int, scope=None, default_type=None, default_class=CLASS.unknown):
411+
def access_id(self, id_: str, lineno: int, scope=None, default_type=None, default_class=CLASS.unknown,
412+
ignore_explicit_flag=False):
412413
""" Access a symbol by its identifier and checks if it exists.
413414
If not, it's supposed to be an implicit declared variable.
414415
@@ -418,7 +419,7 @@ def access_id(self, id_: str, lineno: int, scope=None, default_type=None, defaul
418419
default_type = symbols.TYPEREF(default_type, lineno, implicit=False)
419420
assert default_type is None or isinstance(default_type, symbols.TYPEREF)
420421

421-
if not check.check_is_declared_explicit(lineno, id_):
422+
if not ignore_explicit_flag and not check.check_is_declared_explicit(lineno, id_):
422423
return None
423424

424425
result = self.get_entry(id_, scope)

src/zxbc/zxbparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,8 @@ def p_addr_of_id(p):
26332633
""" bexpr : ADDRESSOF singleid
26342634
"""
26352635
id_: Id = p[2]
2636-
entry = SYMBOL_TABLE.access_id(id_.name, id_.lineno)
2636+
# Access id. For @ operator we ignore the explicit flag
2637+
entry = SYMBOL_TABLE.access_id(id_.name, id_.lineno, ignore_explicit_flag=True)
26372638
if entry is None:
26382639
p[0] = None
26392640
return

tests/functional/explicit6.asm

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
jp __MAIN_PROGRAM__
14+
__CALL_BACK__:
15+
DEFW 0
16+
ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
19+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
20+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
21+
ZXBASIC_USER_DATA_END:
22+
__MAIN_PROGRAM__:
23+
xor a
24+
ld (__LABEL__a), a
25+
__LABEL__a:
26+
ld hl, 0
27+
ld b, h
28+
ld c, l
29+
__END_PROGRAM:
30+
di
31+
ld hl, (__CALL_BACK__)
32+
ld sp, hl
33+
exx
34+
pop hl
35+
exx
36+
pop iy
37+
pop ix
38+
ei
39+
ret
40+
;; --- end of user code ---
41+
END

tests/functional/explicit6.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma explicit = true
2+
3+
POKE @a, 0
4+
5+
a:
6+

tests/functional/explicit7.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma explicit = true
2+
3+
POKE @a, 0
4+
5+

0 commit comments

Comments
 (0)