ruby-changes:60368
From: Nobuyoshi <ko1@a...>
Date: Wed, 11 Mar 2020 18:18:11 +0900 (JST)
Subject: [ruby-changes:60368] f020d340f4 (master): parse.y: hoisted out new_nil_at
https://git.ruby-lang.org/ruby.git/commit/?id=f020d340f4 From f020d340f4eceb2fc809499e3e57924eac4bb75b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 11 Mar 2020 18:11:24 +0900 Subject: parse.y: hoisted out new_nil_at new_nil_at: create NEW_NIL node with zero-width location. diff --git a/parse.y b/parse.y index 5a0ee21..bbe460b 100644 --- a/parse.y +++ b/parse.y @@ -454,6 +454,7 @@ set_line_body(NODE *body, int line) https://github.com/ruby/ruby/blob/trunk/parse.y#L454 static NODE* cond(struct parser_params *p, NODE *node, const YYLTYPE *loc); static NODE* method_cond(struct parser_params *p, NODE *node, const YYLTYPE *loc); #define new_nil(loc) NEW_NIL(loc) +static NODE *new_nil_at(struct parser_params *p, const rb_code_position_t *pos); static NODE *new_if(struct parser_params*,NODE*,NODE*,NODE*,const YYLTYPE*); static NODE *new_unless(struct parser_params*,NODE*,NODE*,NODE*,const YYLTYPE*); static NODE *logop(struct parser_params*,ID,NODE*,NODE*,const YYLTYPE*,const YYLTYPE*); @@ -2215,48 +2216,32 @@ arg : lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2216 | arg tDOT2 { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @2.end_pos; - loc.end_pos = @2.end_pos; - value_expr($1); - $$ = NEW_DOT2($1, new_nil(&loc), &@$); + $$ = NEW_DOT2($1, new_nil_at(p, &@2.end_pos), &@$); /*% %*/ /*% ripper: dot2!($1, Qnil) %*/ } | arg tDOT3 { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @2.end_pos; - loc.end_pos = @2.end_pos; - value_expr($1); - $$ = NEW_DOT3($1, new_nil(&loc), &@$); + $$ = NEW_DOT3($1, new_nil_at(p, &@2.end_pos), &@$); /*% %*/ /*% ripper: dot3!($1, Qnil) %*/ } | tBDOT2 arg { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @1.beg_pos; - loc.end_pos = @1.beg_pos; - value_expr($2); - $$ = NEW_DOT2(new_nil(&loc), $2, &@$); + $$ = NEW_DOT2(new_nil_at(p, &@1.beg_pos), $2, &@$); /*% %*/ /*% ripper: dot2!(Qnil, $2) %*/ } | tBDOT3 arg { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @1.beg_pos; - loc.end_pos = @1.beg_pos; - value_expr($2); - $$ = NEW_DOT3(new_nil(&loc), $2, &@$); + $$ = NEW_DOT3(new_nil_at(p, &@1.beg_pos), $2, &@$); /*% %*/ /*% ripper: dot3!(Qnil, $2) %*/ } @@ -4192,25 +4177,17 @@ p_value : p_primitive https://github.com/ruby/ruby/blob/trunk/parse.y#L4177 } | p_primitive tDOT2 { - /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @2.end_pos; - loc.end_pos = @2.end_pos; - + /*%%%*/ value_expr($1); - $$ = NEW_DOT2($1, new_nil(&loc), &@$); + $$ = NEW_DOT2($1, new_nil_at(p, &@2.end_pos), &@$); /*% %*/ /*% ripper: dot2!($1, Qnil) %*/ } | p_primitive tDOT3 { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @2.end_pos; - loc.end_pos = @2.end_pos; - value_expr($1); - $$ = NEW_DOT3($1, new_nil(&loc), &@$); + $$ = NEW_DOT3($1, new_nil_at(p, &@2.end_pos), &@$); /*% %*/ /*% ripper: dot3!($1, Qnil) %*/ } @@ -4220,24 +4197,16 @@ p_value : p_primitive https://github.com/ruby/ruby/blob/trunk/parse.y#L4197 | tBDOT2 p_primitive { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @1.beg_pos; - loc.end_pos = @1.beg_pos; - value_expr($2); - $$ = NEW_DOT2(new_nil(&loc), $2, &@$); + $$ = NEW_DOT2(new_nil_at(p, &@1.beg_pos), $2, &@$); /*% %*/ /*% ripper: dot2!(Qnil, $2) %*/ } | tBDOT3 p_primitive { /*%%%*/ - YYLTYPE loc; - loc.beg_pos = @1.beg_pos; - loc.end_pos = @1.beg_pos; - value_expr($2); - $$ = NEW_DOT3(new_nil(&loc), $2, &@$); + $$ = NEW_DOT3(new_nil_at(p, &@1.beg_pos), $2, &@$); /*% %*/ /*% ripper: dot3!(Qnil, $2) %*/ } @@ -11158,6 +11127,13 @@ method_cond(struct parser_params *p, NODE *node, const YYLTYPE *loc) https://github.com/ruby/ruby/blob/trunk/parse.y#L11127 } static NODE* +new_nil_at(struct parser_params *p, const rb_code_position_t *pos) +{ + YYLTYPE loc = {*pos, *pos}; + return NEW_NIL(&loc); +} + +static NODE* new_if(struct parser_params *p, NODE *cc, NODE *left, NODE *right, const YYLTYPE *loc) { if (!cc) return right; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/