Merge branch 'various-fixes' into next
[nit.git] / src / compiling / table_computation.nit
index 24e5fb2..df7dc3b 100644 (file)
@@ -93,7 +93,7 @@ redef class MMConcreteClass
        readable var _instance_layout: Array[TableElt] = new Array[TableElt]
 
        # Build the local layout of the class and feed the module table
-       private fun build_layout_in(tc: ToolContext, module_table: Array[ModuleTableElt])
+       private fun build_layout_in(module_table: Array[ModuleTableElt])
        do
                var clt = _class_layout
                var ilt = _instance_layout
@@ -140,22 +140,21 @@ redef class Program
        # Associate global classes to compiled classes
        readable var _compiled_classes: HashMap[MMGlobalClass, CompiledClass] = new HashMap[MMGlobalClass, CompiledClass]
 
-       fun do_table_computation(tc: ToolContext)
+       fun do_table_computation
        do
                tc.info("Building tables",1)
-               for m in module.mhe.greaters_and_self do
+               for m in main_module.mhe.greaters_and_self do
                        tc.info("Building tables for module: {m.name}",2)
-                       m.local_analysis(tc)
+                       m.local_analysis
                end
 
                tc.info("Merging all tables",2)
-               do_global_table_analysis(tc)
+               do_global_table_analysis
        end
 
        # Do the complete global analysis
-       private fun do_global_table_analysis(cctx: ToolContext)
+       private fun do_global_table_analysis
        do
-               #print "Do the complete global analysis"
                var smallest_classes = new Array[MMLocalClass]
                var global_properties = new HashSet[MMGlobalProperty]
                var ctab = new Array[TableElt]
@@ -171,17 +170,10 @@ redef class Program
 
                # We have to work on ALL the classes of the module
                var classes = new Array[MMLocalClass]
-               for c in module.local_classes do
-                       c.compute_super_classes
-                       classes.add(c)
-               end
-               (new ClassSorter).sort(classes)
+               for c in main_module.local_classes do classes.add(c)
+               classes.sort !cmp(x,y) = x.total_order_compare(y)
 
                for c in classes do
-                       # Finish processing the class (if invisible)
-                       c.compute_ancestors
-                       c.inherit_global_properties
-
                        # Associate a CompiledClass to the class
                        var cc = new CompiledClass(c)
                        compiled_classes[c.global] = cc
@@ -189,7 +181,7 @@ redef class Program
                        # Assign a unique class identifier
                        # (negative are for primitive classes)
                        var gc = c.global
-                       var bm = gc.module
+                       var bm = gc.mmmodule
                        if c.primitive_info != null then
                                cc.id = pclassid
                                pclassid = pclassid - 4
@@ -402,11 +394,11 @@ redef class MMModule
        readable var _local_table: Array[ModuleTableElt] = new Array[ModuleTableElt]
 
        # Builds the local tables and local classes layouts
-       private fun local_analysis(tc: ToolContext)
+       private fun local_analysis
        do
                for c in local_classes do
                        if c isa MMConcreteClass then
-                               c.build_layout_in(tc, _local_table)
+                               c.build_layout_in(_local_table)
                        end
                end
        end
@@ -488,7 +480,7 @@ special TableElt
 special AbsTableEltClass
        redef fun is_related_to(c)
        do
-               var bc = c.module[_local_class.global]
+               var bc = c.mmmodule[_local_class.global]
                return c.cshe <= bc
        end
 end
@@ -561,37 +553,3 @@ class TableEltVftPointer
 special TableElt
        redef fun is_related_to(c) do return true
 end
-
-###############################################################################
-
-# Used to sort local class in a deterministic total order
-# The total order superset the class refinement and the class specialisation relations
-class ClassSorter
-special AbstractSorter[MMLocalClass]
-       redef fun compare(a, b) do return a.compare(b)
-       init do end
-end
-
-redef class MMLocalClass
-       # Comparaison in a total order that superset the class refinement and the class specialisation relations
-       fun compare(b: MMLocalClass): Int
-       do
-               var a = self
-               if a == b then
-                       return 0
-               else if a.module.mhe < b.module then
-                       return 1
-               else if b.module.mhe < a.module then
-                       return -1
-               end
-               var ar = a.cshe.rank
-               var br = b.cshe.rank
-               if ar > br then
-                       return 1
-               else if br > ar then
-                       return -1
-               else
-                       return b.name.to_s <=> a.name.to_s
-               end
-       end
-end