diff sema/DType.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 6cb2f4201e2a
line wrap: on
line diff
--- a/sema/DType.d	Mon Jul 21 01:05:20 2008 +0200
+++ b/sema/DType.d	Mon Jul 21 17:41:40 2008 +0200
@@ -31,6 +31,16 @@
     /// Return a DStruct if this is one, otherwise return null
     DStruct asStruct() { return null; }
 
+    /// Is this type a DClass
+    bool isClass() { return false; }
+    /// Return a DClass if this is one, otherwise return null
+    DClass asClass() { return null; }
+
+    /// Is this type a DInterface
+    bool isInterface() { return false; }
+    /// Return a DInterface if this is one, otherwise return null
+    DInterface asInterface() { return null; }
+
     /// Is this type a DStaticArray
     bool isStaticArray() { return false; }
     /// Return a DStaticArray if this is one, otherwise return null
@@ -349,6 +359,116 @@
     }
 }
 
+class DClass : DType
+{
+    this(Identifier id, DType actual = null)
+    {
+        super(id, actual);
+    }
+
+    int byteSize() { return bytes_total; }
+
+    override bool isClass() { return true; }
+    override DClass asClass() { return this; }
+
+    void addMember(DType type, char[] name)
+    {
+        auto s = DClassMember(type, members.length);
+        members[name] = s;
+
+        bytes_total += type.byteSize();
+    }
+
+    int indexOf(char[] name)
+    {
+        if(name in members)
+            return members[name].index;
+
+        return -1;
+    }
+
+    DType typeOf(char[] name)
+    {
+        if (auto res = name in members)
+            return res.type;
+        return null;
+    }
+
+    DClassMember[char[]] members;
+    private int bytes_total;
+
+    override char[] mangle()
+    {
+        return "S"~Integer.toString(name.length)~name;
+    }
+
+    struct DClassMember
+    {
+        DType type;
+        int index;
+
+        char[] toString()
+        {
+            return type.toString();
+        }
+    }
+}
+
+class DInterface : DType
+{
+    this(Identifier id, DType actual = null)
+    {
+        super(id, actual);
+    }
+
+    int byteSize() { return bytes_total; }
+
+    override bool isInterface() { return true; }
+    override DInterface asInterface() { return this; }
+
+    void addMember(DType type, char[] name)
+    {
+        auto s = DInterfaceMember(type, members.length);
+        members[name] = s;
+
+        bytes_total += type.byteSize();
+    }
+
+    int indexOf(char[] name)
+    {
+        if(name in members)
+            return members[name].index;
+
+        return -1;
+    }
+
+    DType typeOf(char[] name)
+    {
+        if (auto res = name in members)
+            return res.type;
+        return null;
+    }
+
+    DInterfaceMember[char[]] members;
+    private int bytes_total;
+
+    override char[] mangle()
+    {
+        return "S"~Integer.toString(name.length)~name;
+    }
+
+    struct DInterfaceMember
+    {
+        DType type;
+        int index;
+
+        char[] toString()
+        {
+            return type.toString();
+        }
+    }
+}
+
 class DStaticArray : DType
 {
     this(DType arrayOf, int size, DType actual = null)