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

ruby-changes:49874

From: mame <ko1@a...>
Date: Sun, 21 Jan 2018 02:45:31 +0900 (JST)
Subject: [ruby-changes:49874] mame:r61992 (trunk): parse.y: Remove double meaning of new_qcall/new_command_qcall

mame	2018-01-21 02:45:25 +0900 (Sun, 21 Jan 2018)

  New Revision: 61992

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

  Log:
    parse.y: Remove double meaning of new_qcall/new_command_qcall

  Modified files:
    trunk/ext/ripper/tools/dsl.rb
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 61991)
+++ parse.y	(revision 61992)
@@ -471,8 +471,6 @@ static int id_is_var(struct parser_param https://github.com/ruby/ruby/blob/trunk/parse.y#L471
 #define match_op(p,node1,node2,op_loc,loc) call_bin_op(0, (node1), idEqTilde, (node2), op_loc, loc)
 #define call_uni_op(p, recv,id,op_loc,loc) dispatch2(unary, STATIC_ID2SYM(id), (recv))
 #define logop(p,id,node1,node2,op_loc,loc) call_bin_op(0, (node1), (id), (node2), op_loc, loc)
-static VALUE new_qcall(struct parser_params *p, VALUE q, VALUE r, VALUE m, VALUE a, YYLTYPE *op_loc, const YYLTYPE *loc);
-static VALUE new_command_qcall(struct parser_params* p, VALUE atype, VALUE recv, VALUE mid, VALUE args, VALUE block, const YYLTYPE *op_loc, const YYLTYPE *loc);
 
 #define new_nil(loc) Qnil
 
@@ -636,14 +634,9 @@ static void ripper_error(struct parser_p https://github.com/ruby/ruby/blob/trunk/parse.y#L634
 #define TOKEN2VAL(t) ID2VAL(TOKEN2ID(t))
 #define KWD2EID(t, v) ripper_new_yylval(p, keyword_##t, get_value(v), 0)
 
-#define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b)))
-
 #define params_new(pars, opts, rest, pars2, kws, kwrest, blk) \
         dispatch7(params, (pars), (opts), (rest), (pars2), (kws), (kwrest), (blk))
 
-#define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a)))
-#define method_add_block(p,m,b,loc) dispatch2(method_add_block, (m), (b))
-
 #define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
 
 static inline VALUE
@@ -1311,7 +1304,10 @@ command_call	: command https://github.com/ruby/ruby/blob/trunk/parse.y#L1304
 block_command	: block_call
 		| block_call call_op2 operation2 command_args
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: method_add_arg!(call!($1, $2, $3), $4) %*/
 		    }
 		;
 
@@ -1357,19 +1353,31 @@ command		: fcall command_args       %pre https://github.com/ruby/ruby/blob/trunk/parse.y#L1353
 		    }
 		| primary_value call_op operation2 command_args	%prec tLOWEST
 		    {
+		    /*%%%*/
 			$$ = new_command_qcall(p, $2, $1, $3, $4, Qnull, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: command_call!($1, $2, $3, $4) %*/
 		    }
 		| primary_value call_op operation2 command_args cmd_brace_block
 		    {
+		    /*%%%*/
 			$$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
-		   }
+		    /*% %*/
+		    /*% ripper: method_add_block!(command_call!($1, $2, $3, $4), $5) %*/
+		    }
 		| primary_value tCOLON2 operation2 command_args	%prec tLOWEST
 		    {
+		    /*%%%*/
 			$$ = new_command_qcall(p, ID2VAL(idCOLON2), $1, $3, $4, Qnull, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: command_call!($1, ID2VAL(idCOLON2), $3, $4) %*/
 		    }
 		| primary_value tCOLON2 operation2 command_args cmd_brace_block
 		    {
+		    /*%%%*/
 			$$ = new_command_qcall(p, ID2VAL(idCOLON2), $1, $3, $4, $5, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: method_add_block!(command_call!($1, ID2VAL(idCOLON2), $3, $4), $5) %*/
 		   }
 		| keyword_super command_args
 		    {
@@ -2114,7 +2122,7 @@ call_args	: command https://github.com/ruby/ruby/blob/trunk/parse.y#L2122
 		    /*%%%*/
 			$$ = arg_blk_pass($1, $2);
 		    /*% %*/
-		    /*% ripper: arg_add_optblock($1, $2) %*/
+		    /*% ripper: args_add_block!($1, $2) %*/
 		    }
 		| assocs opt_block_arg
 		    {
@@ -2122,7 +2130,7 @@ call_args	: command https://github.com/ruby/ruby/blob/trunk/parse.y#L2130
 			$$ = $1 ? NEW_LIST(new_hash(p, $1, &@1), &@1) : 0;
 			$$ = arg_blk_pass($$, $2);
 		    /*% %*/
-		    /*% ripper: arg_add_optblock(args_add!(args_new!, bare_assoc_hash!($1)), $2) %*/
+		    /*% ripper: args_add_block!(args_add!(args_new!, bare_assoc_hash!($1)), $2) %*/
 		    }
 		| args ',' assocs opt_block_arg
 		    {
@@ -2130,7 +2138,7 @@ call_args	: command https://github.com/ruby/ruby/blob/trunk/parse.y#L2138
 			$$ = $3 ? arg_append(p, $1, new_hash(p, $3, &@3), &@$) : $1;
 			$$ = arg_blk_pass($$, $4);
 		    /*% %*/
-		    /*% ripper: arg_add_optblock(args_add!($1, bare_assoc_hash!($3)), $4) %*/
+		    /*% ripper: args_add_block!(args_add!($1, bare_assoc_hash!($3)), $4) %*/
 		    }
 		| block_arg
 		    /*% ripper[brace]: args_add_block!(args_new!, $1) %*/
@@ -3093,15 +3101,24 @@ block_call	: command do_block https://github.com/ruby/ruby/blob/trunk/parse.y#L3101
 		    }
 		| block_call call_op2 operation2 opt_paren_args
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: opt_event(:method_add_arg!, call!($1, $2, $3), $4) %*/
 		    }
 		| block_call call_op2 operation2 opt_paren_args brace_block
 		    {
+		    /*%%%*/
 			$$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: opt_event(:method_add_block!, command_call!($1, $2, $3, $4), $5) %*/
 		    }
 		| block_call call_op2 operation2 command_args do_block
 		    {
+		    /*%%%*/
 			$$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: method_add_block!(command_call!($1, $2, $3, $4), $5) %*/
 		    }
 		;
 
