Commit 8ce2af99 authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

CRuby style inclusion order; close #377

parent e8ade381
...@@ -653,40 +653,42 @@ boot_defclass(mrb_state *mrb, struct RClass *super) ...@@ -653,40 +653,42 @@ boot_defclass(mrb_state *mrb, struct RClass *super)
return c; return c;
} }
static int
find_in_ancestors(struct RClass *c, struct RClass *m)
{
while(c) {
if (c == m || c->mt == m->mt){
return 1;
}
c = c->super;
}
return 0;
}
void void
mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m) mrb_include_module(mrb_state *mrb, struct RClass *c, struct RClass *m)
{ {
struct RClass *ic, *ins_pos; struct RClass *ins_pos;
ins_pos = c; ins_pos = c;
while (m) { while (m) {
if (!find_in_ancestors(c, m)) { struct RClass *p = c, *ic;
ic = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_ICLASS, mrb->class_class); int superclass_seen = 0;
if (m->tt == MRB_TT_ICLASS) {
ic->c = m->c; while(p) {
if (c != p && p->tt == MRB_TT_CLASS) {
superclass_seen = 1;
} }
else { else if (p->mt == m->mt){
ic->c = m; if (p->tt == MRB_TT_ICLASS && !superclass_seen) {
ins_pos = p;
}
goto skip;
} }
ic->mt = m->mt; p = p->super;
ic->iv = m->iv; }
ic->super = ins_pos->super; ic = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_ICLASS, mrb->class_class);
ins_pos->super = ic; if (m->tt == MRB_TT_ICLASS) {
mrb_field_write_barrier(mrb, (struct RBasic*)ins_pos, (struct RBasic*)ic); ic->c = m->c;
ins_pos = ic; }
else {
ic->c = m;
} }
ic->mt = m->mt;
ic->iv = m->iv;
ic->super = ins_pos->super;
ins_pos->super = ic;
mrb_field_write_barrier(mrb, (struct RBasic*)ins_pos, (struct RBasic*)ic);
ins_pos = ic;
skip:
m = m->super; m = m->super;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment