Skip to content

Commit 53a3ef3

Browse files
authored
Merge pull request #515 from boriel/bugfix/misleading_warning_when_using_END_at_the_end
Do not add redundant END
2 parents 6d195e1 + e403920 commit 53a3ef3

11 files changed

Lines changed: 7 additions & 84 deletions

File tree

src/zxbc/zxbparser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from src.api.check import is_unsigned
3838
from src.api.check import is_static
3939
from src.api.check import is_string
40+
from src.api.check import is_ender
4041

4142
from src.api.constants import CLASS
4243
from src.api.constants import SCOPE
@@ -530,7 +531,8 @@ def p_start(p):
530531
__end = make_sentence(p.lexer.lineno, 'END', make_number(0, lineno=p.lexer.lineno), sentinel=True)
531532

532533
if not is_null(ast):
533-
ast.appendChild(__end)
534+
if isinstance(ast, symbols.BLOCK) and not is_ender(ast[-1]):
535+
ast.appendChild(__end)
534536
else:
535537
ast = __end
536538

tests/functional/doloop4.asm

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,5 @@ __LABEL__20:
2626
jp __LABEL0
2727
__LABEL1:
2828
jp __LABEL__20
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
4029
;; --- end of user code ---
4130
END

tests/functional/end.asm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,5 @@ __END_PROGRAM:
3434
pop ix
3535
ei
3636
ret
37-
ld hl, 0
38-
ld b, h
39-
ld c, l
40-
jp __END_PROGRAM
4137
;; --- end of user code ---
4238
END

tests/functional/fornextopt.asm

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,5 @@ __LABEL0:
3939
jp nc, __LABEL3
4040
__LABEL2:
4141
jp __LABEL__lbl
42-
__END_PROGRAM:
43-
di
44-
ld hl, (__CALL_BACK__)
45-
ld sp, hl
46-
exx
47-
pop hl
48-
exx
49-
pop iy
50-
pop ix
51-
ei
52-
ret
5342
;; --- end of user code ---
5443
END

tests/functional/fornextopt2.asm

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,5 @@ __LABEL0:
3838
jp nc, __LABEL3
3939
__LABEL2:
4040
jp __LABEL__lbl
41-
__END_PROGRAM:
42-
di
43-
ld hl, (__CALL_BACK__)
44-
ld sp, hl
45-
exx
46-
pop hl
47-
exx
48-
pop iy
49-
pop ix
50-
ei
51-
ret
5241
;; --- end of user code ---
5342
END

tests/functional/ifemptylabel1.asm

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,5 @@ __LABEL__Here:
2828
inc (hl)
2929
__LABEL1:
3030
jp __LABEL__Here
31-
__END_PROGRAM:
32-
di
33-
ld hl, (__CALL_BACK__)
34-
ld sp, hl
35-
exx
36-
pop hl
37-
exx
38-
pop iy
39-
pop ix
40-
ei
41-
ret
4231
;; --- end of user code ---
4332
END

tests/functional/ifemptylabel2.asm

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,5 @@ __LABEL__Here:
3232
ld (_a), a
3333
__LABEL1:
3434
jp __LABEL__Here
35-
__END_PROGRAM:
36-
di
37-
ld hl, (__CALL_BACK__)
38-
ld sp, hl
39-
exx
40-
pop hl
41-
exx
42-
pop iy
43-
pop ix
44-
ei
45-
ret
4635
;; --- end of user code ---
4736
END

tests/functional/ongosub.asm

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ __LABEL__70:
7979
call __PRINTSTR
8080
call PRINT_EOL
8181
ret
82-
ld hl, 0
83-
ld b, h
84-
ld c, l
85-
jp __END_PROGRAM
8682
__LABEL2:
8783
DEFW 0003h
8884
DEFB 45h
@@ -144,7 +140,7 @@ __ON_GOTO_START:
144140
ld h, (hl)
145141
ld l, a
146142
jp (hl)
147-
#line 89 "ongosub.bas"
143+
#line 85 "ongosub.bas"
148144
#line 1 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
149145
; vim:ts=4:sw=4:et:
150146
; vim:ts=4:sw=4:et:
@@ -1078,7 +1074,7 @@ __PRINT_TABLE: ; Jump table for 0 .. 22 codes
10781074
DW __PRINT_AT ; 22 AT
10791075
DW __PRINT_TAB ; 23 TAB
10801076
ENDP
1081-
#line 90 "ongosub.bas"
1077+
#line 86 "ongosub.bas"
10821078
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printstr.asm"
10831079
#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm"
10841080
; vim: ts=4:et:sw=4:
@@ -1383,5 +1379,5 @@ __PRINT_STR:
13831379
ld d, a ; Saves a FLAG
13841380
jp __PRINT_STR_LOOP
13851381
ENDP
1386-
#line 91 "ongosub.bas"
1382+
#line 87 "ongosub.bas"
13871383
END

tests/functional/opt1_endtest.asm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,5 @@ __END_PROGRAM:
3737
pop ix
3838
ei
3939
ret
40-
ld hl, 0
41-
ld b, h
42-
ld c, l
43-
jp __END_PROGRAM
4440
;; --- end of user code ---
4541
END

tests/functional/test_errmsg.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ ifempty0.bas:3: warning: Useless empty IF ignored
107107
forempty.bas:4: warning: STEP value is 0 and FOR might loop forever
108108
>>> process_file('fornextopt.bas')
109109
fornextopt.bas:4: warning: FOR start value is greater than end. This FOR loop is useless
110-
fornextopt.bas:10: warning: Unreachable code
111110
>>> process_file('fornextopt2.bas')
112111
fornextopt2.bas:4: warning: FOR start value is lower than end. This FOR loop is useless
113-
fornextopt2.bas:10: warning: Unreachable code
114112
>>> process_file('atoloduplbl.asm')
115113
atoloduplbl.asm:3: error: label '.SetSubScreen' already defined at line 2
116114
>>> process_file('asmerror2.asm')
@@ -202,6 +200,7 @@ bad_pragma.bas:4: warning: Ignoring unknown pragma 'BAD_PRAGMA'
202200
bad_pragma.bas:6: warning: Ignoring unknown pragma 'BAD_PRAGMA'
203201
>>> process_file('opt2_global_array2.bas')
204202
opt2_global_array2.bas:1: warning: Variable 'myArray' is never used
203+
>>> process_file('end.bas')
205204

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

0 commit comments

Comments
 (0)