[前][次][番号順一覧][スレッド一覧]

ruby-changes:49569

From: yui-knk <ko1@a...>
Date: Mon, 8 Jan 2018 20:50:39 +0900 (JST)
Subject: [ruby-changes:49569] yui-knk:r61685 (trunk): parse.y: Fix the lineno of nd_set_line

yui-knk	2018-01-08 20:50:35 +0900 (Mon, 08 Jan 2018)

  New Revision: 61685

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61685

  Log:
    parse.y: Fix the lineno of nd_set_line
    
    * parse.y: Follow up of r61676. r61676 removed
      ruby_sourceline from some actions. When stop to
      use lineno of "n th" symbol, it's better to
      use last location's lineno of "n-1 th" symbol.
    
      e.g.
    
      ```
      primary : k_begin {} bodystmt k_end
      ```
    
      Before r61676 we use lineno of `@2` (ruby_sourceline).
      In this case, last location's lineno of `k_begin` (`@1`)
      is suitable.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 61684)
+++ parse.y	(revision 61685)
@@ -1584,7 +1584,7 @@ cmd_brace_block	: tLBRACE_ARG brace_body https://github.com/ruby/ruby/blob/trunk/parse.y#L1584
 		    /*%%%*/
 			$$->nd_body->nd_loc.first_loc = @1.first_loc;
 			$$->nd_body->nd_loc.last_loc = @3.last_loc;
-			nd_set_line($$, $$->nd_loc.first_loc.lineno);
+			nd_set_line($$, @1.last_loc.lineno);
 		    /*% %*/
 		    }
 		;
@@ -2598,10 +2598,10 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2598
 			    $$ = NEW_NIL(&@$);
 			}
 			else {
-			    set_line_body($3, @3.first_loc.lineno);
+			    set_line_body($3, @1.last_loc.lineno);
 			    $$ = NEW_BEGIN($3, &@$);
 			}
-			nd_set_line($$, @3.first_loc.lineno);
+			nd_set_line($$, @1.last_loc.lineno);
 		    /*%
 			$$ = dispatch1(begin, $3);
 		    %*/
@@ -2873,8 +2873,8 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2873
 		    /*%%%*/
 			$$ = NEW_CLASS($2, $5, $3, &@$);
 			nd_set_line($$->nd_body, @6.last_loc.lineno);
-			set_line_body($5, @4.last_loc.lineno);
-			nd_set_line($$, @4.last_loc.lineno);
+			set_line_body($5, @3.last_loc.lineno);
+			nd_set_line($$, @3.last_loc.lineno);
 		    /*%
 			$$ = dispatch3(class, $2, $3, $5);
 		    %*/
@@ -2922,8 +2922,8 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2922
 		    /*%%%*/
 			$$ = NEW_MODULE($2, $4, &@$);
 			nd_set_line($$->nd_body, @5.last_loc.lineno);
-			set_line_body($4, @4.first_loc.lineno);
-			nd_set_line($$, @4.first_loc.lineno);
+			set_line_body($4, @2.last_loc.lineno);
+			nd_set_line($$, @2.last_loc.lineno);
 		    /*%
 			$$ = dispatch2(module, $2, $4);
 		    %*/
@@ -3468,7 +3468,7 @@ lambda		:   { https://github.com/ruby/ruby/blob/trunk/parse.y#L3468
 		    /*%%%*/
 			$$ = NEW_LAMBDA($3, $5, &@$);
 			nd_set_line($$->nd_body, @5.last_loc.lineno);
-			nd_set_line($$, @5.first_loc.lineno);
+			nd_set_line($$, @3.last_loc.lineno);
 		    /*%
 			$$ = dispatch2(lambda, $3, $5);
 		    %*/
@@ -3507,7 +3507,7 @@ do_block	: keyword_do_block do_body keyw https://github.com/ruby/ruby/blob/trunk/parse.y#L3507
 		    /*%%%*/
 			$$->nd_body->nd_loc.first_loc = @1.first_loc;
 			$$->nd_body->nd_loc.last_loc = @3.last_loc;
-			nd_set_line($$, @2.first_loc.lineno);
+			nd_set_line($$, @1.last_loc.lineno);
 		    /*% %*/
 		    }
 		;
@@ -3570,12 +3570,12 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3570
 		| primary_value call_op operation2 opt_paren_args
 		    {
 			$$ = new_qcall($2, $1, $3, $4, &@3, &@$);
-			nd_set_line($$, @4.first_loc.lineno);
+			nd_set_line($$, @3.last_loc.lineno);
 		    }
 		| primary_value tCOLON2 operation2 paren_args
 		    {
 			$$ = new_qcall(ID2VAL(idCOLON2), $1, $3, $4, &@3, &@$);
-			nd_set_line($$, @4.first_loc.lineno);
+			nd_set_line($$, @3.last_loc.lineno);
 		    }
 		| primary_value tCOLON2 operation3
 		    {
@@ -3584,12 +3584,12 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3584
 		| primary_value call_op paren_args
 		    {
 			$$ = new_qcall($2, $1, ID2VAL(idCall), $3, &@2, &@$);
-			nd_set_line($$, @3.first_loc.lineno);
+			nd_set_line($$, @2.last_loc.lineno);
 		    }
 		| primary_value tCOLON2 paren_args
 		    {
 			$$ = new_qcall(ID2VAL(idCOLON2), $1, ID2VAL(idCall), $3, &@2, &@$);
-			nd_set_line($$, @3.first_loc.lineno);
+			nd_set_line($$, @2.last_loc.lineno);
 		    }
 		| keyword_super paren_args
 		    {
@@ -3627,7 +3627,7 @@ brace_block	: '{' brace_body '}' https://github.com/ruby/ruby/blob/trunk/parse.y#L3627
 		    /*%%%*/
 			$$->nd_body->nd_loc.first_loc = @1.first_loc;
 			$$->nd_body->nd_loc.last_loc = @3.last_loc;
-			nd_set_line($$, @1.first_loc.lineno);
+			nd_set_line($$, @1.last_loc.lineno);
 		    /*% %*/
 		    }
 		| keyword_do do_body keyword_end
@@ -3636,7 +3636,7 @@ brace_block	: '{' brace_body '}' https://github.com/ruby/ruby/blob/trunk/parse.y#L3636
 		    /*%%%*/
 			$$->nd_body->nd_loc.first_loc = @1.first_loc;
 			$$->nd_body->nd_loc.last_loc = @3.last_loc;
-			nd_set_line($$, @1.first_loc.lineno);
+			nd_set_line($$, @1.last_loc.lineno);
 		    /*% %*/
 		    }
 		;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]