changeset 56:51605de93870

TupleExp.optimize UnrolledLoopStatement.ctor UnrolledLoopStatement.semantic UnrolledLoopStatement.blockExit OrOrExp.checkSideEffect FuncExp.syntaxCopy FuncLiteralDeclaration.syntaxCopy WhileStatement.hasBreak StructInitializer.toExpression StructLiteralExp.ctor StructLiteralExp.optimize BinExp.commonSemanticAssign ModAssignExp.opId Argument.isLazyArray CommaExp.implicitConvTo CommaExp.castTo TypeClass.isBaseOf createTypeInfoArray TypeTuple.getTypeInfoDeclaration TypeInfoTupleDeclaration.ctor TypeNext.constConv XorExp.implicitConvTo TemplateParameter.isTemplateValueParameter
author korDen
date Sat, 21 Aug 2010 14:16:53 +0400
parents 8c2c7b7579f8
children 3adbb28755e8
files commands.txt dmd/Argument.d dmd/ArrayInitializer.d dmd/BE.d dmd/BinExp.d dmd/CommaExp.d dmd/Dsymbol.d dmd/FuncExp.d dmd/FuncLiteralDeclaration.d dmd/ModAssignExp.d dmd/OrOrExp.d dmd/Parser.d dmd/StructInitializer.d dmd/StructLiteralExp.d dmd/TemplateParameter.d dmd/TupleExp.d dmd/TypeClass.d dmd/TypeNext.d dmd/TypeQualified.d dmd/TypeTuple.d dmd/UnrolledLoopStatement.d dmd/WhileStatement.d dmd/XorExp.d
diffstat 23 files changed, 282 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/commands.txt	Sat Aug 21 13:28:16 2010 +0400
+++ b/commands.txt	Sat Aug 21 14:16:53 2010 +0400
@@ -333,6 +333,7 @@
 dmd\TypeTypedef.d
 dmd\TypeTypeof.d
 dmd\TypedefDeclaration.d
+dmd\TypeInfoTupleDeclaration
 dmd\UnionDeclaration.d
 dmd\UnitTestDeclaration.d
 dmd\Utf.d
--- a/dmd/Argument.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/Argument.d	Sat Aug 21 14:16:53 2010 +0400
@@ -2,6 +2,9 @@
 
 import dmd.Type;
 import dmd.Identifier;
+import dmd.TypeArray;
+import dmd.TypeFunction;
+import dmd.TypeDelegate;
 import dmd.TypeTuple;
 import dmd.TY;
 import dmd.Expression;
@@ -40,9 +43,32 @@
 		return new Argument(storageClass, type ? type.syntaxCopy() : null, ident, defaultArg ? defaultArg.syntaxCopy() : null);
 	}
 	
+	/****************************************************
+	 * Determine if parameter is a lazy array of delegates.
+	 * If so, return the return type of those delegates.
+	 * If not, return null.
+	 */
     Type isLazyArray()
 	{
-		assert(false);
+	//    if (inout == Lazy)
+		{
+			Type tb = type.toBasetype();
+			if (tb.ty == Tsarray || tb.ty == Tarray)
+			{
+				Type tel = (cast(TypeArray)tb).next.toBasetype();
+				if (tel.ty == Tdelegate)
+				{
+					TypeDelegate td = cast(TypeDelegate)tel;
+					TypeFunction tf = cast(TypeFunction)td.next;
+
+					if (!tf.varargs && Argument.dim(tf.parameters) == 0)
+					{
+						return tf.next;	// return type of delegate
+					}
+				}
+			}
+		}
+		return null;
 	}
 	
     void toDecoBuffer(OutBuffer buf)
--- a/dmd/ArrayInitializer.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/ArrayInitializer.d	Sat Aug 21 14:16:53 2010 +0400
@@ -340,6 +340,7 @@
 				else if (dim > tadim)
 				{
 					debug writef("1: ");
+					assert(false);
 					error(loc, "too many initializers, %d, for array[%d]", dim, tadim);
 				}
 				break;
--- a/dmd/BE.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/BE.d	Sat Aug 21 14:16:53 2010 +0400
@@ -13,4 +13,7 @@
     BEbreak =	 0x20,
     BEcontinue = 0x40,
     BEany = (BEfallthru | BEthrow | BEreturn | BEgoto | BEhalt),
