changeset 686:e8c09d13f2a5

Added class Deferred to SemanticPass1.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Tue, 22 Jan 2008 13:56:21 +0100
parents c5fd3b7bfcab
children f14cd41fc87d
files trunk/src/dil/ast/Expressions.d trunk/src/dil/semantic/Pass1.d
diffstat 2 files changed, 59 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/ast/Expressions.d	Mon Jan 21 19:07:23 2008 +0100
+++ b/trunk/src/dil/ast/Expressions.d	Tue Jan 22 13:56:21 2008 +0100
@@ -118,6 +118,7 @@
   }
 }
 
+/// Expression "!"? "is" Expression
 class IdentityExpression : CmpExpression
 {
   this(Expression left, Expression right, Token* tok)
--- a/trunk/src/dil/semantic/Pass1.d	Mon Jan 21 19:07:23 2008 +0100
+++ b/trunk/src/dil/semantic/Pass1.d	Tue Jan 22 13:56:21 2008 +0100
@@ -25,6 +25,12 @@
 import dil.CompilerInfo;
 import common;
 
+/++
+  The fist pass is the declaration pass.
+  The basic task of this class is to traverse the parse tree,
+  find all kinds of declarations and add them
+  to the symbol tables of their respective scopes.
++/
 class SemanticPass1 : Visitor
 {
   Scope scop; /// The current scope.
@@ -36,6 +42,11 @@
   StorageClass storageClass;
   uint alignSize = DEFAULT_ALIGN_SIZE;
 
+  /++
+    Construct a SemanticPass1 object.
+    Params:
+      modul = the module to be processed.
+  +/
   this(Module modul)
   {
     this.modul = modul;
@@ -102,11 +113,42 @@
 
   void error(Token* token, char[] formatMsg, ...)
   {
+    if (!modul.infoMan)
+      return;
     auto location = token.getErrorLocation();
     auto msg = Format(_arguments, _argptr, formatMsg);
     modul.infoMan ~= new SemanticError(location, msg);
   }
 
+
+  static class Deferred
+  {
+    Node node;
+    ScopeSymbol symbol;
+    // Saved attributes.
+    LinkageType linkageType;
+    Protection protection;
+    StorageClass storageClass;
+    uint alignSize;
+  }
+
+  // List of mixin and static if declarations.
+  // Their analysis must be deferred because they entail
+  // evaluation of expressions.
+  Deferred[] deferred;
+
+  void addDeferred(Node node, ScopeSymbol symbol)
+  {
+    auto d = new Deferred;
+    d.node = node;
+    d.symbol = symbol;
+    d.linkageType = linkageType;
+    d.protection = protection;
+    d.storageClass = storageClass;
+    d.alignSize = alignSize;
+    deferred ~= d;
+  }
+
   private alias Declaration D;
 
 override
@@ -116,7 +158,7 @@
     foreach (node; d.children)
     {
       assert(node.category == NodeCategory.Declaration, Format("{}", node));
-      visitD(cast(Declaration)cast(void*)node);
+      visitN(node);
     }
     return d;
   }
@@ -129,38 +171,19 @@
 
   D visit(ModuleDeclaration)
   { return null; }
-  D visit(ImportDeclaration)
-  { return null; }
+
+  D visit(ImportDeclaration d)
+  {
+    return d;
+  }
 
   D visit(AliasDeclaration ad)
   {
-    /+
-    decl.semantic(scop); // call semantic() or do SA in if statements?
-    if (auto fd = TryCast!(FunctionDeclaration)(decl))
-    {
-      // TODO: do SA here?
-    }
-    else if (auto vd = TryCast!(VariableDeclaration)(decl))
-    {
-      // TODO: do SA here?
-    }
-    +/
     return ad;
   }
 
   D visit(TypedefDeclaration td)
   {
-    /+
-    decl.semantic(scop); // call semantic() or do SA in if statements?
-    if (auto fd = TryCast!(FunctionDeclaration)(decl))
-    {
-      // TODO: do SA here?
-    }
-    else if (auto vd = TryCast!(VariableDeclaration)(decl))
-    {
-      // TODO: do SA here?
-    }
-    +/
     return td;
   }
 
@@ -299,14 +322,18 @@
 
   D visit(StaticIfDeclaration d)
   {
-    visitE(d.condition);
-    visitD(d.ifDecls);
-    d.elseDecls && visitD(d.elseDecls);
-    return null;
+    addDeferred(d, scop.symbol);
+    return d;
   }
 
-  D visit(StaticAssertDeclaration d)
-  { return d; } // SP2
+  D visit(MixinDeclaration d)
+  {
+    addDeferred(d, scop.symbol);
+    return d;
+  }
+
+  D visit(StaticAssertDeclaration)
+  { return null; }
 
   D visit(TemplateDeclaration d)
   {
@@ -376,14 +403,5 @@
     visitS(s.pragmaBody);
     return s;
   }
-
-  D visit(MixinDeclaration md)
-  {
-    // Add md to vector of (Scope, MixinDeclaration)
-    // and evaluate them in 2nd pass?
-    // TODO: store all attributes in md; they have to be applied
-    // to the content that is mixed in.
-    return md;
-  }
 } // override
 }