changeset 736:2eee29aaa357

Fixed couple of regressions. Autoincludes for convenience.
author Jari-Matti M?kel? <jmjm@iki.fi>
date Mon, 04 Feb 2008 21:55:44 +0200
parents 30e6f1b302a1
children f88b5285b86b
files trunk/src/docgen/config/default.cfg trunk/src/docgen/docgen.d trunk/src/docgen/misc/parser.d
diffstat 3 files changed, 55 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/docgen/config/default.cfg	Sun Feb 03 22:15:51 2008 +0200
+++ b/trunk/src/docgen/config/default.cfg	Mon Feb 04 21:55:44 2008 +0200
@@ -19,7 +19,7 @@
     (cyclicDepColor red)
     (publicDepColor blue)
     (clusterColor blue)
-    (includeUnlocatableModules false)
+    (includeUnlocatableModules true)
     (highlightCyclicEdges true)
     (highlightCyclicVertices true)
     (groupByPackageNames true)
--- a/trunk/src/docgen/docgen.d	Sun Feb 03 22:15:51 2008 +0200
+++ b/trunk/src/docgen/docgen.d	Mon Feb 04 21:55:44 2008 +0200
@@ -11,8 +11,11 @@
 import docgen.document.xmlgenerator;
 import docgen.document.plaintextgenerator;
 
+//import dil.Settings;
+import dil.SettingsLoader;
+
 import tango.core.Array;
-import tango.text.Ascii;
+import tango.text.Text;
 import tango.io.Stdout;
 
 void usage() {
@@ -22,6 +25,8 @@
 }
 
 void main(char[][] args) {
+  dil.SettingsLoader.loadSettings();
+
   Stdout(docgen_version).newline.newline;
 
   if (args.length<3) {
@@ -84,9 +89,9 @@
       modules
     );
 
-//    modules.sort(
-//      (Module a, Module b){ return icompare(a.moduleFQN, b.moduleFQN); }
-//    );
+    modules.sort(
+      (Module a, Module b) { return ((new Text!(char)(a.moduleFQN)).compare(b.moduleFQN)) < 0; }
+    );
 
     depGraph.edges = edges;
     depGraph.vertices = vertices.values;
--- a/trunk/src/docgen/misc/parser.d	Sun Feb 03 22:15:51 2008 +0200
+++ b/trunk/src/docgen/misc/parser.d	Mon Feb 04 21:55:44 2008 +0200
@@ -11,14 +11,20 @@
 public import dil.semantic.Module;
 import tango.text.Regex : RegExp = Regex;
 import tango.io.FilePath;
+import tango.io.FileSystem;
+import tango.core.Array : remove;
 import tango.text.Util;
+import docgen.misc.meta;
 debug import tango.io.Stdout;
 
 alias void delegate (char[] fqn, char[] path, Module module_) modDg;
 alias void delegate (Module imported, Module importer, bool isPublic, bool isStatic) importDg;
 
 class Parser {
-  private:
+  protected:
+
+//  ParserOptions m_options;
+
     
   static char[] findModuleFilePath(char[] moduleFQNPath, char[][] importPaths) {
     auto filePath = new FilePath();
@@ -29,6 +35,7 @@
       foreach (moduleSuffix; [".d", ".di"/*interface file*/])
       {
         filePath.suffix(moduleSuffix);
+        debug Stdout("Trying ")(filePath.toString()).newline;
         if (filePath.exists())
           return filePath.toString();
       }
@@ -91,6 +98,8 @@
     foreach (strRegexp; strRegexps)
       regexps ~= new RegExp(strRegexp);
 
+    importPaths ~= ".";
+
     // Add directory of file and global directories to import paths.
     foreach(filePath; filePaths) {
       auto fileDir = (new FilePath(filePath)).folder();
@@ -98,7 +107,7 @@
         importPaths ~= fileDir;
     }
 
-    importPaths ~= GlobalSettings.importPaths;
+//    importPaths ~= GlobalSettings.importPaths;
 
     debug foreach(path; importPaths) {
       Stdout("Import path: ")(path).newline;
@@ -125,8 +134,6 @@
         if (rx.test(FQN)) return null;
 
       auto moduleFilePath = findModuleFilePath(moduleFQNPath, importPaths);
-      //foreach(filePath; filePaths)
-        //if (moduleFQNPath == filePath) modulePath = filePath;
 
       debug Stdout("  FQN ")(FQN).newline;
       debug Stdout("  Module path ")(moduleFilePath).newline;
@@ -140,9 +147,38 @@
         mod = new Module(moduleFilePath);
         
         // Use lightweight ImportParser.
-        mod.parser = new ImportParser(loadFile(moduleFilePath), moduleFilePath);
+//        mod.parser = new ImportParser(loadFile(moduleFilePath), moduleFilePath);
         mod.parse();
 
+        debug Stdout("  Parsed FQN ")(mod.getFQN()).newline;
+
+        // autoinclude dirs (similar to Java)
+        // running docgen in foo/bar/abc/ also finds foo/xyz/zzz.d if module names are right
+        {
+          // foo.bar.mod -> [ "foo", "bar" ]
+          auto modPackage = split(mod.getFQN, ".")[0..$-1];
+          auto modDir = split(FileSystem.toAbsolute(new FilePath(moduleFilePath)).standard().folder(), "/");
+          auto modLocation = modDir[0..modDir.remove(".")];
+
+          bool matches = false;
+          int i;
+
+          for(i = 1; i <= min(modPackage.length, modLocation.length); i++) {
+            matches = true;
+            debug Stdout("  Decl: ")(modPackage[$-i]).newline;
+            debug Stdout("  Path: ")(modLocation[$-i]).newline;
+            if (modPackage[$-i] != modLocation[$-i]) {
+              matches = false;
+              break;
+            }
+          }
+          if (matches) {
+            auto loc = modLocation[0..$-i+1].join("/");
+            debug Stdout("  Autoadding import: ")(loc).newline;
+            importPaths ~= loc;
+          }
+        }
+
         mdg(FQN, moduleFQNPath, mod);
         loadedModules[moduleFQNPath] = mod;
 
@@ -152,10 +188,10 @@
 
             if (loaded_mod !is null) {
               idg(loaded_mod, mod, importDecl.isPublic(), importDecl.isStatic());
-            } else if (IncludeUnlocatableModules) {/* FIXME
-              auto tmp = new Module(null, true);
-              tmp.moduleFQN = replace(moduleFQN_.dup, dirSep, '.');
-              idg(tmp, mod, importList.isPublic());*/
+            } else if (IncludeUnlocatableModules) {
+              auto tmp = new Module(null);
+              tmp.setFQN(replace(moduleFQN_.dup, dirSep, '.'));
+              idg(tmp, mod, importDecl.isPublic(), importDecl.isStatic());
             }
           }
       }