- var mmodules = model.mmodules.to_a
- model.mmodule_importation_hierarchy.sort(mmodules)
- var nmodules = new Array[AModule]
- for mm in mmodules do
- nmodules.add(mmodule2nmodule[mm])
- end
- toolcontext.run_phases(nmodules)
- end
-
- # Instantiate a modelbuilder for a model and a toolcontext
- # Important, the options of the toolcontext must be correctly set (parse_option already called)
- init(model: Model, toolcontext: ToolContext)
- do
- self.model = model
- self.toolcontext = toolcontext
- assert toolcontext.modelbuilder_real == null
- toolcontext.modelbuilder_real = self
-
- # Setup the paths value
- paths.append(toolcontext.opt_path.value)
-
- var path_env = "NIT_PATH".environ
- if not path_env.is_empty then
- paths.append(path_env.split_with(':'))
- end
-
- path_env = "NIT_DIR".environ
- if not path_env.is_empty then
- var libname = "{path_env}/lib"
- if libname.file_exists then paths.add(libname)
- end
-
- var libname = "{sys.program_name.dirname}/../lib"
- if libname.file_exists then paths.add(libname.simplify_path)
- end
-
- # Load a bunch of modules.
- # `modules' can contains filenames or module names.
- # Imported modules are automatically loaded and modelized.
- # The result is the corresponding model elements.
- # Errors and warnings are printed with the toolcontext.
- #
- # Note: class and property model element are not analysed.
- fun parse(modules: Sequence[String]): Array[MModule]
- do
- var time0 = get_time
- # Parse and recursively load
- self.toolcontext.info("*** PARSE ***", 1)
- var mmodules = new Array[MModule]
- for a in modules do
- var nmodule = self.load_module(null, a)
- if nmodule == null then continue # Skip error
- mmodules.add(nmodule.mmodule.as(not null))
- end
- var time1 = get_time
- self.toolcontext.info("*** END PARSE: {time1-time0} ***", 2)
-
- self.toolcontext.check_errors
- return mmodules
- end
-
- # Return a class named `name' visible by the module `mmodule'.
- # Visibility in modules is correctly handled.
- # If no such a class exists, then null is returned.
- # If more than one class exists, then an error on `anode' is displayed and null is returned.
- # FIXME: add a way to handle class name conflict
- fun try_get_mclass_by_name(anode: ANode, mmodule: MModule, name: String): nullable MClass
- do
- var classes = model.get_mclasses_by_name(name)
- if classes == null then
- return null
- end
-
- var res: nullable MClass = null
- for mclass in classes do
- if not mmodule.in_importation <= mclass.intro_mmodule then continue
- if not mmodule.is_visible(mclass.intro_mmodule, mclass.visibility) then continue
- if res == null then
- res = mclass
- else
- error(anode, "Ambigous class name '{name}'; conflict between {mclass.full_name} and {res.full_name}")
- return null
- end
+ assert not mmodules.is_empty
+ var mainmodule
+ # 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
+ # Or else run phases on it
+ modelbuilder.run_phases