compile: new class GlobalCompilerVisitor
authorJean Privat <jean@pryen.org>
Tue, 23 Jun 2009 03:35:45 +0000 (23:35 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 19:48:19 +0000 (15:48 -0400)
Specialize CompilerVisitor to add global analysis information instead
of refininig it.

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

src/compiling/compiling.nit
src/compiling/compiling_global.nit

index 7bfe046..3ce3798 100644 (file)
@@ -80,8 +80,7 @@ redef class MMSrcModule
        # Compile the main file
        private meth compile_main(tc: ToolContext, ga: GlobalAnalysis)
        do
-               var v = new CompilerVisitor(self, tc)
-               v.global_analysis = ga
+               var v = new GlobalCompilerVisitor(self, tc, ga)
                v.add_decl("#include <nit_common.h>")
                compile_tables_to_c(v)
                compile_main_part(v)
@@ -97,8 +96,7 @@ redef class MMSrcModule
        # Compile the sep files (of the current module only)
        private meth compile_separate_module(tc: ToolContext, ga: GlobalAnalysis)
        do
-               var v = new CompilerVisitor(self, tc)
-               v.global_analysis = ga
+               var v = new GlobalCompilerVisitor(self, tc, ga)
                v.add_decl("#include <nit_common.h>")
                var native_name = filename.strip_extension(".nit")
                native_name += ("_nit.h")
index c404b8d..c9dea50 100644 (file)
@@ -69,9 +69,15 @@ special ColorContext
        end
 end
 
-redef class CompilerVisitor
-       # The global analysis result, if any
-       readable writable attr _global_analysis: GlobalAnalysis 
+class GlobalCompilerVisitor
+special CompilerVisitor
+       # The global analysis result
+       readable attr _global_analysis: GlobalAnalysis
+       init(m: MMSrcModule, tc: ToolContext, ga: GlobalAnalysis)
+       do
+               super(m, tc)
+               _global_analysis = ga
+       end
 end
 
 # A compiled class is a class in a program
@@ -411,7 +417,7 @@ redef class MMSrcModule
        end
 
        # Compile module and class tables
-       meth compile_tables_to_c(v: CompilerVisitor)
+       meth compile_tables_to_c(v: GlobalCompilerVisitor)
        do
                for m in mhe.greaters_and_self do
                        assert m isa MMSrcModule
@@ -434,7 +440,7 @@ redef class MMSrcModule
        end
 
        # Declare class table (for _sep.h)
-       meth declare_class_tables_to_c(v: CompilerVisitor)
+       meth declare_class_tables_to_c(v: GlobalCompilerVisitor)
        do
                for c in local_classes do
                        if c.global.module == self then
@@ -444,7 +450,7 @@ redef class MMSrcModule
        end
 
        # Compile main part (for _table.c)
-       meth compile_main_part(v: CompilerVisitor)
+       meth compile_main_part(v: GlobalCompilerVisitor)
        do
                v.add_instr("int main(int argc, char **argv) \{")
                v.indent
@@ -471,7 +477,7 @@ redef class MMSrcModule
        end
        
        # Compile sep files 
-       meth compile_mod_to_c(v: CompilerVisitor)
+       meth compile_mod_to_c(v: GlobalCompilerVisitor)
        do
                v.add_decl("extern const char *LOCATE_{name};")
                if not v.tc.global then
@@ -507,7 +513,7 @@ redef class MMSrcModule
        end
 
        # Compile module file for the current module
-       meth compile_local_table_to_c(v: CompilerVisitor)
+       meth compile_local_table_to_c(v: GlobalCompilerVisitor)
        do
                v.add_instr("const char *LOCATE_{name} = \"{filename}\";")
 
@@ -530,7 +536,7 @@ end
 # An element of a class, an instance or a module table
 abstract class AbsTableElt
        # Compile the macro needed to use the element and other related elements
-       meth compile_macros(v: CompilerVisitor, value: String) is abstract
+       meth compile_macros(v: GlobalCompilerVisitor, value: String) is abstract
 end
 
 # An element of a class or an instance table
@@ -547,7 +553,7 @@ special AbsTableElt
        meth item(i: Int): TableElt do return self
 
        # Return the value of the element for a given class
-       meth compile_to_c(v: CompilerVisitor, c: MMLocalClass): String is abstract
+       meth compile_to_c(v: GlobalCompilerVisitor, c: MMLocalClass): String is abstract
 end
 
 # An element of a module table
@@ -815,7 +821,7 @@ redef class MMLocalClass
        end
 
        # Declaration and macros related to the class table
-       meth declare_tables_to_c(v: CompilerVisitor)
+       meth declare_tables_to_c(v: GlobalCompilerVisitor)
        do
                v.add_decl("")
                var pi = primitive_info
@@ -832,7 +838,7 @@ redef class MMLocalClass
        end
 
        # Compilation of table and new (or box)
-       meth compile_tables_to_c(v: CompilerVisitor)
+       meth compile_tables_to_c(v: GlobalCompilerVisitor)
        do
                var cc = v.global_analysis.compiled_classes[self.global]
                var ctab =  cc.class_table