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
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);

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 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);
}