nitmetrics: set private visibility to internal services
[nit.git] / src / layout_builders.nit
index 8a323eb..56ee306 100644 (file)
@@ -127,7 +127,7 @@ class ResolutionBMizer
 end
 
 # Abstract BMizing for MProperties
-class MPropertyBMizer[E: MProperty]
+abstract class MPropertyBMizer[E: MProperty]
        super PropertyLayoutBuilder[E]
 
        type MPROP: MProperty
@@ -139,7 +139,8 @@ class MPropertyBMizer[E: MProperty]
        redef fun build_layout(elements) do
                var result = new Layout[E]
                var ids = new HashMap[E, Int]
-               for mclass in elements do
+               var lin = linearize_mclasses(elements)
+               for mclass in lin do
                        for mproperty in properties(mclass) do
                                if ids.has_key(mproperty) then continue
                                ids[mproperty] = ids.length
@@ -156,6 +157,8 @@ class MPropertyBMizer[E: MProperty]
                end
                return properties
        end
+
+       private fun linearize_mclasses(mclasses: Set[MClass]): Array[MClass] is abstract
 end
 
 # BMizing for MMethods
@@ -164,6 +167,8 @@ class MMethodBMizer
 
        redef type MPROP: MMethod
        init(mmodule: MModule) do super(mmodule)
+       # Less holes in tables with reverse linearization for method tables
+       redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses)
 end
 
 # BMizing for MMAttributes
@@ -172,6 +177,8 @@ class MAttributeBMizer
 
        redef type MPROP: MAttribute
        init(mmodule: MModule) do super(mmodule)
+       # Less holes in tables with linearization for attribute tables
+       redef fun linearize_mclasses(mclasses) do return self.mmodule.linearize_mclasses_2(mclasses)
 end
 
 # BMizing for MVirtualTypeProps
@@ -180,6 +187,8 @@ class MVirtualTypePropBMizer
 
        redef type MPROP: MVirtualTypeProp
        init(mmodule: MModule) do super(mmodule)
+       # Less holes in tables with reverse linearization for method tables
+       redef fun linearize_mclasses(mclasses) do return self.mmodule.reverse_linearize_mclasses(mclasses)
 end
 
 # Colorers
@@ -359,7 +368,7 @@ class MClassColorer
        fun parent_elements(element: MClass): Set[MClass] do return self.mmodule.parent_mclasses(element)
        redef fun is_element_mi(element, elements) do return self.parent_elements(element).length > 1
        redef fun sub_elements(element, elements) do do return self.mmodule.sub_mclasses(element)
-       redef fun linearize(elements) do return self.mmodule.linearize_mclasses(elements)
+       redef fun linearize(elements) do return self.mmodule.linearize_mclasses_2(elements)
        redef fun reverse_linearize(elements) do return self.mmodule.reverse_linearize_mclasses(elements)
 end
 
@@ -367,6 +376,8 @@ end
 abstract class MPropertyColorer[E: MProperty]
        super PropertyLayoutBuilder[E]
 
+       type MPROP: MProperty
+
        private var mmodule: MModule
        private var class_colorer: MClassColorer
        private var coloration_result: Map[E, Int] = new HashMap[E, Int]
@@ -444,52 +455,37 @@ abstract class MPropertyColorer[E: MProperty]
        end
 
        # Filter properties
-       private fun properties(mclass: MClass): Set[E] is abstract
+       private fun properties(mclass: MClass): Set[E] do
+               var properties = new HashSet[E]
+               for mprop in self.mmodule.properties(mclass) do
+                       if mprop isa MPROP then properties.add(mprop)
+               end
+               return properties
+       end
 end
 
 # Coloring for MMethods
 class MMethodColorer
        super MPropertyColorer[MMethod]
 
+       redef type MPROP: MMethod
        init(mmodule: MModule) do super
-
-       redef fun properties(mclass) do
-               var properties = new HashSet[MMethod]
-               for mprop in self.mmodule.properties(mclass) do
-                       if mprop isa MMethod then properties.add(mprop)
-               end
-               return properties
-       end
 end
 
 # Coloring for MMAttributes
 class MAttributeColorer
        super MPropertyColorer[MAttribute]
 
+       redef type MPROP: MAttribute
        init(mmodule: MModule) do super
-
-       redef fun properties(mclass) do
-               var properties = new HashSet[MAttribute]
-               for mprop in self.mmodule.properties(mclass) do
-                       if mprop isa MAttribute then properties.add(mprop)
-               end
-               return properties
-       end
 end
 
 # Coloring for MVirtualTypeProps
 class MVirtualTypePropColorer
        super MPropertyColorer[MVirtualTypeProp]
 
+       redef type MPROP: MVirtualTypeProp
        init(mmodule: MModule) do super
-
-       redef fun properties(mclass) do
-               var properties = new HashSet[MVirtualTypeProp]
-               for mprop in self.mmodule.properties(mclass) do
-                       if mprop isa MVirtualTypeProp then properties.add(mprop)
-               end
-               return properties
-       end
 end
 
 # Colorer for type resolution table
@@ -744,4 +740,4 @@ class ResolutionHasher
                result.hashes = self.compute_hashes(elements, ids, result.masks)
                return result
        end
-end
\ No newline at end of file
+end