diff sema/AstAction.d @ 53:da551f90e03f new_gen

Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
author Anders Johnsen <skabet@gmail.com>
date Sat, 26 Apr 2008 18:52:27 +0200
parents c96cdcbdb9d6
children 79cb0afafabe
line wrap: on
line diff
--- a/sema/AstAction.d	Sat Apr 26 16:12:36 2008 +0200
+++ b/sema/AstAction.d	Sat Apr 26 18:52:27 2008 +0200
@@ -23,7 +23,20 @@
     override DeclT actOnDeclarator(ref Id type, ref Id id, ExprT init)
     {
         Exp exp = cast(Exp)init;
-        return new VarDecl(new Identifier(type.tok), new Identifier(id.tok), exp);
+        if(type.tok.type == Tok.Struct)
+            return new StructDecl(new Identifier(id.tok));
+        else
+            return new VarDecl(new Identifier(type.tok), new Identifier(id.tok), exp);
+    }
+    
+    override void actOnStructMember(DeclT decl, ref Id type, ref Id name, ExprT init)
+    {
+        Exp exp = cast(Exp)init;
+        StructDecl st = cast(StructDecl)decl;
+        st.addMember(
+                new Identifier(type.tok), 
+                new Identifier(name.tok), 
+                exp);
     }
 
     override DeclT actOnStartOfFunctionDef(ref Id type, ref Id name)