nitg: refactor the ToolChain class by adding an abstract super class
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 25 Feb 2014 05:09:11 +0000 (00:09 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 4 Mar 2014 17:46:40 +0000 (12:46 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/abstract_compiler.nit

index f900351..55ae1f2 100644 (file)
@@ -84,20 +84,23 @@ redef class ModelBuilder
        # Simple indirection to `Toolchain::write_and_make`
        protected fun write_and_make(compiler: AbstractCompiler)
        do
-               var toolchain = new MakefileToolchain(toolcontext)
+               var platform = compiler.mainmodule.target_platform(toolcontext)
+               var toolchain
+               if platform == null then
+                       toolchain = new MakefileToolchain(toolcontext)
+               else
+                       toolchain = platform.toolchain(toolcontext)
+               end
                compile_dir = toolchain.compile_dir
                toolchain.write_and_make compiler
        end
 end
 
-class MakefileToolchain
-       # The list of directories to search for included C headers (-I for C compilers)
-       # The list is initially set with :
-       #   * the toolcontext --cc-path option
-       #   * the NIT_CC_PATH environment variable
-       #   * some heuristics including the NIT_DIR environment variable and the progname of the process
-       # Path can be added (or removed) by the client
-       var cc_paths = new Array[String]
+redef class Platform
+       fun toolchain(toolcontext: ToolContext): Toolchain is abstract
+end
+
+class Toolchain
        var toolcontext: ToolContext
 
        fun compile_dir: String
@@ -107,6 +110,19 @@ class MakefileToolchain
                return compile_dir
        end
 
+       fun write_and_make(compiler: AbstractCompiler) is abstract
+end
+
+class MakefileToolchain
+       super Toolchain
+       # The list of directories to search for included C headers (-I for C compilers)
+       # The list is initially set with :
+       #   * the toolcontext --cc-path option
+       #   * the NIT_CC_PATH environment variable
+       #   * some heuristics including the NIT_DIR environment variable and the progname of the process
+       # Path can be added (or removed) by the client
+       var cc_paths = new Array[String]
+
        protected fun gather_cc_paths
        do
                # Look for the the Nit clib path
@@ -132,7 +148,7 @@ class MakefileToolchain
                end
        end
 
-       fun write_and_make(compiler: AbstractCompiler)
+       redef fun write_and_make(compiler)
        do
                gather_cc_paths