vm_method.c: use the current visibility

* vm_method.c (rb_attr): simply use the current visibility,
  instead of tests for each visibilities.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-06-24 08:31:43 +00:00
Родитель d92b0dc58a
Коммит 220f9d5053
1 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -912,17 +912,17 @@ rb_method_boundp(VALUE klass, ID id, int ex)
return 0;
}
static int
rb_scope_visibility_test(rb_method_visibility_t visi)
static rb_method_visibility_t
rb_scope_visibility_get(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
if (!vm_env_cref_by_cref(cfp->ep)) {
return METHOD_VISI_PUBLIC == visi;
return METHOD_VISI_PUBLIC;
}
else {
return CREF_SCOPE_VISI(rb_vm_cref())->method_visi == visi;
return CREF_SCOPE_VISI(rb_vm_cref())->method_visi;
}
}
@ -958,17 +958,19 @@ rb_attr(VALUE klass, ID id, int read, int write, int ex)
visi = METHOD_VISI_PUBLIC;
}
else {
if (rb_scope_visibility_test(METHOD_VISI_PRIVATE)) {
visi = METHOD_VISI_PRIVATE;
switch (rb_scope_visibility_get()) {
case METHOD_VISI_PRIVATE:
if (rb_scope_module_func_check()) {
rb_warning("attribute accessor as module_function");
}
}
else if (rb_scope_visibility_test(METHOD_VISI_PROTECTED)) {
visi = METHOD_VISI_PRIVATE;
break;
case METHOD_VISI_PROTECTED:
visi = METHOD_VISI_PROTECTED;
}
else {
break;
default:
visi = METHOD_VISI_PUBLIC;
break;
}
}