diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 23:10:08 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 23:14:44 +0100 |
commit | c2265f526ee638fa6f9cbb6e13be69e49e1a0f71 (patch) | |
tree | 28195683344032efa37ff244d58b1a492397514f | |
parent | c0ef23ca400012ca0f4c1cd098e32b685e8f4f09 (diff) | |
download | busybox-w32-c2265f526ee638fa6f9cbb6e13be69e49e1a0f71.tar.gz busybox-w32-c2265f526ee638fa6f9cbb6e13be69e49e1a0f71.tar.bz2 busybox-w32-c2265f526ee638fa6f9cbb6e13be69e49e1a0f71.zip |
bc: remove lexer function pointer
function old new delta
zbc_lex_next 81 1930 +1849
bc_parse_create 131 124 -7
common_parse_init 31 - -31
zdc_lex_token 672 - -672
zbc_lex_token 1193 - -1193
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 1/1 up/down: 1849/-1903) Total: -54 bytes
text data bss dec hex filename
980634 485 7296 988415 f14ff busybox_old
980580 485 7296 988361 f14c9 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 630a343d1..70ef0fa4a 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -549,9 +549,6 @@ enum { | |||
549 | # define BC_STATUS void | 549 | # define BC_STATUS void |
550 | #endif | 550 | #endif |
551 | 551 | ||
552 | struct BcLex; | ||
553 | typedef BC_STATUS (*BcLexNext)(struct BcLex *) FAST_FUNC; | ||
554 | |||
555 | typedef struct BcLex { | 552 | typedef struct BcLex { |
556 | 553 | ||
557 | const char *buf; | 554 | const char *buf; |
@@ -566,8 +563,6 @@ typedef struct BcLex { | |||
566 | BcVec v; | 563 | BcVec v; |
567 | } t; | 564 | } t; |
568 | 565 | ||
569 | BcLexNext next; | ||
570 | |||
571 | } BcLex; | 566 | } BcLex; |
572 | 567 | ||
573 | #define BC_PARSE_STREND ((char) UCHAR_MAX) | 568 | #define BC_PARSE_STREND ((char) UCHAR_MAX) |
@@ -2911,9 +2906,8 @@ static void bc_lex_name(BcLex *l) | |||
2911 | //return BC_STATUS_SUCCESS; | 2906 | //return BC_STATUS_SUCCESS; |
2912 | } | 2907 | } |
2913 | 2908 | ||
2914 | static void bc_lex_init(BcLex *l, BcLexNext next) | 2909 | static void bc_lex_init(BcLex *l) |
2915 | { | 2910 | { |
2916 | l->next = next; | ||
2917 | bc_char_vec_init(&l->t.v); | 2911 | bc_char_vec_init(&l->t.v); |
2918 | } | 2912 | } |
2919 | 2913 | ||
@@ -2928,6 +2922,17 @@ static void bc_lex_file(BcLex *l) | |||
2928 | l->newline = false; | 2922 | l->newline = false; |
2929 | } | 2923 | } |
2930 | 2924 | ||
2925 | static BC_STATUS zbc_lex_token(BcLex *l); | ||
2926 | static BC_STATUS zdc_lex_token(BcLex *l); | ||
2927 | |||
2928 | static BC_STATUS zcommon_lex_token(BcLex *l) | ||
2929 | { | ||
2930 | if (IS_BC) { | ||
2931 | IF_BC(RETURN_STATUS(zbc_lex_token(l));) | ||
2932 | } | ||
2933 | IF_DC(RETURN_STATUS(zdc_lex_token(l));) | ||
2934 | } | ||
2935 | |||
2931 | static BC_STATUS zbc_lex_next(BcLex *l) | 2936 | static BC_STATUS zbc_lex_next(BcLex *l) |
2932 | { | 2937 | { |
2933 | BcStatus s; | 2938 | BcStatus s; |
@@ -2947,7 +2952,7 @@ static BC_STATUS zbc_lex_next(BcLex *l) | |||
2947 | s = BC_STATUS_SUCCESS; | 2952 | s = BC_STATUS_SUCCESS; |
2948 | do { | 2953 | do { |
2949 | //TODO: replace pointer with if(IS_BC) | 2954 | //TODO: replace pointer with if(IS_BC) |
2950 | ERROR_RETURN(s =) l->next(l); | 2955 | ERROR_RETURN(s =) zcommon_lex_token(l); |
2951 | } while (!s && l->t.t == BC_LEX_WHITESPACE); | 2956 | } while (!s && l->t.t == BC_LEX_WHITESPACE); |
2952 | 2957 | ||
2953 | RETURN_STATUS(s); | 2958 | RETURN_STATUS(s); |
@@ -3091,7 +3096,7 @@ static BC_STATUS zbc_lex_comment(BcLex *l) | |||
3091 | # define zbc_lex_comment(...) (zbc_lex_comment(__VA_ARGS__), BC_STATUS_SUCCESS) | 3096 | # define zbc_lex_comment(...) (zbc_lex_comment(__VA_ARGS__), BC_STATUS_SUCCESS) |
3092 | #endif | 3097 | #endif |
3093 | 3098 | ||
3094 | static FAST_FUNC BC_STATUS zbc_lex_token(BcLex *l) | 3099 | static BC_STATUS zbc_lex_token(BcLex *l) |
3095 | { | 3100 | { |
3096 | BcStatus s = BC_STATUS_SUCCESS; | 3101 | BcStatus s = BC_STATUS_SUCCESS; |
3097 | char c = l->buf[l->i++], c2; | 3102 | char c = l->buf[l->i++], c2; |
@@ -3341,7 +3346,7 @@ static BC_STATUS zdc_lex_string(BcLex *l) | |||
3341 | # define zdc_lex_string(...) (zdc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS) | 3346 | # define zdc_lex_string(...) (zdc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS) |
3342 | #endif | 3347 | #endif |
3343 | 3348 | ||
3344 | static FAST_FUNC BC_STATUS zdc_lex_token(BcLex *l) | 3349 | static BC_STATUS zdc_lex_token(BcLex *l) |
3345 | { | 3350 | { |
3346 | BcStatus s = BC_STATUS_SUCCESS; | 3351 | BcStatus s = BC_STATUS_SUCCESS; |
3347 | char c = l->buf[l->i++], c2; | 3352 | char c = l->buf[l->i++], c2; |
@@ -3563,11 +3568,11 @@ static void bc_parse_free(BcParse *p) | |||
3563 | bc_lex_free(&p->l); | 3568 | bc_lex_free(&p->l); |
3564 | } | 3569 | } |
3565 | 3570 | ||
3566 | static void bc_parse_create(BcParse *p, size_t func, BcLexNext next) | 3571 | static void bc_parse_create(BcParse *p, size_t func) |
3567 | { | 3572 | { |
3568 | memset(p, 0, sizeof(BcParse)); | 3573 | memset(p, 0, sizeof(BcParse)); |
3569 | 3574 | ||
3570 | bc_lex_init(&p->l, next); | 3575 | bc_lex_init(&p->l); |
3571 | bc_vec_init(&p->flags, sizeof(uint8_t), NULL); | 3576 | bc_vec_init(&p->flags, sizeof(uint8_t), NULL); |
3572 | bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL); | 3577 | bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL); |
3573 | bc_vec_init(&p->conds, sizeof(size_t), NULL); | 3578 | bc_vec_init(&p->conds, sizeof(size_t), NULL); |
@@ -4933,11 +4938,6 @@ static BC_STATUS zbc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | |||
4933 | # define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS) | 4938 | # define zbc_parse_expr(...) (zbc_parse_expr(__VA_ARGS__), BC_STATUS_SUCCESS) |
4934 | #endif | 4939 | #endif |
4935 | 4940 | ||
4936 | static void bc_parse_init(BcParse *p, size_t func) | ||
4937 | { | ||
4938 | bc_parse_create(p, func, zbc_lex_token); | ||
4939 | } | ||
4940 | |||
4941 | static BC_STATUS zbc_parse_expression(BcParse *p, uint8_t flags) | 4941 | static BC_STATUS zbc_parse_expression(BcParse *p, uint8_t flags) |
4942 | { | 4942 | { |
4943 | RETURN_STATUS(zbc_parse_expr(p, flags, bc_parse_next_read)); | 4943 | RETURN_STATUS(zbc_parse_expr(p, flags, bc_parse_next_read)); |
@@ -5159,22 +5159,8 @@ static BC_STATUS zdc_parse_parse(BcParse *p) | |||
5159 | # define zdc_parse_parse(...) (zdc_parse_parse(__VA_ARGS__), BC_STATUS_SUCCESS) | 5159 | # define zdc_parse_parse(...) (zdc_parse_parse(__VA_ARGS__), BC_STATUS_SUCCESS) |
5160 | #endif | 5160 | #endif |
5161 | 5161 | ||
5162 | static void dc_parse_init(BcParse *p, size_t func) | ||
5163 | { | ||
5164 | bc_parse_create(p, func, zdc_lex_token); | ||
5165 | } | ||
5166 | |||
5167 | #endif // ENABLE_DC | 5162 | #endif // ENABLE_DC |
5168 | 5163 | ||
5169 | static void common_parse_init(BcParse *p, size_t func) | ||
5170 | { | ||
5171 | if (IS_BC) { | ||
5172 | IF_BC(bc_parse_init(p, func);) | ||
5173 | } else { | ||
5174 | IF_DC(dc_parse_init(p, func);) | ||
5175 | } | ||
5176 | } | ||
5177 | |||
5178 | static BC_STATUS zcommon_parse_expr(BcParse *p, uint8_t flags) | 5164 | static BC_STATUS zcommon_parse_expr(BcParse *p, uint8_t flags) |
5179 | { | 5165 | { |
5180 | if (IS_BC) { | 5166 | if (IS_BC) { |
@@ -5411,7 +5397,7 @@ static BC_STATUS zbc_program_read(void) | |||
5411 | 5397 | ||
5412 | bc_read_line(&buf); | 5398 | bc_read_line(&buf); |
5413 | 5399 | ||
5414 | common_parse_init(&parse, BC_PROG_READ); | 5400 | bc_parse_create(&parse, BC_PROG_READ); |
5415 | bc_lex_file(&parse.l); | 5401 | bc_lex_file(&parse.l); |
5416 | 5402 | ||
5417 | s = zbc_parse_text(&parse, buf.v); | 5403 | s = zbc_parse_text(&parse, buf.v); |
@@ -6612,7 +6598,7 @@ static BC_STATUS zbc_program_execStr(char *code, size_t *bgn, | |||
6612 | f = bc_program_func(fidx); | 6598 | f = bc_program_func(fidx); |
6613 | 6599 | ||
6614 | if (f->code.len == 0) { | 6600 | if (f->code.len == 0) { |
6615 | common_parse_init(&prs, fidx); | 6601 | bc_parse_create(&prs, fidx); |
6616 | s = zbc_parse_text(&prs, *str); | 6602 | s = zbc_parse_text(&prs, *str); |
6617 | if (s) goto err; | 6603 | if (s) goto err; |
6618 | s = zcommon_parse_expr(&prs, BC_PARSE_NOCALL); | 6604 | s = zcommon_parse_expr(&prs, BC_PARSE_NOCALL); |
@@ -7480,7 +7466,7 @@ static int bc_vm_init(const char *env_len) | |||
7480 | if (IS_BC) | 7466 | if (IS_BC) |
7481 | IF_BC(bc_vm_envArgs();) | 7467 | IF_BC(bc_vm_envArgs();) |
7482 | bc_program_init(); | 7468 | bc_program_init(); |
7483 | common_parse_init(&G.prs, BC_PROG_MAIN); | 7469 | bc_parse_create(&G.prs, BC_PROG_MAIN); |
7484 | 7470 | ||
7485 | if (isatty(0)) { | 7471 | if (isatty(0)) { |
7486 | #if ENABLE_FEATURE_BC_SIGNALS | 7472 | #if ENABLE_FEATURE_BC_SIGNALS |