-}
\ No newline at end of file
+}
+
+import dmd.EnumUtils;
+mixin(BringToCurrentScope!(BE));
\ No newline at end of file
--- a/dmd/BinExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/BinExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -423,9 +423,47 @@
 		return this;
 	}
 	
+	/***************************
+	 * Common semantic routine for some xxxAssignExp's.
+	 */
     Expression commonSemanticAssign(Scope sc)
 	{
-		assert(false);
+		Expression e;
+
+		if (!type)
+		{
+			BinExp.semantic(sc);
+			e2 = resolveProperties(sc, e2);
+
+			e = op_overload(sc);
+			if (e)
+				return e;
+
+			if (e1.op == TOKslice)
+			{   
+				// T[] op= ...
+				typeCombine(sc);
+				type = e1.type;
+				return arrayOp(sc);
+			}
+
+			e1 = e1.modifiableLvalue(sc, e1);
+			e1.checkScalar();
+			type = e1.type;
+			if (type.toBasetype().ty == Tbool)
+			{
+				error("operator not allowed on bool expression %s", toChars());
+			}
+			typeCombine(sc);
+			e1.checkArithmetic();
+			e2.checkArithmetic();
+
+			if (op == TOKmodass && e2.type.iscomplex())
+			{   error("cannot perform modulo complex arithmetic");
+				return new ErrorExp();
+			}
+		}
+		return this;
 	}
 
     Expression commonSemanticAssignIntegral(Scope sc)
--- a/dmd/CommaExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/CommaExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -78,12 +78,25 @@
 	
     MATCH implicitConvTo(Type t)
 	{
-		assert(false);
+		return e2.implicitConvTo(t);
 	}
 	
     Expression castTo(Scope sc, Type t)
 	{
-		assert(false);
+		Expression e2c = e2.castTo(sc, t);
+		Expression e;
+
+		if (e2c != e2)
+		{
+			e = new CommaExp(loc, e1, e2c);
+			e.type = e2c.type;
+		}
+		else
+		{	
+			e = this;
+			e.type = e2.type;
+		}
+		return e;
 	}
 	
     Expression optimize(int result)
--- a/dmd/Dsymbol.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/Dsymbol.d	Sat Aug 21 14:16:53 2010 +0400
@@ -471,51 +471,45 @@
 	 * Returns:
 	 *	symbol found, null if not
 	 */
-    Dsymbol searchX(Loc loc, Scope sc, Identifier id)
+    Dsymbol searchX(Loc loc, Scope sc, Object o)
 	{
 		//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
 		Dsymbol s = toAlias();
 		Dsymbol sm;
 
-		/// HUH????
-		switch (id.dyncast())
+		if (auto ident = cast(Identifier)o)
+		{
+			sm = s.search(loc, ident, 0);
+		}
+		else if (auto st = cast(Dsymbol)o)
 		{
-			case DYNCAST.DYNCAST_IDENTIFIER:
-				sm = s.search(loc, id, 0);
-				break;
-
-			case DYNCAST.DYNCAST_DSYMBOL:
-			{  
-				assert(false);	/// how can it happen?
-				// It's a template instance
-				//printf("\ttemplate instance id\n");
-				Dsymbol st = cast(Dsymbol)id;
-				TemplateInstance ti = st.isTemplateInstance();
-				id = ti.name;
-				sm = s.search(loc, id, 0);
-				if (!sm)
-				{   
-					error("template identifier %s is not a member of %s %s", id.toChars(), s.kind(), s.toChars());
-					return null;
-				}
-				sm = sm.toAlias();
-				TemplateDeclaration td = sm.isTemplateDeclaration();
-				if (!td)
-				{
-					error("%s is not a template, it is a %s", id.toChars(), sm.kind());
-					return null;
-				}
-
-				ti.tempdecl = td;
-				if (!ti.semanticRun)
-					ti.semantic(sc);
-
-				sm = ti.toAlias();
-				break;
+			// It's a template instance
+			//printf("\ttemplate instance id\n");
+			TemplateInstance ti = st.isTemplateInstance();
+			Identifier id = ti.name;
+			sm = s.search(loc, cast(Identifier)id, 0);
+			if (!sm)
+			{   
+				error("template identifier %s is not a member of %s %s", id.toChars(), s.kind(), s.toChars());
+				return null;
+			}
+			sm = sm.toAlias();
+			TemplateDeclaration td = sm.isTemplateDeclaration();
+			if (!td)
+			{
+				error("%s is not a template, it is a %s", id.toChars(), sm.kind());
+				return null;
 			}
 
-			default:
-				assert(0);
+			ti.tempdecl = td;
+			if (!ti.semanticRun)
+				ti.semantic(sc);
+
+			sm = ti.toAlias();
+		}
+		else
+		{
+			assert(0);
 		}
 		return sm;
 	}
--- a/dmd/FuncExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/FuncExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -33,7 +33,7 @@
 
 	Expression syntaxCopy()
 	{
-		assert(false);
+		return new FuncExp(loc, cast(FuncLiteralDeclaration)fd.syntaxCopy(null));
 	}
 
 	Expression semantic(Scope sc)
--- a/dmd/FuncLiteralDeclaration.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/FuncLiteralDeclaration.d	Sat Aug 21 14:16:53 2010 +0400
@@ -40,9 +40,20 @@
 		assert(false);
 	}
 
