comparison sema/DType.d @ 136:2be29b296081

Lots of changes: - Parsing classes and interfaces - Fixed some seg faults in sema - Supporting "private" to some extend - And a lot of other small fixes
author johnsen@johnsen-laptop
date Fri, 11 Jul 2008 21:47:57 +0200
parents a101853eaae0
children 6e6355fb5f0f
comparison
equal deleted inserted replaced
135:9869194de9b7 136:2be29b296081
28 28
29 /// Is this type a DStruct 29 /// Is this type a DStruct
30 bool isStruct() { return false; } 30 bool isStruct() { return false; }
31 /// Return a DStruct if this is one, otherwise return null 31 /// Return a DStruct if this is one, otherwise return null
32 DStruct asStruct() { return null; } 32 DStruct asStruct() { return null; }
33
34 /// Is this type a DStaticArray
35 bool isStaticArray() { return false; }
36 /// Return a DStaticArray if this is one, otherwise return null
37 DStaticArray asStaticArray() { return null; }
33 38
34 /// Is this type a DArray 39 /// Is this type a DArray
35 bool isArray() { return false; } 40 bool isArray() { return false; }
36 /// Return a DArray if this is one, otherwise return null 41 /// Return a DArray if this is one, otherwise return null
37 DArray asArray() { return null; } 42 DArray asArray() { return null; }
127 } 132 }
128 133
129 /** 134 /**
130 Get a type representing a static array of this type with length 'size' 135 Get a type representing a static array of this type with length 'size'
131 */ 136 */
132 DArray getAsArray(int size) 137 DStaticArray getAsStaticArray(int size)
133 { 138 {
134 if(size in myArray) 139 if(size in myStaticArray)
135 return myArray[size]; 140 return myStaticArray[size];
136 myArray[size] = new DArray(this, size); 141 myStaticArray[size] = new DStaticArray(this, size);
137 return myArray[size]; 142 return myStaticArray[size];
138 } 143 }
139 private DArray[int] myArray; 144 private DStaticArray[int] myStaticArray;
145
146 DArray getAsArray()
147 {
148 if(myArray !is null)
149 return myArray;
150 myArray = new DArray(this);
151 return myArray;
152 }
153 private DArray myArray;
140 154
141 static DInteger 155 static DInteger
142 Bool, 156 Bool,
143 Byte, UByte, Short, UShort, 157 Byte, UByte, Short, UShort,
144 Int, UInt, Long, ULong, 158 Int, UInt, Long, ULong,
333 return type.toString(); 347 return type.toString();
334 } 348 }
335 } 349 }
336 } 350 }
337 351
338 class DArray : DType 352 class DStaticArray : DType
339 { 353 {
340 this(DType arrayOf, int size, DType actual = null) 354 this(DType arrayOf, int size, DType actual = null)
341 { 355 {
342 super(id, actual); 356 super(id, actual);
343 this.arrayOf = arrayOf; 357 this.arrayOf = arrayOf;
344 this.size = size; 358 this.size = size;
345 } 359 }
346 360
361 override bool isStaticArray() { return true; }
362 override DStaticArray asStaticArray() { return this; }
363
364 int byteSize() { return arrayOf.byteSize * size; }
365
366 override char[] mangle()
367 {
368 return "G"~Integer.toString(size)~arrayOf.mangle;
369 }
370
371 DType arrayOf;
372 const int size;
373 }
374
375 class DArray : DType
376 {
377 this(DType arrayOf, DType actual = null)
378 {
379 super(id, actual);
380 this.arrayOf = arrayOf;
381 }
382
347 override bool isArray() { return true; } 383 override bool isArray() { return true; }
348 override DArray asArray() { return this; } 384 override DArray asArray() { return this; }
349 385
350 int byteSize() { return arrayOf.byteSize * size; } 386 int byteSize() { return 8; } // FIXME: Size is a pointer + on size. (platform depend)
351 387
352 override char[] mangle() 388 override char[] mangle()
353 { 389 {
354 return "G"~Integer.toString(size)~arrayOf.mangle; 390 return "G"~arrayOf.mangle; // FIXME: Need correct mangling
355 } 391 }
356 392
357 DType arrayOf; 393 DType arrayOf;
358 const int size;
359 } 394 }
360 395
361 class DPointer : DType 396 class DPointer : DType
362 { 397 {
363 this(DType pointerOf, DType actual = null) 398 this(DType pointerOf, DType actual = null)
386 super(id, actual); 421 super(id, actual);
387 } 422 }
388 423
389 override bool isFunction() { return true; } 424 override bool isFunction() { return true; }
390 override DFunction asFunction() { return this; } 425 override DFunction asFunction() { return this; }
426
427 override bool hasImplicitConversionTo(DType that)
428 {
429 return returnType.hasImplicitConversionTo(that);
430 }
391 431
392 override char[] mangle() 432 override char[] mangle()
393 { 433 {
394 char[] res; 434 char[] res;
395 435