changeset 93:df6d0f967680

implemented a whole bunch of methods to make phobos 2.035 compile and some additional ones I came across
author Trass3r
date Mon, 30 Aug 2010 22:50:30 +0200
parents 0c891ec48515
children 3a0b150c9841 ae5b11064a9a
files dmd/CompoundStatement.d dmd/Expression.d dmd/ForeachRangeStatement.d dmd/FuncDeclaration.d dmd/FuncExp.d dmd/FuncLiteralDeclaration.d dmd/OutBuffer.d dmd/ReturnStatement.d dmd/StringExp.d dmd/TypeEnum.d dmd/TypeInfoConstDeclaration.d dmd/TypeInfoInvariantDeclaration.d
diffstat 12 files changed, 211 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/CompoundStatement.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/CompoundStatement.d	Mon Aug 30 22:50:30 2010 +0200
@@ -62,9 +62,13 @@
 		return new CompoundStatement(loc, a);
 	}
 	
-    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		for (int i = 0; i < statements.dim; i++)
+		{   Statement s = cast(Statement) statements.data[i];
+			if (s)
+				s.toCBuffer(buf, hgs);
+		}
 	}
 	
 	static int indent = 0;
--- a/dmd/Expression.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/Expression.d	Mon Aug 30 22:50:30 2010 +0200
@@ -42,6 +42,7 @@
 import dmd.TypeStruct;
 import dmd.CastExp;
 import dmd.Global;
+import dmd.GlobalExpressions;
 import dmd.Token;
 import dmd.TypeClass;
 import dmd.PtrExp;
@@ -324,7 +325,9 @@
 
     ulong toInteger()
 	{
-		assert(false);
+		//printf("Expression %s\n", Token.toChars(op));
+		error("Integer constant expression expected instead of %s", toChars());
+		return 0;
 	}
     
     ulong toUInteger()
@@ -335,17 +338,20 @@
     
     real toReal()
 	{
-		assert(false);
+		error("Floating point constant expression expected instead of %s", toChars());
+		return 0;
 	}
     
     real toImaginary()
 	{
-		assert(false);
+		error("Floating point constant expression expected instead of %s", toChars());
+		return 0;
 	}
     
     Complex!(real) toComplex()
 	{
-		assert(false);
+		error("Floating point constant expression expected instead of %s", toChars());
+		return Complex!real(0);
 	}
     
     void toCBuffer(OutBuffer buf, HdrGenState* hgs)
@@ -369,12 +375,21 @@
 	{
 		return 0;
 	}
-    
-    Expression toLvalue(Scope sc, Expression e)
+
+	/*******************************
+	 * Give error if we're not an lvalue.
+	 * If we can, convert expression to be an lvalue.
+	 */
+	Expression toLvalue(Scope sc, Expression e)
 	{
-		assert(false);
+		   if (!e)
+				e = this;
+			else if (!loc.filename)
+				loc = e.loc;
+			error("%s is not an lvalue", e.toChars());
+			return this;
 	}
-    
+
     Expression modifiableLvalue(Scope sc, Expression e)
 	{
 		//printf("Expression::modifiableLvalue() %s, type = %s\n", toChars(), type.toChars());
@@ -831,9 +846,16 @@
 		return this;
 	}
     
-    Expression interpret(InterState istate)
+	Expression interpret(InterState istate)
 	{
-		assert(false);
+version(LOG)
+{
+		writef("Expression::interpret() %s\n", toChars());
+		writef("type = %s\n", type.toChars());
+		dump(0);
+}
+		error("Cannot interpret %s at compile time", toChars());
+		return EXP_CANT_INTERPRET;
 	}
 
     int isConst()
--- a/dmd/ForeachRangeStatement.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/ForeachRangeStatement.d	Mon Aug 30 22:50:30 2010 +0200
@@ -2,6 +2,7 @@
 
 import dmd.Statement;
 import dmd.TOK;
+import dmd.Token;
 import dmd.Argument;
 import dmd.Expression;
 import dmd.Statement;
@@ -31,6 +32,7 @@
 import dmd.Loc;
 import dmd.BE;
 
+version(DMDV2)
 class ForeachRangeStatement : Statement
 {
     TOK op;		// TOK.TOKforeach or TOK.TOKforeach_reverse
@@ -177,44 +179,83 @@
 	}
 	}
 	