-    Dsymbol syntaxCopy(Dsymbol)
+    Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+		FuncLiteralDeclaration f;
+
+		//printf("FuncLiteralDeclaration.syntaxCopy('%s')\n", toChars());
+		if (s)
+			f = cast(FuncLiteralDeclaration)s;
+		else
+		{	
+			f = new FuncLiteralDeclaration(loc, endloc, type.syntaxCopy(), tok, fes);
+			f.ident = ident;		// keep old identifier
+		}
+		FuncDeclaration.syntaxCopy(f);
+		return f;
 	}
 	
     bool isNested()
--- a/dmd/ModAssignExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/ModAssignExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -10,6 +10,7 @@
 import dmd.Identifier;
 import dmd.IRState;
 import dmd.TOK;
+import dmd.Id;
 
 import dmd.backend.elem;
 
@@ -42,7 +43,7 @@
 
     Identifier opId()    /* For operator overloading */
 	{
-		assert(false);
+		return Id.modass;
 	}
 
     elem* toElem(IRState* irs)
--- a/dmd/OrOrExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/OrOrExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -115,7 +115,15 @@
 
     bool checkSideEffect(int flag)
 	{
-		assert(false);
+		if (flag == 2)
+		{
+			return e1.checkSideEffect(2) || e2.checkSideEffect(2);
+		}
+		else
+		{	
+			e1.checkSideEffect(1);
+			return e2.checkSideEffect(flag);
+		}
 	}
 
     elem* toElem(IRState* irs)
--- a/dmd/Parser.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/Parser.d	Sat Aug 21 14:16:53 2010 +0400
@@ -2353,7 +2353,7 @@
 				else
 				// ident!template_argument
 				tempinst.tiargs = parseTemplateArgument();
-				tid.addIdent(cast(Identifier)tempinst);
+				tid.addIdent(tempinst);
 			}
 			else
 				tid.addIdent(id);
--- a/dmd/StructInitializer.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/StructInitializer.d	Sat Aug 21 14:16:53 2010 +0400
@@ -4,6 +4,8 @@
 import dmd.TOK;
 import dmd.FuncLiteralDeclaration;
 import dmd.TypeFunction;
+import dmd.StructDeclaration;
+import dmd.StructLiteralExp;
 import dmd.ArrayTypes;
 import dmd.Array;
 import dmd.Loc;
@@ -170,9 +172,44 @@
 		return this;
 	}
 	
+	/***************************************
+	 * This works by transforming a struct initializer into
+	 * a struct literal. In the future, the two should be the
+	 * same thing.
+	 */
     Expression toExpression()
 	{
-		assert(false);
+		Expression e;
+
+		//printf("StructInitializer.toExpression() %s\n", toChars());
+		if (!ad)				// if fwd referenced
+		{
+			return null;
+		}
+		StructDeclaration sd = ad.isStructDeclaration();
+		if (!sd)
+			return null;
+		Expressions elements = new Expressions();
+		for (size_t i = 0; i < value.dim; i++)
+		{
+			if (field.data[i])
+				goto Lno;
+			Initializer iz = cast(Initializer)value.data[i];
+			if (!iz)
+				goto Lno;
+			Expression ex = iz.toExpression();
+			if (!ex)
+				goto Lno;
+			elements.push(cast(void*)ex);
+		}
+		e = new StructLiteralExp(loc, sd, elements);
+		e.type = sd.type;
+		return e;
+
+	Lno:
+		delete elements;
+		//error(loc, "struct initializers as expressions are not allowed");
+		return null;
 	}
 	
     void toCBuffer(OutBuffer buf, HdrGenState* hgs)
