changeset 525:a3f66502ea64

Added struct Types with pre-defined types. Added PTR_SIZE to dil.CompilerInfo. Fixed size of some types in metaInfoTable. Moved Cent and Ucent in a few places in enum TOK.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 16 Dec 2007 21:24:54 +0100
parents 39b497c76e2b
children ee22dc0ba82c
files trunk/src/dil/CompilerInfo.d trunk/src/dil/TokensEnum.d trunk/src/dil/TypeSystem.d
diffstat 3 files changed, 94 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/CompilerInfo.d	Sun Dec 16 19:34:36 2007 +0100
+++ b/trunk/src/dil/CompilerInfo.d	Sun Dec 16 21:24:54 2007 +0100
@@ -41,3 +41,12 @@
 
 /// The global, default alignment size for struct fields.
 const DEFAULT_ALIGN_SIZE = 4;
+
+version(X86_64)
+{
+  const PTR_SIZE = 8; /// Pointer size on 64-bit platforms.
+}
+else
+{
+  const PTR_SIZE = 4; /// Pointer size on 32-bit platforms.
+}
--- a/trunk/src/dil/TokensEnum.d	Sun Dec 16 19:34:36 2007 +0100
+++ b/trunk/src/dil/TokensEnum.d	Sun Dec 16 21:24:54 2007 +0100
@@ -102,9 +102,10 @@
   Typeof, Union, Unittest,
   Version, Volatile, While, With,
   // Integral types.
-  Char,   Wchar,   Dchar, Bool, Cent, Ucent,
+  Char,   Wchar,   Dchar, Bool,
   Byte,   Ubyte,   Short, Ushort,
   Int,    Uint,    Long,  Ulong,
+  Cent,   Ucent,
   Float,  Double,  Real,
   Ifloat, Idouble, Ireal,
   Cfloat, Cdouble, Creal, Void,
--- a/trunk/src/dil/TypeSystem.d	Sun Dec 16 19:34:36 2007 +0100
+++ b/trunk/src/dil/TypeSystem.d	Sun Dec 16 21:24:54 2007 +0100
@@ -6,6 +6,7 @@
 
 import dil.Symbol;
 import dil.TypesEnum;
+import dil.CompilerInfo;
 
 abstract class Type : Symbol
 {
@@ -19,11 +20,19 @@
     this.next = next;
     this.typ = typ;
   }
+
+  TypePointer ptrTo()
+  {
+    return new TypePointer(this);
+  }
 }
 
 class TypeBasic : Type
 {
-
+  this(TYP typ)
+  {
+    super(null, typ);
+  }
 }
 
 class TypeDArray : Type
@@ -43,7 +52,10 @@
 
 class TypePointer : Type
 {
-
+  this(Type next)
+  {
+    super(next, TYP.Pointer);
+  }
 }
 
 class TypeReference : Type
@@ -87,21 +99,82 @@
 
   {'n', -1},  // None
 
-  {'A', 8}, // Dynamic array
-  {'G', 8}, // Static array
-  {'H', 8}, // Associative array
+  {'A', PTR_SIZE*2}, // Dynamic array
+  {'G', PTR_SIZE*2}, // Static array
+  {'H', PTR_SIZE*2}, // Associative array
 
   {'E', -1}, // Enum
   {'S', -1}, // Struct
-  {'C', -1}, // Class
+  {'C', PTR_SIZE}, // Class
   {'T', -1}, // Typedef
-  {'F', -1}, // Function
-  {'D', -1}, // Delegate
-  {'P', -1}, // Pointer
-  {'R', -1}, // Reference
+  {'F', PTR_SIZE}, // Function
+  {'D', PTR_SIZE*2}, // Delegate
+  {'P', PTR_SIZE}, // Pointer
+  {'R', PTR_SIZE}, // Reference
   {'I', -1}, // Identifier
   {'?', -1}, // Template instance
   {'B', -1}, // Tuple
   {'x', -1}, // Const, D2
   {'y', -1}, // Invariant, D2
 ];
+
+/// A set of pre-defined types.
+struct Types
+{
+static:
+  TypeBasic Char,   Wchar,   Dchar, Bool,
+            Byte,   Ubyte,   Short, Ushort,
+            Int,    Uint,    Long,  Ulong,
+            Cent,   Ucent,
+            Float,  Double,  Real,
+            Ifloat, Idouble, Ireal,
+            Cfloat, Cdouble, Creal, Void;
+
+  TypeBasic Size_t, Ptrdiff_t;
+  TypePointer Void_ptr;
+
+  /// Allocates an instance of TypeBasic and assigns it to typeName.
+  template newTB(char[] typeName)
+  {
+    const TypeBasic newTB = mixin(typeName~" = new TypeBasic(TYP."~typeName~")");
+  }
+
+  static this()
+  {
+    newTB!("Char");
+    newTB!("Wchar");
+    newTB!("Dchar");
+    newTB!("Bool");
+    newTB!("Byte");
+    newTB!("Ubyte");
+    newTB!("Short");
+    newTB!("Ushort");
+    newTB!("Int");
+    newTB!("Uint");
+    newTB!("Long");
+    newTB!("Ulong");
+    newTB!("Cent");
+    newTB!("Ucent");
+    newTB!("Float");
+    newTB!("Double");
+    newTB!("Real");
+    newTB!("Ifloat");
+    newTB!("Idouble");
+    newTB!("Ireal");
+    newTB!("Cfloat");
+    newTB!("Cdouble");
+    newTB!("Creal");
+    newTB!("Void");
+    version(X86_64)
+    {
+      Size_t = Ulong;
+      Ptrdiff_t = Long;
+    }
+    else
+    {
+      Size_t = Uint;
+      Ptrdiff_t = Int;
+    }
+    Void_ptr = Void.ptrTo;
+  }
+}