diff dmd/ArrayLiteralExp.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents 9e39c7de8438
children af1bebfd96a4
line wrap: on
line diff
--- a/dmd/ArrayLiteralExp.d	Sun Sep 05 15:32:22 2010 +0400
+++ b/dmd/ArrayLiteralExp.d	Thu Sep 09 22:51:44 2010 +0100
@@ -58,58 +58,19 @@
 
 	override Expression semantic(Scope sc)
 	{
-		Expression e;
-		Type t0 = null;
-
 	version (LOGSEMANTIC) {
 		printf("ArrayLiteralExp.semantic('%s')\n", toChars());
 	}
 		if (type)
 			return this;
 
-		// Run semantic() on each element
-		foreach (ref Expression e; elements)
-		{	
-			e = e.semantic(sc);
-			assert(e.type);
-		}
+		arrayExpressionSemantic(elements, sc);    // run semantic() on each element
 
 		expandTuples(elements);
 
-		foreach (size_t i, Expression e; elements)
-		{	
-			if (!e.type)
-				error("%s has no value", e.toChars());
-
-			e = resolveProperties(sc, e);
-
-			ubyte committed = 1;
-			if (e.op == TOKstring)
-				committed = (cast(StringExp)e).committed;
-
-			if (!t0)
-			{   
-				t0 = e.type;
-				// Convert any static arrays to dynamic arrays
-				if (t0.ty == Tsarray)
-				{
-					t0 = (cast(TypeSArray)t0).next.arrayOf();
-					e = e.implicitCastTo(sc, t0);
-				}
-			}
-			else
-				e = e.implicitCastTo(sc, t0);
-
-			if (!committed && e.op == TOKstring)
-			{   
-				auto se = cast(StringExp)e;
-				se.committed = 0;
-			}
-			elements[i] = e;
-		}
-
-		if (!t0)
-			t0 = Type.tvoid;
+		Type t0;
+		elements = arrayExpressionToCommonType(sc, elements, &t0);
+		
 		type = new TypeSArray(t0, new IntegerExp(elements.dim));
 		type = type.semantic(loc, sc);
 		return this;