comparison sema/DType.d @ 176:dc9bf56b7ace

Can now use & as a unary operator and take an AddressOf
author Anders Johnsen <skabet@gmail.com>
date Thu, 24 Jul 2008 23:03:18 +0200
parents 6cb2f4201e2a
children 2a1a635bd531
comparison
equal deleted inserted replaced
175:c8e26556c24d 176:dc9bf56b7ace
97 */ 97 */
98 hash_t toHash() 98 hash_t toHash()
99 { 99 {
100 return cast(hash_t)(cast(void*)this); 100 return cast(hash_t)(cast(void*)this);
101 } 101 }
102 102 /*
103 char[] toString() 103 char[] toString()
104 { 104 {
105 return id; 105 return id;
106 } 106 }
107 107 */
108 char[] name() { return id; } 108 char[] name() { return id; }
109 SourceLocation getLoc() { return loc; } 109 SourceLocation getLoc() { return loc; }
110 int byteSize() { return 0; } 110 int byteSize() { return 0; }
111 111
112 /** 112 /**
164 return myArray; 164 return myArray;
165 myArray = new DArray(this); 165 myArray = new DArray(this);
166 return myArray; 166 return myArray;
167 } 167 }
168 private DArray myArray; 168 private DArray myArray;
169
170 bool isSame(DType d)
171 {
172 return d is this;
173 }
169 174
170 static DInteger 175 static DInteger
171 Bool, 176 Bool,
172 Byte, UByte, Short, UShort, 177 Byte, UByte, Short, UShort,
173 Int, UInt, Long, ULong, 178 Int, UInt, Long, ULong,
350 override char[] mangle() 355 override char[] mangle()
351 { 356 {
352 return "S"~Integer.toString(name.length)~name; 357 return "S"~Integer.toString(name.length)~name;
353 } 358 }
354 359
360 override bool isSame(DType d)
361 {
362 if (d is this)
363 return true;
364
365 if (!d.isStruct)
366 return false;
367
368 auto s = d.asStruct;
369
370 return id == s.id;
371 }
372
355 struct DStructMember 373 struct DStructMember
356 { 374 {
357 DType type; 375 DType type;
358 int index; 376 int index;
359 377
405 override char[] mangle() 423 override char[] mangle()
406 { 424 {
407 return "S"~Integer.toString(name.length)~name; 425 return "S"~Integer.toString(name.length)~name;
408 } 426 }
409 427
428 override bool isSame(DType d)
429 {
430 if (d is this)
431 return true;
432
433 if (!d.isClass)
434 return false;
435
436 auto c = d.asClass;
437
438 return id == c.id;
439 }
440
410 struct DClassMember 441 struct DClassMember
411 { 442 {
412 DType type; 443 DType type;
413 int index; 444 int index;
414 445
452 if (auto res = name in members) 483 if (auto res = name in members)
453 return res.type; 484 return res.type;
454 return null; 485 return null;
455 } 486 }
456 487
488 override bool isSame(DType d)
489 {
490 if (d is this)
491 return true;
492
493 if (!d.isInterface)
494 return false;
495
496 auto i = d.asInterface;
497
498 return id == i.id;
499 }
500
457 DInterfaceMember[char[]] members; 501 DInterfaceMember[char[]] members;
458 private int bytes_total; 502 private int bytes_total;
459 503
460 override char[] mangle() 504 override char[] mangle()
461 { 505 {
486 override bool isStaticArray() { return true; } 530 override bool isStaticArray() { return true; }
487 override DStaticArray asStaticArray() { return this; } 531 override DStaticArray asStaticArray() { return this; }
488 532
489 int byteSize() { return arrayOf.byteSize * size; } 533 int byteSize() { return arrayOf.byteSize * size; }
490 534
535 override bool isSame(DType d)
536 {
537 if (d is this)
538 return true;
539
540 if (!d.isArray)
541 return false;
542
543 auto a = d.asStaticArray;
544
545 if (size != a.size)
546 return false;
547
548 return arrayOf.isSame(a.arrayOf);
549 }
550
491 override char[] mangle() 551 override char[] mangle()
492 { 552 {
493 return "G"~Integer.toString(size)~arrayOf.mangle; 553 return "G"~Integer.toString(size)~arrayOf.mangle;
494 } 554 }
495 555
508 override bool isArray() { return true; } 568 override bool isArray() { return true; }
509 override DArray asArray() { return this; } 569 override DArray asArray() { return this; }
510 570
511 int byteSize() { return 8; } // FIXME: Size is a pointer + on size. (platform depend) 571 int byteSize() { return 8; } // FIXME: Size is a pointer + on size. (platform depend)
512 572
573 override bool isSame(DType d)
574 {
575 if (d is this)
576 return true;
577
578 if (!d.isArray)
579 return false;
580
581 auto a = d.asArray;
582
583 return arrayOf.isSame(a.arrayOf);
584 }
585
513 override char[] mangle() 586 override char[] mangle()
514 { 587 {
515 return "G"~arrayOf.mangle; // FIXME: Need correct mangling 588 return "G"~arrayOf.mangle; // FIXME: Need correct mangling
516 } 589 }
517 590
529 override bool isPointer() { return true; } 602 override bool isPointer() { return true; }
530 override DPointer asPointer() { return this; } 603 override DPointer asPointer() { return this; }
531 604
532 int byteSize() { return DType.Int.byteSize; } 605 int byteSize() { return DType.Int.byteSize; }
533 606
607 override bool isSame(DType d)
608 {
609 if (d is this)
610 return true;
611
612 if (!d.isPointer)
613 return false;
614
615 auto p = d.asPointer;
616
617 return pointerOf.isSame(p.pointerOf);
618 }
619
534 override char[] mangle() 620 override char[] mangle()
535 { 621 {
536 return "P"~pointerOf.mangle; 622 return "P"~pointerOf.mangle;
537 } 623 }
538 624
565 651
566 res ~= "Z"; 652 res ~= "Z";
567 res ~= returnType.mangle; 653 res ~= returnType.mangle;
568 654
569 return res; 655 return res;
656 }
657
658 override bool isSame(DType f)
659 {
660 if (f is this)
661 return true;
662
663 if (!f.isFunction)
664 return false;
665
666 auto func = f.asFunction;
667
668 if (returnType != func.returnType)
669 return false;
670
671 if (params.length != func.params.length)
672 return false;
673
674 foreach (i, p ; params)
675 if (!p.isSame(func.params[0]))
676 return false;
677
678 return true;
570 } 679 }
571 680
572 DType[] params; 681 DType[] params;
573 DType returnType; 682 DType returnType;
574 bool firstParamIsReturnValue = false; 683 bool firstParamIsReturnValue = false;