changeset 649:3ebe76ad680e

Using SemanticPass1 in main.d do start semantic analysis. visit() methods in class Visitor are not abstract anymore, because it's a pain having to override all abstract methods in subclasses. Removed semantic() method from Module. Implemented SemanticPass1.start().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 15 Jan 2008 11:11:03 +0100
parents 4ae7b13aaac8
children eb490ba8dba0
files trunk/src/dil/ast/Visitor.d trunk/src/dil/semantic/Module.d trunk/src/dil/semantic/Pass1.d trunk/src/main.d
diffstat 4 files changed, 29 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/ast/Visitor.d	Mon Jan 14 22:34:09 2008 +0100
+++ b/trunk/src/dil/ast/Visitor.d	Tue Jan 15 11:11:03 2008 +0100
@@ -13,18 +13,16 @@
        dil.ast.Parameters;
 
 /++
-  Generate abstract visit methods.
+  Generate visit methods.
   E.g.:
-    Declaration visit(ClassDeclaration);
-    Expression visit(CommaExpression);
+    Declaration visit(ClassDeclaration){return null;};
+    Expression visit(CommaExpression){return null;};
 +/
-char[] generateAbstractVisitMethods()
+char[] generateVisitMethods()
 {
   char[] text;
   foreach (className; classNames)
-  {
-    text ~= "returnType!(\""~className~"\") visit("~className~");\n";
-  }
+    text ~= "returnType!(\""~className~"\") visit("~className~"){return null;}\n";
   return text;
 }
 // pragma(msg, generateAbstractVisitMethods());
@@ -84,8 +82,7 @@
 
 abstract class Visitor
 {
-  abstract
-    mixin(generateAbstractVisitMethods());
+  mixin(generateVisitMethods());
 
   static
     mixin(generateDispatchFunctions());
--- a/trunk/src/dil/semantic/Module.d	Mon Jan 14 22:34:09 2008 +0100
+++ b/trunk/src/dil/semantic/Module.d	Tue Jan 15 11:11:03 2008 +0100
@@ -85,18 +85,6 @@
     }
   }
 
-  /// Starts the semantic analysis of this module.
-  void semantic()
-  {
-    if (this.hasErrors)
-      return;
-    // Create module scope.
-    auto scop = new Scope();
-    scop.symbol = this; // Set this module as the scope's symbol.
-    scop.infoMan = this.infoMan;
-//     this.root.semantic(scop);
-  }
-
   /// Returns true if there are errors in the source file.
   bool hasErrors()
   {
--- a/trunk/src/dil/semantic/Pass1.d	Mon Jan 14 22:34:09 2008 +0100
+++ b/trunk/src/dil/semantic/Pass1.d	Tue Jan 15 11:11:03 2008 +0100
@@ -25,8 +25,8 @@
 
 class SemanticPass1 : Visitor
 {
-  Scope scop;
-  Module modul;
+  Scope scop; /// The current scope.
+  Module modul; /// The module to be semantically checked.
 
   this(Module modul)
   {
@@ -37,6 +37,10 @@
   void start()
   {
     assert(modul.root !is null);
+    // Create module scope.
+    scop = new Scope();
+    scop.symbol = modul; // Set this module as the scope's symbol.
+    scop.infoMan = modul.infoMan;
     visitN(modul.root);
   }
 
@@ -80,8 +84,8 @@
   Declaration visit(ImportDeclaration)
   { return null; }
 
-//   Declaration visit(AliasDeclaration ad)
-//   {
+  Declaration visit(AliasDeclaration ad)
+  {
     /+
     decl.semantic(scop); // call semantic() or do SA in if statements?
     if (auto fd = TryCast!(FunctionDeclaration)(decl))
@@ -93,8 +97,8 @@
       // TODO: do SA here?
     }
     +/
-//     return ad;
-//   }
+    return ad;
+  }
 
   Declaration visit(TypedefDeclaration td)
   {
@@ -271,16 +275,15 @@
   { return null; }
   Declaration visit(DeleteDeclaration)
   { return null; }
-  Declaration visit(AttributeDeclaration)
-  { return null; }
-  Declaration visit(ProtectionDeclaration)
-  { return null; }
-  Declaration visit(StorageClassDeclaration)
-  { return null; }
-  Declaration visit(LinkageDeclaration)
-  { return null; }
-  Declaration visit(AlignDeclaration)
-  { return null; }
+
+  Declaration visit(ProtectionDeclaration d)
+  { visitD(d.decls); return d; }
+  Declaration visit(StorageClassDeclaration d)
+  { visitD(d.decls); return d; }
+  Declaration visit(LinkageDeclaration d)
+  { visitD(d.decls); return d; }
+  Declaration visit(AlignDeclaration d)
+  { visitD(d.decls); return d; }
 
   Declaration visit(PragmaDeclaration d)
   {
--- a/trunk/src/main.d	Mon Jan 14 22:34:09 2008 +0100
+++ b/trunk/src/main.d	Tue Jan 15 11:11:03 2008 +0100
@@ -53,8 +53,11 @@
       auto mod = new Module(filePath, infoMan);
       // Parse the file.
       mod.parse();
+      if (mod.hasErrors)
+        continue;
       // Start semantic analysis.
-      mod.semantic();
+      auto pass1 = new SemanticPass1(mod);
+      pass1.start();
 
       void printSymbolTable(ScopeSymbol scopeSym)
       {