本文整理汇总了C++中RCLASS_SUPER函数的典型用法代码示例。如果您正苦于以下问题:C++ RCLASS_SUPER函数的具体用法?C++ RCLASS_SUPER怎么用?C++ RCLASS_SUPER使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RCLASS_SUPER函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_module
static void add_module(VALUE self, VALUE module)
{
VALUE super = RCLASS_SUPER(rb_singleton_class(self));
#ifdef RUBY_19
VALUE klass = class_alloc(T_ICLASS, rb_cClass);
#else
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_ICLASS);
#endif
if (BUILTIN_TYPE(module) == T_ICLASS) {
module = KLASS_OF(module);
}
if (!RCLASS_IV_TBL(module)) {
RCLASS_IV_TBL(module) = (void*)st_init_numtable();
}
RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
RCLASS_SUPER(klass) = super;
if (TYPE(module) == T_ICLASS) {
KLASS_OF(klass) = KLASS_OF(module);
} else {
KLASS_OF(klass) = module;
}
OBJ_INFECT(klass, module);
OBJ_INFECT(klass, super);
RCLASS_SUPER(rb_singleton_class(self)) = (VALUE)klass;
}
示例2: rb_singleton_class_clone
VALUE
rb_singleton_class_clone(VALUE obj)
{
VALUE klass = RBASIC(obj)->klass;
if (!FL_TEST(klass, FL_SINGLETON))
return klass;
else {
struct clone_method_data data;
/* copy singleton(unnamed) class */
VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
if (BUILTIN_TYPE(obj) == T_CLASS) {
RBASIC(clone)->klass = (VALUE)clone;
}
else {
RBASIC(clone)->klass = rb_singleton_class_clone(klass);
}
RCLASS_SUPER(clone) = RCLASS_SUPER(klass);
if (RCLASS_IV_TBL(klass)) {
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass));
}
RCLASS_M_TBL(clone) = st_init_numtable();
data.tbl = RCLASS_M_TBL(clone);
data.klass = (VALUE)clone;
st_foreach(RCLASS_M_TBL(klass), clone_method,
(st_data_t)&data);
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
FL_SET(clone, FL_SINGLETON);
return (VALUE)clone;
}
}
示例3: rb_to_module
VALUE
rb_to_module(VALUE self)
{
VALUE rclass, chain_start, jcur, klass;
switch(BUILTIN_TYPE(self)) {
case T_MODULE:
return self;
case T_CLASS:
klass = self;
break;
case T_OBJECT:
default:
klass = rb_singleton_class(self);
}
chain_start = j_class_new(klass, rb_cObject);
KLASS_OF(chain_start) = rb_cModule;
RBASIC(chain_start)->flags = T_MODULE;
jcur = chain_start;
for(rclass = RCLASS_SUPER(klass); rclass != rb_cObject;
rclass = RCLASS_SUPER(rclass)) {
RCLASS_SUPER(jcur) = j_class_new(rclass, rb_cObject);
jcur = RCLASS_SUPER(jcur);
}
RCLASS_SUPER(jcur) = (VALUE)NULL;
return chain_start;
}
示例4: rb_obj_singleton_methods
VALUE
rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
{
VALUE recur, ary, klass;
st_table *list;
if (argc == 0) {
recur = Qtrue;
}
else {
rb_scan_args(argc, argv, "01", &recur);
}
klass = CLASS_OF(obj);
list = st_init_numtable();
if (klass && FL_TEST(klass, FL_SINGLETON)) {
st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
if (RTEST(recur)) {
while (klass && (FL_TEST(klass, FL_SINGLETON) || TYPE(klass) == T_ICLASS)) {
st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
}
ary = rb_ary_new();
st_foreach(list, ins_methods_i, ary);
st_free_table(list);
return ary;
}
示例5: rb_extend_object
void
rb_extend_object(VALUE obj, VALUE module)
{
VALUE klass;
if (TYPE(obj) == T_CLASS && RCLASS_RUBY(obj)) {
VALUE sklass = rb_make_singleton_class(RCLASS_SUPER(obj));
RCLASS_SET_SUPER(obj, sklass);
klass = *(VALUE *)sklass;
}
else {
klass = rb_singleton_class(obj);
}
rb_include_module(klass, module);
VALUE m = module;
do {
VALUE ary = rb_attr_get(m, idIncludedModules);
if (ary != Qnil) {
for (int i = 0, count = RARRAY_LEN(ary); i < count; i++) {
VALUE mod = RARRAY_AT(ary, i);
rb_extend_object(obj, mod);
}
}
m = RCLASS_SUPER(m);
}
while (m == 0 || RCLASS_SINGLETON(m));
}
示例6: make_metametaclass
/*!
* Creates a meta^(n+1)-class for a meta^(n)-class.
* \param metaclass a class of a class
* \return the created meta^(n+1)-class.
* \pre \a metaclass is a metaclass
* \post the class of \a metaclass is the returned class.
*/
static VALUE
make_metametaclass(VALUE metaclass)
{
VALUE metametaclass, super_of_metaclass;
if (RBASIC(metaclass)->klass == metaclass) { /* for meta^(n)-class of Class */
metametaclass = rb_class_boot(Qnil);
RBASIC(metametaclass)->klass = metametaclass;
}
else {
metametaclass = rb_class_boot(Qnil);
RBASIC(metametaclass)->klass =
(RBASIC(RBASIC(metaclass)->klass)->klass == RBASIC(metaclass)->klass)
? make_metametaclass(RBASIC(metaclass)->klass)
: RBASIC(RBASIC(metaclass)->klass)->klass;
}
FL_SET(metametaclass, FL_SINGLETON);
rb_singleton_class_attached(metametaclass, metaclass);
RBASIC(metaclass)->klass = metametaclass;
super_of_metaclass = RCLASS_SUPER(metaclass);
while (FL_TEST(super_of_metaclass, T_ICLASS)) {
super_of_metaclass = RCLASS_SUPER(super_of_metaclass);
}
RCLASS_SUPER(metametaclass) =
rb_iv_get(RBASIC(super_of_metaclass)->klass, "__attached__") == super_of_metaclass
? RBASIC(super_of_metaclass)->klass
: make_metametaclass(super_of_metaclass);
OBJ_INFECT(metametaclass, RCLASS_SUPER(metametaclass));
return metametaclass;
}
示例7: include_modules_at
static int
include_modules_at(const VALUE klass, VALUE c, VALUE module)
{
VALUE p, iclass;
int method_changed = 0, constant_changed = 0;
const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
while (module) {
int superclass_seen = FALSE;
if (RCLASS_ORIGIN(module) != module)
goto skip;
if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
return -1;
/* ignore if the module included already in superclasses */
for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
switch (BUILTIN_TYPE(p)) {
case T_ICLASS:
if (RCLASS_M_TBL_WRAPPER(p) == RCLASS_M_TBL_WRAPPER(module)) {
if (!superclass_seen) {
c = p; /* move insertion point */
}
goto skip;
}
break;
case T_CLASS:
superclass_seen = TRUE;
break;
}
}
iclass = rb_include_class_new(module, RCLASS_SUPER(c));
c = RCLASS_SET_SUPER(c, iclass);
if (BUILTIN_TYPE(module) == T_ICLASS) {
rb_module_add_to_subclasses_list(RBASIC(module)->klass, iclass);
} else {
rb_module_add_to_subclasses_list(module, iclass);
}
if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
VALUE refined_class =
rb_refinement_module_get_refined_class(klass);
st_foreach(RMODULE_M_TBL(module), add_refined_method_entry_i,
(st_data_t) refined_class);
FL_SET(c, RMODULE_INCLUDED_INTO_REFINEMENT);
}
if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
method_changed = 1;
if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
constant_changed = 1;
skip:
module = RCLASS_SUPER(module);
}
if (method_changed) rb_clear_method_cache_by_class(klass);
if (constant_changed) rb_clear_constant_cache();
return method_changed;
}
示例8: make_metaclass
/*!
* Creates a metaclass of \a klass
* \param klass a class
* \return created metaclass for the class
* \pre \a klass is a Class object
* \pre \a klass has no singleton class.
* \post the class of \a klass is the returned class.
* \post the returned class is meta^(n+1)-class when \a klass is a meta^(n)-klass for n >= 0
*/
static inline VALUE
make_metaclass(VALUE klass)
{
VALUE super;
VALUE metaclass = rb_class_boot(Qundef);
FL_SET(metaclass, FL_SINGLETON);
rb_singleton_class_attached(metaclass, klass);
if (META_CLASS_OF_CLASS_CLASS_P(klass)) {
METACLASS_OF(klass) = METACLASS_OF(metaclass) = metaclass;
}
else {
VALUE tmp = METACLASS_OF(klass); /* for a meta^(n)-class klass, tmp is meta^(n)-class of Class class */
METACLASS_OF(klass) = metaclass;
METACLASS_OF(metaclass) = ENSURE_EIGENCLASS(tmp);
}
super = RCLASS_SUPER(klass);
while (RB_TYPE_P(super, T_ICLASS)) super = RCLASS_SUPER(super);
RCLASS_SUPER(metaclass) = super ? ENSURE_EIGENCLASS(super) : rb_cClass;
OBJ_INFECT(metaclass, RCLASS_SUPER(metaclass));
return metaclass;
}
示例9: rb_obj_singleton_methods
VALUE
rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
{
VALUE recur, ary, klass, origin;
st_table *list, *mtbl;
if (argc == 0) {
recur = Qtrue;
}
else {
rb_scan_args(argc, argv, "01", &recur);
}
klass = CLASS_OF(obj);
origin = RCLASS_ORIGIN(klass);
list = st_init_numtable();
if (klass && FL_TEST(klass, FL_SINGLETON)) {
if ((mtbl = RCLASS_M_TBL(origin)) != 0)
st_foreach(mtbl, method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
if (RTEST(recur)) {
while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0)
st_foreach(mtbl, method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
}
ary = rb_ary_new();
st_foreach(list, ins_methods_i, ary);
st_free_table(list);
return ary;
}
示例10: superclass_name
static VALUE superclass_name(VALUE module)
{
if(TYPE(module) == T_MODULE)
{
return Qnil;
}
else
{
VALUE super = RCLASS_SUPER(module);
while(TYPE(super) == T_ICLASS)
{
super = RCLASS_SUPER(super);
}
if(!super)
{
return Qnil;
}
if(FL_TEST(super, FL_SINGLETON))
{
VALUE v = rb_iv_get(super, "__attached__");
VALUE name = rb_mod_name(v);
rb_str_cat2(name, "::<Singleton>");
return name;
}
else
{
return rb_mod_name(super);
}
}
}
示例11: rb_mod_init_copy
/* :nodoc: */
VALUE
rb_mod_init_copy(VALUE clone, VALUE orig)
{
rb_obj_init_copy(clone, orig);
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
RBASIC(clone)->klass = rb_singleton_class_clone(orig);
}
RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
if (RCLASS_IV_TBL(orig)) {
ID id;
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
CONST_ID(id, "__classpath__");
st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
CONST_ID(id, "__classid__");
st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
}
if (RCLASS_M_TBL(orig)) {
struct clone_method_data data;
data.tbl = RCLASS_M_TBL(clone) = st_init_numtable();
data.klass = clone;
st_foreach(RCLASS_M_TBL(orig), clone_method,
(st_data_t)&data);
}
return clone;
}
示例12: rb_singleton_class_clone
VALUE
rb_singleton_class_clone(VALUE obj)
{
VALUE klass = RBASIC(obj)->klass;
if (!RCLASS_SINGLETON(klass)) {
return klass;
}
// Create new singleton class.
VALUE clone = rb_objc_create_class(NULL, RCLASS_SUPER(klass));
// Copy ivars.
CFMutableDictionaryRef ivar_dict = rb_class_ivar_dict(klass);
if (ivar_dict != NULL) {
CFMutableDictionaryRef cloned_ivar_dict =
CFDictionaryCreateMutableCopy(NULL, 0, (CFDictionaryRef)ivar_dict);
rb_class_ivar_set_dict(clone, cloned_ivar_dict);
CFMakeCollectable(cloned_ivar_dict);
}
// Copy methods.
rb_vm_copy_methods((Class)klass, (Class)clone);
rb_singleton_class_attached(clone, obj);
if (RCLASS_SUPER(clone) == rb_cRubyObject) {
long v = RCLASS_VERSION(clone) ^ RCLASS_IS_OBJECT_SUBCLASS;
RCLASS_SET_VERSION(clone, v);
}
RCLASS_SET_VERSION_FLAG(clone, RCLASS_IS_SINGLETON);
return clone;
}
示例13: rb_mod_append_features
static VALUE
rb_mod_append_features(VALUE module, SEL sel, VALUE include)
{
VALUE orig = include;
switch (TYPE(include)) {
case T_CLASS:
case T_MODULE:
break;
default:
Check_Type(include, T_CLASS);
break;
}
if (RCLASS_RUBY(include)) {
VALUE sinclude = rb_make_singleton_class(RCLASS_SUPER(include));
RCLASS_SET_SUPER(include, sinclude);
include = sinclude;
}
rb_include_module2(include, orig, module, true, true);
VALUE m = module;
do {
VALUE ary = rb_attr_get(m, idIncludedModules);
if (ary != Qnil) {
for (int i = 0, count = RARRAY_LEN(ary); i < count; i++) {
VALUE mod = RARRAY_AT(ary, i);
rb_mod_append_features(mod, sel, include);
}
}
m = RCLASS_SUPER(m);
}
while (m == 0 || RCLASS_SINGLETON(m));
return module;
}
示例14: remove_nested_module
static void remove_nested_module(VALUE klass, VALUE module) {
if (CLASS_OF(RCLASS_SUPER(klass)) == CLASS_OF(RCLASS_SUPER(module))) {
if (RCLASS_SUPER(RCLASS_SUPER(module)) && BUILTIN_TYPE(RCLASS_SUPER(module)) == T_ICLASS) {
remove_nested_module(RCLASS_SUPER(klass), RCLASS_SUPER(module));
}
RCLASS_SUPER(klass) = RCLASS_SUPER(RCLASS_SUPER(klass));
}
}
示例15: evilr__iclass_matching_before
/* Walk the super chain from klass until either before or an iclass for mod is encountered. If
* before is encountered first, return NULL. If an iclass for mod is encountered first, return
* the iclass. */
static VALUE evilr__iclass_matching_before(VALUE klass, VALUE mod, VALUE before) {
VALUE c;
for (c = RCLASS_SUPER(klass); c && c != before; c = RCLASS_SUPER(c)) {
if (BUILTIN_TYPE(c) == T_ICLASS && RBASIC_KLASS(c) == mod) {
return c;
}
}
return NULL;
}