Promote mixin concept to the abstractmetamodel module.
authorJean Privat <jean@pryen.org>
Mon, 26 Jan 2009 20:03:25 +0000 (15:03 -0500)
committerJean Privat <jean@pryen.org>
Mon, 26 Jan 2009 20:03:25 +0000 (15:03 -0500)
Add is_mixin and mixing_of in MMGlobalClass.
Add is_init_for in MMGlobalProperty.
Update process_default_constructors in mmbuilder.

src/metamodel/abstractmetamodel.nit
src/syntax/mmbuilder.nit

index 878ef46..debc34f 100644 (file)
@@ -334,6 +334,19 @@ class MMGlobalClass
        # 1 -> public
        # 3 -> private
        readable writable attr _visibility_level: Int
+
+       # Is the global class a mixin class?
+       # A mixin class inherits all constructors from a superclass
+       meth is_mixin: Bool
+       do
+               return _mixin_of != self
+       end
+
+       # Indicate the superclass the class is a mixin of.
+       # If mixin_of == self then the class is not a mixin
+       # Is two classes have the same mixin_of value, then they both belong to the same mixing group
+       readable writable attr _mixin_of: MMGlobalClass = self
+
 end
 
 # Local classes are classes defined, refined or imported in a module
@@ -579,6 +592,15 @@ class MMGlobalProperty
        # Is the global property a constructor (thus also a method)?
        readable writable attr _is_init: Bool
 
+       # Is the global property a constructor for a given class?
+       meth is_init_for(c: MMLocalClass): Bool
+       do
+               if not is_init then return false
+               var sc = intro.local_class
+               var res = c.che <= sc and c.global.mixin_of == sc.global.mixin_of
+               return res
+       end
+
        # Visibility of the property
        # 1 -> public
        # 2 -> protected
index 11678c8..e9bdce5 100644 (file)
@@ -153,9 +153,6 @@ redef class MMSrcLocalClass
                end
        end
 
-       # A mixin class can be build the same way that one of its superclasses
-       readable attr _is_mixin: Bool = false
-
        # Introduce or inherit default constructors
        private meth process_default_constructors(v: PropertyBuilderVisitor)
        do
@@ -199,8 +196,7 @@ redef class MMSrcLocalClass
                        for gp in super_constructors do
                                var sc = gp.local_class
                                if supers.has(sc) then continue
-                               assert sc isa MMSrcLocalClass
-                               if not sc.is_mixin then
+                               if not sc.global.is_mixin then
                                        supers.add(sc)
                                end
                        end
@@ -222,7 +218,7 @@ redef class MMSrcLocalClass
                                        make_visible_an_inherited_global_property(gp)
                                end
                        end
-                       _is_mixin = true
+                       global.mixin_of = superclass.global
                else
                        # v.error(nodes.first, "Error, constructor required in {self} since no anonimous init found in {sc}.")