ruby-changes:33385
From: nobu <ko1@a...>
Date: Fri, 28 Mar 2014 21:36:31 +0900 (JST)
Subject: [ruby-changes:33385] nobu:r45464 (trunk): parse.y: rb_id_attrget
nobu 2014-03-28 21:36:26 +0900 (Fri, 28 Mar 2014) New Revision: 45464 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45464 Log: parse.y: rb_id_attrget * parse.y (rb_id_attrget): new function to convert setter ID to getter ID. Modified files: trunk/internal.h trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 45463) +++ parse.y (revision 45464) @@ -8820,6 +8820,7 @@ static const char id_type_names[][9] = { https://github.com/ruby/ruby/blob/trunk/parse.y#L8820 }; 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) https://github.com/ruby/ruby/blob/trunk/parse.y#L8862 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L10998 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L11018 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); } Index: internal.h =================================================================== --- internal.h (revision 45463) +++ internal.h (revision 45464) @@ -752,6 +752,7 @@ ID rb_sym2id_without_pindown(VALUE); https://github.com/ruby/ruby/blob/trunk/internal.h#L752 #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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/