X-Git-Url: http://nitlanguage.org diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index 9492734..eac98df 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -22,11 +22,7 @@ # FIXME add missing error checks module modelbuilder -import parser import model -import poset -import opts -import toolcontext import phase private import more_collections @@ -64,7 +60,8 @@ redef class ToolContext mainmodule = mmodules.first else # We need a main module, so we build it by importing all modules - mainmodule = new MModule(modelbuilder.model, null, "
", new Location(null, 0, 0, 0, 0)) + mainmodule = new MModule(modelbuilder.model, null, mmodules.first.name, new Location(mmodules.first.location.file, 0, 0, 0, 0)) + mainmodule.is_fictive = true mainmodule.set_imported_mmodules(mmodules) end for phase in phases_list do @@ -79,7 +76,7 @@ redef class Phase # Called by the `ToolContext::run_global_phases`. # # `mainmodule` is the main module of the program. - # It could be an implicit module (called "
"). + # It could be an implicit module (called like the first given_mmodules). # # `given_modules` is the list of explicitely requested modules. # from the command-line for instance. @@ -134,14 +131,11 @@ class ModelBuilder paths.append(path_env.split_with(':')) end - path_env = "NIT_DIR".environ - if not path_env.is_empty then - var libname = "{path_env}/lib" + var nit_dir = toolcontext.nit_dir + if nit_dir != null then + var libname = "{nit_dir}/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. @@ -292,7 +286,7 @@ class ModelBuilder # The list is initially set with : # * the toolcontext --path option # * the NIT_PATH environment variable - # * some heuristics including the NIT_DIR environment variable and the progname of the process + # * `toolcontext.nit_dir` # Path can be added (or removed) by the client var paths: Array[String] = new Array[String] @@ -471,11 +465,22 @@ class ModelBuilder return mgroups[rdp] end - # Hack, a dir is determined by the presence of a honomymous nit file + # Hack, a group is determined by: + # * the presence of a honomymous nit file + # * the fact that the directory is named `src` var pn = rdp.basename(".nit") var mp = dirpath.join_path(pn + ".nit").simplify_path - if not mp.file_exists then return null + var dirpath2 = dirpath + if not mp.file_exists then + if pn == "src" then + # With a src directory, the group name is the name of the parent directory + dirpath2 = rdp.dirname + pn = dirpath2.basename("") + else + return null + end + end # check parent directory var parentpath = dirpath.join_path("..").simplify_path @@ -492,6 +497,17 @@ class ModelBuilder mgroup = new MGroup(pn, parent.mproject, parent) toolcontext.info("found sub group `{mgroup.full_name}` at {dirpath}", 2) end + var readme = dirpath2.join_path("README.md") + if not readme.file_exists then readme = dirpath2.join_path("README") + if readme.file_exists then + var mdoc = new MDoc + var s = new IFStream.open(readme) + while not s.eof do + mdoc.content.add(s.read_line) + end + mgroup.mdoc = mdoc + mdoc.original_mentity = mgroup + end mgroup.filepath = dirpath mgroups[rdp] = mgroup return mgroup @@ -610,7 +626,11 @@ class ModelBuilder if decl != null then var ndoc = decl.n_doc - if ndoc != null then mmodule.mdoc = ndoc.to_mdoc + if ndoc != null then + var mdoc = ndoc.to_mdoc + mmodule.mdoc = mdoc + mdoc.original_mentity = mmodule + end end return mmodule @@ -665,6 +685,18 @@ class ModelBuilder end self.toolcontext.info("{mmodule} imports {imported_modules.join(", ")}", 3) mmodule.set_imported_mmodules(imported_modules) + + # TODO: Correctly check for useless importation + # It is even doable? + var directs = mmodule.in_importation.direct_greaters + for nim in nmodule.n_imports do + if not nim isa AStdImport then continue + var im = nim.mmodule + if im == null then continue + if directs.has(im) then continue + # This generates so much noise that it is simpler to just comment it + #warning(nim, "Warning: possible useless importation of {im}") + end end # All the loaded modules