src: cleanup importations
[nit.git] / src / modelbuilder.nit
index 85f9443..eac98df 100644 (file)
 # 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, mmodules.first.name, 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
@@ -474,10 +471,12 @@ class ModelBuilder
                var pn = rdp.basename(".nit")
                var mp = dirpath.join_path(pn + ".nit").simplify_path
 
+               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
-                               pn = rdp.dirname.basename("")
+                               dirpath2 = rdp.dirname
+                               pn = dirpath2.basename("")
                        else
                                return null
                        end
@@ -498,7 +497,8 @@ class ModelBuilder
                        mgroup = new MGroup(pn, parent.mproject, parent)
                        toolcontext.info("found sub group `{mgroup.full_name}` at {dirpath}", 2)
                end
-               var readme = dirpath.join_path("README")
+               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)
@@ -685,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