From 402ce90e19aad0109b4f73fbeff6e0a46c4ebbe5 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Sat, 22 Mar 2008 12:20:32 +0100 Subject: [PATCH] [svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling --- dmd/statement.c | 58 +++++++++++++++++++++++----------------------- dmd/statement.h | 28 +++++++++++----------- gen/irstate.cpp | 4 ++-- gen/irstate.h | 4 ++-- gen/statements.cpp | 46 ++++++++++++++++++------------------ 5 files changed, 70 insertions(+), 70 deletions(-) diff --git a/dmd/statement.c b/dmd/statement.c index 922f126b..5caa25cb 100644 --- a/dmd/statement.c +++ b/dmd/statement.c @@ -561,7 +561,7 @@ UnrolledLoopStatement::UnrolledLoopStatement(Loc loc, Statements *s) : Statement(loc) { statements = s; - enclosingtry = NULL; + enclosingtryfinally = NULL; } Statement *UnrolledLoopStatement::syntaxCopy() @@ -583,7 +583,7 @@ Statement *UnrolledLoopStatement::semantic(Scope *sc) { //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc); - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; sc->noctor++; Scope *scd = sc->push(); @@ -774,7 +774,7 @@ WhileStatement::WhileStatement(Loc loc, Expression *c, Statement *b) { condition = c; body = b; - enclosingtry = NULL; + enclosingtryfinally = NULL; } Statement *WhileStatement::syntaxCopy() @@ -809,7 +809,7 @@ Statement *WhileStatement::semantic(Scope *sc) } #endif - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; condition = condition->semantic(sc); condition = resolveProperties(sc, condition); @@ -876,7 +876,7 @@ DoStatement::DoStatement(Loc loc, Statement *b, Expression *c) { body = b; condition = c; - enclosingtry = NULL; + enclosingtryfinally = NULL; } Statement *DoStatement::syntaxCopy() @@ -888,7 +888,7 @@ Statement *DoStatement::syntaxCopy() Statement *DoStatement::semantic(Scope *sc) { - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; sc->noctor++; if (body) @@ -952,7 +952,7 @@ ForStatement::ForStatement(Loc loc, Statement *init, Expression *condition, Expr this->condition = condition; this->increment = increment; this->body = body; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; } Statement *ForStatement::syntaxCopy() @@ -972,7 +972,7 @@ Statement *ForStatement::syntaxCopy() Statement *ForStatement::semantic(Scope *sc) { - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; ScopeDsymbol *sym = new ScopeDsymbol(); sym->parent = sc->scopesym; @@ -1086,7 +1086,7 @@ ForeachStatement::ForeachStatement(Loc loc, enum TOK op, Arguments *arguments, this->arguments = arguments; this->aggr = aggr; this->body = body; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; this->key = NULL; this->value = NULL; @@ -1115,7 +1115,7 @@ Statement *ForeachStatement::semantic(Scope *sc) Type *tn = NULL; Type *tnv = NULL; - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; func = sc->func; if (func->fes) @@ -1971,7 +1971,7 @@ SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b) cases = NULL; hasNoDefault = 0; // LLVMDC - enclosingtry = NULL; + enclosingtryfinally = NULL; } Statement *SwitchStatement::syntaxCopy() @@ -1986,7 +1986,7 @@ Statement *SwitchStatement::semantic(Scope *sc) //printf("SwitchStatement::semantic(%p)\n", this); assert(!cases); // ensure semantic() is only run once - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; condition = condition->semantic(sc); condition = resolveProperties(sc, condition); @@ -2274,7 +2274,7 @@ GotoDefaultStatement::GotoDefaultStatement(Loc loc) : Statement(loc) { sw = NULL; - enclosingtry = NULL; + enclosingtryfinally = NULL; } Statement *GotoDefaultStatement::syntaxCopy() @@ -2285,7 +2285,7 @@ Statement *GotoDefaultStatement::syntaxCopy() Statement *GotoDefaultStatement::semantic(Scope *sc) { - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; sw = sc->sw; if (!sw) error("goto default not in switch statement"); @@ -2309,7 +2309,7 @@ GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp) { cs = NULL; this->exp = exp; - enclosingtry = NULL; + enclosingtryfinally = NULL; sw = NULL; } @@ -2322,7 +2322,7 @@ Statement *GotoCaseStatement::syntaxCopy() Statement *GotoCaseStatement::semantic(Scope *sc) { - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; if (exp) exp = exp->semantic(sc); @@ -2381,7 +2381,7 @@ ReturnStatement::ReturnStatement(Loc loc, Expression *exp) : Statement(loc) { this->exp = exp; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; } Statement *ReturnStatement::syntaxCopy() @@ -2396,7 +2396,7 @@ Statement *ReturnStatement::syntaxCopy() Statement *ReturnStatement::semantic(Scope *sc) { //printf("ReturnStatement::semantic() %s\n", toChars()); - this->enclosingtry = sc->tfOfTry; + this->enclosingtryfinally = sc->tfOfTry; FuncDeclaration *fd = sc->parent->isFuncDeclaration(); Scope *scx = sc; @@ -2657,7 +2657,7 @@ BreakStatement::BreakStatement(Loc loc, Identifier *ident) : Statement(loc) { this->ident = ident; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; } Statement *BreakStatement::syntaxCopy() @@ -2668,7 +2668,7 @@ Statement *BreakStatement::syntaxCopy() Statement *BreakStatement::semantic(Scope *sc) { - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; // If: // break Identifier; if (ident) @@ -2751,7 +2751,7 @@ ContinueStatement::ContinueStatement(Loc loc, Identifier *ident) : Statement(loc) { this->ident = ident; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; } Statement *ContinueStatement::syntaxCopy() @@ -2762,7 +2762,7 @@ Statement *ContinueStatement::syntaxCopy() Statement *ContinueStatement::semantic(Scope *sc) { - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; //printf("ContinueStatement::semantic() %p\n", this); if (ident) { @@ -3195,7 +3195,7 @@ TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *fi { this->body = body; this->finalbody = finalbody; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; } Statement *TryFinallyStatement::syntaxCopy() @@ -3209,10 +3209,10 @@ Statement *TryFinallyStatement::semantic(Scope *sc) { //printf("TryFinallyStatement::semantic()\n"); - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; sc->tfOfTry = this; body = body->semantic(sc); - sc->tfOfTry = enclosingtry; + sc->tfOfTry = enclosingtryfinally; sc = sc->push(); sc->tf = this; @@ -3447,7 +3447,7 @@ GotoStatement::GotoStatement(Loc loc, Identifier *ident) this->ident = ident; this->label = NULL; this->tf = NULL; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; } Statement *GotoStatement::syntaxCopy() @@ -3461,7 +3461,7 @@ Statement *GotoStatement::semantic(Scope *sc) //printf("GotoStatement::semantic()\n"); tf = sc->tf; - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; label = fd->searchLabel(ident); if (!label->statement && sc->fes) { @@ -3505,7 +3505,7 @@ LabelStatement::LabelStatement(Loc loc, Identifier *ident, Statement *statement) this->ident = ident; this->statement = statement; this->tf = NULL; - this->enclosingtry = NULL; + this->enclosingtryfinally = NULL; this->lblock = NULL; this->isReturnLabel = 0; this->llvmBB = NULL; @@ -3528,7 +3528,7 @@ Statement *LabelStatement::semantic(Scope *sc) else ls->statement = this; tf = sc->tf; - enclosingtry = sc->tfOfTry; + enclosingtryfinally = sc->tfOfTry; sc = sc->push(); sc->scopesym = sc->enclosing->scopesym; sc->callSuper |= CSXlabel; diff --git a/dmd/statement.h b/dmd/statement.h index d8305913..c67b877d 100644 --- a/dmd/statement.h +++ b/dmd/statement.h @@ -193,7 +193,7 @@ struct CompoundStatement : Statement struct UnrolledLoopStatement : Statement { Statements *statements; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; UnrolledLoopStatement(Loc loc, Statements *statements); Statement *syntaxCopy(); @@ -238,7 +238,7 @@ struct WhileStatement : Statement { Expression *condition; Statement *body; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; WhileStatement(Loc loc, Expression *c, Statement *b); Statement *syntaxCopy(); @@ -260,7 +260,7 @@ struct DoStatement : Statement { Statement *body; Expression *condition; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; DoStatement(Loc loc, Statement *b, Expression *c); Statement *syntaxCopy(); @@ -284,7 +284,7 @@ struct ForStatement : Statement Expression *condition; Expression *increment; Statement *body; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; ForStatement(Loc loc, Statement *init, Expression *condition, Expression *increment, Statement *body); Statement *syntaxCopy(); @@ -309,7 +309,7 @@ struct ForeachStatement : Statement Arguments *arguments; // array of Argument*'s Expression *aggr; Statement *body; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; VarDeclaration *key; VarDeclaration *value; @@ -406,7 +406,7 @@ struct SwitchStatement : Statement Expression *condition; Statement *body; DefaultStatement *sdefault; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; Array gotoCases; // array of unresolved GotoCaseStatement's Array *cases; // array of CaseStatement's @@ -480,7 +480,7 @@ struct DefaultStatement : Statement struct GotoDefaultStatement : Statement { SwitchStatement *sw; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; GotoDefaultStatement(Loc loc); Statement *syntaxCopy(); @@ -496,7 +496,7 @@ struct GotoCaseStatement : Statement { Expression *exp; // NULL, or which case to goto CaseStatement *cs; // case statement it resolves to - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; SwitchStatement *sw; GotoCaseStatement(Loc loc, Expression *exp); @@ -521,7 +521,7 @@ struct SwitchErrorStatement : Statement struct ReturnStatement : Statement { Expression *exp; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; ReturnStatement(Loc loc, Expression *exp); Statement *syntaxCopy(); @@ -542,7 +542,7 @@ struct ReturnStatement : Statement struct BreakStatement : Statement { Identifier *ident; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; BreakStatement(Loc loc, Identifier *ident); Statement *syntaxCopy(); @@ -560,7 +560,7 @@ struct BreakStatement : Statement struct ContinueStatement : Statement { Identifier *ident; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; ContinueStatement(Loc loc, Identifier *ident); Statement *syntaxCopy(); @@ -652,7 +652,7 @@ struct TryFinallyStatement : Statement { Statement *body; Statement *finalbody; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody); Statement *syntaxCopy(); @@ -719,7 +719,7 @@ struct GotoStatement : Statement Identifier *ident; LabelDsymbol *label; TryFinallyStatement *tf; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; GotoStatement(Loc loc, Identifier *ident); Statement *syntaxCopy(); @@ -737,7 +737,7 @@ struct LabelStatement : Statement Identifier *ident; Statement *statement; TryFinallyStatement *tf; - TryFinallyStatement *enclosingtry; + TryFinallyStatement *enclosingtryfinally; block *lblock; // back end int isReturnLabel; diff --git a/gen/irstate.cpp b/gen/irstate.cpp index 9c555245..263b5162 100644 --- a/gen/irstate.cpp +++ b/gen/irstate.cpp @@ -35,13 +35,13 @@ IRLoopScope::IRLoopScope() { } -IRLoopScope::IRLoopScope(Statement* s, TryFinallyStatement* enclosingtry, llvm::BasicBlock* b, llvm::BasicBlock* e) +IRLoopScope::IRLoopScope(Statement* s, TryFinallyStatement* enclosingtryfinally, llvm::BasicBlock* b, llvm::BasicBlock* e) { begin = b; end = e; builder.SetInsertPoint(b); this->s = s; - this->enclosingtry = enclosingtry; + this->enclosingtryfinally = enclosingtryfinally; } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/irstate.h b/gen/irstate.h index 133b66ac..e38ea1d3 100644 --- a/gen/irstate.h +++ b/gen/irstate.h @@ -42,10 +42,10 @@ struct IRLoopScope : IRScope // generating statement Statement* s; // the try of a TryFinally that encloses the loop - TryFinallyStatement* enclosingtry; + TryFinallyStatement* enclosingtryfinally; IRLoopScope(); - IRLoopScope(Statement* s, TryFinallyStatement* enclosingtry, llvm::BasicBlock* b, llvm::BasicBlock* e); + IRLoopScope(Statement* s, TryFinallyStatement* enclosingtryfinally, llvm::BasicBlock* b, llvm::BasicBlock* e); }; struct IRBuilderHelper diff --git a/gen/statements.cpp b/gen/statements.cpp index 6f4e956f..3b50cc5b 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -53,7 +53,7 @@ void emit_finallyblocks(IRState* p, TryFinallyStatement* start, TryFinallyStatem // verify that end encloses start TryFinallyStatement* endfinally = start; while(endfinally != NULL && endfinally != end) { - endfinally = endfinally->enclosingtry; + endfinally = endfinally->enclosingtryfinally; } assert(endfinally == end); @@ -61,7 +61,7 @@ void emit_finallyblocks(IRState* p, TryFinallyStatement* start, TryFinallyStatem TryFinallyStatement* tf = start; while(tf != end) { tf->finalbody->toIR(p); - tf = tf->enclosingtry; + tf = tf->enclosingtryfinally; } } @@ -90,7 +90,7 @@ void ReturnStatement::toIR(IRState* p) if (!e->inPlace()) DtoAssign(rvar, e); - emit_finallyblocks(p, enclosingtry, NULL); + emit_finallyblocks(p, enclosingtryfinally, NULL); if (global.params.symdebug) DtoDwarfFuncEnd(f->decl); new llvm::ReturnInst(p->scopebb()); @@ -103,7 +103,7 @@ void ReturnStatement::toIR(IRState* p) delete e; Logger::cout() << "return value is '" <<*v << "'\n"; - emit_finallyblocks(p, enclosingtry, NULL); + emit_finallyblocks(p, enclosingtryfinally, NULL); if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); new llvm::ReturnInst(v, p->scopebb()); @@ -112,7 +112,7 @@ void ReturnStatement::toIR(IRState* p) else { if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { - emit_finallyblocks(p, enclosingtry, NULL); + emit_finallyblocks(p, enclosingtryfinally, NULL); if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); new llvm::ReturnInst(p->scopebb()); @@ -254,7 +254,7 @@ void WhileStatement::toIR(IRState* p) gIR->scope() = IRScope(whilebodybb,endbb); // while body code - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,whilebb,endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,whilebb,endbb)); body->toIR(p); p->loopbbs.pop_back(); @@ -286,7 +286,7 @@ void DoStatement::toIR(IRState* p) gIR->scope() = IRScope(dowhilebb,endbb); // do-while body code - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,dowhilebb,endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,dowhilebb,endbb)); body->toIR(p); p->loopbbs.pop_back(); @@ -324,7 +324,7 @@ void ForStatement::toIR(IRState* p) assert(!gIR->scopereturned()); new llvm::BranchInst(forbb, gIR->scopebb()); - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,forincbb,endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,forincbb,endbb)); // replace current scope gIR->scope() = IRScope(forbb,forbodybb); @@ -375,7 +375,7 @@ void BreakStatement::toIR(IRState* p) if (ident != 0) { Logger::println("ident = %s", ident->toChars()); - emit_finallyblocks(p, enclosingtry, target->enclosingtry); + emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally); // get the loop statement the label refers to Statement* targetLoopStatement = target->statement; @@ -394,7 +394,7 @@ void BreakStatement::toIR(IRState* p) assert(0); } else { - emit_finallyblocks(p, enclosingtry, gIR->loopbbs.back().enclosingtry); + emit_finallyblocks(p, enclosingtryfinally, gIR->loopbbs.back().enclosingtryfinally); new llvm::BranchInst(gIR->loopbbs.back().end, gIR->scopebb()); } } @@ -409,7 +409,7 @@ void ContinueStatement::toIR(IRState* p) if (ident != 0) { Logger::println("ident = %s", ident->toChars()); - emit_finallyblocks(p, enclosingtry, target->enclosingtry); + emit_finallyblocks(p, enclosingtryfinally, target->enclosingtryfinally); // get the loop statement the label refers to Statement* targetLoopStatement = target->statement; @@ -428,7 +428,7 @@ void ContinueStatement::toIR(IRState* p) assert(0); } else { - emit_finallyblocks(p, enclosingtry, gIR->loopbbs.back().enclosingtry); + emit_finallyblocks(p, enclosingtryfinally, gIR->loopbbs.back().enclosingtryfinally); new llvm::BranchInst(gIR->loopbbs.back().begin, gIR->scopebb()); } } @@ -713,7 +713,7 @@ void SwitchStatement::toIR(IRState* p) { llvm::BasicBlock* nextbb = (i == n-1) ? (defbb ? defbb : endbb) : vcases[i+1].first; p->scope() = IRScope(vcases[i].first,nextbb); - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,p->scopebb(),endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb)); vbodies[i]->toIR(p); p->loopbbs.pop_back(); @@ -728,7 +728,7 @@ void SwitchStatement::toIR(IRState* p) if (defbb) { p->scope() = IRScope(defbb,endbb); - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,p->scopebb(),endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb)); Logger::println("doing default statement"); sdefault->statement->toIR(p); p->loopbbs.pop_back(); @@ -763,7 +763,7 @@ void UnrolledLoopStatement::toIR(IRState* p) llvm::BasicBlock* endbb = new llvm::BasicBlock("unrolledend", p->topfunc(), oldend); p->scope() = IRScope(p->scopebb(),endbb); - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,p->scopebb(),endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,p->scopebb(),endbb)); for (int i=0; idim; ++i) { @@ -921,7 +921,7 @@ void ForeachStatement::toIR(IRState* p) } // emit body - p->loopbbs.push_back(IRLoopScope(this,enclosingtry,nextbb,endbb)); + p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,nextbb,endbb)); body->toIR(p); p->loopbbs.pop_back(); @@ -981,17 +981,17 @@ void GotoStatement::toIR(IRState* p) assert(!p->scopereturned()); // find finallys between goto and label - TryFinallyStatement* endfinally = enclosingtry; - while(endfinally != NULL && endfinally != label->statement->enclosingtry) { - endfinally = endfinally->enclosingtry; + TryFinallyStatement* endfinally = enclosingtryfinally; + while(endfinally != NULL && endfinally != label->statement->enclosingtryfinally) { + endfinally = endfinally->enclosingtryfinally; } // error if didn't find tf statement of label - if(endfinally != label->statement->enclosingtry) + if(endfinally != label->statement->enclosingtryfinally) error("cannot goto into try block", loc.toChars()); // emit code for finallys between goto and label - emit_finallyblocks(p, enclosingtry, endfinally); + emit_finallyblocks(p, enclosingtryfinally, endfinally); new llvm::BranchInst(label->statement->llvmBB, p->scopebb()); p->scope() = IRScope(bb,oldend); @@ -1010,7 +1010,7 @@ void GotoDefaultStatement::toIR(IRState* p) assert(!p->scopereturned()); assert(sw->sdefault->bodyBB); - emit_finallyblocks(p, enclosingtry, sw->enclosingtry); + emit_finallyblocks(p, enclosingtryfinally, sw->enclosingtryfinally); new llvm::BranchInst(sw->sdefault->bodyBB, p->scopebb()); p->scope() = IRScope(bb,oldend); @@ -1029,7 +1029,7 @@ void GotoCaseStatement::toIR(IRState* p) assert(!p->scopereturned()); assert(cs->bodyBB); - emit_finallyblocks(p, enclosingtry, sw->enclosingtry); + emit_finallyblocks(p, enclosingtryfinally, sw->enclosingtryfinally); new llvm::BranchInst(cs->bodyBB, p->scopebb()); p->scope() = IRScope(bb,oldend);