Merge branch 'package2module' into wip
[nit.git] / src / program.nit
index 63572e3..217031a 100644 (file)
@@ -39,7 +39,7 @@ class Program
        readable var _tc: ToolContext
 
        # This module is the 'main' module, the one where we find the 'main' method
-       readable var _module: MMModule
+       readable var _main_module: MMModule
 
        # This method is the entry point of this program
        # There might be no entry point (if in fact we are compiling a library)
@@ -49,30 +49,25 @@ class Program
        # Would be null if there is no main method
        readable var _main_class: nullable MMLocalClass = null
 
-       # When we are using global compilation, we generate _glob files instead
-       # of _sep files so that we do not corrupt separate compilation
-       fun get_file_ending: String do return if tc.global then "_glob" else "_sep"
-
        # This method will ensure that all the metamodel is computed before we
        # start using all the classes
        private fun finish_processing_classes do
                var classes = new Array[MMLocalClass]
-               for c in module.local_classes do
+               for c in main_module.local_classes do
                        c.compute_super_classes
                        classes.add(c)
                end
 
                for c in classes do
                        c.compute_ancestors
-                       c.inherit_global_properties
                end
        end
 
        fun compute_main_method do
                # Check for the 'Sys' class
                var sysname = once "Sys".to_symbol
-               if not module.has_global_class_named(sysname) then return
-               var sys = module.class_by_name(sysname)
+               if not main_module.has_global_class_named(sysname) then return
+               var sys = main_module.class_by_name(sysname)
 
                # Check for 'Sys::main' method
                var entryname = once "main".to_symbol
@@ -85,7 +80,8 @@ class Program
        # Generation of allocation function of this class
        fun generate_allocation_iroutines
        do
-               for c in module.local_classes do
+               for c in main_module.local_classes do
+                       if c.global.is_abstract or c.global.is_interface then continue
                        var pi = c.primitive_info
                        if pi == null then
                                do
@@ -93,9 +89,10 @@ class Program
                                        var iself = new IRegister(c.get_type)
                                        var iselfa = [iself]
                                        var iroutine = new IRoutine(iselfa, null)
-                                       var icb = new ICodeBuilder(module, iroutine)
+                                       var icb = new ICodeBuilder(main_module, iroutine)
 
                                        for g in c.global_properties do
+                                               if not g.intro isa MMAttribute then continue
                                                var p = c[g]
                                                var t = p.signature.return_type
                                                if p isa MMAttribute and t != null then
@@ -114,8 +111,9 @@ class Program
                                        var iself = new IRegister(c.get_type)
                                        var iselfa = [iself]
                                        var iroutine = new IRoutine(iselfa, null)
-                                       var icb = new ICodeBuilder(module, iroutine)
+                                       var icb = new ICodeBuilder(main_module, iroutine)
                                        for g in c.global_properties do
+                                               if not g.intro isa MMAttribute then continue
                                                var p = c[g]
                                                var t = p.signature.return_type
                                                if p isa MMAttribute and t != null and not t.is_nullable then
@@ -127,9 +125,9 @@ class Program
                                end
 
                                for g in c.global_properties do
-                                       var p = c[g]
                                        # FIXME skip invisible constructors
-                                       if not p.global.is_init_for(c) then continue
+                                       if not g.is_init_for(c) then continue
+                                       var p = c[g]
                                        assert p isa MMMethod
 
                                        var iself = new IRegister(c.get_type)
@@ -137,7 +135,7 @@ class Program
                                        for i in [0..p.signature.arity[ do iparams.add(new IRegister(p.signature[i]))
                                        var iroutine = new IRoutine(iparams, iself)
                                        iroutine.location = p.iroutine.location
-                                       var icb = new ICodeBuilder(module, iroutine)
+                                       var icb = new ICodeBuilder(main_module, iroutine)
 
                                        var inew = new IAllocateInstance(c.get_type)
                                        inew.result = iself
@@ -160,7 +158,7 @@ class Program
        fun with_each_iroutines
                !action(i: IRoutine, m: MMModule)
        do
-               for m in module.mhe.greaters_and_self do
+               for m in main_module.mhe.greaters_and_self do
                        for c in m.local_classes do
                                var iroutine: nullable IRoutine = null
 
@@ -196,7 +194,7 @@ class Program
        fun with_each_methods
                !action(m: MMMethod)
        do
-               for m in module.mhe.greaters_and_self do
+               for m in main_module.mhe.greaters_and_self do
                        for c in m.local_classes do
                                # Process methods and attributes initialization
                                for p in c.local_local_properties do
@@ -213,13 +211,13 @@ class Program
        fun with_each_live_local_classes
                !action(m: MMLocalClass)
        do
-               for c in module.local_classes do
+               for c in main_module.local_classes do
                        action(c)
                end
        end
 
        init(m: MMModule, toolcontext: ToolContext) do
-               _module = m
+               _main_module = m
                _tc = toolcontext
                finish_processing_classes
        end