diff src/cmd/Compile.d @ 810:525ee3f848d9

Added modules cmd.Compile and dil.ModuleManager. Added options -I, -release and -unittest to the compile command. Tidied main.d up a bit. Renamed start() methods of SemanticPass1 and 2 to run(). Moved function findModuleFilePath() to class ModuleManager. Added msg CouldntLoadModule. Corrected two others. Added member semanticPass to class Module. Implemented visit(ImportDeclaration) in SemanticPass1.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 11 Mar 2008 02:48:01 +0100
parents
children 35d238d502cb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cmd/Compile.d	Tue Mar 11 02:48:01 2008 +0100
@@ -0,0 +1,80 @@
+/++
+  Author: Aziz Köksal
+  License: GPL3
++/
+module cmd.Compile;
+
+import dil.semantic.Module;
+import dil.semantic.Pass1;
+import dil.semantic.Pass2;
+import dil.semantic.Symbols;
+import dil.doc.Doc;
+import dil.Compilation;
+import dil.Information;
+import dil.ModuleManager;
+import common;
+
+/// The compile command.
+struct CompileCommand
+{
+  string[] filePaths; /// Explicitly specified modules (on the command line.)
+  ModuleManager moduleMan;
+  SemanticPass1[] passes1;
+
+  CompilationContext context;
+  InfoManager infoMan;
+
+  /// Executes the compile command.
+  void run()
+  {
+    moduleMan = new ModuleManager(context.importPaths, infoMan);
+    foreach (filePath; filePaths)
+    {
+      auto modul = moduleMan.loadModuleFile(filePath);
+      runPass1(modul);
+      printSymbolTable(modul, "");
+    }
+
+    // foreach (modul; moduleMan.loadedModules)
+    // {
+    //   auto pass2 = new SemanticPass2(modul);
+    //   pass2.run();
+    // }
+  }
+
+  /// Runs the first pass on modul.
+  void runPass1(Module modul)
+  {
+    if (modul.hasErrors || modul.semanticPass != 0)
+      return;
+    auto pass1 = new SemanticPass1(modul, context);
+    pass1.importModule = &importModule;
+    pass1.run();
+    passes1 ~= pass1;
+  }
+
+  /// Imports a module and runs the first pass on it.
+  Module importModule(string moduleFQNPath)
+  {
+    auto modul = moduleMan.loadModule(moduleFQNPath);
+    modul && runPass1(modul);
+    return modul;
+  }
+
+  /// Prints all symbols recursively (for debugging.)
+  static void printSymbolTable(ScopeSymbol scopeSym, char[] indent)
+  {
+    foreach (member; scopeSym.members)
+    {
+      auto tokens = getDocTokens(member.node);
+      char[] docText;
+      foreach (token; tokens)
+        docText ~= token.srcText;
+      Stdout(indent).formatln("Id:{}, Symbol:{}, DocText:{}",
+                              member.name.str, member.classinfo.name,
+                              docText);
+      if (auto s = cast(ScopeSymbol)member)
+        printSymbolTable(s, indent ~ "→ ");
+    }
+  }
+}