changeset 162:0f38f1a0f06f

Fixed symbol for a functions members.
author Anders Johnsen <skabet@gmail.com>
date Tue, 22 Jul 2008 16:22:58 +0200
parents 0e10479623f6
children 362265427838
files ast/Exp.d sema/ScopeBuilder.d sema/Visitor.d tests/parser/new_1.d
diffstat 4 files changed, 36 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ast/Exp.d	Tue Jul 22 13:39:15 2008 +0200
+++ b/ast/Exp.d	Tue Jul 22 16:22:58 2008 +0200
@@ -387,12 +387,23 @@
         if (myType)
             return myType;
 
-        DStruct st = cast(DStruct)target.type;
-        assert(st, "Only structs have members");
-        if (auto t = st.typeOf(child.name))
-            myType = t;
+        if ( target.type.isStruct )
+        {
+            DStruct st = target.type.asStruct;
+            if (auto t = st.typeOf(child.name))
+                myType = t;
+//            else assert(0, "Referencing non-existant member");
+        }
+        else if ( target.type.isClass )
+        {
+            DClass cl = target.type.asClass;
+            if (auto t = cl.typeOf(child.name))
+                myType = t;
+//            else assert(0, "Referencing non-existant member");
+        }
+        else
+            assert(0, "Only structs and classes have members");
         // no error reporting here
-        else assert(0, "Referencing non-existant member");
 
         return myType;
     }
--- a/sema/ScopeBuilder.d	Tue Jul 22 13:39:15 2008 +0200
+++ b/sema/ScopeBuilder.d	Tue Jul 22 16:22:58 2008 +0200
@@ -30,6 +30,15 @@
 
         visitExp(d.returnType);
         visitExp(d.identifier);
+
+        d.sym = current.symbol.createMember(
+                d.identifier.get, 
+                d.type, 
+                d);
+
+        auto old = current.symbol;
+        current.symbol = d.sym;
+
         foreach (arg; d.funcArgs)
             visitDecl(arg);
 
@@ -40,10 +49,8 @@
 
         inFunctionBodyStack.pop();
 
-        d.sym = current.symbol.createMember(
-                d.identifier.get, 
-                d.type, 
-                d);
+        current.symbol = old;
+
     }
 
     override void visitVarDecl(VarDecl d)
--- a/sema/Visitor.d	Tue Jul 22 13:39:15 2008 +0200
+++ b/sema/Visitor.d	Tue Jul 22 16:22:58 2008 +0200
@@ -263,9 +263,12 @@
     
     StmtT visitForStmt(ForStmt s)
     {
-        visitStmt(s.init);
-        visitExp(s.cond);
-        visitExp(s.incre);
+        if(s.init)
+            visitStmt(s.init);
+        if(s.cond)
+            visitExp(s.cond);
+        if(s.incre)
+            visitExp(s.incre);
         visitStmt(s.forBody);
         static if (is(StmtT == void))
             return;
--- a/tests/parser/new_1.d	Tue Jul 22 13:39:15 2008 +0200
+++ b/tests/parser/new_1.d	Tue Jul 22 16:22:58 2008 +0200
@@ -8,6 +8,8 @@
     this(int y)
     {
     }
+
+    int x;
 }
 
 struct B
@@ -18,5 +20,5 @@
 {
     B b;
     long x;
-    A a = new A(b);
+    A a = new A(x);
 }