diff src/dil/semantic/Pass1.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 bcb74c9b895c
children 1d06b4aed7cf
line wrap: on
line diff
--- a/src/dil/semantic/Pass1.d	Sun Mar 09 16:39:46 2008 +0100
+++ b/src/dil/semantic/Pass1.d	Tue Mar 11 02:48:01 2008 +0100
@@ -26,6 +26,9 @@
 import dil.CompilerInfo;
 import common;
 
+import tango.io.FileConst;
+alias FileConst.PathSeparatorChar dirSep;
+
 /// The first pass is the declaration pass.
 ///
 /// The basic task of this class is to traverse the parse tree,
@@ -36,6 +39,7 @@
   Scope scop; /// The current scope.
   Module modul; /// The module to be semantically checked.
   CompilationContext context; /// The compilation context.
+  Module delegate(string) importModule; /// Called when importing a module.
 
   // Attributes:
   LinkageType linkageType; /// Current linkage type.
@@ -55,11 +59,12 @@
   }
 
   /// Starts processing the module.
-  void start()
+  void run()
   {
     assert(modul.root !is null);
     // Create module scope.
     scop = new Scope(null, modul);
+    modul.semanticPass = 1;
     visit(modul.root);
   }
 
@@ -187,14 +192,23 @@
   D visit(IllegalDeclaration)
   { assert(0, "semantic pass on invalid AST"); return null; }
 
-  D visit(EmptyDeclaration ed)
-  { return ed; }
+  // D visit(EmptyDeclaration ed)
+  // { return ed; }
 
-  D visit(ModuleDeclaration)
-  { return null; }
+  // D visit(ModuleDeclaration)
+  // { return null; }
 
   D visit(ImportDeclaration d)
   {
+    if (importModule is null)
+      return d;
+    foreach (moduleFQNPath; d.getModuleFQNs(dirSep))
+    {
+      auto importedModule = importModule(moduleFQNPath);
+      if (importedModule is null)
+        error(d.begin, MSG.CouldntLoadModule, moduleFQNPath ~ ".d");
+      modul.modules ~= importedModule;
+    }
     return d;
   }