33#define id_attached id__attached__
35#define METACLASS_OF(k) RBASIC(k)->klass
36#define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls)
43 if (super && super !=
Qundef) {
60rb_module_add_to_subclasses_list(
VALUE module,
VALUE iclass)
65 entry->
klass = iclass;
189RCLASS_M_TBL_INIT(
VALUE c)
208 RCLASS_SET_SUPER(
klass, super);
209 RCLASS_M_TBL_INIT(
klass);
270clone_method_i(
ID key,
VALUE value,
void *data)
325 class_init_copy_check(clone, orig);
363 arg.old_klass = orig;
364 arg.new_klass = clone;
365 RCLASS_M_TBL_INIT(clone);
394 bool klass_of_clone_is_new;
398 klass_of_clone_is_new =
true;
423 RCLASS_M_TBL_INIT(clone);
427 arg.new_klass = clone;
430 if (klass_of_clone_is_new) {
459#define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
462rb_singleton_class_has_metaclass_p(
VALUE sklass)
471 !rb_singleton_class_has_metaclass_p(sklass));
479#define HAVE_METACLASS_P(k) \
480 (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
481 rb_singleton_class_has_metaclass_p(k))
490#define ENSURE_EIGENCLASS(klass) \
491 (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
551boot_defclass(
const char *
name,
VALUE super)
596 return make_metaclass(
obj);
599 return make_singleton_class(
obj);
774 RCLASS_M_TBL_INIT(mdl);
847 module =
RBASIC(module)->klass;
858 RCLASS_SET_SUPER(
klass, super);
886 ensure_includable(
klass, module);
894add_refined_method_entry_i(
ID key,
VALUE value,
void *data)
906 int method_changed = 0, constant_changed = 0;
910 ensure_origin(module);
914 int origin_seen =
FALSE;
915 int superclass_seen =
FALSE;
929 if (!superclass_seen && origin_seen) {
936 if (!search_super)
break;
937 superclass_seen =
TRUE;
941 c = RCLASS_SET_SUPER(c, iclass);
942 RCLASS_SET_INCLUDER(iclass,
klass);
947 rb_module_add_to_subclasses_list(m, iclass);
951 VALUE refined_class =
970 return method_changed;
974move_refined_method(
ID key,
VALUE value,
void *data)
1004 if (origin ==
klass) {
1008 RCLASS_SET_SUPER(
klass, origin);
1009 RCLASS_SET_ORIGIN(
klass, origin);
1011 RCLASS_M_TBL_INIT(
klass);
1021 ensure_includable(
klass, module);
1022 ensure_origin(
klass);
1147 ins_methods_push(
name, ary);
1157 ins_methods_push(
name, ary);
1166 ins_methods_push(
name, ary);
1175 ins_methods_push(
name, ary);
1186method_entry_i(
ID key,
VALUE value,
void *data)
1221 if (!
mod)
return false;
1241 add_instance_method_list(
mod, &me_arg);
1251 add_instance_method_list(
mod, &me_arg);
1292 return class_instance_method_list(
argc,
argv,
mod, 0, ins_methods_i);
1307 return class_instance_method_list(
argc,
argv,
mod, 0, ins_methods_prot_i);
1330 return class_instance_method_list(
argc,
argv,
mod, 0, ins_methods_priv_i);
1345 return class_instance_method_list(
argc,
argv,
mod, 0, ins_methods_pub_i);
1556#ifdef rb_define_method_id
1557#undef rb_define_method_id
1565#ifdef rb_define_method
1566#undef rb_define_method
1574#ifdef rb_define_protected_method
1575#undef rb_define_protected_method
1583#ifdef rb_define_private_method
1584#undef rb_define_private_method
1623#define SPECIAL_SINGLETON(x,c) do {\
1630special_singleton_class_of(
VALUE obj)
1641 return special_singleton_class_of(
obj);
1663 klass = special_singleton_class_of(
obj);
1665 rb_bug(
"unknown immediate %p", (
void *)
obj);
1762#ifdef rb_define_singleton_method
1763#undef rb_define_singleton_method
1778#ifdef rb_define_module_function
1779#undef rb_define_module_function
1795#ifdef rb_define_global_function
1796#undef rb_define_global_function
1847 if (++
i >=
len)
break;
1864unknown_keyword_error(
VALUE hash,
const ID *table,
int keywords)
1867 for (
i = 0;
i < keywords;
i++) {
1888 VALUE parthash[2] = {0, 0};
1889 VALUE hash = *orighash;
1896 *orighash = parthash[1];
1911#define extract_kwarg(keyword, val) \
1912 (key = (st_data_t)(keyword), values ? \
1913 (rb_hash_stlike_delete(keyword_hash, &key, &(val)) || ((val) = Qundef, 0)) : \
1914 rb_hash_stlike_lookup(keyword_hash, key, NULL))
1916 if (
NIL_P(keyword_hash)) keyword_hash = 0;
1923 for (;
i < required;
i++) {
1933 if (!
NIL_P(missing)) {
1934 rb_keyword_error(
"missing", missing);
1945 if (!rest && keyword_hash) {
1946 if (
RHASH_SIZE(keyword_hash) > (
unsigned int)(values ? 0 : j)) {
1947 unknown_keyword_error(keyword_hash, table, required+
optional);
1950 if (values && !keyword_hash) {
1980 const char *p =
fmt;
1981 VALUE *tmp_buffer =
arg->tmp_buffer;
1982 int keyword_given = 0;
1983 int empty_keyword_given = 0;
1984 int last_hash_keyword = 0;
2000 empty_keyword_given = 1;
2003 last_hash_keyword = 1;
2008 arg->n_lead = *p -
'0';
2011 arg->n_opt = *p -
'0';
2020 arg->n_trail = *p -
'0';
2034 arg->n_mand =
arg->n_lead +
arg->n_trail;
2038 if (
argc > 0 && !(
arg->f_hash && empty_keyword_given)) {
2042 if (keyword_given) {
2044 rb_warn(
"Keyword flag set when calling rb_scan_args, but last entry is not a hash");
2056 rb_warn(
"The last argument is nil, treating as empty keywords");
2068 if (!(
arg->last_hash =
arg->hash)) {
2069 if (!keyword_given && !last_hash_keyword) {
2072 rb_warn(
"Using the last argument as keyword parameters is deprecated");
2079 rb_warn(
"The last argument is split into positional and keyword parameters");
2082 arg->hash = opts ? opts :
Qnil;
2085 else if (
arg->f_hash && keyword_given &&
arg->n_mand ==
argc) {
2087 rb_warn(
"Passing the keyword argument as the last hash parameter is deprecated");
2090 if (
arg->f_hash &&
arg->n_mand ==
argc+1 && empty_keyword_given) {
2096 rb_warn(
"Passing the keyword argument as the last hash parameter is deprecated");
2110 if (
arg->argc <
arg->n_mand) {
2115 for (
i =
arg->n_lead;
i-- > 0; ) {
2117 if (var) *var = (argi ==
arg->last_idx) ?
arg->last_hash :
arg->argv[argi];
2121 for (
i =
arg->n_opt;
i-- > 0; ) {
2123 if (argi < arg->
argc -
arg->n_trail) {
2124 if (var) *var = (argi ==
arg->last_idx) ?
arg->last_hash :
arg->argv[argi];
2128 if (var) *var =
Qnil;
2133 int n_var =
arg->argc - argi -
arg->n_trail;
2138 int f_last = (
arg->last_idx + 1 ==
arg->argc -
arg->n_trail);
2149 for (
i =
arg->n_trail;
i-- > 0; ) {
2151 if (var) *var = (argi ==
arg->last_idx) ?
arg->last_hash :
arg->argv[argi];
2157 if (var) *var =
arg->hash;
2170 if (argi < arg->
argc)
return 1;
2181 VALUE tmp_buffer = 0;
#define extract_kwarg(keyword, val)
VALUE rb_class_protected_instance_methods(int argc, const VALUE *argv, VALUE mod)
#define SET_METACLASS_OF(k, cls)
void rb_class_foreach_subclass(VALUE klass, void(*f)(VALUE, VALUE), VALUE arg)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_class_new(VALUE super)
Creates a new class.
VALUE rb_singleton_class_clone(VALUE obj)
VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj)
void rb_class_subclass_add(VALUE super, VALUE klass)
VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj)
void rb_prepend_module(VALUE klass, VALUE module)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
void rb_class_detach_subclasses(VALUE klass)
void Init_class_hierarchy(void)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
VALUE rb_include_class_new(VALUE module, VALUE super)
VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj)
VALUE rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
VALUE rb_module_new(void)
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
int rb_singleton_class_internal_p(VALUE sklass)
#define SPECIAL_SINGLETON(x, c)
VALUE rb_class_instance_methods(int argc, const VALUE *argv, VALUE mod)
MJIT_FUNC_EXPORTED VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
void rb_check_inheritable(VALUE super)
Ensures a class can be derived from super.
VALUE rb_class_public_instance_methods(int argc, const VALUE *argv, VALUE mod)
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
VALUE rb_define_module(const char *name)
void rb_class_modify_check(VALUE)
Asserts that klass is not a frozen class.
void rb_class_detach_module_subclasses(VALUE klass)
VALUE rb_special_singleton_class(VALUE obj)
VALUE rb_define_module_id_under(VALUE outer, ID id)
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attach a object to a singleton class.
void rb_freeze_singleton_class(VALUE x)
VALUE rb_mod_included_modules(VALUE mod)
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_mod_ancestors(VALUE mod)
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
VALUE rb_class_private_instance_methods(int argc, const VALUE *argv, VALUE mod)
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
void rb_class_remove_from_module_subclasses(VALUE klass)
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
VALUE rb_define_module_under(VALUE outer, const char *name)
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
VALUE rb_make_metaclass(VALUE obj, VALUE unused)
VALUE rb_define_module_id(ID id)
VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj)
VALUE rb_define_class_id(ID id, VALUE super)
Defines a new class.
void rb_class_remove_from_super_subclasses(VALUE klass)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_extract_keywords(VALUE *orighash)
int rb_class_has_methods(VALUE c)
MJIT_FUNC_EXPORTED VALUE rb_keyword_error_new(const char *error, VALUE keys)
void rb_define_attr(VALUE klass, const char *name, int read, int write)
Defines (a) public accessor method(s) for an attribute.
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_undef_method(VALUE klass, const char *name)
int rb_scan_args_kw(int kw_flag, int argc, const VALUE *argv, const char *fmt,...)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_undef_methods_from(VALUE klass, VALUE super)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
NORETURN(static void rb_keyword_error(const char *error, VALUE keys))
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
VALUE rb_cTrueClass
TrueClass class.
VALUE rb_cNilClass
NilClass class.
VALUE rb_mKernel
Kernel module.
VALUE rb_cClass
Class class.
VALUE rb_cBasicObject
BasicObject class.
VALUE rb_cObject
Object class.
VALUE rb_cFalseClass
FalseClass class.
VALUE rb_cModule
Module class.
@ RMODULE_INCLUDED_INTO_REFINEMENT
void rb_raise(VALUE exc, const char *fmt,...)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
void rb_fatal(const char *fmt,...)
void rb_warn(const char *fmt,...)
VALUE rb_exc_new_str(VALUE, VALUE)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
VALUE rb_class_real(VALUE cl)
Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions.
int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val)
size_t rb_id_table_size(const struct rb_id_table *tbl)
struct rb_id_table * rb_id_table_create(size_t capa)
void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)
rb_id_table_iterator_result
VALUE type(ANYARGS)
ANYARGS-ed function type.
void st_free_table(st_table *tab)
int st_delete(st_table *tab, st_data_t *key, st_data_t *value)
void st_add_direct(st_table *tab, st_data_t key, st_data_t value)
st_table * st_init_numtable(void)
int st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg)
struct rb_method_definition_struct *const def
union rb_method_definition_struct::@41 body
rb_method_refined_t refined
rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
rb_cref_t * cref
class reference, should be marked
struct rb_method_entry_struct * orig_me
rb_subclass_entry_t * next
void rb_vm_rewrite_cref(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_cref_t **new_cref_ptr)
MJIT_STATIC void rb_error_arity(int argc, int min, int max)