diff dmd/expression/Util.d @ 84:be2ab491772e

Expressions -> Vector!Expression
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 30 Aug 2010 16:12:19 +0100
parents 43073c7c7769
children 5c859d5fbe27
line wrap: on
line diff
--- a/dmd/expression/Util.d	Mon Aug 30 18:42:04 2010 +0400
+++ b/dmd/expression/Util.d	Mon Aug 30 16:12:19 2010 +0100
@@ -317,12 +317,9 @@
 {
     if (exps)
     {
-		for (size_t i = 0; i < exps.dim; i++)
+		foreach (ref Expression e; exps)
 		{   
-			Expression e = cast(Expression)exps.data[i];
-
 			e = e.semantic(sc);
-			exps.data[i] = cast(void*)e;
 		}
     }
 }
@@ -337,10 +334,8 @@
     {
 		expandTuples(exps);
 		
-		for (size_t i = 0; i < exps.dim; i++)
+		foreach (size_t i, ref Expression arg; exps)
 		{   
-			Expression arg = cast(Expression)exps.data[i];
-
 			if (!arg.type)
 			{
 debug {
@@ -353,7 +348,6 @@
 			}
 
 			arg = resolveProperties(sc, arg);
-			exps.data[i] = cast(void*) arg;
 
 			//arg.rvalue();
 static if (false) {
@@ -361,7 +355,6 @@
 			{
 				arg = new AddrExp(arg.loc, arg);
 				arg = arg.semantic(sc);
-				exps.data[i] = cast(void*) arg;
 			}
 }
 		}
@@ -503,7 +496,7 @@
 		Expression arg;
 
 		if (i < nargs)
-			arg = cast(Expression)arguments.data[i];
+			arg = arguments[i];
 		else
 			arg = null;
 
@@ -511,7 +504,7 @@
 
 		if (i < nparams)
 		{
-			Argument p = Argument.getNth(tf.parameters, i);
+			auto p = Argument.getNth(tf.parameters, i);
 
 			if (!arg)
 			{
@@ -537,7 +530,7 @@
 } else {
 				arg = arg.copy();
 }
-				arguments.push(cast(void*)arg);
+				arguments.push(arg);
 				nargs++;
 			}
 
@@ -581,13 +574,13 @@
 
 						for (size_t u = i; u < nargs; u++)
 						{   
-							Expression a = cast(Expression)arguments.data[u];
+							auto a = arguments[u];
 							if (tret && !(cast(TypeArray)tb).next.equals(a.type))
 								a = a.toDelegate(sc, tret);
 
 							Expression e = new VarExp(loc, v);
 							e = new IndexExp(loc, e, new IntegerExp(u + 1 - nparams));
-							AssignExp ae = new AssignExp(loc, e, a);
+							auto ae = new AssignExp(loc, e, a);
 
 			version (DMDV2) {
 							ae.op = TOK.TOKconstruct;
@@ -612,7 +605,7 @@
 						Expressions args = new Expressions();
 						args.setDim(nargs - i);
 						for (size_t u = i; u < nargs; u++)
-							args.data[u - i] = arguments.data[u];
+							args[u - i] = arguments[u];
 						arg = new NewExp(loc, null, null, p.type, args);
 						break;
 					}
@@ -768,7 +761,7 @@
 	}
 
 		arg = arg.optimize(WANT.WANTvalue);
-		arguments.data[i] = cast(void*) arg;
+		arguments[i] = arg;
 		if (done)
 			break;
     }
@@ -776,8 +769,8 @@
     // If D linkage and variadic, add _arguments[] as first argument
     if (tf.linkage == LINK.LINKd && tf.varargs == 1)
     {
-		Expression e = createTypeInfoArray(sc, cast(Expression*)&arguments.data[nparams], arguments.dim - nparams);
-		arguments.insert(0, cast(void*)e);
+		auto e = createTypeInfoArray(sc, &arguments[nparams], arguments.dim - nparams);
+		arguments.insert(0, e);
     }
 }
 
@@ -790,8 +783,8 @@
 {
     if (exps)
     {
-	for (size_t i = 0; i < exps.dim; i++)
-	{   Expression e = cast(Expression)exps.data[i];
+	foreach (e; exps)
+	{
 	    if (e && e.canThrow())
 		return true;
 	}
@@ -811,17 +804,17 @@
     {
 		for (size_t i = 0; i < exps.dim; i++)
 		{   
-			Expression arg = cast(Expression)exps.data[i];
+			auto arg = exps[i];
 			if (!arg)
 				continue;
 
 			// Look for tuple with 0 members
 			if (arg.op == TOK.TOKtype)
 			{
-				TypeExp e = cast(TypeExp)arg;
+				auto e = cast(TypeExp)arg;
 				if (e.type.toBasetype().ty == TY.Ttuple)
 				{   
-					TypeTuple tt = cast(TypeTuple)e.type.toBasetype();
+					auto tt = cast(TypeTuple)e.type.toBasetype();
 
 					if (!tt.arguments || tt.arguments.dim == 0)
 					{
@@ -837,7 +830,7 @@
 			// Inline expand all the tuples
 			while (arg.op == TOK.TOKtuple)
 			{	
-				TupleExp te = cast(TupleExp)arg;
+				auto te = cast(TupleExp)arg;
 
 				exps.remove(i);		// remove arg
 				exps.insert(i, te.exps);	// replace with tuple contents
@@ -845,7 +838,7 @@
 				if (i == exps.dim)
 					return;		// empty tuple, no more arguments
 
-				arg = cast(Expression)exps.data[i];
+				arg = exps[i];
 			}
 		}
     }
@@ -861,10 +854,8 @@
     {	
 		scope OutBuffer argbuf = new OutBuffer();
 
-		for (size_t i = 0; i < arguments.dim; i++)
+		foreach (size_t i, Expression arg; arguments)
 		{   
-			Expression arg = cast(Expression)arguments.data[i];
-
 			if (i)
 				buf.writeByte(',');
 
@@ -1071,7 +1062,7 @@
 Expression eval_builtin(BUILTIN builtin, Expressions arguments)
 {
 	assert(arguments && arguments.dim);
-    Expression arg0 = cast(Expression)arguments.data[0];
+    auto arg0 = arguments[0];
     Expression e = null;
     switch (builtin)
     {
@@ -1521,10 +1512,8 @@
 {
     if (arguments)
     {
-		for (size_t i = 0; i < arguments.dim; i++)
+		foreach (size_t i, Expression arg; arguments)
 		{   
-			Expression arg = cast(Expression)arguments.data[i];
-
 			if (arg)
 			{	
 				if (i)
@@ -1554,10 +1543,8 @@
     //printf("arrayExpressionScanForNestedRef(%p)\n", a);
     if (a)
     {
-		for (int i = 0; i < a.dim; i++)
+		foreach (e; a)
 		{   
-			Expression e = cast(Expression)a.data[i];
-
 			if (e)
 			{
 				e.scanForNestedRef(sc);