diff dmd/statement.c @ 1141:f99a3b393c03

Reorganize EnclosingHandlers to require less changes to the frontend and allow us to implement the synchronized storage class for functions.
author Christian Kamm <kamm incasoftware de>
date Tue, 24 Mar 2009 21:18:18 +0100
parents eeb8b95ea92e
children c6d6a68bb5db
line wrap: on
line diff
--- a/dmd/statement.c	Tue Mar 24 14:34:16 2009 +0100
+++ b/dmd/statement.c	Tue Mar 24 21:18:18 2009 +0100
@@ -582,7 +582,6 @@
     : Statement(loc)
 {
     statements = s;
-    enclosinghandler = NULL;
 }
 
 Statement *UnrolledLoopStatement::syntaxCopy()
@@ -604,8 +603,6 @@
 {
     //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc);
 
-    enclosinghandler = sc->tfOfTry;
-
     sc->noctor++;
     Scope *scd = sc->push();
     scd->sbreak = this;
@@ -795,7 +792,6 @@
 {
     condition = c;
     body = b;
-    enclosinghandler = NULL;
 }
 
 Statement *WhileStatement::syntaxCopy()
@@ -830,8 +826,6 @@
     }
 #endif
 
-    enclosinghandler = sc->tfOfTry;
-
     condition = condition->semantic(sc);
     condition = resolveProperties(sc, condition);
     condition = condition->optimize(WANTvalue);
@@ -919,7 +913,6 @@
 {
     body = b;
     condition = c;
-    enclosinghandler = NULL;
 }
 
 Statement *DoStatement::syntaxCopy()
@@ -931,8 +924,6 @@
 
 Statement *DoStatement::semantic(Scope *sc)
 {
-    enclosinghandler = sc->tfOfTry;
-
     sc->noctor++;
     if (body)
 	body = body->semanticScope(sc, this, this);
@@ -1010,7 +1001,6 @@
     this->condition = condition;
     this->increment = increment;
     this->body = body;
-    this->enclosinghandler = NULL;
 }
 
 Statement *ForStatement::syntaxCopy()
@@ -1030,8 +1020,6 @@
 
 Statement *ForStatement::semantic(Scope *sc)
 {
-    enclosinghandler = sc->tfOfTry;
-
     ScopeDsymbol *sym = new ScopeDsymbol();
     sym->parent = sc->scopesym;
     sc = sc->push(sym);
@@ -1169,7 +1157,6 @@
     this->arguments = arguments;
     this->aggr = aggr;
     this->body = body;
-    this->enclosinghandler = NULL;
 
     this->key = NULL;
     this->value = NULL;
@@ -1197,8 +1184,6 @@
     Type *tn = NULL;
     Type *tnv = NULL;
 
-    enclosinghandler = sc->tfOfTry;
-
     func = sc->func;
     if (func->fes)
 	func = func->fes->func;
@@ -2253,8 +2238,6 @@
     sdefault = NULL;
     cases = NULL;
     hasNoDefault = 0;
-    // LDC
-    enclosinghandler = NULL;
 }
 
 Statement *SwitchStatement::syntaxCopy()
@@ -2269,8 +2252,6 @@
     //printf("SwitchStatement::semantic(%p)\n", this);
     assert(!cases);		// ensure semantic() is only run once
 
-    enclosinghandler = sc->tfOfTry;
-
     condition = condition->semantic(sc);
     condition = resolveProperties(sc, condition);
     if (condition->type->isString())
@@ -2571,7 +2552,6 @@
     : Statement(loc)
 {
     sw = NULL;
-    enclosinghandler = NULL;
 }
 
 Statement *GotoDefaultStatement::syntaxCopy()
