aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-01-08 19:29:35 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-01-08 19:29:35 +0100
commit132d7c098b1f74ae9b85fc47c15ce4f35c9dd86a (patch)
tree64af02b7728f604361cd9adce72f18330e8ff80b /miscutils
parentfc7aa7a296cf13d13aae5457f4f7cd2b73700234 (diff)
downloadbusybox-w32-132d7c098b1f74ae9b85fc47c15ce4f35c9dd86a.tar.gz
busybox-w32-132d7c098b1f74ae9b85fc47c15ce4f35c9dd86a.tar.bz2
busybox-w32-132d7c098b1f74ae9b85fc47c15ce4f35c9dd86a.zip
bc: zbc_parse_expr_empty_ok() is unused except by zbc_parse_expr(), fold it in
function old new delta zbc_parse_expr 1865 1848 -17 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index faf6226e1..cf0fdd6d8 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -203,7 +203,6 @@ static uint8_t lex_indent;
203typedef enum BcStatus { 203typedef enum BcStatus {
204 BC_STATUS_SUCCESS = 0, 204 BC_STATUS_SUCCESS = 0,
205 BC_STATUS_FAILURE = 1, 205 BC_STATUS_FAILURE = 1,
206 BC_STATUS_PARSE_EMPTY_EXP = 2, // bc_parse_expr_empty_ok() uses this
207} BcStatus; 206} BcStatus;
208 207
209#define BC_VEC_INVALID_IDX ((size_t) -1) 208#define BC_VEC_INVALID_IDX ((size_t) -1)
@@ -3715,17 +3714,7 @@ static size_t bc_program_addFunc(char *name)
3715// first in the expr enum. Note: This only works for binary operators. 3714// first in the expr enum. Note: This only works for binary operators.
3716#define BC_TOKEN_2_INST(t) ((char) ((t) - XC_LEX_OP_POWER + XC_INST_POWER)) 3715#define BC_TOKEN_2_INST(t) ((char) ((t) - XC_LEX_OP_POWER + XC_INST_POWER))
3717 3716
3718static BcStatus bc_parse_expr_empty_ok(uint8_t flags); 3717static BC_STATUS zbc_parse_expr(uint8_t flags);
3719
3720static BC_STATUS zbc_parse_expr(uint8_t flags)
3721{
3722 BcStatus s;
3723
3724 s = bc_parse_expr_empty_ok(flags);
3725 if (s == BC_STATUS_PARSE_EMPTY_EXP)
3726 RETURN_STATUS(bc_error("empty expression"));
3727 RETURN_STATUS(s);
3728}
3729#define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__) COMMA_SUCCESS) 3718#define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__) COMMA_SUCCESS)
3730 3719
3731static BC_STATUS zbc_parse_stmt_possibly_auto(bool auto_allowed); 3720static BC_STATUS zbc_parse_stmt_possibly_auto(bool auto_allowed);
@@ -4692,8 +4681,8 @@ static BC_STATUS zbc_parse_stmt_or_funcdef(void)
4692} 4681}
4693#define zbc_parse_stmt_or_funcdef(...) (zbc_parse_stmt_or_funcdef(__VA_ARGS__) COMMA_SUCCESS) 4682#define zbc_parse_stmt_or_funcdef(...) (zbc_parse_stmt_or_funcdef(__VA_ARGS__) COMMA_SUCCESS)
4694 4683
4695// This is not a "z" function: can also return BC_STATUS_PARSE_EMPTY_EXP 4684#undef zbc_parse_expr
4696static BcStatus bc_parse_expr_empty_ok(uint8_t flags) 4685static BC_STATUS zbc_parse_expr(uint8_t flags)
4697{ 4686{
4698 BcParse *p = &G.prs; 4687 BcParse *p = &G.prs;
4699 BcInst prev = XC_INST_PRINT; 4688 BcInst prev = XC_INST_PRINT;
@@ -4722,7 +4711,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4722 case BC_LEX_OP_INC: 4711 case BC_LEX_OP_INC:
4723 case BC_LEX_OP_DEC: 4712 case BC_LEX_OP_DEC:
4724 dbg_lex("%s:%d LEX_OP_INC/DEC", __func__, __LINE__); 4713 dbg_lex("%s:%d LEX_OP_INC/DEC", __func__, __LINE__);
4725 if (incdec) return bc_error_bad_assignment(); 4714 if (incdec) RETURN_STATUS(bc_error_bad_assignment());
4726 s = zbc_parse_incdec(&prev, &nexprs, flags); 4715 s = zbc_parse_incdec(&prev, &nexprs, flags);
4727 incdec = true; 4716 incdec = true;
4728 rprn = bin_last = false; 4717 rprn = bin_last = false;
@@ -4748,7 +4737,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4748 && prev != XC_INST_SCALE && prev != XC_INST_IBASE 4737 && prev != XC_INST_SCALE && prev != XC_INST_IBASE
4749 && prev != XC_INST_OBASE && prev != BC_INST_LAST 4738 && prev != XC_INST_OBASE && prev != BC_INST_LAST
4750 ) { 4739 ) {
4751 return bc_error_bad_assignment(); 4740 RETURN_STATUS(bc_error_bad_assignment());
4752 } 4741 }
4753 // Fallthrough. 4742 // Fallthrough.
4754 case XC_LEX_OP_POWER: 4743 case XC_LEX_OP_POWER:
@@ -4768,9 +4757,9 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4768 dbg_lex("%s:%d LEX_OP_xyz", __func__, __LINE__); 4757 dbg_lex("%s:%d LEX_OP_xyz", __func__, __LINE__);
4769 if (t == BC_LEX_OP_BOOL_NOT) { 4758 if (t == BC_LEX_OP_BOOL_NOT) {
4770 if (!bin_last && p->lex_last != BC_LEX_OP_BOOL_NOT) 4759 if (!bin_last && p->lex_last != BC_LEX_OP_BOOL_NOT)
4771 return bc_error_bad_expression(); 4760 RETURN_STATUS(bc_error_bad_expression());
4772 } else if (prev == XC_INST_BOOL_NOT) { 4761 } else if (prev == XC_INST_BOOL_NOT) {
4773 return bc_error_bad_expression(); 4762 RETURN_STATUS(bc_error_bad_expression());
4774 } 4763 }
4775 4764
4776 nrelops += (t >= XC_LEX_OP_REL_EQ && t <= XC_LEX_OP_REL_GT); 4765 nrelops += (t >= XC_LEX_OP_REL_EQ && t <= XC_LEX_OP_REL_GT);
@@ -4783,7 +4772,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4783 case BC_LEX_LPAREN: 4772 case BC_LEX_LPAREN:
4784 dbg_lex("%s:%d LEX_LPAREN", __func__, __LINE__); 4773 dbg_lex("%s:%d LEX_LPAREN", __func__, __LINE__);
4785 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4774 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4786 return bc_error_bad_expression(); 4775 RETURN_STATUS(bc_error_bad_expression());
4787 bc_vec_push(&p->ops, &t); 4776 bc_vec_push(&p->ops, &t);
4788 nparens++; 4777 nparens++;
4789 get_token = true; 4778 get_token = true;
@@ -4792,11 +4781,10 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4792 case BC_LEX_RPAREN: 4781 case BC_LEX_RPAREN:
4793 dbg_lex("%s:%d LEX_RPAREN", __func__, __LINE__); 4782 dbg_lex("%s:%d LEX_RPAREN", __func__, __LINE__);
4794 if (p->lex_last == BC_LEX_LPAREN) { 4783 if (p->lex_last == BC_LEX_LPAREN) {
4795 dbg_lex_done("%s:%d done (returning EMPTY_EXP)", __func__, __LINE__); 4784 RETURN_STATUS(bc_error("empty expression"));
4796 return BC_STATUS_PARSE_EMPTY_EXP;
4797 } 4785 }
4798 if (bin_last || prev == XC_INST_BOOL_NOT) 4786 if (bin_last || prev == XC_INST_BOOL_NOT)
4799 return bc_error_bad_expression(); 4787 RETURN_STATUS(bc_error_bad_expression());
4800 if (nparens == 0) { 4788 if (nparens == 0) {
4801 goto exit_loop; 4789 goto exit_loop;
4802 } 4790 }
@@ -4809,7 +4797,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4809 case XC_LEX_NAME: 4797 case XC_LEX_NAME:
4810 dbg_lex("%s:%d LEX_NAME", __func__, __LINE__); 4798 dbg_lex("%s:%d LEX_NAME", __func__, __LINE__);
4811 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4799 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4812 return bc_error_bad_expression(); 4800 RETURN_STATUS(bc_error_bad_expression());
4813 s = zbc_parse_name(&prev, flags & ~BC_PARSE_NOCALL); 4801 s = zbc_parse_name(&prev, flags & ~BC_PARSE_NOCALL);
4814 rprn = (prev == BC_INST_CALL); 4802 rprn = (prev == BC_INST_CALL);
4815 bin_last = false; 4803 bin_last = false;
@@ -4819,7 +4807,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4819 case XC_LEX_NUMBER: 4807 case XC_LEX_NUMBER:
4820 dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__); 4808 dbg_lex("%s:%d LEX_NUMBER", __func__, __LINE__);
4821 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4809 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4822 return bc_error_bad_expression(); 4810 RETURN_STATUS(bc_error_bad_expression());
4823 xc_parse_pushNUM(); 4811 xc_parse_pushNUM();
4824 prev = XC_INST_NUM; 4812 prev = XC_INST_NUM;
4825 get_token = true; 4813 get_token = true;
@@ -4831,7 +4819,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4831 case BC_LEX_KEY_OBASE: 4819 case BC_LEX_KEY_OBASE:
4832 dbg_lex("%s:%d LEX_IBASE/LAST/OBASE", __func__, __LINE__); 4820 dbg_lex("%s:%d LEX_IBASE/LAST/OBASE", __func__, __LINE__);
4833 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4821 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4834 return bc_error_bad_expression(); 4822 RETURN_STATUS(bc_error_bad_expression());
4835 prev = (char) (t - BC_LEX_KEY_IBASE + XC_INST_IBASE); 4823 prev = (char) (t - BC_LEX_KEY_IBASE + XC_INST_IBASE);
4836 xc_parse_push((char) prev); 4824 xc_parse_push((char) prev);
4837 get_token = true; 4825 get_token = true;
@@ -4842,7 +4830,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4842 case BC_LEX_KEY_SQRT: 4830 case BC_LEX_KEY_SQRT:
4843 dbg_lex("%s:%d LEX_LEN/SQRT", __func__, __LINE__); 4831 dbg_lex("%s:%d LEX_LEN/SQRT", __func__, __LINE__);
4844 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4832 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4845 return bc_error_bad_expression(); 4833 RETURN_STATUS(bc_error_bad_expression());
4846 s = zbc_parse_builtin(t, flags, &prev); 4834 s = zbc_parse_builtin(t, flags, &prev);
4847 get_token = true; 4835 get_token = true;
4848 rprn = bin_last = incdec = false; 4836 rprn = bin_last = incdec = false;
@@ -4851,7 +4839,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4851 case BC_LEX_KEY_READ: 4839 case BC_LEX_KEY_READ:
4852 dbg_lex("%s:%d LEX_READ", __func__, __LINE__); 4840 dbg_lex("%s:%d LEX_READ", __func__, __LINE__);
4853 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4841 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4854 return bc_error_bad_expression(); 4842 RETURN_STATUS(bc_error_bad_expression());
4855 s = zbc_parse_read(); 4843 s = zbc_parse_read();
4856 prev = XC_INST_READ; 4844 prev = XC_INST_READ;
4857 get_token = true; 4845 get_token = true;
@@ -4861,21 +4849,21 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4861 case BC_LEX_KEY_SCALE: 4849 case BC_LEX_KEY_SCALE:
4862 dbg_lex("%s:%d LEX_SCALE", __func__, __LINE__); 4850 dbg_lex("%s:%d LEX_SCALE", __func__, __LINE__);
4863 if (BC_PARSE_LEAF(prev, bin_last, rprn)) 4851 if (BC_PARSE_LEAF(prev, bin_last, rprn))
4864 return bc_error_bad_expression(); 4852 RETURN_STATUS(bc_error_bad_expression());
4865 s = zbc_parse_scale(&prev, flags); 4853 s = zbc_parse_scale(&prev, flags);
4866 //get_token = false; - already is 4854 //get_token = false; - already is
4867 rprn = bin_last = false; 4855 rprn = bin_last = false;
4868 nexprs++; 4856 nexprs++;
4869 break; 4857 break;
4870 default: 4858 default:
4871 return bc_error_bad_token(); 4859 RETURN_STATUS(bc_error_bad_token());
4872 } 4860 }
4873 4861
4874 if (s || G_interrupt) // error, or ^C: stop parsing 4862 if (s || G_interrupt) // error, or ^C: stop parsing
4875 return BC_STATUS_FAILURE; 4863 RETURN_STATUS(BC_STATUS_FAILURE);
4876 if (get_token) { 4864 if (get_token) {
4877 s = zxc_lex_next(); 4865 s = zxc_lex_next();
4878 if (s) return s; 4866 if (s) RETURN_STATUS(s);
4879 } 4867 }
4880 } 4868 }
4881 exit_loop: 4869 exit_loop:
@@ -4885,7 +4873,7 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4885 assign = (top >= BC_LEX_OP_ASSIGN_POWER && top <= BC_LEX_OP_ASSIGN); 4873 assign = (top >= BC_LEX_OP_ASSIGN_POWER && top <= BC_LEX_OP_ASSIGN);
4886 4874
4887 if (top == BC_LEX_LPAREN || top == BC_LEX_RPAREN) 4875 if (top == BC_LEX_LPAREN || top == BC_LEX_RPAREN)
4888 return bc_error_bad_expression(); 4876 RETURN_STATUS(bc_error_bad_expression());
4889 4877
4890 xc_parse_push(BC_TOKEN_2_INST(top)); 4878 xc_parse_push(BC_TOKEN_2_INST(top));
4891 4879
@@ -4894,16 +4882,16 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4894 } 4882 }
4895 4883
4896 if (prev == XC_INST_BOOL_NOT || nexprs != 1) 4884 if (prev == XC_INST_BOOL_NOT || nexprs != 1)
4897 return bc_error_bad_expression(); 4885 RETURN_STATUS(bc_error_bad_expression());
4898 4886
4899 if (!(flags & BC_PARSE_REL) && nrelops) { 4887 if (!(flags & BC_PARSE_REL) && nrelops) {
4900 BcStatus s; 4888 BcStatus s;
4901 s = zbc_POSIX_does_not_allow("comparison operators outside if or loops"); 4889 s = zbc_POSIX_does_not_allow("comparison operators outside if or loops");
4902 if (s) return s; 4890 if (s) RETURN_STATUS(s);
4903 } else if ((flags & BC_PARSE_REL) && nrelops > 1) { 4891 } else if ((flags & BC_PARSE_REL) && nrelops > 1) {
4904 BcStatus s; 4892 BcStatus s;
4905 s = zbc_POSIX_requires("exactly one comparison operator per condition"); 4893 s = zbc_POSIX_requires("exactly one comparison operator per condition");
4906 if (s) return s; 4894 if (s) RETURN_STATUS(s);
4907 } 4895 }
4908 4896
4909 if (flags & BC_PARSE_PRINT) { 4897 if (flags & BC_PARSE_PRINT) {
@@ -4913,8 +4901,9 @@ static BcStatus bc_parse_expr_empty_ok(uint8_t flags)
4913 } 4901 }
4914 4902
4915 dbg_lex_done("%s:%d done", __func__, __LINE__); 4903 dbg_lex_done("%s:%d done", __func__, __LINE__);
4916 return BC_STATUS_SUCCESS; 4904 RETURN_STATUS(BC_STATUS_SUCCESS);
4917} 4905}
4906#define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__) COMMA_SUCCESS)
4918 4907
4919#endif // ENABLE_BC 4908#endif // ENABLE_BC
4920 4909