From fd8f3cb98718be52976753e4580213b6062c2949 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 28 Mar 2014 12:36:26 +0000 Subject: [PATCH] parse.y: rb_id_attrget * parse.y (rb_id_attrget): new function to convert setter ID to getter ID. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- internal.h | 1 + parse.y | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal.h b/internal.h index 613a5bf018..6c2951fa18 100644 --- a/internal.h +++ b/internal.h @@ -752,6 +752,7 @@ ID rb_sym2id_without_pindown(VALUE); #ifdef RUBY_ENCODING_H ID rb_check_id_cstr_without_pindown(const char *, long, rb_encoding *); #endif +ID rb_id_attrget(ID id); /* proc.c */ VALUE rb_proc_location(VALUE self); diff --git a/parse.y b/parse.y index f04c10846d..0303387bab 100644 --- a/parse.y +++ b/parse.y @@ -8820,6 +8820,7 @@ static const char id_type_names[][9] = { }; static ID rb_pin_dynamic_symbol(VALUE); +static ID attrsetname_to_attr(VALUE name); ID rb_id_attrset(ID id) @@ -8861,6 +8862,12 @@ rb_id_attrset(ID id) return id; } +ID +rb_id_attrget(ID id) +{ + return attrsetname_to_attr(rb_id2str(id)); +} + static NODE * attrset_gen(struct parser_params *parser, NODE *recv, ID id) { @@ -10991,7 +10998,19 @@ rb_check_id_without_pindown(VALUE *namep) if (st_lookup(global_symbols.sym_id, (st_data_t)name, &id)) return (ID)id; + { + ID gid = attrsetname_to_attr(name); + if (gid) return rb_id_attrset(gid); + } + + return (ID)0; +} + +static ID +attrsetname_to_attr(VALUE name) +{ if (rb_is_attrset_name(name)) { + st_data_t id; struct RString fake_str; /* make local name by chopping '=' */ const VALUE localname = setup_fake_str(&fake_str, RSTRING_PTR(name), RSTRING_LEN(name) - 1); @@ -10999,7 +11018,7 @@ rb_check_id_without_pindown(VALUE *namep) OBJ_FREEZE(localname); if (st_lookup(global_symbols.sym_id, (st_data_t)localname, &id)) { - return rb_id_attrset((ID)id); + return (ID)id; } RB_GC_GUARD(name); }