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

ruby-changes:37001

From: nobu <ko1@a...>
Date: Wed, 31 Dec 2014 16:48:57 +0900 (JST)
Subject: [ruby-changes:37001] nobu:r49082 (trunk): parse.y: disable past scope warnings

nobu	2014-12-31 16:48:47 +0900 (Wed, 31 Dec 2014)

  New Revision: 49082

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

  Log:
    parse.y: disable past scope warnings
    
    * parse.y (gettable_gen): disable warnings of possible reference
      to a local variable defined in a past scope.
      [ruby-core:67162] [Bug #10661]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49081)
+++ ChangeLog	(revision 49082)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 31 16:48:44 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (gettable_gen): disable warnings of possible reference
+	  to a local variable defined in a past scope.
+	  [ruby-core:67162] [Bug #10661]
+
 Wed Dec 31 13:43:48 2014  Tanaka Akira  <akr@f...>
 
 	* lib/resolv.rb (Resolv::DNS::Name#==): Compare an array of Label:Str
Index: parse.y
===================================================================
--- parse.y	(revision 49081)
+++ parse.y	(revision 49082)
@@ -31,6 +31,10 @@ https://github.com/ruby/ruby/blob/trunk/parse.y#L31
 #include <ctype.h>
 #include "probes.h"
 
+#ifndef WARN_PAST_SCOPE
+# define WARN_PAST_SCOPE 0
+#endif
+
 #define YYMALLOC(size)		rb_parser_malloc(parser, (size))
 #define YYREALLOC(ptr, size)	rb_parser_realloc(parser, (ptr), (size))
 #define YYCALLOC(nelem, size)	rb_parser_calloc(parser, (nelem), (size))
@@ -113,7 +117,9 @@ struct local_vars { https://github.com/ruby/ruby/blob/trunk/parse.y#L117
     struct vtable *args;
     struct vtable *vars;
     struct vtable *used;
+# if WARN_PAST_SCOPE
     struct vtable *past;
+# endif
     struct local_vars *prev;
     stack_type cmdargs;
 };
@@ -270,6 +276,9 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L276
 #ifndef RIPPER
     /* Ruby core only */
     unsigned int parser_token_info_enabled: 1;
+# if WARN_PAST_SCOPE
+    unsigned int parser_past_scope_enabled: 1;
+# endif
     int nerr;
 
     NODE *parser_eval_tree_begin;
@@ -6891,6 +6900,15 @@ parser_set_token_info(struct parser_para https://github.com/ruby/ruby/blob/trunk/parse.y#L6900
     int b = parser_get_bool(parser, name, val);
     if (b >= 0) parser->parser_token_info_enabled = b;
 }
+
+# if WARN_PAST_SCOPE
+static void
+parser_set_past_scope(struct parser_params *parser, const char *name, const char *val)
+{
+    int b = parser_get_bool(parser, name, val);
+    if (b >= 0) parser->parser_past_scope_enabled = b;
+}
+# endif
 #endif
 
 struct magic_comment {
@@ -6904,6 +6922,9 @@ static const struct magic_comment magic_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6922
     {"encoding", magic_comment_encoding, parser_encode_length},
 #ifndef RIPPER
     {"warn_indent", parser_set_token_info},
+# if WARN_PAST_SCOPE
+    {"warn_past_scope", parser_set_past_scope},
+# endif
 #endif
 };
 
@@ -8829,6 +8850,7 @@ match_op_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8850
     return NEW_CALL(node1, tMATCH, NEW_LIST(node2));
 }
 
+# if WARN_PAST_SCOPE
 static int
 past_dvar_p(struct parser_params *parser, ID id)
 {
@@ -8839,6 +8861,7 @@ past_dvar_p(struct parser_params *parser https://github.com/ruby/ruby/blob/trunk/parse.y#L8861
     }
     return 0;
 }
+# endif
 
 static NODE*
 gettable_gen(struct parser_params *parser, ID id)
@@ -8873,9 +8896,11 @@ gettable_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8896
 	    }
 	    return NEW_LVAR(id);
 	}
+# if WARN_PAST_SCOPE
 	if (!in_defined && RTEST(ruby_verbose) && past_dvar_p(parser, id)) {
 	    rb_warningV("possible reference to past scope - %"PRIsVALUE, rb_id2str(id));
 	}
+# endif
 	/* method call without arguments */
 	return NEW_VCALL(id);
       case ID_GLOBAL:
@@ -9995,7 +10020,9 @@ local_push_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L10020
     local->used = !(inherit_dvars &&
 		    (ifndef_ripper(compile_for_eval || e_option_supplied(parser))+0)) &&
 	RTEST(ruby_verbose) ? vtable_alloc(0) : 0;
+# if WARN_PAST_SCOPE
     local->past = 0;
+# endif
     local->cmdargs = cmdarg_stack;
     cmdarg_stack = 0;
     lvtbl = local;
@@ -10009,11 +10036,13 @@ local_pop_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L10036
 	warn_unused_var(parser, lvtbl);
 	vtable_free(lvtbl->used);
     }
+# if WARN_PAST_SCOPE
     while (lvtbl->past) {
 	struct vtable *past = lvtbl->past;
 	lvtbl->past = past->prev;
 	vtable_free(past);
     }
+# endif
     vtable_free(lvtbl->args);
     vtable_free(lvtbl->vars);
     cmdarg_stack = lvtbl->cmdargs;
@@ -10102,6 +10131,21 @@ dyna_push_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L10131
 }
 
 static void
+dyna_pop_vtable(struct parser_params *parser, struct vtable **vtblp)
+{
+    struct vtable *tmp = *vtblp;
+    *vtblp = tmp->prev;
+# if WARN_PAST_SCOPE
+    if (parser->parser_past_scope_enabled) {
+	tmp->prev = lvtbl->past;
+	lvtbl->past = tmp;
+	return;
+    }
+# endif
+    vtable_free(tmp);
+}
+
+static void
 dyna_pop_1(struct parser_params *parser)
 {
     struct vtable *tmp;
@@ -10111,14 +10155,8 @@ dyna_pop_1(struct parser_params *parser) https://github.com/ruby/ruby/blob/trunk/parse.y#L10155
 	lvtbl->used = lvtbl->used->prev;
 	vtable_free(tmp);
     }
-    tmp = lvtbl->args;
-    lvtbl->args = lvtbl->args->prev;
-    tmp->prev = lvtbl->past;
-    lvtbl->past = tmp;
-    tmp = lvtbl->vars;
-    lvtbl->vars = lvtbl->vars->prev;
-    tmp->prev = lvtbl->past;
-    lvtbl->past = tmp;
+    dyna_pop_vtable(parser, &lvtbl->args);
+    dyna_pop_vtable(parser, &lvtbl->vars);
 }
 
 static void
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 49081)
+++ test/ruby/test_parse.rb	(revision 49082)
@@ -874,7 +874,9 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L874
     assert_warning(/#{a}/) {eval("#{a} = 1; /(?<#{a}>)/ =~ ''")}
   end
 
+=begin
   def test_past_scope_variable
     assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
   end
+=end
 end

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

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