model_collect: introduce `collect_linearization` service
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 7 Jun 2016 15:56:14 +0000 (11:56 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 7 Jun 2016 15:56:35 +0000 (11:56 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/model/model_collect.nit

index 79970e5..bd7d12c 100644 (file)
@@ -37,6 +37,11 @@ redef class MEntity
        fun collect_modifiers: Array[String] do
                return new Array[String]
        end
+
+       # Collect `self` linearization anchored on `mainmodule`.
+       fun collect_linearization(mainmodule: MModule): nullable Array[MEntity] do
+               return null
+       end
 end
 
 redef class MPackage
@@ -163,6 +168,12 @@ redef class MClass
 
        redef fun collect_modifiers do return intro.collect_modifiers
 
+       redef fun collect_linearization(mainmodule) do
+               var mclassdefs = self.mclassdefs.to_a
+               mainmodule.linearize_mclassdefs(mclassdefs)
+               return mclassdefs
+       end
+
        # Collect direct parents of `self` with `visibility >= to min_visibility`.
        fun collect_parents(view: ModelView): Set[MClass] do
                var res = new HashSet[MClass]
@@ -411,6 +422,15 @@ end
 
 redef class MClassDef
 
+       redef fun collect_linearization(mainmodule) do
+               var mclassdefs = new Array[MClassDef]
+               for mclassdef in in_hierarchy.as(not null).greaters do
+                       if mclassdef.mclass == self.mclass then mclassdefs.add mclassdef
+               end
+               mainmodule.linearize_mclassdefs(mclassdefs)
+               return mclassdefs
+       end
+
        # Collect mpropdefs in 'self' with `visibility >= min_visibility`.
        fun collect_mpropdefs(view: ModelView): Set[MPropDef] do
                var res = new HashSet[MPropDef]
@@ -457,6 +477,12 @@ end
 
 redef class MProperty
        redef fun collect_modifiers do return intro.collect_modifiers
+
+       redef fun collect_linearization(mainmodule) do
+               var mpropdefs = self.mpropdefs.to_a
+               mainmodule.linearize_mpropdefs(mpropdefs)
+               return mpropdefs
+       end
 end
 
 redef class MPropDef
@@ -486,4 +512,16 @@ redef class MPropDef
                end
                return res
        end
+
+       redef fun collect_linearization(mainmodule) do
+               var mpropdefs = new Array[MPropDef]
+               var mentity = self
+               while not mentity.is_intro do
+                       mpropdefs.add mentity
+                       mentity = mentity.lookup_next_definition(mainmodule, mentity.mclassdef.bound_mtype)
+               end
+               mpropdefs.add mentity
+               mainmodule.linearize_mpropdefs(mpropdefs)
+               return mpropdefs
+       end
 end