when (switch) statements now match C style, requiring explicit 'break' to avoid

falling through to next of (case) clause.
This commit is contained in:
David Schmenk 2014-07-04 19:52:23 -07:00
parent f0c628016e
commit e543bda768
2 changed files with 27 additions and 2 deletions

View File

@ -634,7 +634,8 @@ int parse_expr()
}
int parse_stmnt(void)
{
int tag_prevbrk, tag_else, tag_endif, tag_while, tag_wend, tag_repeat, tag_for, tag_choice, type, addr, step;
int tag_prevbrk, tag_else, tag_endif, tag_while, tag_wend, tag_repeat, tag_for, tag_choice, tag_of;
int type, addr, step;
char *idptr;
/*
@ -802,6 +803,7 @@ int parse_stmnt(void)
tag_prevbrk = break_tag;
break_tag = tag_new(BRANCH_TYPE);
tag_choice = tag_new(BRANCH_TYPE);
tag_of = tag_new(BRANCH_TYPE);
if (!parse_expr())
{
parse_error("Bad CASE expression");
@ -818,14 +820,19 @@ int parse_stmnt(void)
return (0);
}
emit_brne(tag_choice);
emit_codetag(tag_of);
while (parse_stmnt()) next_line();
emit_brnch(break_tag);
//emit_brnch(break_tag);
tag_of = tag_new(BRANCH_TYPE);
emit_brnch(tag_of);
emit_codetag(tag_choice);
tag_choice = tag_new(BRANCH_TYPE);
}
else if (scantoken == DEFAULT_TOKEN)
{
scan();
emit_codetag(tag_of);
tag_of = 0;
while (parse_stmnt()) next_line();
if (scantoken != ENDCASE_TOKEN)
{
@ -839,6 +846,8 @@ int parse_stmnt(void)
return (0);
}
}
if (tag_of)
emit_codetag(tag_of);
emit_codetag(break_tag);
emit_drop();
break_tag = tag_prevbrk;

View File

@ -17,6 +17,7 @@ byte a2e[] = "//e"
byte a2c[] = "//c"
byte a3[] = "///"
word struct[] = 1, 10, 100, 1000, 10000
word ptr
byte spaces[] = " "
;
@ -61,21 +62,36 @@ export def main(range)
when MACHID & $C8
is $08
puts(@a1)
break
is $00
puts(@a2)
break
is $40
puts(@a2p)
break
is $80
puts(@a2e)
break
is $88
puts(@a2c)
break
is $C0
puts(@a3)
break
otherwise
putc('?')
wend
putln
end
ptr=@struct
main(@struct:6)
puti((ptr):6)
putln
puti(ptr=>6)
putln
puti((ptr).6)
putln
puti(ptr->6)
putln
done