diff dmd/Expression.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 7171e6ea651d
children cd48cb899aee
line wrap: on
line diff
--- a/dmd/Expression.d	Sun Oct 10 10:38:55 2010 +0400
+++ b/dmd/Expression.d	Sun Oct 17 07:42:00 2010 +0400
@@ -183,7 +183,9 @@
     return type ? type.toChars() : "null";
 }
 
-class Expression
+import dmd.TObject;
+
+class Expression : TObject
 {
     Loc loc;			// file location
     TOK op;		// handy to minimize use of dynamic_cast
@@ -192,6 +194,7 @@
 
     this(Loc loc, TOK op, int size)
 	{
+		register();
 		this.loc = loc;
 		//writef("Expression.Expression(op = %d %s) this = %p\n", op, to!(string)(op), this);
 		this.op = op;
@@ -207,23 +210,9 @@
 	/*********************************
 	 * Does *not* do a deep copy.
 	 */
-    Expression copy()	/// bad bad bad
+    Expression copy()
 	{
-		Expression e;
-		if (!size)
-		{
-debug {
-			writef("No expression copy for: %s\n", toChars());
-			writef("op = %d\n", op);
-			dump(0);
-}
-			assert(0);
-		}
-		auto size = this.classinfo.init.length;
-		auto ptr = GC.malloc(size);
-		memcpy(ptr, cast(void*)this, size);
-
-		return cast(Expression)ptr;
+		return cloneThis(this);
 	}
 	
     Expression syntaxCopy()