Skip to content

Commit a04acb2

Browse files
committed
Fix nested #IF <cond> not working
1 parent 869b2ef commit a04acb2

7 files changed

Lines changed: 43 additions & 1 deletion

File tree

tests/functional/prepro91.bi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
#ifdef MACRO
3+
# if MACRO != VALUE
4+
WRONG
5+
# endif
6+
#else
7+
OK
8+
#endif
9+

tests/functional/prepro91.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#line 1 "prepro91.bi"
2+
#line 7 "prepro91.bi"
3+
OK
4+
#line 9 "prepro91.bi"

tests/functional/prepro92.bi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
REM Checks -D MACRO=VALUE is defined correctly from zxbc commandline
3+
4+
#ifdef MACRO
5+
# error This should not happen
6+
#else
7+
OK
8+
#endif
9+

tests/functional/prepro92.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#line 1 "prepro92.bi"
2+
#line 7 "prepro92.bi"
3+
OK
4+
#line 9 "prepro92.bi"

tests/functional/prepro93.bi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
REM Checks -D MACRO=VALUE is defined correctly from zxbc commandline
3+
4+
#ifdef MACRO
5+
# if MACRO != VALUE
6+
# error This should not happen
7+
# endif
8+
#else
9+
OK
10+
#endif
11+

tests/functional/prepro93.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#line 1 "prepro93.bi"
2+
#line 9 "prepro93.bi"
3+
OK
4+
#line 11 "prepro93.bi"

zxbpp/zxbpp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ def p_if_expr_header(p):
552552
global ENABLED
553553

554554
IFDEFS.append((ENABLED, p.lineno(1)))
555-
ENABLED = bool(int(p[2])) if p[2].isdigit() else ID_TABLE.defined(p[2])
555+
if ENABLED:
556+
ENABLED = bool(int(p[2])) if p[2].isdigit() else ID_TABLE.defined(p[2])
556557

557558

558559
def p_expr(p):

0 commit comments

Comments
 (0)