@@ -3116,27 +3133,42 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3133
 		    }
 		| primary_value call_op operation2 opt_paren_args
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
 			nd_set_line($$, @3.end_pos.lineno);
+		    /*% %*/
+		    /*% ripper: opt_event(:method_add_arg!, call!($1, $2, $3), $4) %*/
 		    }
 		| primary_value tCOLON2 operation2 paren_args
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, ID2VAL(idCOLON2), $1, $3, $4, &@3, &@$);
 			nd_set_line($$, @3.end_pos.lineno);
+		    /*% %*/
+		    /*% ripper: method_add_arg!(call!($1, ID2VAL(idCOLON2), $3), $4) %*/
 		    }
 		| primary_value tCOLON2 operation3
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, ID2VAL(idCOLON2), $1, $3, Qnull, &@3, &@$);
+		    /*% %*/
+		    /*% ripper: call!($1, ID2VAL(idCOLON2), $3) %*/
 		    }
 		| primary_value call_op paren_args
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, $2, $1, ID2VAL(idCall), $3, &@2, &@$);
 			nd_set_line($$, @2.end_pos.lineno);
+		    /*% %*/
+		    /*% ripper: method_add_arg!(call!($1, $2, ID2VAL(idCall)), $3) %*/
 		    }
 		| primary_value tCOLON2 paren_args
 		    {
+		    /*%%%*/
 			$$ = new_qcall(p, ID2VAL(idCOLON2), $1, ID2VAL(idCall), $3, &@2, &@$);
 			nd_set_line($$, @2.end_pos.lineno);
+		    /*% %*/
+		    /*% ripper: method_add_arg!(call!($1, ID2VAL(idCOLON2), ID2VAL(idCall)), $3) %*/
 		    }
 		| keyword_super paren_args
 		    {
@@ -10034,21 +10066,6 @@ const_decl(struct parser_params *p, NODE https://github.com/ruby/ruby/blob/trunk/parse.y#L10066
 }
 #else
 static VALUE
-new_qcall(struct parser_params *p, VALUE q, VALUE r, VALUE m, VALUE a, YYLTYPE *op_loc, const YYLTYPE *loc)
-{
-    VALUE ret = dispatch3(call, (r), (q), (m));
-    return method_optarg(ret, (a));
-}
-
-static VALUE
-new_command_qcall(struct parser_params* p, VALUE atype, VALUE recv, VALUE mid, VALUE args, VALUE block, const YYLTYPE *op_loc, const YYLTYPE *loc)
-{
-    VALUE ret = dispatch4(command_call, recv, atype, mid, args);
-    if (block == Qundef) ret = method_add_block(p, ret, block, loc);
-    return ret;
-}
-
-static VALUE
 const_decl(struct parser_params *p, VALUE path)
 {
     if (p->in_def) {
Index: ext/ripper/tools/dsl.rb
===================================================================
--- ext/ripper/tools/dsl.rb	(revision 61991)
+++ ext/ripper/tools/dsl.rb	(revision 61992)
@@ -50,18 +50,28 @@ class DSL https://github.com/ruby/ruby/blob/trunk/ext/ripper/tools/dsl.rb#L50
     "v#{ @vars += 1 }"
   end
 
+  def opt_event(event, default, addend)
+    add_event(event, [default, addend], true)
+  end
+
+  def add_event(event, args, qundef_check = false)
+    event = event.to_s.delete_suffix("!")
+    @events[event] = args.size
+    vars = []
+    args.each do |arg|
+      vars << v = new_var
+      @code << "#{ v }=#{ arg };"
+    end
+    v = new_var
+    d = "dispatch#{ args.size }(#{ [event, *vars].join(",") })"
+    d = "#{ vars.last }==Qundef ? #{ vars.first } : #{ d }" if qundef_check
+    @code << "#{ v }=#{ d };"
+    v
+  end
+
   def method_missing(event, *args)
     if event.to_s =~ /!\z/
-      event = $`
-      @events[event] = args.size
-      vars = []
-      args.each do |arg|
-        vars << v = new_var
-        @code << "#{ v }=#{ arg };"
-      end
-      v = new_var
-      @code << "#{ v }=dispatch#{ args.size }(#{ [event, *vars].join(",") });"
-      v
+      add_event(event, args)
     elsif args.empty? and /\Aid[A-Z]/ =~ event.to_s
       event
     else

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

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