X-Git-Url: http://nitlanguage.org diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index 38db14a..b442704 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -25,7 +25,7 @@ private import more_collections redef class ToolContext # Option --ignore-visibility - var opt_ignore_visibility = new OptionBool("Do not check, and produce errors, on visibility issues.", "--ignore-visibility") + var opt_ignore_visibility = new OptionBool("Do not check, and produce errors, on visibility issues", "--ignore-visibility") redef init do @@ -38,13 +38,18 @@ redef class ToolContext do assert not mmodules.is_empty var mainmodule - if mmodules.length == 1 then + # We need a main module, so we build it by importing all modules + mainmodule = new MModule(modelbuilder.model, null, mmodules.first.name + "-m", new Location(mmodules.first.location.file, 0, 0, 0, 0)) + mainmodule.is_fictive = true + mainmodule.first_real_mmodule = mmodules.first.first_real_mmodule + mainmodule.set_imported_mmodules(mmodules) + modelbuilder.apply_conditional_importations(mainmodule) + if mainmodule.in_importation.direct_greaters.length == 1 and mainmodule.in_importation.direct_greaters.first == mmodules.first then + # Drop the fictive module if not needed mainmodule = mmodules.first else - # We need a main module, so we build it by importing all modules - mainmodule = new MModule(modelbuilder.model, null, mmodules.first.name + "-m", new Location(mmodules.first.location.file, 0, 0, 0, 0)) - mainmodule.is_fictive = true - mainmodule.set_imported_mmodules(mmodules) + # Or else run phases on it + modelbuilder.run_phases end return mainmodule end @@ -59,6 +64,9 @@ redef class ToolContext phase.process_mainmodule(mainmodule, mmodules) end end + + check_errors + errors_info end end @@ -84,18 +92,37 @@ redef class ModelBuilder # Run phases on all loaded modules fun run_phases do - var mmodules = model.mmodules.to_a + var mmodules = parsed_modules.to_a model.mmodule_importation_hierarchy.sort(mmodules) var nmodules = new Array[AModule] for mm in mmodules do + if mm.is_fictive then continue nmodules.add(mmodule2node(mm).as(not null)) end toolcontext.run_phases(nmodules) if toolcontext.opt_only_metamodel.value then self.toolcontext.info("*** ONLY METAMODEL", 1) - exit(0) + toolcontext.quit end end + # Load module `filename` and add it as a conditional importation of `mmodule`. + # + # This means that current (and future) submodules of `module` will also import `filename`. + fun inject_module_subimportation(mmodule: MModule, filename: String) + do + var am = load_module(filename) + if am == null then return # forward error + var mm = am.mmodule + if mm == null then return # forward error + # Add the new module before the existing submodules in the hierarchy + for subm in mmodule.in_importation.direct_smallers do + subm.set_imported_mmodules([mm]) + end + # Register the new module as a conditional_importations for future submodules + conditional_importations.add([mm, mmodule]) + # Register the new amodule to be processed by `run_phases` + toolcontext.todo_nmodules.unshift am + end end