diff ast/Decl.d @ 63:9f8131676242 new_gen

Now Decl's have a DType type(), and should use varType and returnType to get the old type id
author Anders Halager <halager@gmail.com>
date Tue, 29 Apr 2008 15:13:38 +0200
parents 2451f0904bf6
children 91f10c34cd7b
line wrap: on
line diff
--- a/ast/Decl.d	Tue Apr 29 15:00:11 2008 +0200
+++ b/ast/Decl.d	Tue Apr 29 15:13:38 2008 +0200
@@ -7,7 +7,9 @@
 
 import tango.io.Stdout;
 
-import sema.SymbolTable;
+import sema.SymbolTable,
+       sema.DType,
+       basic.SmallArray;
 
 enum DeclType
 {
@@ -27,6 +29,8 @@
     {
     }
 
+    DType type() { return null; }
+
     DeclType declType;
     Scope env;
 }
@@ -37,7 +41,7 @@
             Exp e = null)
     {
         super(DeclType.VarDecl);
-        this.type = type;
+        this.varType = type;
         this.identifier = identifier;
         this.init = e;
     }
@@ -46,7 +50,12 @@
     {
     }
 
-    Identifier type, identifier;
+    override DType type()
+    {
+        return env.find(identifier).type;
+    }
+
+    Identifier varType, identifier;
     Exp init;
 }
 
@@ -55,7 +64,7 @@
     this(Identifier type, Identifier identifier)
     {
         super(DeclType.FuncDecl);
-        this.type = type;
+        this.returnType = type;
         this.identifier = identifier;
     }
 
@@ -73,20 +82,20 @@
     {
         if(auto t = cast(DFunction)env.find(identifier).type)
         {
-            if(auto s = cast(DStruct)t.return_type)
+            if(auto s = cast(DStruct)t.returnType)
             {
                 VarDecl[] funcArgs;
                 auto i = new Identifier("ret.val");
                 i.env = env;
                 i.env.add(i);
                 i.env.find(i).type = s;
-                auto var = new VarDecl(type, i);
+                auto var = new VarDecl(returnType, i);
                 var.env = env;
                 funcArgs ~= var;
                 funcArgs ~= this.funcArgs;
                 this.funcArgs = funcArgs;
-                t.return_type = DType.Void;
-                this.type = new Identifier("void");
+                t.returnType = DType.Void;
+                this.returnType = new Identifier("void");
                 env.find(identifier).type = t;
                 sret = true;
             }
@@ -98,10 +107,26 @@
             stmt.simplify();
     }
 
-    Identifier type, identifier;
+    override DType type()
+    {
+        if (myType !is null)
+            return myType;
+
+        auto t = new DFunction(identifier);
+        t.returnType = env.findType(returnType);
+        SmallArray!(DType) array;
+        foreach (a; funcArgs)
+            array ~= a.type();
+        t.params = array.safe();
+        myType = t;
+        return myType;
+    }
+
+    Identifier returnType, identifier;
     VarDecl[] funcArgs;
     Stmt[] statements;
     bool sret = false;
+    private DType myType;
 }
 
 class StructDecl : Decl
@@ -122,7 +147,13 @@
     {
     }
 
+    override DType type()
+    {
+        return env.find(identifier).type;
+    }
+
     Identifier identifier;
     VarDecl[] vars;
+    private DType myType;
 }