tool: use ccache in gccx, if available
[nit.git] / src / program.nit
index 05214aa..7284fc6 100644 (file)
@@ -22,6 +22,15 @@ import icode
 import primitive_info
 import mmloader
 
+redef class ToolContext
+       readable writable var _global: Bool = false
+       writable var _use_SFT_optimization: Bool = true
+
+       # We can say that we are using SFT optimization *only* when we are
+       # doing global compilation and we enabled the command line option
+       fun use_SFT_optimization: Bool do return global and _use_SFT_optimization
+end
+
 # Instances of this class represent a program/library that will
 # be analyzed/compiled by nitc
 class Program
@@ -40,6 +49,20 @@ class Program
        # Would be null if there is no main method
        readable var _main_class: nullable MMLocalClass = null
 
+       # 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
+                       c.compute_super_classes
+                       classes.add(c)
+               end
+
+               for c in classes do
+                       c.compute_ancestors
+               end
+       end
+
        fun compute_main_method do
                # Check for the 'Sys' class
                var sysname = once "Sys".to_symbol
@@ -68,6 +91,7 @@ class Program
                                        var icb = new ICodeBuilder(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
@@ -88,6 +112,7 @@ class Program
                                        var iroutine = new IRoutine(iselfa, null)
                                        var icb = new ICodeBuilder(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
@@ -99,9 +124,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)
@@ -127,9 +152,73 @@ class Program
                end
        end
 
+       # This function will call the attached block for each IRoutines
+       # in this program
+       fun with_each_iroutines
+               !action(i: IRoutine, m: MMModule)
+       do
+               for m in module.mhe.greaters_and_self do
+                       for c in m.local_classes do
+                               var iroutine: nullable IRoutine = null
+
+                               # Process methods and attributes initialization
+                               for p in c.local_local_properties do
+                                       if p isa MMAttribute then
+                                               iroutine = p.iroutine
+                                       else if p isa MMMethod then
+                                               iroutine = p.iroutine
+                                       end
+                                       if iroutine == null then continue
+                                       action(iroutine, m)
+                               end
+
+                               # Process class-specific iroutines
+                               iroutine = c.init_var_iroutine
+                               if iroutine != null then
+                                       action(iroutine, m)
+                               end
+                               iroutine = c.checknew_iroutine
+                               if iroutine != null then
+                                       action(iroutine, m)
+                               end
+                               for i in c.new_instance_iroutine do
+                                       action(i, m)
+                               end
+                       end
+               end
+       end
+
+       # This function will call the attached block for each MMMethods
+       # in this program
+       fun with_each_methods
+               !action(m: MMMethod)
+       do
+               for m in 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
+                                       if p isa MMMethod then
+                                               action(p)
+                                       end
+                               end
+                       end
+               end
+       end
+
+       # This function will call the attached block for each live local classes
+       # in this program
+       fun with_each_live_local_classes
+               !action(m: MMLocalClass)
+       do
+               for c in module.local_classes do
+                       action(c)
+               end
+       end
+
        init(m: MMModule, toolcontext: ToolContext) do
                _module = m
                _tc = toolcontext
+               finish_processing_classes
        end
 end