Merge branch 'dump_rta'
[nit.git] / src / abstract_compiler.nit
index f900351..a472d8f 100644 (file)
@@ -22,6 +22,7 @@ import typing
 import auto_super_init
 import frontend
 import common_ffi
+import platform
 
 # Add compiling options
 redef class ToolContext
@@ -84,20 +85,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
+               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 +111,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 +149,7 @@ class MakefileToolchain
                end
        end
 
-       fun write_and_make(compiler: AbstractCompiler)
+       redef fun write_and_make(compiler)
        do
                gather_cc_paths
 
@@ -219,7 +236,12 @@ class MakefileToolchain
                        hfile.write "#include \"{hfilename}\"\n"
                        for key in f.required_declarations do
                                if not compiler.provided_declarations.has_key(key) then
-                                       print "No provided declaration for {key}"
+                                       var node = compiler.requirers_of_declarations.get_or_null(key)
+                                       if node != null then
+                                               node.debug "No provided declaration for {key}"
+                                       else
+                                               print "No provided declaration for {key}"
+                                       end
                                        abort
                                end
                                hfile.write compiler.provided_declarations[key]
@@ -405,6 +427,8 @@ abstract class AbstractCompiler
 
        private var provided_declarations = new HashMap[String, String]
 
+       private var requirers_of_declarations = new HashMap[String, ANode]
+
        # Builds the .c and .h files to be used when generating a Stack Trace
        # Binds the generated C function names to Nit function names
        fun build_c_to_nit_bindings
@@ -698,9 +722,6 @@ abstract class AbstractCompiler
                nmodule.finalize_ffi(visitor, modelbuilder)
                nmodule.finalize_nitni(visitor)
        end
-
-       # Does this compiler support the FFI?
-       fun supports_ffi: Bool do return false
 end
 
 # A file unit (may be more than one file if
@@ -1057,7 +1078,11 @@ abstract class AbstractCompilerVisitor
        # Request the presence of a global declaration
        fun require_declaration(key: String)
        do
-               self.writer.file.required_declarations.add(key)
+               var reqs = self.writer.file.required_declarations
+               if reqs.has(key) then return
+               reqs.add(key)
+               var node = current_node
+               if node != null then compiler.requirers_of_declarations[key] = node
        end
 
        # Add a declaration in the local-header
@@ -1534,10 +1559,10 @@ redef class AConcreteMethPropdef
                        var args = [arguments.first]
                        for auto_super_init in auto_super_inits do
                                args.clear
-                               for i in [0..auto_super_init.intro.msignature.arity+1[ do
+                               for i in [0..auto_super_init.msignature.arity+1[ do
                                        args.add(arguments[i])
                                end
-                               v.send(auto_super_init, args)
+                               v.compile_callsite(auto_super_init, args)
                        end
                end
                v.stmt(self.n_block)
@@ -2485,7 +2510,7 @@ redef class ASuperExpr
                end
 
                # stantard call-next-method
-               return v.supercall(v.frame.mpropdef.as(MMethodDef), recv.mtype.as(MClassType), args)
+               return v.supercall(mpropdef.as(not null), recv.mtype.as(MClassType), args)
        end
 end