comparison trunk/src/dil/TypeSystem.d @ 527:c8c3aec130f7

Added struct MITable. Added methods sizeOf() and sizeOf_() to class Type. Moved metaInfoTable into MITable.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 16 Dec 2007 22:45:23 +0100
parents ee22dc0ba82c
children 0781ac288537
comparison
equal deleted inserted replaced
526:ee22dc0ba82c 527:c8c3aec130f7
24 24
25 TypePointer ptrTo() 25 TypePointer ptrTo()
26 { 26 {
27 return new TypePointer(this); 27 return new TypePointer(this);
28 } 28 }
29
30 /// Get byte size of this type.
31 final size_t sizeOf()
32 {
33 return MITable.getSize(this);
34 }
35
36 /// Size is not in MITable. Find out via virtual method.
37 size_t sizeOf_()
38 {
39 return sizeOf();
40 }
29 } 41 }
30 42
31 class TypeBasic : Type 43 class TypeBasic : Type
32 { 44 {
33 this(TYP typ) 45 this(TYP typ)
178 { 190 {
179 char mangle; /// Mangle character of the type. 191 char mangle; /// Mangle character of the type.
180 size_t size; /// Byte size of the type. 192 size_t size; /// Byte size of the type.
181 } 193 }
182 194
183 static const TypeMetaInfo metaInfoTable[] = [ 195 struct MITable
184 {'?', -1}, // Error 196 {
185 197 static:
186 {'a', 1}, // Char 198 const size_t SIZE_NOT_AVAILABLE = -1; /// Size not available.
187 {'u', 2}, // Wchar 199 private alias SIZE_NOT_AVAILABLE SNA;
188 {'w', 4}, // Dchar 200 private alias PTR_SIZE PS;
189 {'b', 1}, // Bool 201 private const TypeMetaInfo metaInfoTable[] = [
190 {'g', 1}, // Byte 202 {'?', SNA}, // Error
191 {'h', 1}, // Ubyte 203
192 {'s', 2}, // Short 204 {'a', 1}, // Char
193 {'t', 2}, // Ushort 205 {'u', 2}, // Wchar
194 {'i', 4}, // Int 206 {'w', 4}, // Dchar
195 {'k', 4}, // Uint 207 {'b', 1}, // Bool
196 {'l', 8}, // Long 208 {'g', 1}, // Byte
197 {'m', 8}, // Ulong 209 {'h', 1}, // Ubyte
198 {'?', 16}, // Cent 210 {'s', 2}, // Short
199 {'?', 16}, // Ucent 211 {'t', 2}, // Ushort
200 {'f', 4}, // Float 212 {'i', 4}, // Int
201 {'d', 8}, // Double 213 {'k', 4}, // Uint
202 {'e', 12}, // Real 214 {'l', 8}, // Long
203 {'o', 4}, // Ifloat 215 {'m', 8}, // Ulong
204 {'p', 8}, // Idouble 216 {'?', 16}, // Cent
205 {'j', 12}, // Ireal 217 {'?', 16}, // Ucent
206 {'q', 8}, // Cfloat 218 {'f', 4}, // Float
207 {'r', 16}, // Cdouble 219 {'d', 8}, // Double
208 {'c', 24}, // Creal 220 {'e', 12}, // Real
209 {'v', 1}, // void 221 {'o', 4}, // Ifloat
210 222 {'p', 8}, // Idouble
211 {'n', -1}, // None 223 {'j', 12}, // Ireal
212 224 {'q', 8}, // Cfloat
213 {'A', PTR_SIZE*2}, // Dynamic array 225 {'r', 16}, // Cdouble
214 {'G', PTR_SIZE*2}, // Static array 226 {'c', 24}, // Creal
215 {'H', PTR_SIZE*2}, // Associative array 227 {'v', 1}, // void
216 228
217 {'E', -1}, // Enum 229 {'n', SNA}, // None
218 {'S', -1}, // Struct 230
219 {'C', PTR_SIZE}, // Class 231 {'A', PS*2}, // Dynamic array
220 {'T', -1}, // Typedef 232 {'G', PS*2}, // Static array
221 {'F', PTR_SIZE}, // Function 233 {'H', PS*2}, // Associative array
222 {'D', PTR_SIZE*2}, // Delegate 234
223 {'P', PTR_SIZE}, // Pointer 235 {'E', SNA}, // Enum
224 {'R', PTR_SIZE}, // Reference 236 {'S', SNA}, // Struct
225 {'I', -1}, // Identifier 237 {'C', PS}, // Class
226 {'?', -1}, // Template instance 238 {'T', SNA}, // Typedef
227 {'B', -1}, // Tuple 239 {'F', PS}, // Function
228 {'x', -1}, // Const, D2 240 {'D', PS*2}, // Delegate
229 {'y', -1}, // Invariant, D2 241 {'P', PS}, // Pointer
230 ]; 242 {'R', PS}, // Reference
243 {'I', SNA}, // Identifier
244 {'?', SNA}, // Template instance
245 {'B', SNA}, // Tuple
246 {'x', SNA}, // Const, D2
247 {'y', SNA}, // Invariant, D2
248 ];
249
250 size_t getSize(Type type)
251 {
252 auto size = metaInfoTable[type.typ].size;
253 if (size == SIZE_NOT_AVAILABLE)
254 return type.sizeOf_();
255 return size;
256 }
257 }
231 258
232 /// A set of pre-defined types. 259 /// A set of pre-defined types.
233 struct Types 260 struct Types
234 { 261 {
235 static: 262 static: