diff dmd/IndexExp.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 60bb0fe4563e
children b0d41ff5e0df
line wrap: on
line diff
--- a/dmd/IndexExp.d	Sun Oct 10 10:38:55 2010 +0400
+++ b/dmd/IndexExp.d	Sun Oct 17 07:42:00 2010 +0400
@@ -12,6 +12,7 @@
 import dmd.Type;
 import dmd.ScopeDsymbol;
 import dmd.TY;
+import dmd.Util;
 import dmd.ArrayScopeSymbol;
 import dmd.PREC;
 import dmd.TypeNext;
@@ -55,6 +56,7 @@
 
 	this(Loc loc, Expression e1, Expression e2)
 	{
+		register();
 		super(loc, TOK.TOKindex, IndexExp.sizeof, e1, e2);
 		//printf("IndexExp.IndexExp('%s')\n", toChars());
 	}
@@ -82,7 +84,7 @@
 		t1 = e1.type.toBasetype();
 
 		if (t1.ty == Tsarray || t1.ty == Tarray || t1.ty == Ttuple)
-		{	
+		{
 			// Create scope for 'length' variable
 			sym = new ArrayScopeSymbol(sc, this);
 			sym.loc = loc;
@@ -132,7 +134,7 @@
 			}
 
 			case Taarray:
-			{   
+			{
 				TypeAArray taa = cast(TypeAArray)t1;
 				if (!arrayTypeCompatible(e2.loc, e2.type, taa.index))
 				{
@@ -152,7 +154,7 @@
 				TypeTuple tup;
 
 				if (e1.op == TOKtuple)
-				{	
+				{
 					te = cast(TupleExp)e1;
 					length = te.exps.dim;
 				}
@@ -229,10 +231,10 @@
 		Expression e1 = this.e1.optimize(WANTvalue | (result & WANTinterpret));
 		e1 = fromConstInitializer(result, e1);
 		if (this.e1.op == TOKvar)
-		{	
+		{
 			VarExp ve = cast(VarExp)this.e1;
 			if (ve.var.storage_class & STCmanifest)
-			{   
+			{
 				/* We generally don't want to have more than one copy of an
 				 * array literal, but if it's an enum we have to because the
 				 * enum isn't stored elsewhere. See Bugzilla 2559
@@ -295,9 +297,8 @@
 			ExpInitializer ieto;
 			VarDeclaration vto;
 
-			vto = new VarDeclaration(vd.loc, vd.type, vd.ident, vd.init);
-			///*vto = *vd;
-			memcpy(cast(void*)vto, cast(void*)vd, VarDeclaration.classinfo.init.length);
+			vto = cloneThis(vd);
+
 			vto.parent = ids.parent;
 			vto.csym = null;
 			vto.isym = null;
@@ -324,7 +325,7 @@
 		e1.scanForNestedRef(sc);
 
 		if (lengthVar)
-		{	
+		{
 			//printf("lengthVar\n");
 			lengthVar.parent = sc.parent;
 		}
@@ -391,7 +392,7 @@
 
 				// Construct: ((e || ModuleAssert(line)),n)
 				Symbol* sassert = irs.blx.module_.toModuleArray();
-				
+
 				ea = el_bin(OPcall,TYvoid,el_var(sassert),
 				el_long(TYint, loc.linnum));
 				e = el_bin(OPoror,TYvoid,e,ea);
@@ -402,7 +403,7 @@
 				e.Enumbytes = cast(uint)type.size();
 		}
 		else
-		{	
+		{
 			elem* einit = resolveLengthVar(lengthVar, &n1, t1);
 			elem* n2 = e2.toElem(irs);
 
@@ -442,7 +443,7 @@
 
 			n1 = array_toPtr(t1, n1);
 
-			{   
+			{
 				elem* escale;
 
 				escale = el_long(TYint, t1.nextOf().size());
@@ -450,7 +451,7 @@
 				e = el_bin(OPadd, TYnptr, n1, n2);
 				e = el_una(OPind, type.totym(), e);
 				if (tybasic(e.Ety) == TYstruct || tybasic(e.Ety) == TYarray)
-				{	
+				{
 					e.Ety = TYstruct;
 					e.Enumbytes = cast(uint)type.size();
 				}