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

ruby-changes:48698

From: yui-knk <ko1@a...>
Date: Fri, 17 Nov 2017 08:13:30 +0900 (JST)
Subject: [ruby-changes:48698] yui-knk:r60814 (trunk): Fix location of NODEs generated by new_op_assign_gen

yui-knk	2017-11-17 08:13:24 +0900 (Fri, 17 Nov 2017)

  New Revision: 60814

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

  Log:
    Fix location of NODEs generated by new_op_assign_gen
    
    * parse.y (new_op_assign_gen): Use a location of lhs
      when call gettable, bacause gettable creates a variable
      node. Use a location of rhs when call new_list,
      because item of new_list is rhs.
    
      The locations of NODE_DVAR(nd_vid: :a) and NODE_ARRAY
      are fixed:
    
      ```
      a -= 1
      ```
    
      * Before
    
      ```
      NODE_DVAR (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 6)
      NODE_ARRAY (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 6)
      ```
    
      * After
    
      ```
      NODE_DVAR (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 1)
      NODE_ARRAY (line: 1, first_lineno: 1, first_column: 5, last_lineno: 1, last_column: 6)
      ```

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 60813)
+++ parse.y	(revision 60814)
@@ -10861,9 +10861,10 @@ new_op_assign_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L10861
 
     if (lhs) {
 	ID vid = lhs->nd_vid;
+	YYLTYPE *lhs_location = &lhs->nd_loc;
 	if (op == tOROP) {
 	    lhs->nd_value = rhs;
-	    asgn = NEW_OP_ASGN_OR(gettable(vid, location), lhs);
+	    asgn = NEW_OP_ASGN_OR(gettable(vid, lhs_location), lhs);
 	    asgn->nd_loc = *location;
 	    if (is_notop_id(vid)) {
 		switch (id_type(vid)) {
@@ -10876,12 +10877,12 @@ new_op_assign_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L10877
 	}
 	else if (op == tANDOP) {
 	    lhs->nd_value = rhs;
-	    asgn = NEW_OP_ASGN_AND(gettable(vid, location), lhs);
+	    asgn = NEW_OP_ASGN_AND(gettable(vid, lhs_location), lhs);
 	    asgn->nd_loc = *location;
 	}
 	else {
 	    asgn = lhs;
-	    asgn->nd_value = new_call(gettable(vid, location), op, new_list(rhs, location), location);
+	    asgn->nd_value = new_call(gettable(vid, lhs_location), op, new_list(rhs, &rhs->nd_loc), location);
 	    asgn->nd_loc = *location;
 	}
     }

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

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