diff sema/ScopeBuilder.d @ 144:6e6355fb5f0f

- Parsing nested attributes. - Creating classes and interfaces in AST. - Updated AstPrinter to print attributes, classes and interfaces.
author Anders Johnsen <skabet@gmail.com>
date Mon, 21 Jul 2008 17:41:40 +0200
parents 2be29b296081
children a14ac9e5c858
line wrap: on
line diff
--- a/sema/ScopeBuilder.d	Mon Jul 21 01:05:20 2008 +0200
+++ b/sema/ScopeBuilder.d	Mon Jul 21 17:41:40 2008 +0200
@@ -72,6 +72,26 @@
         current.symbol = old;
     }
 
+    override void visitClassDecl(ClassDecl s)
+    {
+        auto old = current.symbol;
+        current.symbol = s.sym;
+        inFunctionBodyStack.push(false);
+        super.visitClassDecl(s);
+        inFunctionBodyStack.pop();
+        current.symbol = old;
+    }
+
+    override void visitInterfaceDecl(InterfaceDecl s)
+    {
+        auto old = current.symbol;
+        current.symbol = s.sym;
+        inFunctionBodyStack.push(false);
+        super.visitInterfaceDecl(s);
+        inFunctionBodyStack.pop();
+        current.symbol = old;
+    }
+
     DType typeOf(Identifier id, Scope sc)
     {
         if(auto i = cast(PointerIdentifier)id)
@@ -124,6 +144,59 @@
         }
     }
 
+    override void visitClassDecl(ClassDecl s)
+    {
+        auto st = s.env.findType(s.identifier).asClass;
+        s.sym = current.symbol.createMember(
+                s.identifier.get, 
+                st,
+                s.env.find(s.identifier));
+
+        foreach (decl; s.decls)
+        {
+            DType type;
+            char[] name;
+            if (auto varDecl = cast(VarDecl)decl)
+            {
+                type = typeOf(varDecl.varType, varDecl.env);
+                name = varDecl.identifier.get;
+            }
+            else if (auto fd = cast(FuncDecl)decl)
+            {
+                type = fd.type;
+                name = fd.identifier.get;
+            }
+            st.addMember(type, name);
+        }
+    }
+
+    override void visitInterfaceDecl(InterfaceDecl s)
+    {
+        auto st = s.env.findType(s.identifier).asInterface;
+        s.sym = current.symbol.createMember(
+                s.identifier.get, 
+                st,
+                s.env.find(s.identifier));
+
+        foreach (decl; s.decls)
+        {
+            DType type;
+            char[] name;
+            if (auto varDecl = cast(VarDecl)decl)
+            {
+                type = typeOf(varDecl.varType, varDecl.env);
+                name = varDecl.identifier.get;
+            }
+            else if (auto fd = cast(FuncDecl)decl)
+            {
+                type = fd.type;
+                name = fd.identifier.get;
+            }
+            st.addMember(type, name);
+        }
+    }
+
+
     DType typeOf(Identifier id, Scope sc)
     {
         if(auto i = cast(PointerIdentifier)id)
@@ -282,11 +355,38 @@
         sc.types[s.identifier.get] = type;
 
         sc = push();
-        Stdout(sc).newline;
         super.visitStructDecl(s);
         pop(sc);
     }
 
+    override void visitClassDecl(ClassDecl s)
+    {
+        auto sc = current();
+        sc.put(s.identifier, s);
+        s.env = sc;
+        auto type = new DClass(s.identifier);
+
+        sc.types[s.identifier.get] = type;
+
+        sc = push();
+        super.visitClassDecl(s);
+        pop(sc);
+    }
+
+    override void visitInterfaceDecl(InterfaceDecl s)
+    {
+        auto sc = current();
+        sc.put(s.identifier, s);
+        s.env = sc;
+        auto type = new DInterface(s.identifier);
+
+        sc.types[s.identifier.get] = type;
+
+        sc = push();
+        super.visitInterfaceDecl(s);
+        pop(sc);
+    }
+
     override void visitDeclStmt(DeclStmt d)
     {
         ++need_push;