ffi: merge `finalize_ffi` and `finalize_nitni`
authorJean Privat <jean@pryen.org>
Thu, 3 Apr 2014 19:14:06 +0000 (15:14 -0400)
committerJean Privat <jean@pryen.org>
Thu, 3 Apr 2014 19:14:06 +0000 (15:14 -0400)
Also, the creation of the visitor in done on the ffi side.

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

src/abstract_compiler.nit
src/compiler_ffi.nit

index aab3918..f26d7d8 100644 (file)
@@ -696,6 +696,8 @@ abstract class AbstractCompiler
                end
        end
 
+       fun finalize_ffi_for_module(mmodule: MModule) do mmodule.finalize_ffi(self)
+
        # Division facility
        # Avoid division by zero by returning the string "n/a"
        fun div(a,b:Int):String
@@ -703,13 +705,6 @@ abstract class AbstractCompiler
                if b == 0 then return "n/a"
                return ((a*10000/b).to_f / 100.0).to_precision(2)
        end
-
-       fun finalize_ffi_for_module(mmodule: MModule)
-       do
-               var visitor = new_visitor
-               mmodule.finalize_ffi(visitor, modelbuilder)
-               mmodule.finalize_nitni(visitor)
-       end
 end
 
 # A file unit (may be more than one file if
@@ -2611,11 +2606,8 @@ redef class MModule
        end
        private var properties_cache: Map[MClass, Set[MProperty]] = new HashMap[MClass, Set[MProperty]]
 
-       # Write FFI results to file
-       fun finalize_ffi(v: AbstractCompilerVisitor, modelbuilder: ModelBuilder) do end
-
-       # Write nitni results to file
-       fun finalize_nitni(v: AbstractCompilerVisitor) do end
+       # Write FFI and nitni results to file
+       fun finalize_ffi(c: AbstractCompiler) do end
 
        # Give requided addinional system libraries (as given to LD_LIBS)
        # Note: can return null instead of an empty set
index 6334be5..2583252 100644 (file)
@@ -31,25 +31,15 @@ redef class MModule
                return m2n.get_or_null(self)
        end
 
-       redef fun finalize_ffi(v: AbstractCompilerVisitor, modelbuilder: ModelBuilder)
+       redef fun finalize_ffi(compiler: AbstractCompiler)
        do
+               if not uses_ffi then return
+
+               var v = compiler.new_visitor
                var n = nmodule(v)
                if n == null then return
                n.finalize_ffi_wrapper(v.compiler.modelbuilder.compile_dir, v.compiler.mainmodule)
                for file in n.ffi_files do v.compiler.extern_bodies.add(file)
-       end
-
-       fun ensure_compile_nitni_base(v: AbstractCompilerVisitor)
-       do
-               if nitni_ccu != null then return
-
-               nitni_ccu = new CCompilationUnit
-       end
-
-       redef fun finalize_nitni(v: AbstractCompilerVisitor)
-       do
-               var n = nmodule(v)
-               if n == null then return
 
                ensure_compile_nitni_base(v)
 
@@ -62,6 +52,13 @@ redef class MModule
                end
        end
 
+       fun ensure_compile_nitni_base(v: AbstractCompilerVisitor)
+       do
+               if nitni_ccu != null then return
+
+               nitni_ccu = new CCompilationUnit
+       end
+
        redef fun collect_linker_libs
        do
                var s = c_linker_options