summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-07 02:49:13 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-07 02:49:13 +0000
commite4256538fd3488bbf0aef14124f7dfcf5027eb17 (patch)
tree4c571bf4d97d9c6d10f371a3dade676effb46908 /parse.y
parent091c0753d7317c1d0d4047381ae955600f9d185f (diff)
merge revision(s) 45845,45847: [Backport #9786]
* parse.y (local_tbl_gen): remove local variables duplicated with arguments. [ruby-core:60501] [Bug #9486] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@46731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y31
1 files changed, 13 insertions, 18 deletions
diff --git a/parse.y b/parse.y
index 3cbf8feb24..1ec06a3431 100644
--- a/parse.y
+++ b/parse.y
@@ -9564,30 +9564,25 @@ local_pop_gen(struct parser_params *parser)
#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;
}