changeset 133:9c48871eb816

Now working with forward ref and structs in scope builder. New Symbol system should now be good to go!
author Anders Johnsen <skabet@gmail.com>
date Mon, 30 Jun 2008 16:43:40 +0200
parents a101853eaae0
children 570a4917413a
files sema/ScopeBuilder.d
diffstat 1 files changed, 34 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sema/ScopeBuilder.d	Mon Jun 30 16:23:52 2008 +0200
+++ b/sema/ScopeBuilder.d	Mon Jun 30 16:43:40 2008 +0200
@@ -14,6 +14,7 @@
 {
     override void visit(Module[] modules)
     {
+        (new TypeBuilder).visit(modules);
         this.modules = modules;
         inFunctionBodyStack.push(false);
         foreach (mod; modules)
@@ -56,16 +57,44 @@
 
     override void visitStructDecl(StructDecl s)
     {
-        auto st = s.env.findType(s.identifier).asStruct;
-        s.sym = current.symbol.createMember(s.identifier.get, st);
-        //s.env.set(s.identifier, s);
-
         auto old = current.symbol;
         current.symbol = s.sym;
         inFunctionBodyStack.push(false);
         super.visitStructDecl(s);
         inFunctionBodyStack.pop();
         current.symbol = old;
+    }
+
+    DType typeOf(Identifier id, Scope sc)
+    {
+        if(auto i = cast(PointerIdentifier)id)
+            return (typeOf(i.pointerOf, sc)).getPointerTo();
+        else if(auto i = cast(ArrayIdentifier)id)
+            return typeOf(i.arrayOf, sc).getAsArray(i.size);
+        return sc.findType(id);
+    }
+
+    Module[] modules;
+    Module current;
+    SmallArray!(bool) inFunctionBodyStack;
+}
+
+class TypeBuilder : Visitor!(void)
+{
+    override void visit(Module[] modules)
+    {
+        foreach (mod; modules)
+        {
+            current = mod;
+            foreach (decl; mod.decls)
+                visitDecl(decl);
+        }
+    }
+
+    override void visitStructDecl(StructDecl s)
+    {
+        auto st = s.env.findType(s.identifier).asStruct;
+        s.sym = current.symbol.createMember(s.identifier.get, st);
 
         foreach (decl; s.decls)
         {
@@ -94,11 +123,10 @@
         return sc.findType(id);
     }
 
-    Module[] modules;
     Module current;
-    SmallArray!(bool) inFunctionBodyStack;
 }
 
+
 /**
   Add scopes to everything, and add all identifiers that correspond to types.
   Types/Symbols are added by ForwardReference.