rename 'package' to 'module'
[nit.git] / src / compiling / table_computation.nit
index cad65e6..73e62cd 100644 (file)
 # limitations under the License.
 
 # Compute tables for classes and modules.
-package table_computation
+module table_computation
 
 import mmloader
-import primitive_info
+private import primitive_info
 import program
 
 # Something that store color of table elements
-class ColorContext
+abstract class ColorContext
        var _colors: HashMap[TableElt, Int] = new HashMap[TableElt, Int]
 
        # The color of a table element.
@@ -52,14 +52,14 @@ end
 
 # All information and results of the global analysis.
 class TableInformation
-special ColorContext
+       super ColorContext
        # FIXME: do something better.
        readable writable var _max_class_table_length: Int = 0
 end
 
 # A compiled class is a class in a program
 class CompiledClass
-special ColorContext
+       super ColorContext
        # The corresponding local class in the main module of the prgram
        readable var _local_class: MMLocalClass
 
@@ -112,6 +112,9 @@ redef class MMConcreteClass
                                        ilt.add(new TableEltAttr(p))
                                else if p isa MMMethod then
                                        clt.add(new TableEltMeth(p))
+                               else if p isa MMTypeProperty then
+                                       clt.add(new TableEltVTClassId(p))
+                                       clt.add(new TableEltVTClassColor(p))
                                end
                        end
                        if p isa MMMethod and p.need_super then
@@ -143,7 +146,7 @@ redef class Program
        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
                end
@@ -162,6 +165,7 @@ redef class Program
 
                ctab.add(new TableEltClassSelfId)
                ctab.add(new TableEltClassObjectSize)
+               ctab.add(new TableEltClassSelfName)
                itab.add(new TableEltVftPointer)
                itab.add(new TableEltObjectId)
 
@@ -170,17 +174,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
+               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
@@ -188,7 +185,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
@@ -414,13 +411,13 @@ end
 ###############################################################################
 
 # An element of a class, an instance or a module table
-abstract class AbsTableElt
+interface AbsTableElt
 end
 
 # An element of a class or an instance table
 # Such an elements represent method function pointers, attribute values, etc.
-abstract class TableElt
-special AbsTableElt
+interface TableElt
+       super AbsTableElt
        # Is the element conflict to class `c' (used for coloring)
        fun is_related_to(c: MMLocalClass): Bool is abstract
 
@@ -433,19 +430,19 @@ end
 
 # An element of a module table
 # Such an elements represent colors or identifiers
-abstract class ModuleTableElt
-special AbsTableElt
+interface ModuleTableElt
+       super AbsTableElt
 end
 
 # An element of a module table that represents a group of TableElt defined in the same local class
 class ModuleTableEltGroup
-special ModuleTableElt
+       super ModuleTableElt
        readable var _elements: Array[TableElt] = new Array[TableElt]
 end
 
 # An element that represents a class property
 abstract class TableEltProp
-special TableElt
+       super TableElt
        readable var _property: MMLocalProperty
 
        init(p: MMLocalProperty)
@@ -456,22 +453,32 @@ end
 
 # An element that represents a function pointer to a global method
 class TableEltMeth
-special TableEltProp
+       super TableEltProp
+end
+
+# An element that represents a class color value for a virtual type
+class TableEltVTClassColor
+       super TableEltProp
+end
+
+# An element that represents a class id value for a virtual type
+class TableEltVTClassId
+       super TableEltProp
 end
 
 # An element that represents a function pointer to the super method of a local method
 class TableEltSuper
-special TableEltProp
+       super TableEltProp
 end
 
 # An element that represents the value stored for a global attribute
 class TableEltAttr
-special TableEltProp
+       super TableEltProp
 end
 
 # An element representing a class information
-class AbsTableEltClass
-special AbsTableElt
+abstract class AbsTableEltClass
+       super AbsTableElt
        # The local class where the information comes from
        readable var _local_class: MMLocalClass
 
@@ -482,25 +489,25 @@ special AbsTableElt
 end
 
 # An element of a class table representing a class information
-class TableEltClass
-special TableElt
-special AbsTableEltClass
+abstract class TableEltClass
+       super TableElt
+       super 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
 
 # An element representing the id of a class in a module table
 class TableEltClassId
-special ModuleTableElt
-special AbsTableEltClass
+       super ModuleTableElt
+       super AbsTableEltClass
 end
 
 # An element representing the constructor marker position in a class table
 class TableEltClassInitTable
-special TableEltClass
+       super TableEltClass
 end
 
 # An element used for a cast
@@ -508,13 +515,13 @@ end
 # At the TableElt offset, there is the id of the super-class
 # At the ModuleTableElt offset, there is the TableElt offset (ie. the color of the super-class).
 class TableEltClassColor
-special TableEltClass
-special ModuleTableElt
+       super TableEltClass
+       super ModuleTableElt
 end
 
 # A Group of elements introduced in the same global-class that are colored together
 class TableEltComposite
-special TableElt
+       super TableElt
        var _table: Array[TableElt]
        var _cc: CompiledClass
        var _offsets: HashMap[MMLocalClass, Int]
@@ -539,24 +546,30 @@ end
 
 # The element that represent the class id
 class TableEltClassSelfId
-special TableElt
+       super TableElt
+       redef fun is_related_to(c) do return true
+end
+
+# The element that represent the class name
+class TableEltClassSelfName
+       super TableElt
        redef fun is_related_to(c) do return true
 end
 
 # The element that represent the Object Size
 class TableEltClassObjectSize
-special TableElt
+       super TableElt
        redef fun is_related_to(c) do return true
 end
 
 # The element that represent the object id
 class TableEltObjectId
-special TableElt
+       super TableElt
        redef fun is_related_to(c) do return true
 end
 
 # The element that
 class TableEltVftPointer
-special TableElt
+       super TableElt
        redef fun is_related_to(c) do return true
 end