Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/api/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def check_type(lineno, type_list, arg):
return False


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

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


def check_type_is_explicit(lineno: int, id_: str, type_):
Expand Down
5 changes: 3 additions & 2 deletions src/api/symboltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ def update_aliases(entry: SymbolVAR):
for symbol in entry.aliased_by:
symbol.alias = entry

def access_id(self, id_: str, lineno: int, scope=None, default_type=None, default_class=CLASS.unknown):
def access_id(self, id_: str, lineno: int, scope=None, default_type=None, default_class=CLASS.unknown,
ignore_explicit_flag=False):
""" Access a symbol by its identifier and checks if it exists.
If not, it's supposed to be an implicit declared variable.

Expand All @@ -418,7 +419,7 @@ def access_id(self, id_: str, lineno: int, scope=None, default_type=None, defaul
default_type = symbols.TYPEREF(default_type, lineno, implicit=False)
assert default_type is None or isinstance(default_type, symbols.TYPEREF)

if not check.check_is_declared_explicit(lineno, id_):
if not ignore_explicit_flag and not check.check_is_declared_explicit(lineno, id_):
return None

result = self.get_entry(id_, scope)
Expand Down
3 changes: 2 additions & 1 deletion src/zxbc/zxbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,8 @@ def p_addr_of_id(p):
""" bexpr : ADDRESSOF singleid
"""
id_: Id = p[2]
entry = SYMBOL_TABLE.access_id(id_.name, id_.lineno)
# Access id. For @ operator we ignore the explicit flag
entry = SYMBOL_TABLE.access_id(id_.name, id_.lineno, ignore_explicit_flag=True)
if entry is None:
p[0] = None
return
Expand Down
41 changes: 41 additions & 0 deletions tests/functional/explicit6.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
org 32768
__START_PROGRAM:
di
push ix
push iy
exx
push hl
exx
ld hl, 0
add hl, sp
ld (__CALL_BACK__), hl
ei
jp __MAIN_PROGRAM__
__CALL_BACK__:
DEFW 0
ZXBASIC_USER_DATA:
; Defines USER DATA Length in bytes
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
ZXBASIC_USER_DATA_END:
__MAIN_PROGRAM__:
xor a
ld (__LABEL__a), a
__LABEL__a:
ld hl, 0
ld b, h
ld c, l
__END_PROGRAM:
di
ld hl, (__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
;; --- end of user code ---
END
6 changes: 6 additions & 0 deletions tests/functional/explicit6.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma explicit = true

POKE @a, 0

a:

5 changes: 5 additions & 0 deletions tests/functional/explicit7.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma explicit = true

POKE @a, 0