changeset 109:ceda59b4d255

expression.c changes, now only ddoc should be left
author Trass3r
date Tue, 31 Aug 2010 22:08:52 +0200
parents 6da99741178e
children 12c0c84d13fd
files dmd/AddrExp.d dmd/AndExp.d dmd/AssocArrayLiteralExp.d dmd/CallExp.d dmd/CastExp.d dmd/DivExp.d dmd/DotIdExp.d dmd/Expression.d dmd/IntegerExp.d dmd/IsExp.d dmd/ModExp.d dmd/MulExp.d dmd/NegExp.d dmd/OrExp.d dmd/StructLiteralExp.d dmd/VarExp.d dmd/XorExp.d dmd/expression/Util.d
diffstat 18 files changed, 67 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/AddrExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/AddrExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -65,7 +65,6 @@
 				return new ErrorExp();
 			}
 
-		//printf("test3 deco = %p\n", e1.type.deco);
 			type = e1.type.pointerTo();
 
 			// See if this should really be a delegate
--- a/dmd/AndExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/AndExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -49,11 +49,10 @@
 			else
 			{
 				typeCombine(sc);
-				if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
-				{   
+				if (!e1.isArrayOperand())
 					e1.checkIntegral();
+				if (!e2.isArrayOperand())
 					e2.checkIntegral();
-				}
 			}
 		}
 		return this;
--- a/dmd/AssocArrayLiteralExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/AssocArrayLiteralExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -57,6 +57,9 @@
 			printf("AssocArrayLiteralExp.semantic('%s')\n", toChars());
 		}
 
+		if (type)
+			return this;
+
 		// Run semantic() on each element
 		for (size_t i = 0; i < keys.dim; i++)
 		{	auto key = keys[i];
--- a/dmd/CallExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/CallExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -184,7 +184,8 @@
 
 					return new RemoveExp(loc, dotid.e1, key);
 				}
-				else if (e1ty == TY.Tarray || e1ty == TY.Tsarray || e1ty == TY.Taarray)
+				else if (e1ty == TY.Tarray || e1ty == TY.Tsarray ||
+				         (e1ty == Taarray && dotid.ident != Id.apply && dotid.ident != Id.applyReverse))
 				{
 					if (!arguments)
 						arguments = new Expressions();
--- a/dmd/CastExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/CastExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -106,6 +106,12 @@
 				}
 			}
 
