diff options
author | Oxore <oxore@protonmail.com> | 2023-08-10 01:44:33 +0300 |
---|---|---|
committer | Oxore <oxore@protonmail.com> | 2023-08-10 01:44:33 +0300 |
commit | de62710a3e90a0f513443bbdbe5ef60673bb040f (patch) | |
tree | 233783a8acc6d1ad52e29206905b3668f1d7ff33 | |
parent | 4ce10dab5eae51dcec32eee5d7a9cd71d4f73c07 (diff) |
Extract the parts counter out and increment it inside the loop
-rw-r--r-- | main.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -2167,7 +2167,7 @@ static int pars_parse_arg_starts_with_minus( struct inside_parens_state { bool an1_found, an2_found, dn_found, pc_found; enum opsize size; - uint8_t an1, an2, dn, parts; + uint8_t an1, an2, dn; }; static int pars_parse_arg_inside_parens_single_item( @@ -2281,10 +2281,6 @@ static int pars_parse_arg_inside_parens_single_item( } else { return pars_yield_error(self, self->cur_tok_id, E_EA_PART_NOT_EXPR); } - state->parts++; - if (pars_is_eof_reached(self)) { - return pars_yield_error_eof(self, E_EA_PART_DELIM); - } return OK; } @@ -2306,10 +2302,9 @@ static int pars_parse_arg_inside_parens( // - (An,expr,Xi.w) in any order (6 variants) // - (PC,expr,Xi) in any order (6 variants) // - (PC,expr,Xi.w) in any order (6 variants) - struct inside_parens_state state = { - .parts = arg->expr.first_token ? 1 : 0, - }; - while (state.parts < 3) { + unsigned parts = arg->expr.first_token ? 1 : 0; + struct inside_parens_state state = {0}; + while (parts < 3) { if (pars_is_eof_reached(self)) { return pars_yield_error_eof(self, E_EA_PART); } @@ -2317,12 +2312,16 @@ static int pars_parse_arg_inside_parens( if (ret != OK) { return ret; } + parts++; + if (pars_is_eof_reached(self)) { + return pars_yield_error_eof(self, E_EA_PART_DELIM); + } const struct token delim = pars_peek(self); const size_t delim_id = pars_commit(self); if (delim.type == TT_COMMA) { continue; } else if (delim.type == TT_RPAREN) { - if (state.parts == 1 && arg->expr.first_token) { + if (parts == 1 && arg->expr.first_token) { assert(!state.an1_found && !state.an2_found && !state.dn_found && !state.pc_found); // It turns out we are inside of expression, so this closing // parenthesis is part of it. Let's accumulate it and move @@ -2337,7 +2336,7 @@ static int pars_parse_arg_inside_parens( return pars_yield_error(self, delim_id, E_EA_PART); } } - if (state.parts == 1 && state.an1_found) { + if (parts == 1 && state.an1_found) { // It is either (An) or (An)+ assert(!state.pc_found && !state.dn_found && !arg->expr.first_token); if (pars_is_eof_reached(self)) { @@ -2354,20 +2353,20 @@ static int pars_parse_arg_inside_parens( arg->xn = state.an1; arg->num_tokens = self->cur_tok_id - arg->first_token; return OK; - } else if (state.parts == 2 && state.an1_found && arg->expr.first_token) { + } else if (parts == 2 && state.an1_found && arg->expr.first_token) { // It is (An,d16) or (d16,An) assert(!state.an2_found && !state.pc_found && !state.dn_found); arg->type = ARG_AN_ADDR_16; arg->xn = state.an1; arg->num_tokens = self->cur_tok_id - arg->first_token; return OK; - } else if (state.parts == 2 && state.pc_found && arg->expr.first_token) { + } else if (parts == 2 && state.pc_found && arg->expr.first_token) { // It is (PC,d16) or (d16,PC) assert(!state.an1_found && !state.an2_found && !state.dn_found); arg->type = ARG_PC_ADDR_16; arg->num_tokens = self->cur_tok_id - arg->first_token; return OK; - } else if (state.parts == 3 && state.pc_found && arg->expr.first_token && (state.an1_found || state.dn_found)) { + } else if (parts == 3 && state.pc_found && arg->expr.first_token && (state.an1_found || state.dn_found)) { // It is (d8,PC,Xn) assert((state.an1_found && !state.dn_found) || (!state.an1_found && state.dn_found)); arg->type = ARG_PC_ADDR_8_XI; @@ -2375,7 +2374,7 @@ static int pars_parse_arg_inside_parens( arg->num_tokens = self->cur_tok_id - arg->first_token; arg->briefext_size = state.size; return OK; - } else if (state.parts == 3 && state.an1_found && arg->expr.first_token && (state.an2_found || state.dn_found)) { + } else if (parts == 3 && state.an1_found && arg->expr.first_token && (state.an2_found || state.dn_found)) { // It is (d8,An,Xn) assert((state.an2_found && !state.dn_found) || (!state.an2_found && state.dn_found)); arg->type = ARG_AN_ADDR_8_XI; |