Mercurial > projects > dil
comparison trunk/src/dil/TypeSystem.d @ 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 | 812f497b20dc |
children | ee22dc0ba82c |
comparison
equal
deleted
inserted
replaced
524:39b497c76e2b | 525:a3f66502ea64 |
---|---|
4 +/ | 4 +/ |
5 module dil.TypeSystem; | 5 module dil.TypeSystem; |
6 | 6 |
7 import dil.Symbol; | 7 import dil.Symbol; |
8 import dil.TypesEnum; | 8 import dil.TypesEnum; |
9 import dil.CompilerInfo; | |
9 | 10 |
10 abstract class Type : Symbol | 11 abstract class Type : Symbol |
11 { | 12 { |
12 Type next; | 13 Type next; |
13 TYP typ; | 14 TYP typ; |
17 this(Type next, TYP typ) | 18 this(Type next, TYP typ) |
18 { | 19 { |
19 this.next = next; | 20 this.next = next; |
20 this.typ = typ; | 21 this.typ = typ; |
21 } | 22 } |
23 | |
24 TypePointer ptrTo() | |
25 { | |
26 return new TypePointer(this); | |
27 } | |
22 } | 28 } |
23 | 29 |
24 class TypeBasic : Type | 30 class TypeBasic : Type |
25 { | 31 { |
26 | 32 this(TYP typ) |
33 { | |
34 super(null, typ); | |
35 } | |
27 } | 36 } |
28 | 37 |
29 class TypeDArray : Type | 38 class TypeDArray : Type |
30 { | 39 { |
31 | 40 |
41 | 50 |
42 } | 51 } |
43 | 52 |
44 class TypePointer : Type | 53 class TypePointer : Type |
45 { | 54 { |
46 | 55 this(Type next) |
56 { | |
57 super(next, TYP.Pointer); | |
58 } | |
47 } | 59 } |
48 | 60 |
49 class TypeReference : Type | 61 class TypeReference : Type |
50 { | 62 { |
51 | 63 |
85 {'c', 24}, // Creal | 97 {'c', 24}, // Creal |
86 {'v', 1}, // void | 98 {'v', 1}, // void |
87 | 99 |
88 {'n', -1}, // None | 100 {'n', -1}, // None |
89 | 101 |
90 {'A', 8}, // Dynamic array | 102 {'A', PTR_SIZE*2}, // Dynamic array |
91 {'G', 8}, // Static array | 103 {'G', PTR_SIZE*2}, // Static array |
92 {'H', 8}, // Associative array | 104 {'H', PTR_SIZE*2}, // Associative array |
93 | 105 |
94 {'E', -1}, // Enum | 106 {'E', -1}, // Enum |
95 {'S', -1}, // Struct | 107 {'S', -1}, // Struct |
96 {'C', -1}, // Class | 108 {'C', PTR_SIZE}, // Class |
97 {'T', -1}, // Typedef | 109 {'T', -1}, // Typedef |
98 {'F', -1}, // Function | 110 {'F', PTR_SIZE}, // Function |
99 {'D', -1}, // Delegate | 111 {'D', PTR_SIZE*2}, // Delegate |
100 {'P', -1}, // Pointer | 112 {'P', PTR_SIZE}, // Pointer |
101 {'R', -1}, // Reference | 113 {'R', PTR_SIZE}, // Reference |
102 {'I', -1}, // Identifier | 114 {'I', -1}, // Identifier |
103 {'?', -1}, // Template instance | 115 {'?', -1}, // Template instance |
104 {'B', -1}, // Tuple | 116 {'B', -1}, // Tuple |
105 {'x', -1}, // Const, D2 | 117 {'x', -1}, // Const, D2 |
106 {'y', -1}, // Invariant, D2 | 118 {'y', -1}, // Invariant, D2 |
107 ]; | 119 ]; |
120 | |
121 /// A set of pre-defined types. | |
122 struct Types | |
123 { | |
124 static: | |
125 TypeBasic Char, Wchar, Dchar, Bool, | |
126 Byte, Ubyte, Short, Ushort, | |
127 Int, Uint, Long, Ulong, | |
128 Cent, Ucent, | |
129 Float, Double, Real, | |
130 Ifloat, Idouble, Ireal, | |
131 Cfloat, Cdouble, Creal, Void; | |
132 | |
133 TypeBasic Size_t, Ptrdiff_t; | |
134 TypePointer Void_ptr; | |
135 | |
136 /// Allocates an instance of TypeBasic and assigns it to typeName. | |
137 template newTB(char[] typeName) | |
138 { | |
139 const TypeBasic newTB = mixin(typeName~" = new TypeBasic(TYP."~typeName~")"); | |
140 } | |
141 | |
142 static this() | |
143 { | |
144 newTB!("Char"); | |
145 newTB!("Wchar"); | |
146 newTB!("Dchar"); | |
147 newTB!("Bool"); | |
148 newTB!("Byte"); | |
149 newTB!("Ubyte"); | |
150 newTB!("Short"); | |
151 newTB!("Ushort"); | |
152 newTB!("Int"); | |
153 newTB!("Uint"); | |
154 newTB!("Long"); | |
155 newTB!("Ulong"); | |
156 newTB!("Cent"); | |
157 newTB!("Ucent"); | |
158 newTB!("Float"); | |
159 newTB!("Double"); | |
160 newTB!("Real"); | |
161 newTB!("Ifloat"); | |
162 newTB!("Idouble"); | |
163 newTB!("Ireal"); | |
164 newTB!("Cfloat"); | |
165 newTB!("Cdouble"); | |
166 newTB!("Creal"); | |
167 newTB!("Void"); | |
168 version(X86_64) | |
169 { | |
170 Size_t = Ulong; | |
171 Ptrdiff_t = Long; | |
172 } | |
173 else | |
174 { | |
175 Size_t = Uint; | |
176 Ptrdiff_t = Int; | |
177 } | |
178 Void_ptr = Void.ptrTo; | |
179 } | |
180 } |