ffi: move guard into the MModule to simplify management
authorJean Privat <jean@pryen.org>
Wed, 16 Jul 2014 15:38:43 +0000 (11:38 -0400)
committerJean Privat <jean@pryen.org>
Wed, 16 Jul 2014 16:05:55 +0000 (12:05 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/common_ffi/common_ffi.nit

index c22180c..9d793e4 100644 (file)
@@ -63,6 +63,11 @@ redef class MModule
                ffi_ccu.write_as_impl(self, compdir)
                for filename in ffi_ccu.files do ffi_files.add(new ExternCFile(filename, c_compiler_options))
        end
+
+       # Avoid the compile a ffi propdef more than once
+       # See `AMethPropdef::compile_ffi_method`
+       # FIXME find a better way
+       private var compiled_ffi_methods = new HashSet[AMethPropdef]
 end
 
 redef class AModule
@@ -110,15 +115,13 @@ redef class AModule
 end
 
 redef class AMethPropdef
-       private var ffi_has_been_compiled = false
-
        # Compile the necessary wrapper around this extern method or constructor
        fun compile_ffi_method(mmodule: MModule)
        do
                assert n_extern_code_block != null
 
-               if ffi_has_been_compiled then return
-               ffi_has_been_compiled = true
+               if mmodule.compiled_ffi_methods.has(self) then return
+               mmodule.compiled_ffi_methods.add self
 
                var language = n_extern_code_block.language
                assert language != null