-    override bool hasBreak()
+	override bool hasBreak()
 	{
-		assert(false);
+		return true;
+	}
+	
+	override bool hasContinue()
+	{
+		return true;
 	}
 	
-    override bool hasContinue()
+	override bool usesEH()
+	{
+		assert(false); // from dmd
+		return body_.usesEH();
+	}
+
+	override BE blockExit()
 	{
-		assert(false);
+		assert(false); // from dmd
+		BE result = BE.BEfallthru;
+
+		if (lwr && lwr.canThrow())
+			result |= BE.BEthrow;
+		else if (upr && upr.canThrow())
+			result |= BE.BEthrow;
+
+		if (body_)
+		{
+			result |= body_.blockExit() & ~(BE.BEbreak | BE.BEcontinue);
+		}
+		return result;
+	}
+
+	override bool comeFrom()
+	{
+		assert(false); // from dmd
+		if (body_)
+			return body_.comeFrom();
+		return false;
 	}
 	
-    override bool usesEH()
+	override Expression interpret(InterState istate)
 	{
 		assert(false);
 	}
 	
-    override BE blockExit()
+	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
-	}
-	
-    override bool comeFrom()
-	{
-		assert(false);
+		buf.writestring(Token.toChars(op));
+		buf.writestring(" (");
+
+		if (arg.type)
+			arg.type.toCBuffer(buf, arg.ident, hgs);
+		else
+			buf.writestring(arg.ident.toChars());
+
+		buf.writestring("; ");
+		lwr.toCBuffer(buf, hgs);
+		buf.writestring(" .. ");
+		upr.toCBuffer(buf, hgs);
+		buf.writebyte(')');
+		buf.writenl();
+		buf.writebyte('{');
+		buf.writenl();
+		if (body_)
+			body_.toCBuffer(buf, hgs);
+		buf.writebyte('}');
+		buf.writenl();
 	}
 	
-    override Expression interpret(InterState istate)
-	{
-		assert(false);
-	}
-	
-    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	override Statement inlineScan(InlineScanState* iss)
 	{
-		assert(false);
-	}
-	
-    override Statement inlineScan(InlineScanState* iss)
-	{
-		assert(false);
+		 lwr = lwr.inlineScan(iss);
+			upr = upr.inlineScan(iss);
+			if (body_)
+				body_ = body_.inlineScan(iss);
+			return this;
 	}
 	
     override void toIR(IRState* irs)
--- a/dmd/FuncDeclaration.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/FuncDeclaration.d	Mon Aug 30 22:50:30 2010 +0200
@@ -17,6 +17,7 @@
 import dmd.ExpInitializer;
 import dmd.BE;
 import dmd.Id;
+import dmd.StorageClassDeclaration;
 import dmd.StringExp;
 import dmd.DsymbolExp;
 import dmd.HaltExp;
@@ -1650,15 +1651,62 @@
 	{
 		assert(false);
 	}
-	
-    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+
+	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+//		writef("FuncDeclaration.toCBuffer() '%s'\n", toChars());
+
+		StorageClassDeclaration.stcToCBuffer(buf, storage_class);
+		type.toCBuffer(buf, ident, hgs);
+		bodyToCBuffer(buf, hgs);
 	}
 	
