From: Alexandre Terrasa Date: Wed, 6 Nov 2013 00:53:39 +0000 (-0500) Subject: modelbuilder: avoid multiple load of the same module X-Git-Tag: v0.6.4~98^2~2 X-Git-Url: http://nitlanguage.org modelbuilder: avoid multiple load of the same module Signed-off-by: Alexandre Terrasa --- diff --git a/Makefile b/Makefile index 53f4cba..ac55776 100644 --- 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 "
  • Nitlanguage.org
  • " \ --custom-overview-text "

    Documentation for the standard library of Nit
    Version $$(git describe)
    Date: $$(git show --format="%cd" | head -1)

    " \ diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index 25a98ef..3390811 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -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)