layout_builders: introduced PropertyBMizer
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 6 Mar 2013 20:24:28 +0000 (15:24 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 6 Mar 2013 20:24:28 +0000 (15:24 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/layout_builders.nit
src/separate_compiler.nit

index 029afac..8a323eb 100644 (file)
@@ -126,6 +126,62 @@ class ResolutionBMizer
        end
 end
 
+# Abstract BMizing for MProperties
+class MPropertyBMizer[E: MProperty]
+       super PropertyLayoutBuilder[E]
+
+       type MPROP: MProperty
+
+       var mmodule: MModule
+
+       init(mmodule: MModule) do self.mmodule = mmodule
+
+       redef fun build_layout(elements) do
+               var result = new Layout[E]
+               var ids = new HashMap[E, Int]
+               for mclass in elements do
+                       for mproperty in properties(mclass) do
+                               if ids.has_key(mproperty) then continue
+                               ids[mproperty] = ids.length
+                       end
+               end
+               result.pos = ids
+               return result
+       end
+
+       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
+
+# BMizing for MMethods
+class MMethodBMizer
+       super MPropertyBMizer[MMethod]
+
+       redef type MPROP: MMethod
+       init(mmodule: MModule) do super(mmodule)
+end
+
+# BMizing for MMAttributes
+class MAttributeBMizer
+       super MPropertyBMizer[MAttribute]
+
+       redef type MPROP: MAttribute
+       init(mmodule: MModule) do super(mmodule)
+end
+
+# BMizing for MVirtualTypeProps
+class MVirtualTypePropBMizer
+       super MPropertyBMizer[MVirtualTypeProp]
+
+       redef type MPROP: MVirtualTypeProp
+       init(mmodule: MModule) do super(mmodule)
+end
+
 # Colorers
 
 abstract class TypingColorer[E: Object]
index b3a29e2..a260c4a 100644 (file)
@@ -210,16 +210,25 @@ class SeparateCompiler
        fun do_property_coloring do
                var mclasses = new HashSet[MClass].from(modelbuilder.model.mclasses)
 
+               # Layouts
+               var method_layout_builder: PropertyLayoutBuilder[MMethod]
+               var attribute_layout_builder: PropertyLayoutBuilder[MAttribute]
+               if modelbuilder.toolcontext.opt_bm_typing.value then
+                       method_layout_builder = new MMethodBMizer(self.mainmodule)
+                       attribute_layout_builder = new MAttributeBMizer(self.mainmodule)
+               else
+                       method_layout_builder = new MMethodColorer(self.mainmodule)
+                       attribute_layout_builder = new MAttributeColorer(self.mainmodule)
+               end
+
                # methods coloration
-               var method_coloring = new MMethodColorer(mainmodule)
-               var method_layout = method_coloring.build_layout(mclasses)
+               var method_layout = method_layout_builder.build_layout(mclasses)
                self.method_tables = build_method_tables(mclasses, method_layout)
                self.compile_color_consts(method_layout.pos)
                self.method_layout = method_layout
 
                # attributes coloration
-               var attribute_coloring = new MAttributeColorer(mainmodule)
-               var attr_layout = attribute_coloring.build_layout(mclasses)
+               var attr_layout = attribute_layout_builder.build_layout(mclasses)
                self.attr_tables = build_attr_tables(mclasses, attr_layout)
                self.compile_color_consts(attr_layout.pos)
                self.attr_layout = attr_layout