1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

parse.y: reorder in the place

* parse.y (new_args_tail): reorder required and optional keyword
  argument variable IDs in the place.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-22 06:47:53 +00:00
parent b6e2c52857
commit 721b55d70c

40
parse.y
View file

@ -9963,36 +9963,28 @@ new_args_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, ID block,
* #=> <reorder> * #=> <reorder>
* variable order: kr1, k1, k2, internal_id, krest, &b * variable order: kr1, k1, k2, internal_id, krest, &b
*/ */
ID kw_bits; ID kw_bits = internal_id(p), *required_kw_vars, *kw_vars;
struct vtable *vtargs = p->lvtbl->args;
NODE *kwn = kw_args; NODE *kwn = kw_args;
struct vtable *required_kw_vars = vtable_alloc(NULL);
struct vtable *kw_vars = vtable_alloc(NULL);
int i;
vtable_pop(vtargs, !!block + !!kw_rest_arg);
required_kw_vars = kw_vars = &vtargs->tbl[vtargs->pos];
while (kwn) { while (kwn) {
ID vid = kwn->nd_body->nd_vid; if (!NODE_REQUIRED_KEYWORD_P(kwn->nd_body))
--kw_vars;
if (NODE_REQUIRED_KEYWORD_P(kwn->nd_body)) { --required_kw_vars;
vtable_add(required_kw_vars, vid);
}
else {
vtable_add(kw_vars, vid);
}
kwn = kwn->nd_next; kwn = kwn->nd_next;
} }
kw_bits = internal_id(p); for (kwn = kw_args; kwn; kwn = kwn->nd_next) {
ID vid = kwn->nd_body->nd_vid;
/* reorder */ if (NODE_REQUIRED_KEYWORD_P(kwn->nd_body)) {
vtable_pop(p->lvtbl->args, *required_kw_vars++ = vid;
vtable_size(required_kw_vars) + vtable_size(kw_vars) }
+ (block != 0) + (kw_rest_arg != 0)); else {
*kw_vars++ = vid;
for (i=0; i<vtable_size(required_kw_vars); i++) arg_var(p, required_kw_vars->tbl[i]); }
for (i=0; i<vtable_size(kw_vars); i++) arg_var(p, kw_vars->tbl[i]); }
vtable_free(required_kw_vars);
vtable_free(kw_vars);
arg_var(p, kw_bits); arg_var(p, kw_bits);
if (kw_rest_arg) arg_var(p, kw_rest_arg); if (kw_rest_arg) arg_var(p, kw_rest_arg);