diff 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
line wrap: on
line diff
--- a/dmd/Type.d	Sun Oct 10 10:38:55 2010 +0400
+++ b/dmd/Type.d	Sun Oct 17 07:42:00 2010 +0400
@@ -225,7 +225,9 @@
     }
 }
 
-class Type
+import dmd.TObject;
+
+class Type : TObject
 {
     TY ty;
     MOD mod;	// modifiers MODxxxx
@@ -451,6 +453,7 @@
 
     this(TY ty)
 	{
+		register();
 		this.ty = ty;
 	}
 
@@ -831,10 +834,11 @@
 			//if (next)
 				//next = next.merge();
 			toDecoBuffer(buf);
-			StringValue* sv = global.type_stringtable.update(buf.extractString());
-			if (sv.ptrvalue)
+			auto s = buf.extractString();
+			Object* sv = global.type_stringtable.update(s);
+			if (*sv)
 			{
-				t = cast(Type) sv.ptrvalue;
+				t = cast(Type) *sv;
 debug {
 				if (!t.deco)
 					writef("t = %s\n", t.toChars());
@@ -844,8 +848,8 @@
 			}
 			else
 			{
-				sv.ptrvalue = cast(void*)this;
-				deco = sv.lstring.string_;
+				*sv = this;
+				deco = s;
 				//printf("new value, deco = '%s' %p\n", t.deco, t.deco);
 			}
 		}
@@ -864,10 +868,10 @@
 		if (!t.deco)
 			return t.merge();
 
-		StringValue* sv = global.type_stringtable.lookup(t.deco);
-		if (sv && sv.ptrvalue)
+		Object* sv = global.type_stringtable.lookup(t.deco);
+		if (sv && *sv)
 		{
-			t = cast(Type)sv.ptrvalue;
+			t = cast(Type)*sv;
 			assert(t.deco);
 		}
 		else
@@ -1173,9 +1177,7 @@
 
 		if (!t)
 		{
-			uint sz = this.classinfo.init.length;
-			t = cast(Type)GC.malloc(sz);
-			memcpy(cast(void*)t, cast(void*)this, sz);
+			t = cloneThis(this);
 			t.mod = mod & ~MODshared;
 			t.deco = null;
 			t.arrayof = null;
@@ -1709,28 +1711,10 @@
 		assert(false);
 	}
 
-version (DumbClone) {
 	final Type clone()
 	{
-		auto size = this.classinfo.init.length;
-		auto ptr = GC.malloc(size);
-		memcpy(ptr, cast(void*)this, size);
-
-		return cast(Type)ptr;
+		return cloneThis(this);
 	}
-} else {
-	final Type cloneTo(Type t)
-	{
-		t.ctype = ctype;
-		return t;
-	}
-
-	Type clone()
-	{
-		assert(this.classinfo is Type.classinfo);
-		return cloneTo(new Type(ty));
-	}
-}
 
     Type arrayOf()
 	{
@@ -2847,7 +2831,7 @@
 	{
 		return null;
 	}
-	
+
 	@property
 	static ref Type[TY.TMAX] basic()
 	{