-    void bodyToCBuffer(OutBuffer buf, HdrGenState* hgs)
+	void bodyToCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		if (fbody &&
+			(!hgs.hdrgen || hgs.tpltMember || canInline(1,1))
+		   )
+		{
+			buf.writenl();
+
+			// in{}
+			if (frequire)
+			{
+				buf.writestring("in");
+				buf.writenl();
+				frequire.toCBuffer(buf, hgs);
+			}
+
+			// out{}
+			if (fensure)
+			{
+				buf.writestring("out");
+				if (outId)
+				{
+					buf.writebyte('(');
+					buf.writestring(outId.toChars());
+					buf.writebyte(')');
+				}
+				buf.writenl();
+				fensure.toCBuffer(buf, hgs);
+			}
+
+			if (frequire || fensure)
+			{
+				buf.writestring("body");
+				buf.writenl();
+			}
+
+			buf.writebyte('{');
+			buf.writenl();
+			fbody.toCBuffer(buf, hgs);
+			buf.writebyte('}');
+			buf.writenl();
+		}
+		else
+		{   buf.writeByte(';');
+			buf.writenl();
+		}
 	}
 	
 	/****************************************************
--- a/dmd/FuncExp.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/FuncExp.d	Mon Aug 30 22:50:30 2010 +0200
@@ -96,7 +96,8 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		fd.toCBuffer(buf, hgs);
+		//buf.writestring(fd.toChars());
 	}
 
 	override elem* toElem(IRState* irs)
--- a/dmd/FuncLiteralDeclaration.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/FuncLiteralDeclaration.d	Mon Aug 30 22:50:30 2010 +0200
@@ -37,7 +37,10 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+    	buf.writestring(kind());
+        buf.writeByte(' ');
+        type.toCBuffer(buf, null, hgs);
+        bodyToCBuffer(buf, hgs);
 	}
 
     override Dsymbol syntaxCopy(Dsymbol s)
--- a/dmd/OutBuffer.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/OutBuffer.d	Mon Aug 30 22:50:30 2010 +0200
@@ -94,17 +94,25 @@
 	
     final void writenl()			// write newline
 	{
-		assert(false);
-version (_WIN32) {
-	version (M_UNICODE) {
+version (_WIN32)
+{
+	version (M_UNICODE)
+	{
 		write4(0x000A000D);		// newline is CR,LF on Microsoft OS's
-	} else {
+	}
+	else
+	{
 		writeword(0x0A0D);		// newline is CR,LF on Microsoft OS's
 	}
-} else {
-	version (M_UNICODE) {
+}
+else
+{
+	version (M_UNICODE)
+	{
 		writeword('\n');
-	} else {
+	}
+	else
+	{
 		writeByte('\n');
 	}
 }
--- a/dmd/ReturnStatement.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/ReturnStatement.d	Mon Aug 30 22:50:30 2010 +0200
@@ -63,12 +63,16 @@
 		return new ReturnStatement(loc, e);
 	}
 	
-    override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.printf("return ");
+		if (exp)
+			exp.toCBuffer(buf, hgs);
+		buf.writeByte(';');
+		buf.writenl();
 	}
 	
-    override Statement semantic(Scope sc)
+	override Statement semantic(Scope sc)
 	{
 		//printf("ReturnStatement.semantic() %s\n", toChars());
 
--- a/dmd/StringExp.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/StringExp.d	Mon Aug 30 22:50:30 2010 +0200
@@ -637,7 +637,21 @@
 
 	override bool isBool(bool result)
 	{
-		assert(false);
+		return result ? true : false;
+	}
+
+version(DMDV2)
+{
+	override bool isLvalue()
+	{
+		return true;
+	}
+}
+
+	override Expression toLvalue(Scope sc, Expression e)
+	{
+		// writef("StringExp::toLvalue(%s)\n", toChars());
+		return this;
 	}
 
 	uint charAt(size_t i)
--- a/dmd/TypeEnum.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/TypeEnum.d	Mon Aug 30 22:50:30 2010 +0200
@@ -229,9 +229,17 @@
 		return sym.defaultval.isBool(false);
 	}
 	
-    override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
+	override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
 	{
-		assert(false);
+		// Extra check
+		if (tparam && tparam.ty == Tenum)
+		{
+			TypeEnum tp = cast(TypeEnum)tparam;
+
+			if (sym != tp.sym)
+				return MATCHnomatch;
+		}
+		return Type.deduceType(sc, tparam, parameters, dedtypes);
 	}
 	
     override TypeInfoDeclaration getTypeInfoDeclaration()
--- a/dmd/TypeInfoConstDeclaration.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/TypeInfoConstDeclaration.d	Mon Aug 30 22:50:30 2010 +0200
@@ -7,6 +7,7 @@
 import dmd.backend.Util;
 import dmd.backend.TYM;
 
+version(DMDV2)
 class TypeInfoConstDeclaration : TypeInfoDeclaration
 {
 	this(Type tinfo)
--- a/dmd/TypeInfoInvariantDeclaration.d	Mon Aug 30 23:43:38 2010 +0400
+++ b/dmd/TypeInfoInvariantDeclaration.d	Mon Aug 30 22:50:30 2010 +0200
@@ -6,6 +6,7 @@
 import dmd.backend.Util;
 import dmd.backend.TYM;
 
+version(DMDV2)
 class TypeInfoInvariantDeclaration : TypeInfoDeclaration
 {
 	this(Type tinfo)