bc: delete unused (write-only) BcParse::nbraces member

function                                             old     new   delta
zbc_lex_next                                        2296    2309     +13
bc_parse_expr_empty_ok                              2021    2025      +4
bc_vm_init                                           760     757      -3
bc_num_printNewline                                   54      51      -3
zbc_num_divmod                                       156     150      -6
bc_parse_reset                                       113     106      -7
zbc_lex_number                                       200     192      -8
bc_parse_number                                       83      66     -17
zdc_parse_expr                                       707     671     -36
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/7 up/down: 17/-80)            Total: -63 bytes
   text	   data	    bss	    dec	    hex	filename
 982275	    485	   7296	 990056	  f1b68	busybox_old
 982212	    485	   7296	 989993	  f1b29	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-16 18:43:51 +01:00
parent 202dd1943c
commit 9dc5d08baa

View File

@ -435,9 +435,9 @@ typedef enum BcLexType {
BC_LEX_COMMA, BC_LEX_COMMA,
BC_LEX_RBRACKET, BC_LEX_RBRACKET,
BC_LEX_LBRACE, BC_LEX_LBRACE, // '{' is 0x7B, '}' is 0x7D,
BC_LEX_SCOLON, BC_LEX_SCOLON,
BC_LEX_RBRACE, BC_LEX_RBRACE, // should be LBRACE+2: code uses (c - '{' + BC_LEX_LBRACE)
BC_LEX_STR, BC_LEX_STR,
BC_LEX_NAME, BC_LEX_NAME,
@ -589,9 +589,6 @@ typedef struct BcParse {
BcFunc *func; BcFunc *func;
size_t fidx; size_t fidx;
//TODO: needed? Example?
size_t nbraces;
size_t in_funcdef; size_t in_funcdef;
} BcParse; } BcParse;
@ -2777,7 +2774,9 @@ static void bc_lex_whitespace(BcLex *l)
l->t.t = BC_LEX_WHITESPACE; l->t.t = BC_LEX_WHITESPACE;
for (;;) { for (;;) {
char c = l->buf[l->i]; char c = l->buf[l->i];
if (c == '\n' || !isspace(c)) if (c == '\n') // this is BC_LEX_NLINE, not BC_LEX_WHITESPACE
break;
if (!isspace(c))
break; break;
l->i++; l->i++;
} }
@ -3003,6 +3002,7 @@ static BC_STATUS zbc_lex_next(BcLex *l)
// Loop until failure or we don't have whitespace. This // Loop until failure or we don't have whitespace. This
// is so the parser doesn't get inundated with whitespace. // is so the parser doesn't get inundated with whitespace.
// Comments are also BC_LEX_WHITESPACE tokens and eaten here.
s = BC_STATUS_SUCCESS; s = BC_STATUS_SUCCESS;
do { do {
dbg_lex("next string to parse:'%.*s'", dbg_lex("next string to parse:'%.*s'",
@ -3149,9 +3149,9 @@ static BC_STATUS zbc_lex_comment(BcLex *l)
const char *buf = l->buf; const char *buf = l->buf;
l->t.t = BC_LEX_WHITESPACE; l->t.t = BC_LEX_WHITESPACE;
i = ++l->i; i = l->i; /* here buf[l->i] is the '*' of opening comment delimiter */
for (;;) { for (;;) {
char c = buf[i]; char c = buf[++i];
check_star: check_star:
if (c == '*') { if (c == '*') {
c = buf[++i]; c = buf[++i];
@ -3164,7 +3164,6 @@ static BC_STATUS zbc_lex_comment(BcLex *l)
RETURN_STATUS(bc_error("comment end could not be found")); RETURN_STATUS(bc_error("comment end could not be found"));
} }
nls += (c == '\n'); nls += (c == '\n');
i++;
} }
l->i = i + 1; l->i = i + 1;
@ -3184,10 +3183,14 @@ static BC_STATUS zbc_lex_token(BcLex *l)
// This is the workhorse of the lexer. // This is the workhorse of the lexer.
switch (c) { switch (c) {
case '\0': case '\0': // probably never reached
case '\n': l->i--;
l->t.t = BC_LEX_EOF;
l->newline = true;
break;
case '\n':
l->t.t = BC_LEX_NLINE;
l->newline = true; l->newline = true;
l->t.t = !c ? BC_LEX_EOF : BC_LEX_NLINE;
break; break;
case '\t': case '\t':
case '\v': case '\v':
@ -3556,7 +3559,7 @@ static void bc_parse_pushIndex(BcParse *p, size_t idx)
} }
} }
static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs) static void bc_parse_number(BcParse *p)
{ {
char *num = xstrdup(p->l.t.v.v); char *num = xstrdup(p->l.t.v.v);
size_t idx = G.prog.consts.len; size_t idx = G.prog.consts.len;
@ -3565,9 +3568,6 @@ static void bc_parse_number(BcParse *p, BcInst *prev, size_t *nexs)
bc_parse_push(p, BC_INST_NUM); bc_parse_push(p, BC_INST_NUM);
bc_parse_pushIndex(p, idx); bc_parse_pushIndex(p, idx);
++(*nexs);
(*prev) = BC_INST_NUM;
} }
IF_BC(static BC_STATUS zbc_parse_stmt_or_funcdef(BcParse *p);) IF_BC(static BC_STATUS zbc_parse_stmt_or_funcdef(BcParse *p);)
@ -3624,7 +3624,6 @@ static void bc_parse_reset(BcParse *p)
p->l.i = p->l.len; p->l.i = p->l.len;
p->l.t.t = BC_LEX_EOF; p->l.t.t = BC_LEX_EOF;
p->nbraces = 0;
bc_vec_pop_all(&p->exits); bc_vec_pop_all(&p->exits);
bc_vec_pop_all(&p->conds); bc_vec_pop_all(&p->conds);
@ -3650,7 +3649,6 @@ static void bc_parse_create(BcParse *p, size_t func)
bc_vec_init(&p->conds, sizeof(size_t), NULL); bc_vec_init(&p->conds, sizeof(size_t), NULL);
bc_vec_init(&p->ops, sizeof(BcLexType), NULL); bc_vec_init(&p->ops, sizeof(BcLexType), NULL);
// p->nbraces = 0; - already is
bc_parse_updateFunc(p, func); bc_parse_updateFunc(p, func);
} }
@ -4846,7 +4844,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext ne
{ {
if (BC_PARSE_LEAF(prev, rprn)) if (BC_PARSE_LEAF(prev, rprn))
return bc_error_bad_expression(); return bc_error_bad_expression();
bc_parse_number(p, &prev, &nexprs); bc_parse_number(p);
nexprs++;
prev = BC_INST_NUM;
paren_expr = get_token = true; paren_expr = get_token = true;
rprn = bin_last = false; rprn = bin_last = false;
@ -5111,7 +5111,8 @@ static BC_STATUS zdc_parse_token(BcParse *p, BcLexType t, uint8_t flags)
if (p->l.t.t != BC_LEX_NUMBER) if (p->l.t.t != BC_LEX_NUMBER)
RETURN_STATUS(bc_error_bad_token()); RETURN_STATUS(bc_error_bad_token());
} }
bc_parse_number(p, &prev, &p->nbraces); bc_parse_number(p);
prev = BC_INST_NUM;
if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG); if (t == BC_LEX_NEG) bc_parse_push(p, BC_INST_NEG);
get_token = true; get_token = true;
break; break;
@ -5159,8 +5160,6 @@ static BC_STATUS zdc_parse_expr(BcParse *p, uint8_t flags)
BcInst inst; BcInst inst;
BcLexType t; BcLexType t;
if (flags & BC_PARSE_NOCALL) p->nbraces = G.prog.results.len;
for (t = p->l.t.t; !s && t != BC_LEX_EOF; t = p->l.t.t) { for (t = p->l.t.t; !s && t != BC_LEX_EOF; t = p->l.t.t) {
inst = dc_parse_insts[t]; inst = dc_parse_insts[t];