--- a/dmd/StructLiteralExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/StructLiteralExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -5,6 +5,7 @@
 import dmd.backend.elem;
 import dmd.InterState;
 import dmd.MATCH;
+import dmd.WANT;
 import dmd.Type;
 import dmd.OutBuffer;
 import dmd.Loc;
@@ -32,8 +33,12 @@
 
 	this(Loc loc, StructDeclaration sd, Expressions elements)
 	{
-		assert(false);
-		super(loc, TOK.init, 0);
+		super(loc, TOKstructliteral, StructLiteralExp.sizeof);
+		this.sd = sd;
+		this.elements = elements;
+		this.sym = null;
+		this.soffset = 0;
+		this.fillHoles = 1;
 	}
 
 	Expression syntaxCopy()
@@ -83,7 +88,18 @@
 
 	Expression optimize(int result)
 	{
-		assert(false);
+		if (elements)
+		{
+			for (size_t i = 0; i < elements.dim; i++)
+			{   
+				Expression e = cast(Expression)elements.data[i];
+				if (!e)
+					continue;
+				e = e.optimize(WANTvalue | (result & WANTinterpret));
+				elements.data[i] = cast(void*)e;
+			}
+		}
+		return this;
 	}
 
 	Expression interpret(InterState* istate)
--- a/dmd/TemplateParameter.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/TemplateParameter.d	Sat Aug 21 14:16:53 2010 +0400
@@ -41,23 +41,23 @@
 
     TemplateTypeParameter isTemplateTypeParameter()
 	{
-		assert(false);
+		return null;
 	}
 	
     TemplateValueParameter isTemplateValueParameter()
 	{
-		assert(false);
+		return null; 
 	}
 	
     TemplateAliasParameter isTemplateAliasParameter()
 	{
-		assert(false);
+		return null; 
 	}
 	
 version (DMDV2) {
     TemplateThisParameter isTemplateThisParameter()
 	{
-		assert(false);
+		return null; 
 	}
 }
     TemplateTupleParameter isTemplateTupleParameter()
--- a/dmd/TupleExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/TupleExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -4,6 +4,7 @@
 import dmd.TupleDeclaration;
 import dmd.backend.elem;
 import dmd.InterState;
+import dmd.WANT;
 import dmd.Type;
 import dmd.OutBuffer;
 import dmd.Loc;
@@ -207,7 +208,14 @@
 
 	Expression optimize(int result)
 	{
-		assert(false);
+		for (size_t i = 0; i < exps.dim; i++)
+		{   
+			Expression e = cast(Expression)exps.data[i];
+
+			e = e.optimize(WANTvalue | (result & WANTinterpret));
+			exps.data[i] = cast(void*)e;
+		}
+		return this;
 	}
 
 	Expression interpret(InterState* istate)
--- a/dmd/TypeClass.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/TypeClass.d	Sat Aug 21 14:16:53 2010 +0400
@@ -464,7 +464,16 @@
 	
     bool isBaseOf(Type t, int* poffset)
 	{
-		assert(false);
+		if (t.ty == Tclass)
+		{   
+			ClassDeclaration cd;
+
+			cd   = (cast(TypeClass)t).sym;
+			if (sym.isBaseOf(cd, poffset))
+				return true;
+		}
+		
+		return false;
 	}
 	
     MATCH implicitConvTo(Type to)
--- a/dmd/TypeNext.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/TypeNext.d	Sat Aug 21 14:16:53 2010 +0400
@@ -125,7 +125,11 @@
 	
     MATCH constConv(Type to)
 	{
-		assert(false);
+		MATCH m = Type.constConv(to);
+
+		if (m == MATCHconst && next.constConv((cast(TypeNext)to).next) == MATCHnomatch)
+			m = MATCHnomatch;
+		return m;
 	}
 	
     void transitive()
