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

variable.c: split CVAR_LOOKUP

* variable.c (CVAR_LOOKUP): split into helper functions.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-08-06 15:24:01 +00:00
parent 745de093db
commit 6f677a5e00
2 changed files with 32 additions and 21 deletions

View file

@ -1,3 +1,7 @@
Tue Aug 7 00:23:58 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* variable.c (CVAR_LOOKUP): split into helper functions.
Mon Aug 6 19:15:11 2012 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* test/win32ole/test_win32ole_variant.rb: setting WIN32OLE.locale

View file

@ -2249,28 +2249,35 @@ original_module(VALUE c)
return c;
}
static int
cvar_lookup_at(VALUE klass, ID id, st_data_t *v)
{
if (!RCLASS_IV_TBL(klass)) return 0;
return st_lookup(RCLASS_IV_TBL(klass), (st_data_t)id, v);
}
static VALUE
cvar_front_klass(VALUE klass)
{
if (FL_TEST(klass, FL_SINGLETON)) {
VALUE obj = rb_iv_get(klass, "__attached__");
if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {
return obj;
}
}
return RCLASS_SUPER(klass);
}
#define CVAR_FOREACH_ANCESTORS(klass, v, r) \
for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \
if (cvar_lookup_at(klass, id, (v))) { \
r; \
} \
}
#define CVAR_LOOKUP(v,r) do {\
if (RCLASS_IV_TBL(klass) && st_lookup(RCLASS_IV_TBL(klass),(st_data_t)id,(v))) {\
r;\
}\
if (FL_TEST(klass, FL_SINGLETON) ) {\
VALUE obj = rb_iv_get(klass, "__attached__");\
if (RB_TYPE_P(obj, T_MODULE) || RB_TYPE_P(obj, T_CLASS)) {\
klass = obj;\
}\
else {\
klass = RCLASS_SUPER(klass);\
}\
}\
else {\
klass = RCLASS_SUPER(klass);\
}\
while (klass) {\
if (RCLASS_IV_TBL(klass) && st_lookup(RCLASS_IV_TBL(klass),(st_data_t)id,(v))) {\
r;\
}\
klass = RCLASS_SUPER(klass);\
}\
if (cvar_lookup_at(klass, id, (v))) {r;}\
CVAR_FOREACH_ANCESTORS(klass, v, r);\
} while(0)
void