ruby-changes:33764
From: nobu <ko1@a...>
Date: Tue, 6 May 2014 23:28:55 +0900 (JST)
Subject: [ruby-changes:33764] nobu:r45845 (trunk): parse.y: remove duplicated names
nobu 2014-05-06 23:28:48 +0900 (Tue, 06 May 2014) New Revision: 45845 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45845 Log: parse.y: remove duplicated names * parse.y (local_tbl_gen): remove local variables duplicated with arguments. Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_variable.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45844) +++ ChangeLog (revision 45845) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue May 6 23:28:47 2014 Nobuyoshi Nakada <nobu@r...> + + * parse.y (local_tbl_gen): remove local variables duplicated with + arguments. + Tue May 6 18:48:50 2014 Tanaka Akira <akr@f...> * lib/time.rb (Time.make_time): Adjust the time zone of "now". Index: parse.y =================================================================== --- parse.y (revision 45844) +++ parse.y (revision 45845) @@ -9715,30 +9715,25 @@ local_pop_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L9715 #ifndef RIPPER static ID* -vtable_tblcpy(ID *buf, const struct vtable *src) -{ - int i, cnt = vtable_size(src); - - if (cnt > 0) { - buf[0] = cnt; - for (i = 0; i < cnt; i++) { - buf[i] = src->tbl[i]; - } - return buf; - } - return 0; -} - -static ID* local_tbl_gen(struct parser_params *parser) { - int cnt = vtable_size(lvtbl->args) + vtable_size(lvtbl->vars); + int cnt_args = vtable_size(lvtbl->args); + int cnt_vars = vtable_size(lvtbl->vars); + int cnt = cnt_args + cnt_vars; + int i, j; ID *buf; if (cnt <= 0) return 0; buf = ALLOC_N(ID, cnt + 1); - vtable_tblcpy(buf+1, lvtbl->args); - vtable_tblcpy(buf+vtable_size(lvtbl->args)+1, lvtbl->vars); + MEMCPY(buf+1, lvtbl->args->tbl, ID, cnt_args); + /* remove IDs duplicated to warn shadowing */ + for (i = 0, j = cnt_args+1; i < cnt_vars; ++i) { + ID id = lvtbl->vars->tbl[i]; + if (!vtable_included(lvtbl->args, id)) { + buf[j++] = id; + } + } + if (--j < cnt) REALLOC_N(buf, ID, (cnt = j) + 1); buf[0] = cnt; return buf; } Index: test/ruby/test_variable.rb =================================================================== --- test/ruby/test_variable.rb (revision 45844) +++ test/ruby/test_variable.rb (revision 45845) @@ -83,6 +83,12 @@ class TestVariable < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_variable.rb#L83 end.call end + def test_shadowing_local_variables + bug9486 = '[ruby-core:60501] [Bug #9486]' + x = tap {|x| break local_variables} + assert_equal([:x, :bug9486, :x], x) + end + def local_variables_of(bind) this_should_not_be_in_bind = 2 bind.local_variables -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/