ruby-changes:49572
From: mame <ko1@a...>
Date: Mon, 8 Jan 2018 21:30:42 +0900 (JST)
Subject: [ruby-changes:49572] mame:r61688 (trunk): parse.y: Factor out code fragments that merges two code ranges
mame 2018-01-08 21:30:35 +0900 (Mon, 08 Jan 2018) New Revision: 61688 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61688 Log: parse.y: Factor out code fragments that merges two code ranges Modified files: trunk/node.h trunk/parse.y Index: node.h =================================================================== --- node.h (revision 61687) +++ node.h (revision 61688) @@ -232,6 +232,14 @@ typedef struct rb_code_range_struct { https://github.com/ruby/ruby/blob/trunk/node.h#L232 rb_code_location_t last_loc; } rb_code_range_t; +static inline rb_code_range_t code_range_gen(rb_code_range_t *cr1, rb_code_range_t *cr2) +{ + rb_code_range_t cr; + cr.first_loc = cr1->first_loc; + cr.last_loc = cr2->last_loc; + return cr; +} + typedef struct RNode { VALUE flags; union { Index: parse.y =================================================================== --- parse.y (revision 61687) +++ parse.y (revision 61688) @@ -1398,9 +1398,7 @@ stmt : keyword_alias fitem {SET_LEX_STA https://github.com/ruby/ruby/blob/trunk/parse.y#L1398 { /*%%%*/ NODE *resq; - YYLTYPE location; - location.first_loc = @2.first_loc; - location.last_loc = @3.last_loc; + YYLTYPE location = code_range_gen(&@2, &@3); resq = NEW_RESBODY(0, remove_begin($3), 0, &location); $$ = NEW_RESCUE(remove_begin($1), resq, 0, &@$); /*% @@ -1492,9 +1490,7 @@ command_asgn : lhs '=' command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1490 | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs { /*%%%*/ - YYLTYPE location; - location.first_loc = @1.first_loc; - location.last_loc = @3.last_loc; + YYLTYPE location = code_range_gen(&@1, &@3); /*% %*/ $$ = const_path_field($1, $3, &location); @@ -1523,9 +1519,7 @@ command_rhs : command_call %prec tOP_A https://github.com/ruby/ruby/blob/trunk/parse.y#L1519 | command_call modifier_rescue stmt { /*%%%*/ - YYLTYPE location; - location.first_loc = @2.first_loc; - location.last_loc = @3.last_loc; + YYLTYPE location = code_range_gen(&@2, &@3); value_expr($1); $$ = NEW_RESCUE($1, NEW_RESBODY(0, remove_begin($3), 0, &location), 0, &@$); /*% @@ -1582,8 +1576,7 @@ cmd_brace_block : tLBRACE_ARG brace_body https://github.com/ruby/ruby/blob/trunk/parse.y#L1576 { $$ = $2; /*%%%*/ - $$->nd_body->nd_loc.first_loc = @1.first_loc; - $$->nd_body->nd_loc.last_loc = @3.last_loc; + $$->nd_body->nd_loc = code_range_gen(&@1, &@3); nd_set_line($$, @1.last_loc.lineno); /*% %*/ } @@ -2132,9 +2125,7 @@ arg : lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2125 | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs { /*%%%*/ - YYLTYPE location; - location.first_loc = @1.first_loc; - location.last_loc = @3.last_loc; + YYLTYPE location = code_range_gen(&@1, &@3); /*% %*/ $$ = const_path_field($1, $3, &location); @@ -2351,9 +2342,7 @@ arg_rhs : arg %prec tOP_ASGN https://github.com/ruby/ruby/blob/trunk/parse.y#L2342 | arg modifier_rescue arg { /*%%%*/ - YYLTYPE location; - location.first_loc = @2.first_loc; - location.last_loc = @3.last_loc; + YYLTYPE location = code_range_gen(&@2, &@3); value_expr($1); $$ = NEW_RESCUE($1, NEW_RESBODY(0, remove_begin($3), 0, &location), 0, &@$); /*% @@ -2858,9 +2847,7 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2847 | k_class cpath superclass { if (in_def) { - YYLTYPE location; - location.first_loc = @1.first_loc; - location.last_loc = @2.last_loc; + YYLTYPE location = code_range_gen(&@1, &@2); yyerror1(&location, "class definition in method body"); } $<num>1 = in_class; @@ -2907,9 +2894,7 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2894 | k_module cpath { if (in_def) { - YYLTYPE location; - location.first_loc = @1.first_loc; - location.last_loc = @2.last_loc; + YYLTYPE location = code_range_gen(&@1, &@2); yyerror1(&location, "module definition in method body"); } $<num>1 = in_class; @@ -3505,8 +3490,7 @@ do_block : keyword_do_block do_body keyw https://github.com/ruby/ruby/blob/trunk/parse.y#L3490 { $$ = $2; /*%%%*/ - $$->nd_body->nd_loc.first_loc = @1.first_loc; - $$->nd_body->nd_loc.last_loc = @3.last_loc; + $$->nd_body->nd_loc = code_range_gen(&@1, &@3); nd_set_line($$, @1.last_loc.lineno); /*% %*/ } @@ -3625,8 +3609,7 @@ brace_block : '{' brace_body '}' https://github.com/ruby/ruby/blob/trunk/parse.y#L3609 { $$ = $2; /*%%%*/ - $$->nd_body->nd_loc.first_loc = @1.first_loc; - $$->nd_body->nd_loc.last_loc = @3.last_loc; + $$->nd_body->nd_loc = code_range_gen(&@1, &@3); nd_set_line($$, @1.last_loc.lineno); /*% %*/ } @@ -3634,8 +3617,7 @@ brace_block : '{' brace_body '}' https://github.com/ruby/ruby/blob/trunk/parse.y#L3617 { $$ = $2; /*%%%*/ - $$->nd_body->nd_loc.first_loc = @1.first_loc; - $$->nd_body->nd_loc.last_loc = @3.last_loc; + $$->nd_body->nd_loc = code_range_gen(&@1, &@3); nd_set_line($$, @1.last_loc.lineno); /*% %*/ } @@ -4851,9 +4833,7 @@ assoc : arg_value tASSOC arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L4833 | tSTRING_BEG string_contents tLABEL_END arg_value { /*%%%*/ - YYLTYPE location; - location.first_loc = @1.first_loc; - location.last_loc = @3.last_loc; + YYLTYPE location = code_range_gen(&@1, &@3); $$ = list_append(NEW_LIST(dsym_node($2, &location), &location), $4); /*% $$ = dispatch2(assoc_new, dispatch1(dyna_symbol, $2), $4); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/