1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-03-28 12:36:26 +00:00
parent 4a46362239
commit fd8f3cb987
2 changed files with 21 additions and 1 deletions

View file

@ -752,6 +752,7 @@ ID rb_sym2id_without_pindown(VALUE);
#ifdef RUBY_ENCODING_H #ifdef RUBY_ENCODING_H
ID rb_check_id_cstr_without_pindown(const char *, long, rb_encoding *); ID rb_check_id_cstr_without_pindown(const char *, long, rb_encoding *);
#endif #endif
ID rb_id_attrget(ID id);
/* proc.c */ /* proc.c */
VALUE rb_proc_location(VALUE self); VALUE rb_proc_location(VALUE self);

21
parse.y
View file

@ -8820,6 +8820,7 @@ static const char id_type_names[][9] = {
}; };
static ID rb_pin_dynamic_symbol(VALUE); static ID rb_pin_dynamic_symbol(VALUE);
static ID attrsetname_to_attr(VALUE name);
ID ID
rb_id_attrset(ID id) rb_id_attrset(ID id)
@ -8861,6 +8862,12 @@ rb_id_attrset(ID id)
return id; return id;
} }
ID
rb_id_attrget(ID id)
{
return attrsetname_to_attr(rb_id2str(id));
}
static NODE * static NODE *
attrset_gen(struct parser_params *parser, NODE *recv, ID id) 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)) if (st_lookup(global_symbols.sym_id, (st_data_t)name, &id))
return (ID)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)) { if (rb_is_attrset_name(name)) {
st_data_t id;
struct RString fake_str; struct RString fake_str;
/* make local name by chopping '=' */ /* make local name by chopping '=' */
const VALUE localname = setup_fake_str(&fake_str, RSTRING_PTR(name), RSTRING_LEN(name) - 1); 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); OBJ_FREEZE(localname);
if (st_lookup(global_symbols.sym_id, (st_data_t)localname, &id)) { 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); RB_GC_GUARD(name);
} }