nitg: add GlobalCompiler::new_file
authorJean Privat <jean@pryen.org>
Sun, 16 Dec 2012 02:22:28 +0000 (21:22 -0500)
committerJean Privat <jean@pryen.org>
Sun, 16 Dec 2012 02:22:28 +0000 (21:22 -0500)
The point is to avoid contamination between must-be-compiled-separately files

Signed-off-by: Jean Privat <jean@pryen.org>

src/global_compiler.nit
src/separate_compiler.nit
src/separate_erasure_compiler.nit

index 3e309a5..468fc04 100644 (file)
@@ -149,7 +149,7 @@ redef class ModelBuilder
                var i = 0
                for vis in compiler.visitors do
                        count += vis.lines.length
-                       if file == null or count > 10000 then
+                       if file == null or count > 10000 or vis.file_break then
                                i += 1
                                if file != null then file.close
                                var cfilename = ".nit_compile/{mainmodule.name}.{i}.c"
@@ -258,6 +258,14 @@ class GlobalCompiler
                end
        end
 
+       # Force the creation of a new file
+       # The point is to avoid contamination between must-be-compiled-separately files
+       fun new_file
+       do
+               var v = self.new_visitor
+               v.file_break = true
+       end
+
        fun compile_header do
                var v = self.header
                self.header.add_decl("#include <stdlib.h>")
@@ -1016,6 +1024,8 @@ class GlobalCompilerVisitor
                compiler.visitors.add(self)
        end
 
+       var file_break: Bool = false
+
        # Alias for self.compiler.mainmodule.object_type
        fun object_type: MClassType do return self.compiler.mainmodule.object_type
 
index c57b352..612c22d 100644 (file)
@@ -79,14 +79,17 @@ redef class ModelBuilder
                end
 
                # The main function of the C
+               compiler.new_file
                compiler.compile_main_function
 
                # compile methods
                for m in mainmodule.in_importation.greaters do
+                       compiler.new_file
                        compiler.compile_module_to_c(m)
                end
 
                # compile live & cast type structures
+               compiler.new_file
                var mtypes = compiler.do_type_coloring
                for t in mtypes do
                        compiler.compile_type_to_c(t)
index 644b709..3430bfa 100644 (file)
@@ -42,6 +42,7 @@ redef class ModelBuilder
                compiler.compile_header
 
                # compile class structures
+               compiler.new_file
                for m in mainmodule.in_importation.greaters do
                        for mclass in m.intro_mclasses do
                                compiler.compile_class_to_c(mclass)
@@ -49,10 +50,12 @@ redef class ModelBuilder
                end
 
                # The main function of the C
+               compiler.new_file
                compiler.compile_main_function
 
                # compile methods
                for m in mainmodule.in_importation.greaters do
+                       compiler.new_file
                        compiler.compile_module_to_c(m)
                end