Skip to content

Commit 85ce194

Browse files
committed
Add warning for unused arrays
1 parent 7ee5f55 commit 85ce194

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/api/optimize.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,21 @@ def visit_LET(self, node):
284284
else:
285285
yield (yield self.generic_visit(node))
286286

287+
def visit_LETARRAY(self, node):
288+
lvalue = node.args[0].entry
289+
if self.O_LEVEL > 1 and not lvalue.accessed:
290+
warning_not_used(lvalue.lineno, lvalue.name, fname=lvalue.filename)
291+
block = symbols.BLOCK(*[
292+
symbols.CALL(x.entry, x.args, x.lineno, lvalue.filename) for x in self.filter_inorder(
293+
node.children[1],
294+
lambda x: isinstance(x, symbols.FUNCCALL),
295+
lambda x: not isinstance(x, symbols.FUNCTION)
296+
)
297+
])
298+
yield block
299+
else:
300+
yield (yield self.generic_visit(node))
301+
287302
def visit_LETSUBSTR(self, node):
288303
if self.O_LEVEL > 1 and not node.children[0].accessed:
289304
errmsg.warning_not_used(node.children[0].lineno, node.children[0].name)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
_myArray2:
22+
DEFW __LABEL0
23+
_myArray2.__DATA__.__PTR__:
24+
DEFW _myArray2.__DATA__
25+
_myArray2.__DATA__:
26+
DEFB 00h
27+
DEFB 00h
28+
DEFB 00h
29+
DEFB 00h
30+
DEFB 00h
31+
DEFB 00h
32+
__LABEL0:
33+
DEFW 0000h
34+
DEFB 01h
35+
ZXBASIC_USER_DATA_END:
36+
__MAIN_PROGRAM__:
37+
call _Init
38+
ld hl, 0
39+
ld b, h
40+
ld c, l
41+
__END_PROGRAM:
42+
di
43+
ld hl, (__CALL_BACK__)
44+
ld sp, hl
45+
exx
46+
pop hl
47+
pop iy
48+
pop ix
49+
exx
50+
ei
51+
ret
52+
_Init:
53+
push ix
54+
ld ix, 0
55+
add ix, sp
56+
ld hl, 0
57+
push hl
58+
inc sp
59+
_Init__leave:
60+
ld sp, ix
61+
pop ix
62+
ret
63+
;; --- end of user code ---
64+
END
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DIM myArray(1 to 6) as ubyte
2+
DIM myArray2(1 to 6) as Ubyte
3+
4+
5+
SUB Init()
6+
DIM i as ubyte
7+
myArray(i) = 2 * myArray2(i)
8+
END SUB
9+
10+
Init()

tests/functional/test_errmsg.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ dim_at_init_err.bas:4: error: Syntax Error. Unexpected token 'AT' <AT>
200200
bad_pragma.bas:2: warning: Ignoring unknown pragma 'BAD_PRAGMA'
201201
bad_pragma.bas:4: warning: Ignoring unknown pragma 'BAD_PRAGMA'
202202
bad_pragma.bas:6: warning: Ignoring unknown pragma 'BAD_PRAGMA'
203+
>>> process_file('opt2_global_array2.bas')
204+
opt2_global_array2.bas:1: warning: Variable 'myArray' is never used
203205

204206
# Test warning silencing
205207
>>> process_file('mcleod3.bas', ['-S', '-q', '-O --expect-warnings=2'])

0 commit comments

Comments
 (0)