diff dmd/statement.c @ 1159:c6d6a68bb5db

Add back some enclosing scope-exit information to the frontend to produce proper error messages inside switch statements.
author Christian Kamm <kamm incasoftware de>
date Sat, 28 Mar 2009 14:39:16 +0100
parents f99a3b393c03
children 166042b48c28
line wrap: on
line diff
--- a/dmd/statement.c	Sat Mar 28 14:26:23 2009 +0100
+++ b/dmd/statement.c	Sat Mar 28 14:39:16 2009 +0100
@@ -2238,6 +2238,8 @@
     sdefault = NULL;
     cases = NULL;
     hasNoDefault = 0;
+    // LDC
+    enclosingScopeExit = NULL;
 }
 
 Statement *SwitchStatement::syntaxCopy()
@@ -2252,6 +2254,9 @@
     //printf("SwitchStatement::semantic(%p)\n", this);
     assert(!cases);		// ensure semantic() is only run once
 
+    // LDC
+    enclosingScopeExit = sc->enclosingScopeExit;
+
     condition = condition->semantic(sc);
     condition = resolveProperties(sc, condition);
     if (condition->type->isString())
@@ -2404,6 +2409,8 @@
     cblock = NULL;
     bodyBB = NULL;
     llvmIdx = NULL;
+    // LDC
+    enclosingScopeExit = NULL;
 }
 
 Statement *CaseStatement::syntaxCopy()
@@ -2416,6 +2423,14 @@
 {   SwitchStatement *sw = sc->sw;
 
     //printf("CaseStatement::semantic() %s\n", toChars());
+    
+    // LDC
+    enclosingScopeExit = sc->enclosingScopeExit;
+    if (enclosingScopeExit != sw->enclosingScopeExit)
+    {
+	error("case must be inside the same try, synchronized or volatile level as switch");
+    }
+
     exp = exp->semantic(sc);
     if (sw)
     {
@@ -2500,6 +2515,8 @@
 +    cblock = NULL;
 #endif
     bodyBB = NULL;
+    // LDC
+    enclosingScopeExit = NULL;
 }
 
 Statement *DefaultStatement::syntaxCopy()
@@ -2511,6 +2528,7 @@
 Statement *DefaultStatement::semantic(Scope *sc)
 {
     //printf("DefaultStatement::semantic()\n");
+
     if (sc->sw)
     {
 	if (sc->sw->sdefault)
@@ -2518,6 +2536,13 @@
 	    error("switch statement already has a default");
 	}
 	sc->sw->sdefault = this;
+
+	// LDC
+	enclosingScopeExit = sc->enclosingScopeExit;
+	if (enclosingScopeExit != sc->sw->enclosingScopeExit)
+	{
+	    error("default must be inside the same try, synchronized or volatile level as switch");
+	}
     }
     else
 	error("default not in switch statement");