comparison lphobos/internal/objectimpl.d @ 58:2c3cd3596187 trunk

[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum Added initial support for CatExp aka 'a ~ b' Fixed global constant static arrays initialized with string literals Fixed casting any dynamic array to void* Fixed new expression with temporary storage Fixed alias declarations in function scope Fixed relational comparisons of pointers
author lindquist
date Thu, 25 Oct 2007 09:02:55 +0200
parents 28e99b04a132
children d7e764e62462
comparison
equal deleted inserted replaced
57:a9d29e9f1fed 58:2c3cd3596187
464 464
465 class TypeInfo_Enum : TypeInfo_Typedef 465 class TypeInfo_Enum : TypeInfo_Typedef
466 { 466 {
467 } 467 }
468 468
469 /+
470
471 class TypeInfo_Pointer : TypeInfo 469 class TypeInfo_Pointer : TypeInfo
472 { 470 {
473 char[] toString() { return m_next.toString() ~ "*"; } 471 char[] toString() { return m_next.toString() ~ "*"; }
474 472
475 int opEquals(Object o) 473 int opEquals(Object o)
593 } 591 }
594 592
595 uint flags() { return 1; } 593 uint flags() { return 1; }
596 } 594 }
597 595
596 private const char[10] digits = "0123456789"; /// 0..9
597
598 private char[] lengthToString(uint u)
599 { char[uint.sizeof * 3] buffer = void;
600 int ndigits;
601 char[] result;
602
603 ndigits = 0;
604 if (u < 10)
605 // Avoid storage allocation for simple stuff
606 result = digits[u .. u + 1];
607 else
608 {
609 while (u)
610 {
611 uint c = (u % 10) + '0';
612 u /= 10;
613 ndigits++;
614 buffer[buffer.length - ndigits] = cast(char)c;
615 }
616 result = new char[ndigits];
617 result[] = buffer[buffer.length - ndigits .. buffer.length];
618 }
619 return result;
620 }
621
622 private char[] lengthToString(ulong u)
623 { char[ulong.sizeof * 3] buffer;
624 int ndigits;
625 char[] result;
626
627 if (u < 0x1_0000_0000)
628 return lengthToString(cast(uint)u);
629 ndigits = 0;
630 while (u)
631 {
632 char c = cast(char)((u % 10) + '0');
633 u /= 10;
634 ndigits++;
635 buffer[buffer.length - ndigits] = c;
636 }
637 result = new char[ndigits];
638 result[] = buffer[buffer.length - ndigits .. buffer.length];
639 return result;
640 }
641
598 class TypeInfo_StaticArray : TypeInfo 642 class TypeInfo_StaticArray : TypeInfo
599 { 643 {
600 char[] toString() 644 char[] toString()
601 { 645 {
602 return value.toString() ~ "[" ~ std.string.toString(len) ~ "]"; 646 return value.toString() ~ "[" ~ lengthToString(len) ~ "]";
603 } 647 }
604 648
605 int opEquals(Object o) 649 int opEquals(Object o)
606 { TypeInfo_StaticArray c; 650 { TypeInfo_StaticArray c;
607 651
656 ubyte[16] buffer; 700 ubyte[16] buffer;
657 void* pbuffer; 701 void* pbuffer;
658 702
659 if (sz < buffer.sizeof) 703 if (sz < buffer.sizeof)
660 tmp = buffer.ptr; 704 tmp = buffer.ptr;
661 else 705 else {
706 if (value.flags() & 1)
662 tmp = pbuffer = (new void[sz]).ptr; 707 tmp = pbuffer = (new void[sz]).ptr;
708 else
709 tmp = pbuffer = (new byte[sz]).ptr;
710 }
663 711
664 for (size_t u = 0; u < len; u += sz) 712 for (size_t u = 0; u < len; u += sz)
665 { size_t o = u * sz; 713 { size_t o = u * sz;
666 memcpy(tmp, p1 + o, sz); 714 memcpy(tmp, p1 + o, sz);
667 memcpy(p1 + o, p2 + o, sz); 715 memcpy(p1 + o, p2 + o, sz);
758 806
759 uint flags() { return 1; } 807 uint flags() { return 1; }
760 808
761 TypeInfo next; 809 TypeInfo next;
762 } 810 }
811
812 /+
763 813
764 class TypeInfo_Class : TypeInfo 814 class TypeInfo_Class : TypeInfo
765 { 815 {
766 char[] toString() { return info.name; } 816 char[] toString() { return info.name; }
767 817
1039 { 1089 {
1040 assert(0); 1090 assert(0);
1041 } 1091 }
1042 } 1092 }
1043 1093
1094 +/
1095
1044 class TypeInfo_Const : TypeInfo 1096 class TypeInfo_Const : TypeInfo
1045 { 1097 {
1046 char[] toString() { return "const " ~ base.toString(); } 1098 char[] toString() { return "const " ~ base.toString(); }
1047 1099
1048 int opEquals(Object o) { return base.opEquals(o); } 1100 int opEquals(Object o) { return base.opEquals(o); }
1062 class TypeInfo_Invariant : TypeInfo_Const 1114 class TypeInfo_Invariant : TypeInfo_Const
1063 { 1115 {
1064 char[] toString() { return "invariant " ~ base.toString(); } 1116 char[] toString() { return "invariant " ~ base.toString(); }
1065 } 1117 }
1066 1118
1067 +/
1068
1069 /** 1119 /**
1070 * All recoverable exceptions should be derived from class Exception. 1120 * All recoverable exceptions should be derived from class Exception.
1071 */ 1121 */
1072 class Exception : Object 1122 class Exception : Object
1073 { 1123 {