diff options
author | Denys Vlasenko | 2018-12-16 19:21:57 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-12-16 19:21:57 +0100 |
commit | a50576a415a9b5d384a28c9bd4b55a4df2974248 (patch) | |
tree | 12db52aea474921a6fb5bc935405309b25e73c88 | |
parent | 6d29879c676a636656c7b29ab5be76518346b19c (diff) | |
download | busybox-a50576a415a9b5d384a28c9bd4b55a4df2974248.zip busybox-a50576a415a9b5d384a28c9bd4b55a4df2974248.tar.gz |
bc: fold zbc_parse_else() into its only caller
While at it, allow newline between "else" and its body
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 59 | ||||
-rwxr-xr-x | testsuite/bc.tests | 5 |
2 files changed, 26 insertions, 38 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index cca64ea..9ce6ab6 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -4112,41 +4112,6 @@ static BC_STATUS zbc_parse_return(BcParse *p) # define zbc_parse_return(...) (zbc_parse_return(__VA_ARGS__), BC_STATUS_SUCCESS) #endif -static BC_STATUS zbc_parse_else(BcParse *p) -{ - BcStatus s; - BcInstPtr ip; - BcInstPtr *ipp; - size_t *label; - - dbg_lex_enter("%s:%d entered", __func__, __LINE__); - - ip.idx = p->func->labels.len; - ip.func = ip.len = 0; - - dbg_lex("%s:%d after if() body: BC_INST_JUMP to %d", __func__, __LINE__, ip.idx); - bc_parse_push(p, BC_INST_JUMP); - bc_parse_pushIndex(p, ip.idx); - - ipp = bc_vec_top(&p->exits); - label = bc_vec_item(&p->func->labels, ipp->idx); - dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); - *label = p->func->code.len; - bc_vec_pop(&p->exits); - - bc_vec_push(&p->exits, &ip); - bc_vec_push(&p->func->labels, &ip.idx); - - s = zbc_parse_stmt(p); - if (s) RETURN_STATUS(s); - - dbg_lex_done("%s:%d done", __func__, __LINE__); - RETURN_STATUS(s); -} -#if ERRORS_ARE_FATAL -# define zbc_parse_else(...) (zbc_parse_else(__VA_ARGS__), BC_STATUS_SUCCESS) -#endif - static BC_STATUS zbc_parse_if(BcParse *p) { BcStatus s; @@ -4179,12 +4144,30 @@ static BC_STATUS zbc_parse_if(BcParse *p) s = zbc_parse_stmt(p); if (s) RETURN_STATUS(s); + dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t); if (p->l.t.t == BC_LEX_KEY_ELSE) { - s = zbc_lex_next(&p->l); + s = zbc_lex_next_and_skip_NLINE(&p->l); + if (s) RETURN_STATUS(s); + + ip.idx = p->func->labels.len; + ip.func = ip.len = 0; + + dbg_lex("%s:%d after if() body: BC_INST_JUMP to %d", __func__, __LINE__, ip.idx); + bc_parse_push(p, BC_INST_JUMP); + bc_parse_pushIndex(p, ip.idx); + + ipp = bc_vec_top(&p->exits); + label = bc_vec_item(&p->func->labels, ipp->idx); + dbg_lex("%s:%d rewriting label: %d -> %d", __func__, __LINE__, *label, p->func->code.len); + *label = p->func->code.len; + bc_vec_pop(&p->exits); + + bc_vec_push(&p->exits, &ip); + bc_vec_push(&p->func->labels, &ip.idx); + + s = zbc_parse_stmt(p); if (s) RETURN_STATUS(s); - dbg_lex("%s:%d calling zbc_parse_else(), p->l.t.t:%d", __func__, __LINE__, p->l.t.t); - s = zbc_parse_else(p); } ipp = bc_vec_top(&p->exits); diff --git a/testsuite/bc.tests b/testsuite/bc.tests index 95cc28d..36baeea 100755 --- a/testsuite/bc.tests +++ b/testsuite/bc.tests @@ -61,6 +61,11 @@ testing "bc if(cond)<NL>" \ "9\n" \ "" "if(0)\n3\n9" +testing "bc if(cond) stmt else<NL>" \ + "bc" \ + "4\n9\n" \ + "" "if(0)3 else\n4\n9" + testing "bc while(cond)<NL>" \ "bc" \ "8\n7\n6\n5\n4\n3\n2\n1\n9\n" \ |