From 771a1bdb9ea61889dfdadfb54df3b0c08492c9d8 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Fri, 4 Jul 2014 19:53:52 -0700 Subject: [PATCH] when (switch) statements now match C style of requiring 'break' to avoid falling through to next of (case) clause. --- src/samplesrc/test.pla | 12 ++++++++++++ src/toolsrc/parse.c | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/samplesrc/test.pla b/src/samplesrc/test.pla index f080820..ae2b514 100755 --- a/src/samplesrc/test.pla +++ b/src/samplesrc/test.pla @@ -62,16 +62,22 @@ 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 @@ -81,5 +87,11 @@ end ptr=@struct main(@struct:6) puti((ptr):6) +putln puti(ptr=>6) +putln +puti((ptr).6) +putln +puti(ptr->6) +putln done diff --git a/src/toolsrc/parse.c b/src/toolsrc/parse.c index da5bc5f..9ba2384 100755 --- a/src/toolsrc/parse.c +++ b/src/toolsrc/parse.c @@ -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;