changeset 366:dcbd3bf9bf74

- Added command importgraph/igraph to main.d. - Added includePaths parameter to ImportGraph.execute(). - Added method getModuleFQNs() to ImportDeclaration. - Fix: added member isStatic to ImportDeclaration. - Added method getImports() to class Module.
author aziz
date Fri, 31 Aug 2007 12:14:03 +0000
parents ed67acc82268
children dda55fae37de
files trunk/src/cmd/ImportGraph.d trunk/src/dil/Declarations.d trunk/src/dil/Module.d trunk/src/dil/Parser.d trunk/src/main.d
diffstat 5 files changed, 46 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/cmd/ImportGraph.d	Fri Aug 31 11:07:05 2007 +0000
+++ b/trunk/src/cmd/ImportGraph.d	Fri Aug 31 12:14:03 2007 +0000
@@ -9,8 +9,9 @@
 import dil.Parser, dil.Lexer;
 import dil.File;
 import dil.Module;
+import std.stdio : writefln;
 
-void execute(string fileName)
+void execute(string fileName, string[] includePaths)
 {
   auto mod = new Module(fileName);
   mod.parse();
--- a/trunk/src/dil/Declarations.d	Fri Aug 31 11:07:05 2007 +0000
+++ b/trunk/src/dil/Declarations.d	Fri Aug 31 12:14:03 2007 +0000
@@ -87,7 +87,7 @@
     foreach (pckg; packages)
       if (pckg)
         pname ~= pckg.identifier ~ separator;
-    pname = pname[0..$-1];
+    pname = pname[0..$-1]; // Remove last separator
     return pname;
   }
 }
@@ -98,7 +98,8 @@
   Token*[] moduleAliases;
   Token*[] bindNames;
   Token*[] bindAliases;
-  this(ModuleFQN[] moduleFQNs, Token*[] moduleAliases, Token*[] bindNames, Token*[] bindAliases)
+  bool isStatic;
+  this(ModuleFQN[] moduleFQNs, Token*[] moduleAliases, Token*[] bindNames, Token*[] bindAliases, bool isStatic)
   {
     super(false);
     mixin(set_kind);
@@ -106,6 +107,21 @@
     this.moduleAliases = moduleAliases;
     this.bindNames = bindNames;
     this.bindAliases = bindAliases;
+    this.isStatic = isStatic;
+  }
+
+  string[] getModuleFQNs(char separator)
+  {
+    string[] FQNs;
+    foreach (moduleFQN; moduleFQNs)
+    {
+      char[] FQN;
+      foreach (ident; moduleFQN)
+        if (ident)
+          FQN ~= ident.identifier ~ separator;
+      FQNs ~= FQN[0..$-1]; // Remove last separator
+    }
+    return FQNs;
   }
 }
 
--- a/trunk/src/dil/Module.d	Fri Aug 31 11:07:05 2007 +0000
+++ b/trunk/src/dil/Module.d	Fri Aug 31 12:14:03 2007 +0000
@@ -40,7 +40,7 @@
       if (moduleDecl)
       {
         this.moduleName = moduleDecl.getName();
-        this.packageName = moduleDecl.getPackageName('/');
+        this.packageName = moduleDecl.getPackageName(std.path.sep[0]);
       }
       else
       {
@@ -52,4 +52,12 @@
       this.imports = parser.imports;
     }
   }
+
+  string[] getImports()
+  {
+    string[] result;
+    foreach (import_; imports)
+      result ~= import_.getModuleFQNs(std.path.sep[0]);
+    return result;
+  }
 }
--- a/trunk/src/dil/Parser.d	Fri Aug 31 11:07:05 2007 +0000
+++ b/trunk/src/dil/Parser.d	Fri Aug 31 12:14:03 2007 +0000
@@ -857,7 +857,7 @@
 
     require(T.Semicolon);
 
-    return new ImportDeclaration(moduleFQNs, moduleAliases, bindNames, bindAliases);
+    return new ImportDeclaration(moduleFQNs, moduleAliases, bindNames, bindAliases, isStatic);
   }
 
   Declaration parseEnumDeclaration()
--- a/trunk/src/main.d	Fri Aug 31 11:07:05 2007 +0000
+++ b/trunk/src/main.d	Fri Aug 31 12:14:03 2007 +0000
@@ -46,6 +46,21 @@
       options |= DocOption.XML; // Default to XML.
     cmd.Generate.execute(fileName, options);
     break;
+  case "importgraph", "igraph":
+    string fileName;
+    string[] includePaths;
+    foreach (arg; args[2..$])
+    {
+      if (arg.length >= 2 && arg[0..2] == "-I")
+      {
+        if (arg.length >= 3)
+          includePaths ~= args[2..$];
+      }
+      else
+        fileName = arg;
+    }
+    cmd.ImportGraph.execute(fileName, includePaths);
+    break;
   case "stats", "statistics":
     cmd.Statistics.execute(args[2]);
     break;
@@ -66,6 +81,7 @@
 const char[] COMMANDS =
   "  generate (gen)\n"
   "  help (?)\n"
+  "  importgraph (igraph)\n"
   "  statistics (stats)\n";
 
 char[] helpMain()