diff sema/DType.d @ 26:b4dc2b2c0e38 new_gen

Added a DType class
author Anders Halager <halager@gmail.com>
date Sat, 19 Apr 2008 22:19:14 +0200
parents
children 9031487e97d7
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sema/DType.d	Sat Apr 19 22:19:14 2008 +0200
@@ -0,0 +1,65 @@
+module sema.DType;
+
+import tango.text.Util : jhash;
+
+import sema.SymbolTable;
+
+class DType
+{
+    Identifier id;
+    Scope sc;
+    DType actual;
+
+    this(Identifier id, Scope sc, DType actual = null)
+    {
+        this.id = id;
+        this.sc = sc;
+        if (actual is null)
+            this.actual = this;
+        _name = id.get;
+    }
+
+    int opEquals(Object o)
+    {
+        if (auto t = cast(DType)o)
+            return this.actual is t.actual;
+        return 0;
+    }
+
+    int opCmp(Object o)
+    {
+        if (auto t = cast(DType)o)
+            return cast(void*)this.actual - cast(void*)t.actual;
+        return 0;
+    }
+
+    hash_t toHash()
+    {
+        return cast(hash_t)(cast(void*)this);
+    }
+
+    char[] name() { return _name; }
+
+private:
+    char[] _name;
+}
+
+class DStruct : DType
+{
+    this(Identifier id, Scope sc, DType actual = null)
+    {
+        super(id, sc, actual);
+    }
+    DType[] members;
+}
+
+class DFunction : DType
+{
+    this(Identifier id, Scope sc, DType actual = null)
+    {
+        super(id, sc, actual);
+    }
+    DType[] params;
+    DType return_type;
+}
+