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

ruby-changes:50826

From: nobu <ko1@a...>
Date: Thu, 29 Mar 2018 12:42:37 +0900 (JST)
Subject: [ruby-changes:50826] nobu:r63033 (trunk): Use only CMDARG/COND _PUSH/POP for cmdarg/cond management.

nobu	2018-03-29 12:42:32 +0900 (Thu, 29 Mar 2018)

  New Revision: 63033

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

  Log:
    Use only CMDARG/COND _PUSH/POP for cmdarg/cond management.
    
    From: Ilya Bylich <ibylich@g...>

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 63032)
+++ parse.y	(revision 63033)
@@ -157,7 +157,6 @@ struct local_vars { https://github.com/ruby/ruby/blob/trunk/parse.y#L157
     struct vtable *past;
 # endif
     struct local_vars *prev;
-    stack_type cmdargs, cond; /* XXX: backup for cmdargs_stack and p->cond_stack.  Because this is not a part of local variables, refactoring is needed. */
 };
 
 #define DVARS_INHERIT ((void*)1)
@@ -2271,13 +2270,12 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2270
 		    }
 		| k_begin
 		    {
-			$<val>1 = p->cmdarg_stack;
-			CMDARG_SET(0);
+			CMDARG_PUSH(0);
 		    }
 		  bodystmt
 		  k_end
 		    {
-			CMDARG_SET($<val>1);
+			CMDARG_POP();
 		    /*%%%*/
 			set_line_body($3, @1.end_pos.lineno);
 			$$ = NEW_BEGIN($3, &@$);
@@ -3267,14 +3265,14 @@ brace_body	: {$<vars>$ = dyna_push(p);} https://github.com/ruby/ruby/blob/trunk/parse.y#L3265
 		;
 
 do_body 	: {$<vars>$ = dyna_push(p);}
-		  {$<val>$ = p->cmdarg_stack; CMDARG_SET(0);}
+		  {CMDARG_PUSH(0);}
 		  opt_block_param bodystmt
 		    {
 		    /*%%%*/
 			$$ = NEW_ITER($3, $4, &@$);
 		    /*% %*/
 		    /*% ripper: do_block!(escape_Qundef($3), $4) %*/
-			CMDARG_SET($<val>2);
+			CMDARG_POP();
 			dyna_pop(p, $<vars>1);
 		    }
 		;
@@ -3621,10 +3619,8 @@ string_content	: tSTRING_CONTENT https://github.com/ruby/ruby/blob/trunk/parse.y#L3619
 		    }
 		| tSTRING_DBEG
 		    {
-			$<val>1 = p->cond_stack;
-			$<val>$ = p->cmdarg_stack;
-			COND_SET(0);
-			CMDARG_SET(0);
+			CMDARG_PUSH(0);
+			COND_PUSH(0);
 		    }
 		    {
 			/* need to backup p->lex.strterm so that a string literal `%!foo,#{ !0 },bar!` can be parsed */
@@ -3645,8 +3641,8 @@ string_content	: tSTRING_CONTENT https://github.com/ruby/ruby/blob/trunk/parse.y#L3641
 		    }
 		  compstmt tSTRING_DEND
 		    {
-			COND_SET($<val>1);
-			CMDARG_SET($<val>2);
+			COND_POP();
+			CMDARG_POP();
 			p->lex.strterm = $<strterm>3;
 			SET_LEX_STATE($<num>4);
 			p->lex.brace_nest = $<num>5;
@@ -8006,10 +8002,11 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L8002
 	return c;
 
       case '}':
+	/* tSTRING_DEND does COND_POP and CMDARG_POP in the yacc's rule */
+	if (!p->lex.brace_nest--) return tSTRING_DEND;
 	COND_POP();
 	CMDARG_POP();
 	SET_LEX_STATE(EXPR_END);
-	if (!p->lex.brace_nest--) return tSTRING_DEND;
 	p->lex.paren_nest--;
 	return c;
 
@@ -10260,10 +10257,8 @@ local_push(struct parser_params *p, int https://github.com/ruby/ruby/blob/trunk/parse.y#L10257
 # if WARN_PAST_SCOPE
     local->past = 0;
 # endif
-    local->cmdargs = p->cmdarg_stack;
-    CMDARG_SET(0);
-    local->cond = p->cond_stack;
-    COND_SET(0);
+    CMDARG_PUSH(0);
+    COND_PUSH(0);
     p->lvtbl = local;
 }
 
@@ -10284,8 +10279,8 @@ local_pop(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L10279
 # endif
     vtable_free(p->lvtbl->args);
     vtable_free(p->lvtbl->vars);
-    CMDARG_SET(p->lvtbl->cmdargs);
-    COND_SET(p->lvtbl->cond);
+    CMDARG_POP();
+    COND_POP();
     xfree(p->lvtbl);
     p->lvtbl = local;
 }
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 63032)
+++ test/ruby/test_parse.rb	(revision 63033)
@@ -1149,6 +1149,14 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1149
     end
   end
 
+  def test_command_def_cmdarg
+    assert_valid_syntax("\n#{<<~"begin;"}\n#{<<~'end;'}")
+    begin;
+      m def x(); end
+      1.tap do end
+    end;
+  end
+
 =begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}

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

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