modelbuilder: avoid multiple load of the same module
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 6 Nov 2013 00:53:39 +0000 (19:53 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 6 Nov 2013 00:53:39 +0000 (19:53 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

Makefile
src/modelbuilder.nit

index 53f4cba..ac55776 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ doc/stdlib/index.html: bin/nitdoc
        @echo '***************************************************************'
        @echo '* Generate doc for NIT standard library                       *'
        @echo '***************************************************************'
-       bin/nitdoc lib/*.nit $$(find lib/* -maxdepth 0 -type d ) -d doc/stdlib \
+       bin/nitdoc lib/*.nit $$(find lib/*/*.nit -maxdepth 0 -type f ) -d doc/stdlib \
                --custom-title "Nit Standard Library" \
                --custom-menu-items "<li><a href=\"http://nitlanguage.org/\">Nitlanguage.org</a></li>" \
                --custom-overview-text "<p>Documentation for the standard library of Nit<br/>Version $$(git describe)<br/>Date: $$(git show --format="%cd" | head -1)</p>" \
index 25a98ef..3390811 100644 (file)
@@ -359,16 +359,28 @@ class ModelBuilder
                return path
        end
 
+       # loaded module by absolute path
+       private var loaded_nmodules = new HashMap[String, AModule]
+
        # Try to load a module using a path.
        # Display an error if there is a problem (IO / lexer / parser) and return null
        # Note: usually, you do not need this method, use `get_mmodule_by_name` instead.
        fun load_module(owner: nullable MModule, filename: String): nullable AModule
        do
+               if filename.file_extension != "nit" then
+                       self.toolcontext.error(null, "Error: file {filename} is not a valid nit module.")
+                       return null
+               end
                if not filename.file_exists then
                        self.toolcontext.error(null, "Error: file {filename} not found.")
                        return null
                end
 
+               var module_path = module_absolute_path(filename)
+               if loaded_nmodules.keys.has(module_path) then
+                       return loaded_nmodules[module_path]
+               end
+
                var x = if owner != null then owner.to_s else "."
                self.toolcontext.info("load module {filename} in {x}", 2)
 
@@ -405,6 +417,7 @@ class ModelBuilder
                nmodule.mmodule = mmodule
                nmodules.add(nmodule)
                self.mmodule2nmodule[mmodule] = nmodule
+               self.loaded_nmodules[module_path] = nmodule
 
                build_module_importation(nmodule)