comparison dmd/Type.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents 1475fd394c9e
children 190ba98276b3
comparison
equal deleted inserted replaced
177:1475fd394c9e 178:e3afd1303184
223 default: 223 default:
224 assert(0); 224 assert(0);
225 } 225 }
226 } 226 }
227 227
228 class Type 228 import dmd.TObject;
229
230 class Type : TObject
229 { 231 {
230 TY ty; 232 TY ty;
231 MOD mod; // modifiers MODxxxx 233 MOD mod; // modifiers MODxxxx
232 /* pick this order of numbers so switch statements work better 234 /* pick this order of numbers so switch statements work better
233 */ 235 */
449 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], 451 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
450 ]; 452 ];
451 453
452 this(TY ty) 454 this(TY ty)
453 { 455 {
456 register();
454 this.ty = ty; 457 this.ty = ty;
455 } 458 }
456 459
457 Type syntaxCopy() 460 Type syntaxCopy()
458 { 461 {
829 OutBuffer buf = new OutBuffer(); 832 OutBuffer buf = new OutBuffer();
830 833
831 //if (next) 834 //if (next)
832 //next = next.merge(); 835 //next = next.merge();
833 toDecoBuffer(buf); 836 toDecoBuffer(buf);
834 StringValue* sv = global.type_stringtable.update(buf.extractString()); 837 auto s = buf.extractString();
835 if (sv.ptrvalue) 838 Object* sv = global.type_stringtable.update(s);
839 if (*sv)
836 { 840 {
837 t = cast(Type) sv.ptrvalue; 841 t = cast(Type) *sv;
838 debug { 842 debug {
839 if (!t.deco) 843 if (!t.deco)
840 writef("t = %s\n", t.toChars()); 844 writef("t = %s\n", t.toChars());
841 } 845 }
842 assert(t.deco); 846 assert(t.deco);
843 //printf("old value, deco = '%s' %p\n", t.deco, t.deco); 847 //printf("old value, deco = '%s' %p\n", t.deco, t.deco);
844 } 848 }
845 else 849 else
846 { 850 {
847 sv.ptrvalue = cast(void*)this; 851 *sv = this;
848 deco = sv.lstring.string_; 852 deco = s;
849 //printf("new value, deco = '%s' %p\n", t.deco, t.deco); 853 //printf("new value, deco = '%s' %p\n", t.deco, t.deco);
850 } 854 }
851 } 855 }
852 return t; 856 return t;
853 } 857 }
862 Type t = this; 866 Type t = this;
863 assert(t); 867 assert(t);
864 if (!t.deco) 868 if (!t.deco)
865 return t.merge(); 869 return t.merge();
866 870
867 StringValue* sv = global.type_stringtable.lookup(t.deco); 871 Object* sv = global.type_stringtable.lookup(t.deco);
868 if (sv && sv.ptrvalue) 872 if (sv && *sv)
869 { 873 {
870 t = cast(Type)sv.ptrvalue; 874 t = cast(Type)*sv;
871 assert(t.deco); 875 assert(t.deco);
872 } 876 }
873 else 877 else
874 assert(0); 878 assert(0);
875 879
1171 assert(!t || !t.isShared()); 1175 assert(!t || !t.isShared());
1172 } 1176 }
1173 1177
1174 if (!t) 1178 if (!t)
1175 { 1179 {
1176 uint sz = this.classinfo.init.length; 1180 t = cloneThis(this);
1177 t = cast(Type)GC.malloc(sz);
1178 memcpy(cast(void*)t, cast(void*)this, sz);
1179 t.mod = mod & ~MODshared; 1181 t.mod = mod & ~MODshared;
1180 t.deco = null; 1182 t.deco = null;
1181 t.arrayof = null; 1183 t.arrayof = null;
1182 t.pto = null; 1184 t.pto = null;
1183 t.rto = null; 1185 t.rto = null;
1707 Type referenceTo() 1709 Type referenceTo()
1708 { 1710 {
1709 assert(false); 1711 assert(false);
1710 } 1712 }
1711 1713
1712 version (DumbClone) {
1713 final Type clone() 1714 final Type clone()
1714 { 1715 {
1715 auto size = this.classinfo.init.length; 1716 return cloneThis(this);
1716 auto ptr = GC.malloc(size); 1717 }
1717 memcpy(ptr, cast(void*)this, size);
1718
1719 return cast(Type)ptr;
1720 }
1721 } else {
1722 final Type cloneTo(Type t)
1723 {
1724 t.ctype = ctype;
1725 return t;
1726 }
1727
1728 Type clone()
1729 {
1730 assert(this.classinfo is Type.classinfo);
1731 return cloneTo(new Type(ty));
1732 }
1733 }
1734 1718
1735 Type arrayOf() 1719 Type arrayOf()
1736 { 1720 {
1737 if (!arrayof) 1721 if (!arrayof)
1738 { 1722 {
2845 // For eliminating dynamic_cast 2829 // For eliminating dynamic_cast
2846 TypeBasic isTypeBasic() 2830 TypeBasic isTypeBasic()
2847 { 2831 {
2848 return null; 2832 return null;
2849 } 2833 }
2850 2834
2851 @property 2835 @property
2852 static ref Type[TY.TMAX] basic() 2836 static ref Type[TY.TMAX] basic()
2853 { 2837 {
2854 return global.basic; 2838 return global.basic;
2855 } 2839 }