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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yui-knk 2018-01-08 11:50:35 +00:00
Родитель 436eef270d
Коммит a7d49457df
1 изменённых файлов: 15 добавлений и 15 удалений

30
parse.y
Просмотреть файл

@ -1584,7 +1584,7 @@ cmd_brace_block : tLBRACE_ARG brace_body '}'
/*%%%*/
$$->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
$$ = 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
/*%%%*/
$$ = 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
/*%%%*/
$$ = 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 : {
/*%%%*/
$$ = 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 keyword_end
/*%%%*/
$$->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
| 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
| 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 '}'
/*%%%*/
$$->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 '}'
/*%%%*/
$$->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);
/*% %*/
}
;