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

ruby-changes:63306

From: Nobuyoshi <ko1@a...>
Date: Fri, 9 Oct 2020 14:58:44 +0900 (JST)
Subject: [ruby-changes:63306] 8d1b188864 (master): Refactored lex_context management

https://git.ruby-lang.org/ruby.git/commit/?id=8d1b188864

From 8d1b18886459d3f92cbaf6547f22f893a9a2ced1 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 9 Oct 2020 00:19:25 +0900
Subject: Refactored lex_context management

Save and restore `lex_context` as-is wholely, and save in
`k_class` and `k_module` to workaround look-ahead reading.

diff --git a/parse.y b/parse.y
index f8441e8..1a6887e 100644
--- a/parse.y
+++ b/parse.y
@@ -956,8 +956,9 @@ rescued_expr(struct parser_params *p, NODE *arg, NODE *rescue, https://github.com/ruby/ruby/blob/trunk/parse.y#L956
 static void
 restore_defun(struct parser_params *p, NODE *name)
 {
+    YYSTYPE c = {.val = name->nd_cval};
     p->cur_arg = name->nd_vid;
-    p->ctxt.in_def = name->nd_state & 1;
+    p->ctxt.in_def = c.ctxt.in_def;
 }
 
 #ifndef RIPPER
@@ -1689,12 +1690,12 @@ def_name	: fname https://github.com/ruby/ruby/blob/trunk/parse.y#L1690
 		    {
 			ID fname = get_id($1);
 			ID cur_arg = p->cur_arg;
-			int in_def = p->ctxt.in_def;
+			YYSTYPE c = {.ctxt = p->ctxt};
 			numparam_name(p, fname);
 			local_push(p, 0);
 			p->cur_arg = 0;
 			p->ctxt.in_def = 1;
-			$<node>$ = NEW_NODE(NODE_SELF, /*vid*/cur_arg, /*mid*/fname, /*state*/in_def, &@$);
+			$<node>$ = NEW_NODE(NODE_SELF, /*vid*/cur_arg, /*mid*/fname, /*cval*/c.val, &@$);
 		    /*%%%*/
 		    /*%
 			$$ = NEW_RIPPER(fname, get_value($1), $$, &NULL_LOC);
@@ -3068,7 +3069,6 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3069
 			    YYLTYPE loc = code_loc_gen(&@1, &@2);
 			    yyerror1(&loc, "class definition in method body");
 			}
-			$<ctxt>1 = p->ctxt;
 			p->ctxt.in_class = 1;
 			local_push(p, 0);
 		    }
@@ -3087,7 +3087,6 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3087
 		    }
 		| k_class tLSHFT expr
 		    {
-			$<ctxt>$ = p->ctxt;
 			p->ctxt.in_def = 0;
 			p->ctxt.in_class = 0;
 			local_push(p, 0);
@@ -3104,8 +3103,8 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3103
 		    /*% %*/
 		    /*% ripper: sclass!($3, $6) %*/
 			local_pop(p);
-			p->ctxt.in_def = $<ctxt>4.in_def;
-			p->ctxt.in_class = $<ctxt>4.in_class;
+			p->ctxt.in_def = $<ctxt>1.in_def;
+			p->ctxt.in_class = $<ctxt>1.in_class;
 		    }
 		| k_module cpath
 		    {
@@ -3113,7 +3112,6 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3112
 			    YYLTYPE loc = code_loc_gen(&@1, &@2);
 			    yyerror1(&loc, "module definition in method body");
 			}
-			$<ctxt>1 = p->ctxt;
 			p->ctxt.in_class = 1;
 			local_push(p, 0);
 		    }
@@ -3249,12 +3247,14 @@ k_for		: keyword_for https://github.com/ruby/ruby/blob/trunk/parse.y#L3247
 k_class		: keyword_class
 		    {
 			token_info_push(p, "class", &@$);
+			$<ctxt>$ = p->ctxt;
 		    }
 		;
 
 k_module	: keyword_module
 		    {
 			token_info_push(p, "module", &@$);
+			$<ctxt>$ = p->ctxt;
 		    }
 		;
 
-- 
cgit v0.10.2


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

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