diff dmd/GotoCaseStatement.d @ 64:4290d870944a

More fixes
author korDen
date Mon, 23 Aug 2010 20:29:15 +0400
parents cab4c37afb89
children 2e2a5c3f943a
line wrap: on
line diff
--- a/dmd/GotoCaseStatement.d	Mon Aug 23 16:52:24 2010 +0400
+++ b/dmd/GotoCaseStatement.d	Mon Aug 23 20:29:15 2010 +0400
@@ -10,6 +10,7 @@
 import dmd.OutBuffer;
 import dmd.HdrGenState;
 import dmd.BE;
+import dmd.WANT;
 
 class GotoCaseStatement : Statement
 {
@@ -18,18 +19,35 @@
 
     this(Loc loc, Expression exp)
 	{
-		assert(false);
 		super(loc);
+		cs = null;
+		this.exp = exp;
 	}
 	
     Statement syntaxCopy()
 	{
-		assert(false);
+		Expression e = exp ? exp.syntaxCopy() : null;
+		GotoCaseStatement s = new GotoCaseStatement(loc, e);
+		return s;
 	}
 	
     Statement semantic(Scope sc)
 	{
-		assert(false);
+		if (exp)
+			exp = exp.semantic(sc);
+
+		if (!sc.sw)
+			error("goto case not in switch statement");
+		else
+		{
+			sc.sw.gotoCases.push(cast(void*)this);
+			if (exp)
+			{
+				exp = exp.implicitCastTo(sc, sc.sw.condition.type);
+				exp = exp.optimize(WANTvalue);
+			}
+		}
+		return this;
 	}
 	
     Expression interpret(InterState istate)
@@ -39,12 +57,19 @@
 	
     BE blockExit()
 	{
-		assert(false);
+		return BEgoto;
 	}
 	
     void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("goto case");
+		if (exp)
+		{   
+			buf.writebyte(' ');
+			exp.toCBuffer(buf, hgs);
+		}
+		buf.writebyte(';');
+		buf.writenl();
 	}
 
     void toIR(IRState* irs)