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

ruby-changes:48787

From: yui-knk <ko1@a...>
Date: Sat, 25 Nov 2017 10:39:52 +0900 (JST)
Subject: [ruby-changes:48787] yui-knk:r60903 (trunk): parse.y: Fix a location of assignable nodes

yui-knk	2017-11-25 10:39:45 +0900 (Sat, 25 Nov 2017)

  New Revision: 60903

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

  Log:
    parse.y: Fix a location of assignable nodes
    
    * parse.y (new_op_assign_gen): Update the location of
      lhs when NODE_OP_ASGN_OR/NODE_OP_ASGN_AND are generated.
      When NODE_OP_ASGN_OR/NODE_OP_ASGN_AND are generated
      a nd_value of lhs is set, so it is needed to update
      a location of lhs to include a location of rhs (same as
      node_assign_gen).
    
      e.g. The locations of NODE_DASGN_CURR is fixed:
    
      ```
      a ||= 1
      ```
    
      * Before
    
      ```
      NODE_DASGN_CURR (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 1)
      ```
    
      * After
    
      ```
      NODE_DASGN_CURR (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 7)
      ```

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 60902)
+++ parse.y	(revision 60903)
@@ -10858,10 +10858,11 @@ new_op_assign_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L10858
 
     if (lhs) {
 	ID vid = lhs->nd_vid;
-	YYLTYPE *lhs_location = &lhs->nd_loc;
+	YYLTYPE lhs_location = lhs->nd_loc;
 	if (op == tOROP) {
 	    lhs->nd_value = rhs;
-	    asgn = NEW_OP_ASGN_OR(gettable(vid, lhs_location), lhs);
+	    lhs->nd_loc = *location;
+	    asgn = NEW_OP_ASGN_OR(gettable(vid, &lhs_location), lhs);
 	    asgn->nd_loc = *location;
 	    if (is_notop_id(vid)) {
 		switch (id_type(vid)) {
@@ -10874,12 +10875,13 @@ new_op_assign_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L10875
 	}
 	else if (op == tANDOP) {
 	    lhs->nd_value = rhs;
-	    asgn = NEW_OP_ASGN_AND(gettable(vid, lhs_location), lhs);
+	    lhs->nd_loc = *location;
+	    asgn = NEW_OP_ASGN_AND(gettable(vid, &lhs_location), lhs);
 	    asgn->nd_loc = *location;
 	}
 	else {
 	    asgn = lhs;
-	    asgn->nd_value = new_call(gettable(vid, lhs_location), op, new_list(rhs, &rhs->nd_loc), 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/

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