+			if (e1.op == TOKtemplate)
+			{
+			    error("cannot cast template %s to type %s", e1.toChars(), to.toChars());
+			    return new ErrorExp();
+			}
+
 			Type t1b = e1.type.toBasetype();
 			Type tob = to.toBasetype();
 			if (tob.ty == TY.Tstruct &&
--- a/dmd/DivExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/DivExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -41,11 +41,11 @@
 			return e;
 
 		typeCombine(sc);
-		if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
-		{	
+		if (!e1.isArrayOperand())
 			e1.checkArithmetic();
+		if (!e2.isArrayOperand())
 			e2.checkArithmetic();
-		}
+
 		if (type.isfloating())
 		{	
 			Type t1 = e1.type;
--- a/dmd/DotIdExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/DotIdExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -337,11 +337,13 @@
 			 */
 			uint errors = global.errors;
 			global.gag++;
+			Type t1 = e1.type;
 			e = e1.type.dotExp(sc, e1, ident);
 			global.gag--;
 			if (errors != global.errors)	// if failed to find the property
 			{
 				global.errors = errors;
+				e1.type = t1;		// kludge to restore type
 				e = new DotIdExp(loc, new IdentifierExp(loc, Id.empty), ident);
 				e = new CallExp(loc, e, e1);
 			}
--- a/dmd/Expression.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/Expression.d	Tue Aug 31 22:08:52 2010 +0200
@@ -135,6 +135,11 @@
 
 		if (t.ty == TY.Tfunction || e.op == TOK.TOKoverloadset)
 		{
+static if(false)
+{
+		    if (t.ty == Tfunction && !(cast(TypeFunction)t).isproperty)
+			error(e.loc, "not a property %s\n", e.toChars());
+}
 			e = new CallExp(e.loc, e);
 			e = e.semantic(sc);
 		}
@@ -737,14 +742,13 @@
     
     Expression checkToPointer()
 	{
-		Expression e;
-		Type tb;
+		//writef("Expression::checkToPointer()\n");
+		Expression e = this;
 
-		//printf("Expression::checkToPointer()\n");
-		e = this;
-
+version(SARRAYVALUE) {} else
+{
 		// If C static array, convert to pointer
-		tb = type.toBasetype();
+		Type tb = type.toBasetype();
 		if (tb.ty == Tsarray)
 		{	
 			TypeSArray ts = cast(TypeSArray)tb;
@@ -754,6 +758,7 @@
 				e = new AddrExp(loc, this);
 			e.type = ts.next.pointerTo();
 		}
+}
 		return e;
 	}
     
--- a/dmd/IntegerExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/IntegerExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -168,11 +168,7 @@
 					 */
 					if (!global.errors)
 					{
-						printf("ty = %d, %d\n", type.ty, t.ty);
-						if (type.ty == Tenum) {
-							printf("test1\n");
-						}
-						///type.print();
+						writef("%s %p\n", type.toChars(), type);
 						assert(0);
 					}
 					break;
--- a/dmd/IsExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/IsExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -83,6 +83,7 @@
 		Type tded;
 
 		/* is(targ id tok tspec)
+		 * is(targ id :  tok2)
 		 * is(targ id == tok2)
 		 */
 
@@ -238,14 +239,13 @@
 			 * If true, declare id as an alias for the specialized type.
 			 */
 
-			MATCH m;
 			assert(parameters && parameters.dim);
 
 			scope Objects dedtypes = new Objects();
 			dedtypes.setDim(parameters.dim);
 			dedtypes.zero();
 
-			m = targ.deduceType(null, tspec, parameters, dedtypes);
+			MATCH m = targ.deduceType(null, tspec, parameters, dedtypes);
 			if (m == MATCHnomatch ||
 				(m != MATCHexact && tok == TOKequal))
 			{
--- a/dmd/ModExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/ModExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -40,11 +40,11 @@
 			return e;
 
 		typeCombine(sc);
-		if (e1.op != TOKslice && e2.op != TOKslice)
-		{	
+		if (!e1.isArrayOperand())
 			e1.checkArithmetic();
+		if (!e2.isArrayOperand())
 			e2.checkArithmetic();
-		}
+
 		if (type.isfloating())
 		{	
 			type = e1.type;
--- a/dmd/MulExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/MulExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -46,11 +46,11 @@
 			return e;
 
 		typeCombine(sc);
-		if (e1.op != TOKslice && e2.op != TOKslice)
-		{	
+		if (!e1.isArrayOperand())
 			e1.checkArithmetic();
+		if (!e2.isArrayOperand())
 			e2.checkArithmetic();
-		}
+
 		if (type.isfloating())
 		{	
 			Type t1 = e1.type;
--- a/dmd/NegExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/NegExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -41,7 +41,7 @@
 				return e;
 
 			e1.checkNoBool();
-			if (e1.op != TOKslice)
+			if (!e1.isArrayOperand())
 				e1.checkArithmetic();
 
 			type = e1.type;
--- a/dmd/OrExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/OrExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -48,11 +48,10 @@
 			else
 			{
 				typeCombine(sc);
-				if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
-				{
+				if (!e1.isArrayOperand())
 					e1.checkIntegral();
+				if (!e2.isArrayOperand())
 					e2.checkIntegral();
-				}
 			}
 		}
 
--- a/dmd/StructLiteralExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/StructLiteralExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -20,6 +20,7 @@
 import dmd.OutBuffer;
 import dmd.Loc;
 import dmd.Scope;
+import dmd.Initializer;
 import dmd.InlineCostState;
 import dmd.IRState;
 import dmd.InlineDoState;
@@ -138,7 +139,18 @@
 				{   
 					e = v.init.toExpression();
 					if (!e)
+					{
 						error("cannot make expression out of initializer for %s", v.toChars());
+						e = new ErrorExp();
+					}
+					else if (v.scope_)
+					{
+						// Do deferred semantic anaylsis
+						Initializer i2 = v.init.syntaxCopy();
+						i2 = i2.semantic(v.scope_, v.type);
+						e = i2.toExpression();
+						v.scope_ = null;
+					}
 				}
 				else
 				{	
@@ -154,6 +166,10 @@
 		return this;
 	}
 
+	/**************************************
+	 * Gets expression at offset of type.
+	 * Returns null if not found.
+	 */
 	Expression getField(Type type, uint offset)
 	{
 		//printf("StructLiteralExp.getField(this = %s, type = %s, offset = %u)\n",
--- a/dmd/VarExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/VarExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -216,8 +216,8 @@
 	override Expression modifiableLvalue(Scope sc, Expression e)
 	{
 		//printf("VarExp::modifiableLvalue('%s')\n", var.toChars());
-		if (type && type.toBasetype().ty == TY.Tsarray)
-			error("cannot change reference to static array '%s'", var.toChars());
+		//if (type && type.toBasetype().ty == TY.Tsarray)
+		//	error("cannot change reference to static array '%s'", var.toChars());
 
 		var.checkModify(loc, sc, type);
 
--- a/dmd/XorExp.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/XorExp.d	Tue Aug 31 22:08:52 2010 +0200
@@ -47,11 +47,10 @@
 			else
 			{
 				typeCombine(sc);
-				if (e1.op != TOKslice && e2.op != TOKslice)
-				{
+				if (!e1.isArrayOperand())
 					e1.checkIntegral();
+				if (!e2.isArrayOperand())
 					e2.checkIntegral();
-				}
 			}
 		}
 		return this;
--- a/dmd/expression/Util.d	Tue Aug 31 21:41:01 2010 +0200
+++ b/dmd/expression/Util.d	Tue Aug 31 22:08:52 2010 +0200
@@ -631,6 +631,8 @@
 				if (p.type != arg.type)
 				{
 					//printf("arg.type = %s, p.type = %s\n", arg.type.toChars(), p.type.toChars());
+					if (arg.op == TOKtype)
+						arg.error("cannot pass type %s as function argument", arg.toChars());
 					arg = arg.implicitCastTo(sc, p.type);
 					arg = arg.optimize(WANT.WANTvalue);
 				}
@@ -644,12 +646,15 @@
 				arg = arg.modifiableLvalue(sc, arg);
 			}
 
+			tb = arg.type.toBasetype();
+version(SARRAYVALUE) {} else
+{
 			// Convert static arrays to pointers
-			tb = arg.type.toBasetype();
 			if (tb.ty == TY.Tsarray)
 			{
 				arg = arg.checkToPointer();
 			}
+}
 version (DMDV2) {
 			if (tb.ty == TY.Tstruct && !(p.storageClass & (STC.STCref | STC.STCout)))
 			{