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

ruby-changes:49056

From: yui-knk <ko1@a...>
Date: Tue, 12 Dec 2017 23:47:39 +0900 (JST)
Subject: [ruby-changes:49056] yui-knk:r61171 (trunk): parse.y: Change the last location of none

yui-knk	2017-12-12 23:47:34 +0900 (Tue, 12 Dec 2017)

  New Revision: 61171

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

  Log:
    parse.y: Change the last location of none
    
    * parse.y: Change the last location of none to be
      equal to the first location of none.
      Sometimes none has length (`parser->tokp` does not
      match `lex_p` when none is generated).
      This leads to invalid code_ranges.
    
      e.g. The locations of the NODE_CALL (:sort) is fixed:
    
      ```
      x.sort.join(" ")
      ```
    
      * Before
    
      ```
      NODE_CALL (line: 1, code_range: (1,0)-(1,7))
      ```
    
      * After
    
      ```
      NODE_CALL (line: 1, code_range: (1,0)-(1,6))
      ```

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 61170)
+++ parse.y	(revision 61171)
@@ -59,11 +59,13 @@ https://github.com/ruby/ruby/blob/trunk/parse.y#L59
 	  (Current).last_loc  = YYRHSLOC(Rhs, N).last_loc;		\
 	}								\
       else								\
-	RUBY_SET_YYLLOC(Current);					\
+	RUBY_SET_YYLLOC_OF_NONE(Current);				\
     while (0)
 
 #define RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(Current)			\
     rb_parser_set_location_from_strterm_heredoc(parser, &lex_strterm->u.heredoc, &(Current))
+#define RUBY_SET_YYLLOC_OF_NONE(Current)					\
+    rb_parser_set_location_of_none(parser, &(Current))
 #define RUBY_SET_YYLLOC(Current)					\
     rb_parser_set_location(parser, &(Current))
 
@@ -693,6 +695,7 @@ VALUE rb_parser_lex_state_name(enum lex_ https://github.com/ruby/ruby/blob/trunk/parse.y#L695
 void rb_parser_show_bitstack(struct parser_params *, stack_type, const char *, int);
 PRINTF_ARGS(void rb_parser_fatal(struct parser_params *parser, const char *fmt, ...), 2, 3);
 void rb_parser_set_location_from_strterm_heredoc(struct parser_params *parser, rb_strterm_heredoc_t *here, YYLTYPE *yylloc);
+void rb_parser_set_location_of_none(struct parser_params *parser, YYLTYPE *yylloc);
 void rb_parser_set_location(struct parser_params *parser, YYLTYPE *yylloc);
 RUBY_SYMBOL_EXPORT_END
 
@@ -9911,6 +9914,15 @@ rb_parser_set_location_from_strterm_here https://github.com/ruby/ruby/blob/trunk/parse.y#L9914
 }
 
 void
+rb_parser_set_location_of_none(struct parser_params *parser, YYLTYPE *yylloc)
+{
+    yylloc->first_loc.lineno = ruby_sourceline;
+    yylloc->first_loc.column = (int)(parser->tokp - lex_pbeg);
+    yylloc->last_loc.lineno = ruby_sourceline;
+    yylloc->last_loc.column = (int)(parser->tokp - lex_pbeg);
+}
+
+void
 rb_parser_set_location(struct parser_params *parser, YYLTYPE *yylloc)
 {
     yylloc->first_loc.lineno = ruby_sourceline;

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

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