--- a/dmd/TypeQualified.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/TypeQualified.d	Sat Aug 21 14:16:53 2010 +0400
@@ -60,6 +60,7 @@
 	
     void addIdent(Object ident)
 	{
+		assert(ident !is null);
 		idents.push(cast(void*)ident);
 	}
 	
@@ -117,8 +118,10 @@
 			//printf("\t2: s = '%s' %p, kind = '%s'\n",s.toChars(), s, s.kind());
 			for (int i = 0; i < idents.dim; i++)
 			{
-				Identifier id = cast(Identifier)idents.data[i];
-				Dsymbol sm = s.searchX(loc, sc, id);
+				Object o = cast(Object)idents.data[i];
+				
+				Dsymbol sm = s.searchX(loc, sc, o);
+				Identifier id = cast(Identifier)o;
 				//printf("\t3: s = '%s' %p, kind = '%s'\n",s.toChars(), s, s.kind());
 				//printf("\tgetType = '%s'\n", s.getType().toChars());
 				if (!sm)
--- a/dmd/TypeTuple.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/TypeTuple.d	Sat Aug 21 14:16:53 2010 +0400
@@ -3,6 +3,7 @@
 import dmd.Type;
 import dmd.ArrayTypes;
 import dmd.MOD;
+import dmd.TypeInfoTupleDeclaration;
 import dmd.TypeInfoDeclaration;
 import dmd.Expression;
 import dmd.Loc;
@@ -170,6 +171,6 @@
 
 	TypeInfoDeclaration getTypeInfoDeclaration()
 	{
-		assert(false);
+		return new TypeInfoTupleDeclaration(this);
 	}
 }
--- a/dmd/UnrolledLoopStatement.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/UnrolledLoopStatement.d	Sat Aug 21 14:16:53 2010 +0400
@@ -18,10 +18,10 @@
 {
 	Statements statements;
 
-	this(Loc loc, Statements statements)
+	this(Loc loc, Statements s)
 	{
-		assert(false);
-		super(loc);
+		super(loc);
+		statements = s;
 	}
 
 	Statement syntaxCopy()
@@ -31,7 +31,26 @@
 
 	Statement semantic(Scope sc)
 	{
-		assert(false);
+		//printf("UnrolledLoopStatement.semantic(this = %p, sc = %p)\n", this, sc);
+
+		sc.noctor++;
+		Scope scd = sc.push();
+		scd.sbreak = this;
+		scd.scontinue = this;
+
+		for (size_t i = 0; i < statements.dim; i++)
+		{
+			Statement s = cast(Statement) statements.data[i];
+			if (s)
+			{
+				s = s.semantic(scd);
+				statements.data[i] = cast(void*)s;
+			}
+		}
+
+		scd.pop();
+		sc.noctor--;
+		return this;
 	}
 
 	bool hasBreak()
@@ -51,7 +70,17 @@
 
 	BE blockExit()
 	{
-		assert(false);
+		BE result = BEfallthru;
+		for (size_t i = 0; i < statements.dim; i++)
+		{	
+			Statement s = cast(Statement) statements.data[i];
+			if (s)
+			{
+				int r = s.blockExit();
+				result |= r & ~(BEbreak | BEcontinue);
+			}
+		}
+		return result;
 	}
 
 	bool comeFrom()
--- a/dmd/WhileStatement.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/WhileStatement.d	Sat Aug 21 14:16:53 2010 +0400
@@ -41,7 +41,7 @@
 	
     bool hasBreak()
 	{
-		assert(false);
+		return true;
 	}
 	
     bool hasContinue()
--- a/dmd/XorExp.d	Sat Aug 21 13:28:16 2010 +0400
+++ b/dmd/XorExp.d	Sat Aug 21 14:16:53 2010 +0400
@@ -92,7 +92,17 @@
 
 	MATCH implicitConvTo(Type t)
 	{
-		assert(false);
+		MATCH result = Expression.implicitConvTo(t);
+
+		if (result == MATCHnomatch)
+		{
+			MATCH m1 = e1.implicitConvTo(t);
+			MATCH m2 = e2.implicitConvTo(t);
+
+			// Pick the worst match
+			result = (m1 < m2) ? m1 : m2;
+		}
+		return result;
 	}
 
 	IntRange getIntRange()