ruby-changes:37428
From: naruse <ko1@a...>
Date: Thu, 5 Feb 2015 16:30:45 +0900 (JST)
Subject: [ruby-changes:37428] naruse:r49509 (ruby_2_2): merge revision(s) 49082: [Backport #10661]
naruse 2015-02-05 16:30:27 +0900 (Thu, 05 Feb 2015) New Revision: 49509 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49509 Log: merge revision(s) 49082: [Backport #10661] * parse.y (gettable_gen): disable warnings of possible reference to a local variable defined in a past scope. [ruby-core:67162] [Bug #10661] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/parse.y branches/ruby_2_2/test/ruby/test_parse.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 49508) +++ ruby_2_2/ChangeLog (revision 49509) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Thu Feb 5 16:30:09 2015 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] + Mon Jan 26 15:35:16 2015 Seiei Higa <hanachin@g...> * vm_method.c (check_definition): Module#public_method_defined?, Index: ruby_2_2/parse.y =================================================================== --- ruby_2_2/parse.y (revision 49508) +++ ruby_2_2/parse.y (revision 49509) @@ -31,6 +31,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/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/ruby_2_2/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/ruby_2_2/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; @@ -6901,6 +6910,15 @@ parser_set_token_info(struct parser_para https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L6910 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 { @@ -6914,6 +6932,9 @@ static const struct magic_comment magic_ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L6932 {"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 }; @@ -8839,6 +8860,7 @@ match_op_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L8860 return NEW_CALL(node1, tMATCH, NEW_LIST(node2)); } +# if WARN_PAST_SCOPE static int past_dvar_p(struct parser_params *parser, ID id) { @@ -8849,6 +8871,7 @@ past_dvar_p(struct parser_params *parser https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L8871 } return 0; } +# endif static NODE* gettable_gen(struct parser_params *parser, ID id) @@ -8883,9 +8906,11 @@ gettable_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L8906 } 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: @@ -10005,7 +10030,9 @@ local_push_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L10030 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; @@ -10019,11 +10046,13 @@ local_pop_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L10046 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; @@ -10112,6 +10141,21 @@ dyna_push_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L10141 } 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; @@ -10121,14 +10165,8 @@ dyna_pop_1(struct parser_params *parser) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L10165 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: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 49508) +++ ruby_2_2/version.h (revision 49509) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.0" -#define RUBY_RELEASE_DATE "2015-01-26" -#define RUBY_PATCHLEVEL 37 +#define RUBY_RELEASE_DATE "2015-02-05" +#define RUBY_PATCHLEVEL 38 #define RUBY_RELEASE_YEAR 2015 -#define RUBY_RELEASE_MONTH 1 -#define RUBY_RELEASE_DAY 26 +#define RUBY_RELEASE_MONTH 2 +#define RUBY_RELEASE_DAY 5 #include "ruby/version.h" Index: ruby_2_2/test/ruby/test_parse.rb =================================================================== --- ruby_2_2/test/ruby/test_parse.rb (revision 49508) +++ ruby_2_2/test/ruby/test_parse.rb (revision 49509) @@ -874,7 +874,9 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/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 Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r49082 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/