diff dmd/SliceExp.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 af1bebfd96a4
children b0d41ff5e0df
line wrap: on
line diff
--- a/dmd/SliceExp.d	Sun Oct 10 10:38:55 2010 +0400
+++ b/dmd/SliceExp.d	Sun Oct 17 07:42:00 2010 +0400
@@ -12,6 +12,7 @@
 import dmd.InterState;
 import dmd.ScopeDsymbol;
 import dmd.WANT;
+import dmd.Util;
 import dmd.ArrayScopeSymbol;
 import dmd.CallExp;
 import dmd.DotIdExp;
@@ -64,6 +65,7 @@
 
 	this(Loc loc, Expression e1, Expression lwr, Expression upr)
 	{
+		register();
 		super(loc, TOK.TOKslice, SliceExp.sizeof, e1);
 		this.upr = upr;
 		this.lwr = lwr;
@@ -133,7 +135,7 @@
 					e = new CallExp(loc, e, lwr, upr);
 				}
 				else
-				{	
+				{
 					assert(!upr);
 					e = new CallExp(loc, e);
 				}
@@ -165,13 +167,13 @@
 			}
 
 			if (lwr)
-			{	
+			{
 				lwr = lwr.semantic(sc2);
 				lwr = resolveProperties(sc2, lwr);
 				lwr = lwr.implicitCastTo(sc2, Type.tsize_t);
 			}
 			if (upr)
-			{	
+			{
 				upr = upr.semantic(sc2);
 				upr = resolveProperties(sc2, upr);
 				upr = upr.implicitCastTo(sc2, Type.tsize_t);
@@ -193,12 +195,12 @@
 			TypeTuple tup;
 
 			if (e1.op == TOKtuple)		// slicing an expression tuple
-			{   
+			{
 				te = cast(TupleExp)e1;
 				length = te.exps.dim;
 			}
 			else if (e1.op == TOKtype)	// slicing a type tuple
-			{   
+			{
 				tup = cast(TypeTuple)t;
 				length = Parameter.dim(tup.arguments);
 			}
@@ -206,27 +208,27 @@
 				assert(0);
 
 			if (i1 <= i2 && i2 <= length)
-			{   
+			{
 				size_t j1 = cast(size_t) i1;
 				size_t j2 = cast(size_t) i2;
 
 				if (e1.op == TOKtuple)
-				{	
+				{
 					auto exps = new Expressions;
 					exps.setDim(j2 - j1);
 					for (size_t i = 0; i < j2 - j1; i++)
-					{   
+					{
 						auto e2 = te.exps[j1 + i];
 						exps[i] = e2;
 					}
 					e = new TupleExp(loc, exps);
 				}
 				else
-				{	
+				{
 					auto args = new Parameters;
 					args.reserve(j2 - j1);
 					for (size_t i = j1; i < j2; i++)
-					{   
+					{
 						auto arg = Parameter.getNth(tup.arguments, i);
 						args.push(arg);
 					}
@@ -265,7 +267,7 @@
 	{
 		e1.checkEscape();
 	}
-    
+
     override void checkEscapeRef()
     {
         e1.checkEscapeRef();
@@ -315,9 +317,9 @@
 		e = this;
 		e1 = e1.optimize(WANTvalue | (result & WANTinterpret));
 		if (!lwr)
-		{	
+		{
 			if (e1.op == TOKstring)
-			{   
+			{
 				// Convert slice of string literal into dynamic array
 				Type t = e1.type.toBasetype();
 				if (t.nextOf())
@@ -427,7 +429,7 @@
 					goto L2;
 				}
 				else if (t1.ty == Tsarray)
-				{	
+				{
 					TypeSArray tsa = cast(TypeSArray)t1;
 					ulong length = tsa.dim.toInteger();
 
@@ -488,7 +490,7 @@
 		e1.scanForNestedRef(sc);
 
 		if (lengthVar)
-		{	
+		{
 			//printf("lengthVar\n");
 			lengthVar.parent = sc.parent;
 		}
@@ -534,17 +536,15 @@
 		are.e1 = e1.doInline(ids);
 
 		if (lengthVar)
-		{	
+		{
 			//printf("lengthVar\n");
 			VarDeclaration vd = lengthVar;
 			ExpInitializer ie;
 			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;