@@ -2582,7 +2562,6 @@
 
 Statement *GotoDefaultStatement::semantic(Scope *sc)
 {
-    enclosinghandler = sc->tfOfTry;
     sw = sc->sw;
     if (!sw)
 	error("goto default not in switch statement");
@@ -2606,7 +2585,6 @@
 {
     cs = NULL;
     this->exp = exp;
-    enclosinghandler = NULL;
     sw = NULL;
 }
 
@@ -2619,7 +2597,6 @@
 
 Statement *GotoCaseStatement::semantic(Scope *sc)
 {
-    enclosinghandler = sc->tfOfTry;
     if (exp)
 	exp = exp->semantic(sc);
 
@@ -2678,7 +2655,6 @@
     : Statement(loc)
 {
     this->exp = exp;
-    this->enclosinghandler = NULL;
 }
 
 Statement *ReturnStatement::syntaxCopy()
@@ -2693,7 +2669,6 @@
 Statement *ReturnStatement::semantic(Scope *sc)
 {
     //printf("ReturnStatement::semantic() %s\n", toChars());
-    this->enclosinghandler = sc->tfOfTry;
 
     FuncDeclaration *fd = sc->parent->isFuncDeclaration();
     Scope *scx = sc;
@@ -2730,7 +2705,7 @@
 
     if (sc->incontract || scx->incontract)
 	error("return statements cannot be in contracts");
-    if (sc->tf || scx->tf)
+    if (sc->enclosingFinally || scx->enclosingFinally)
 	error("return statements cannot be in finally, scope(exit) or scope(success) bodies");
 
     if (fd->isCtorDeclaration())
@@ -2955,7 +2930,6 @@
     : Statement(loc)
 {
     this->ident = ident;
-    this->enclosinghandler = NULL;
 }
 
 Statement *BreakStatement::syntaxCopy()
@@ -2967,7 +2941,6 @@
 Statement *BreakStatement::semantic(Scope *sc)
 {
     //printf("BreakStatement::semantic()\n");
-    enclosinghandler = sc->tfOfTry;
     // If:
     //	break Identifier;
     if (ident)
@@ -3005,7 +2978,7 @@
 
 		if (!s->hasBreak())
 		    error("label '%s' has no break", ident->toChars());
-		if (ls->tf != sc->tf)
+		if (ls->enclosingFinally != sc->enclosingFinally)
 		    error("cannot break out of finally block");
 		
 		this->target = ls;
@@ -3051,7 +3024,6 @@
     : Statement(loc)
 {
     this->ident = ident;
-    this->enclosinghandler = NULL;
 }
 
 Statement *ContinueStatement::syntaxCopy()
@@ -3062,7 +3034,6 @@
 
 Statement *ContinueStatement::semantic(Scope *sc)
 {
-    enclosinghandler = sc->tfOfTry;
     //printf("ContinueStatement::semantic() %p\n", this);
     if (ident)
     {
@@ -3109,7 +3080,7 @@
 
 		if (!s->hasContinue())
 		    error("label '%s' has no continue", ident->toChars());
-		if (ls->tf != sc->tf)
+		if (ls->enclosingFinally != sc->enclosingFinally)
 		    error("cannot continue out of finally block");
 		
 		this->target = ls;
@@ -3156,7 +3127,6 @@
     this->exp = exp;
     this->body = body;
     this->esync = NULL;
-    this->enclosinghandler = NULL;
     // LDC
     this->llsync = NULL;
 }
@@ -3167,7 +3137,6 @@
     this->exp = NULL;
     this->body = body;
     this->esync = esync;
-    this->enclosinghandler = NULL;
     // LDC
     this->llsync = NULL;
 }
@@ -3199,10 +3168,10 @@
     }
     if (body)
     {
-        enclosinghandler = sc->tfOfTry;
-        sc->tfOfTry = new EnclosingSynchro(this);
-        body = body->semantic(sc);
-        sc->tfOfTry = enclosinghandler;
+	Statement* oldScopeExit = sc->enclosingScopeExit;
+	sc->enclosingScopeExit = this;
+	body = body->semantic(sc);
+	sc->enclosingScopeExit = oldScopeExit;
     }
     return this;
 }
@@ -3455,7 +3424,7 @@
     //printf("Catch::semantic(%s)\n", ident->toChars());
 
 #ifndef IN_GCC
-    if (sc->tf)
+    if (sc->enclosingFinally)
     {
 	/* This is because the _d_local_unwind() gets the stack munged
 	 * up on this. The workaround is to place any try-catches into
@@ -3516,7 +3485,6 @@
 {
     this->body = body;
     this->finalbody = finalbody;
-    this->enclosinghandler = NULL;
 }
 
 Statement *TryFinallyStatement::syntaxCopy()
@@ -3530,13 +3498,13 @@
 {
     //printf("TryFinallyStatement::semantic()\n");
 
-    enclosinghandler = sc->tfOfTry;
-    sc->tfOfTry = new EnclosingTryFinally(this);
+    Statement* oldScopeExit = sc->enclosingScopeExit;
+    sc->enclosingScopeExit = this;
     body = body->semantic(sc);
-    sc->tfOfTry = enclosinghandler;
+    sc->enclosingScopeExit = oldScopeExit;
 
     sc = sc->push();
-    sc->tf = this;
+    sc->enclosingFinally = this;
     sc->sbreak = NULL;
     sc->scontinue = NULL;	// no break or continue out of finally block
     finalbody = finalbody->semantic(sc);
@@ -3711,7 +3679,6 @@
     : Statement(loc)
 {
     this->statement = statement;
-    this->enclosinghandler = NULL;
 }
 
 Statement *VolatileStatement::syntaxCopy()
@@ -3725,10 +3692,10 @@
 {
     if (statement)
     {
-    enclosinghandler = sc->tfOfTry;
-    sc->tfOfTry = new EnclosingVolatile(this);
-    statement = statement->semantic(sc);
-    sc->tfOfTry = enclosinghandler;
+	Statement* oldScopeExit = sc->enclosingScopeExit;
+	sc->enclosingScopeExit = this;
+	statement = statement->semantic(sc);
+	sc->enclosingScopeExit = oldScopeExit;
     }
     return this;
 }
@@ -3775,8 +3742,8 @@
 {
     this->ident = ident;
     this->label = NULL;
-    this->tf = NULL;
-    this->enclosinghandler = NULL;
+    this->enclosingFinally = NULL;
+    this->enclosingScopeExit = NULL;
 }
 
 Statement *GotoStatement::syntaxCopy()
@@ -3789,8 +3756,9 @@
 {   FuncDeclaration *fd = sc->parent->isFuncDeclaration();
 
     //printf("GotoStatement::semantic()\n");
-    tf = sc->tf;
-    enclosinghandler = sc->tfOfTry;
+    enclosingFinally = sc->enclosingFinally;
+    enclosingScopeExit = sc->enclosingScopeExit;
+
     label = fd->searchLabel(ident);
     if (!label->statement && sc->fes)
     {
@@ -3808,7 +3776,7 @@
 	sc->fes->gotos.push(s);		// 'look at this later' list
 	return s;
     }
-    if (label->statement && label->statement->tf != sc->tf)
+    if (label->statement && label->statement->enclosingFinally != sc->enclosingFinally)
 	error("cannot goto in or out of finally block");
     return this;
 }
@@ -3834,8 +3802,8 @@
 {
     this->ident = ident;
     this->statement = statement;
-    this->tf = NULL;
-    this->enclosinghandler = NULL;
+    this->enclosingFinally = NULL;
+    this->enclosingScopeExit = NULL;
     this->lblock = NULL;
     this->isReturnLabel = 0;
     this->asmLabel = false;
@@ -3857,8 +3825,10 @@
 	error("Label '%s' already defined", ls->toChars());
     else
 	ls->statement = this;
-    tf = sc->tf;
-    enclosinghandler = sc->tfOfTry;
+
+    enclosingFinally = sc->enclosingFinally;
+    enclosingScopeExit = sc->enclosingScopeExit;
+
     sc = sc->push();
     sc->scopesym = sc->enclosing->scopesym;
     sc->callSuper |= CSXlabel;