Mercurial > projects > ldc
comparison dmd/statement.c @ 148:86d3bb8ca33e trunk
[svn r154] renaming enclosingtry to enclosingtryfinally to distinguish it from enclosingtrycatch, which will probably need to be added for exception handling
author | ChristianK |
---|---|
date | Sat, 22 Mar 2008 12:20:32 +0100 |
parents | 8f704cb9969b |
children | 5acec6b2eef8 |
comparison
equal
deleted
inserted
replaced
147:0636f6269dfd | 148:86d3bb8ca33e |
---|---|
559 | 559 |
560 UnrolledLoopStatement::UnrolledLoopStatement(Loc loc, Statements *s) | 560 UnrolledLoopStatement::UnrolledLoopStatement(Loc loc, Statements *s) |
561 : Statement(loc) | 561 : Statement(loc) |
562 { | 562 { |
563 statements = s; | 563 statements = s; |
564 enclosingtry = NULL; | 564 enclosingtryfinally = NULL; |
565 } | 565 } |
566 | 566 |
567 Statement *UnrolledLoopStatement::syntaxCopy() | 567 Statement *UnrolledLoopStatement::syntaxCopy() |
568 { | 568 { |
569 Statements *a = new Statements(); | 569 Statements *a = new Statements(); |
581 | 581 |
582 Statement *UnrolledLoopStatement::semantic(Scope *sc) | 582 Statement *UnrolledLoopStatement::semantic(Scope *sc) |
583 { | 583 { |
584 //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc); | 584 //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc); |
585 | 585 |
586 enclosingtry = sc->tfOfTry; | 586 enclosingtryfinally = sc->tfOfTry; |
587 | 587 |
588 sc->noctor++; | 588 sc->noctor++; |
589 Scope *scd = sc->push(); | 589 Scope *scd = sc->push(); |
590 scd->sbreak = this; | 590 scd->sbreak = this; |
591 scd->scontinue = this; | 591 scd->scontinue = this; |
772 WhileStatement::WhileStatement(Loc loc, Expression *c, Statement *b) | 772 WhileStatement::WhileStatement(Loc loc, Expression *c, Statement *b) |
773 : Statement(loc) | 773 : Statement(loc) |
774 { | 774 { |
775 condition = c; | 775 condition = c; |
776 body = b; | 776 body = b; |
777 enclosingtry = NULL; | 777 enclosingtryfinally = NULL; |
778 } | 778 } |
779 | 779 |
780 Statement *WhileStatement::syntaxCopy() | 780 Statement *WhileStatement::syntaxCopy() |
781 { | 781 { |
782 WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body ? body->syntaxCopy() : NULL); | 782 WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body ? body->syntaxCopy() : NULL); |
807 Statement *si = new IfStatement(loc, condition, sw, NULL); | 807 Statement *si = new IfStatement(loc, condition, sw, NULL); |
808 return si->semantic(sc); | 808 return si->semantic(sc); |
809 } | 809 } |
810 #endif | 810 #endif |
811 | 811 |
812 enclosingtry = sc->tfOfTry; | 812 enclosingtryfinally = sc->tfOfTry; |
813 | 813 |
814 condition = condition->semantic(sc); | 814 condition = condition->semantic(sc); |
815 condition = resolveProperties(sc, condition); | 815 condition = resolveProperties(sc, condition); |
816 condition = condition->optimize(WANTvalue); | 816 condition = condition->optimize(WANTvalue); |
817 condition = condition->checkToBoolean(); | 817 condition = condition->checkToBoolean(); |
874 DoStatement::DoStatement(Loc loc, Statement *b, Expression *c) | 874 DoStatement::DoStatement(Loc loc, Statement *b, Expression *c) |
875 : Statement(loc) | 875 : Statement(loc) |
876 { | 876 { |
877 body = b; | 877 body = b; |
878 condition = c; | 878 condition = c; |
879 enclosingtry = NULL; | 879 enclosingtryfinally = NULL; |
880 } | 880 } |
881 | 881 |
882 Statement *DoStatement::syntaxCopy() | 882 Statement *DoStatement::syntaxCopy() |
883 { | 883 { |
884 DoStatement *s = new DoStatement(loc, body ? body->syntaxCopy() : NULL, condition->syntaxCopy()); | 884 DoStatement *s = new DoStatement(loc, body ? body->syntaxCopy() : NULL, condition->syntaxCopy()); |
886 } | 886 } |
887 | 887 |
888 | 888 |
889 Statement *DoStatement::semantic(Scope *sc) | 889 Statement *DoStatement::semantic(Scope *sc) |
890 { | 890 { |
891 enclosingtry = sc->tfOfTry; | 891 enclosingtryfinally = sc->tfOfTry; |
892 | 892 |
893 sc->noctor++; | 893 sc->noctor++; |
894 if (body) | 894 if (body) |
895 body = body->semanticScope(sc, this, this); | 895 body = body->semanticScope(sc, this, this); |
896 sc->noctor--; | 896 sc->noctor--; |
950 { | 950 { |
951 this->init = init; | 951 this->init = init; |
952 this->condition = condition; | 952 this->condition = condition; |
953 this->increment = increment; | 953 this->increment = increment; |
954 this->body = body; | 954 this->body = body; |
955 this->enclosingtry = NULL; | 955 this->enclosingtryfinally = NULL; |
956 } | 956 } |
957 | 957 |
958 Statement *ForStatement::syntaxCopy() | 958 Statement *ForStatement::syntaxCopy() |
959 { | 959 { |
960 Statement *i = NULL; | 960 Statement *i = NULL; |
970 return s; | 970 return s; |
971 } | 971 } |
972 | 972 |
973 Statement *ForStatement::semantic(Scope *sc) | 973 Statement *ForStatement::semantic(Scope *sc) |
974 { | 974 { |
975 enclosingtry = sc->tfOfTry; | 975 enclosingtryfinally = sc->tfOfTry; |
976 | 976 |
977 ScopeDsymbol *sym = new ScopeDsymbol(); | 977 ScopeDsymbol *sym = new ScopeDsymbol(); |
978 sym->parent = sc->scopesym; | 978 sym->parent = sc->scopesym; |
979 sc = sc->push(sym); | 979 sc = sc->push(sym); |
980 if (init) | 980 if (init) |
1084 { | 1084 { |
1085 this->op = op; | 1085 this->op = op; |
1086 this->arguments = arguments; | 1086 this->arguments = arguments; |
1087 this->aggr = aggr; | 1087 this->aggr = aggr; |
1088 this->body = body; | 1088 this->body = body; |
1089 this->enclosingtry = NULL; | 1089 this->enclosingtryfinally = NULL; |
1090 | 1090 |
1091 this->key = NULL; | 1091 this->key = NULL; |
1092 this->value = NULL; | 1092 this->value = NULL; |
1093 | 1093 |
1094 this->func = NULL; | 1094 this->func = NULL; |
1113 TypeAArray *taa = NULL; | 1113 TypeAArray *taa = NULL; |
1114 | 1114 |
1115 Type *tn = NULL; | 1115 Type *tn = NULL; |
1116 Type *tnv = NULL; | 1116 Type *tnv = NULL; |
1117 | 1117 |
1118 enclosingtry = sc->tfOfTry; | 1118 enclosingtryfinally = sc->tfOfTry; |
1119 | 1119 |
1120 func = sc->func; | 1120 func = sc->func; |
1121 if (func->fes) | 1121 if (func->fes) |
1122 func = func->fes->func; | 1122 func = func->fes->func; |
1123 | 1123 |
1969 body = b; | 1969 body = b; |
1970 sdefault = NULL; | 1970 sdefault = NULL; |
1971 cases = NULL; | 1971 cases = NULL; |
1972 hasNoDefault = 0; | 1972 hasNoDefault = 0; |
1973 // LLVMDC | 1973 // LLVMDC |
1974 enclosingtry = NULL; | 1974 enclosingtryfinally = NULL; |
1975 } | 1975 } |
1976 | 1976 |
1977 Statement *SwitchStatement::syntaxCopy() | 1977 Statement *SwitchStatement::syntaxCopy() |
1978 { | 1978 { |
1979 SwitchStatement *s = new SwitchStatement(loc, | 1979 SwitchStatement *s = new SwitchStatement(loc, |
1984 Statement *SwitchStatement::semantic(Scope *sc) | 1984 Statement *SwitchStatement::semantic(Scope *sc) |
1985 { | 1985 { |
1986 //printf("SwitchStatement::semantic(%p)\n", this); | 1986 //printf("SwitchStatement::semantic(%p)\n", this); |
1987 assert(!cases); // ensure semantic() is only run once | 1987 assert(!cases); // ensure semantic() is only run once |
1988 | 1988 |
1989 enclosingtry = sc->tfOfTry; | 1989 enclosingtryfinally = sc->tfOfTry; |
1990 | 1990 |
1991 condition = condition->semantic(sc); | 1991 condition = condition->semantic(sc); |
1992 condition = resolveProperties(sc, condition); | 1992 condition = resolveProperties(sc, condition); |
1993 if (condition->type->isString()) | 1993 if (condition->type->isString()) |
1994 { | 1994 { |
2272 | 2272 |
2273 GotoDefaultStatement::GotoDefaultStatement(Loc loc) | 2273 GotoDefaultStatement::GotoDefaultStatement(Loc loc) |
2274 : Statement(loc) | 2274 : Statement(loc) |
2275 { | 2275 { |
2276 sw = NULL; | 2276 sw = NULL; |
2277 enclosingtry = NULL; | 2277 enclosingtryfinally = NULL; |
2278 } | 2278 } |
2279 | 2279 |
2280 Statement *GotoDefaultStatement::syntaxCopy() | 2280 Statement *GotoDefaultStatement::syntaxCopy() |
2281 { | 2281 { |
2282 GotoDefaultStatement *s = new GotoDefaultStatement(loc); | 2282 GotoDefaultStatement *s = new GotoDefaultStatement(loc); |
2283 return s; | 2283 return s; |
2284 } | 2284 } |
2285 | 2285 |
2286 Statement *GotoDefaultStatement::semantic(Scope *sc) | 2286 Statement *GotoDefaultStatement::semantic(Scope *sc) |
2287 { | 2287 { |
2288 enclosingtry = sc->tfOfTry; | 2288 enclosingtryfinally = sc->tfOfTry; |
2289 sw = sc->sw; | 2289 sw = sc->sw; |
2290 if (!sw) | 2290 if (!sw) |
2291 error("goto default not in switch statement"); | 2291 error("goto default not in switch statement"); |
2292 return this; | 2292 return this; |
2293 } | 2293 } |
2307 GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp) | 2307 GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp) |
2308 : Statement(loc) | 2308 : Statement(loc) |
2309 { | 2309 { |
2310 cs = NULL; | 2310 cs = NULL; |
2311 this->exp = exp; | 2311 this->exp = exp; |
2312 enclosingtry = NULL; | 2312 enclosingtryfinally = NULL; |
2313 sw = NULL; | 2313 sw = NULL; |
2314 } | 2314 } |
2315 | 2315 |
2316 Statement *GotoCaseStatement::syntaxCopy() | 2316 Statement *GotoCaseStatement::syntaxCopy() |
2317 { | 2317 { |
2320 return s; | 2320 return s; |
2321 } | 2321 } |
2322 | 2322 |
2323 Statement *GotoCaseStatement::semantic(Scope *sc) | 2323 Statement *GotoCaseStatement::semantic(Scope *sc) |
2324 { | 2324 { |
2325 enclosingtry = sc->tfOfTry; | 2325 enclosingtryfinally = sc->tfOfTry; |
2326 if (exp) | 2326 if (exp) |
2327 exp = exp->semantic(sc); | 2327 exp = exp->semantic(sc); |
2328 | 2328 |
2329 if (!sc->sw) | 2329 if (!sc->sw) |
2330 error("goto case not in switch statement"); | 2330 error("goto case not in switch statement"); |
2379 | 2379 |
2380 ReturnStatement::ReturnStatement(Loc loc, Expression *exp) | 2380 ReturnStatement::ReturnStatement(Loc loc, Expression *exp) |
2381 : Statement(loc) | 2381 : Statement(loc) |
2382 { | 2382 { |
2383 this->exp = exp; | 2383 this->exp = exp; |
2384 this->enclosingtry = NULL; | 2384 this->enclosingtryfinally = NULL; |
2385 } | 2385 } |
2386 | 2386 |
2387 Statement *ReturnStatement::syntaxCopy() | 2387 Statement *ReturnStatement::syntaxCopy() |
2388 { | 2388 { |
2389 Expression *e = NULL; | 2389 Expression *e = NULL; |
2394 } | 2394 } |
2395 | 2395 |
2396 Statement *ReturnStatement::semantic(Scope *sc) | 2396 Statement *ReturnStatement::semantic(Scope *sc) |
2397 { | 2397 { |
2398 //printf("ReturnStatement::semantic() %s\n", toChars()); | 2398 //printf("ReturnStatement::semantic() %s\n", toChars()); |
2399 this->enclosingtry = sc->tfOfTry; | 2399 this->enclosingtryfinally = sc->tfOfTry; |
2400 | 2400 |
2401 FuncDeclaration *fd = sc->parent->isFuncDeclaration(); | 2401 FuncDeclaration *fd = sc->parent->isFuncDeclaration(); |
2402 Scope *scx = sc; | 2402 Scope *scx = sc; |
2403 int implicit0 = 0; | 2403 int implicit0 = 0; |
2404 | 2404 |
2655 | 2655 |
2656 BreakStatement::BreakStatement(Loc loc, Identifier *ident) | 2656 BreakStatement::BreakStatement(Loc loc, Identifier *ident) |
2657 : Statement(loc) | 2657 : Statement(loc) |
2658 { | 2658 { |
2659 this->ident = ident; | 2659 this->ident = ident; |
2660 this->enclosingtry = NULL; | 2660 this->enclosingtryfinally = NULL; |
2661 } | 2661 } |
2662 | 2662 |
2663 Statement *BreakStatement::syntaxCopy() | 2663 Statement *BreakStatement::syntaxCopy() |
2664 { | 2664 { |
2665 BreakStatement *s = new BreakStatement(loc, ident); | 2665 BreakStatement *s = new BreakStatement(loc, ident); |
2666 return s; | 2666 return s; |
2667 } | 2667 } |
2668 | 2668 |
2669 Statement *BreakStatement::semantic(Scope *sc) | 2669 Statement *BreakStatement::semantic(Scope *sc) |
2670 { | 2670 { |
2671 enclosingtry = sc->tfOfTry; | 2671 enclosingtryfinally = sc->tfOfTry; |
2672 // If: | 2672 // If: |
2673 // break Identifier; | 2673 // break Identifier; |
2674 if (ident) | 2674 if (ident) |
2675 { | 2675 { |
2676 Scope *scx; | 2676 Scope *scx; |
2749 | 2749 |
2750 ContinueStatement::ContinueStatement(Loc loc, Identifier *ident) | 2750 ContinueStatement::ContinueStatement(Loc loc, Identifier *ident) |
2751 : Statement(loc) | 2751 : Statement(loc) |
2752 { | 2752 { |
2753 this->ident = ident; | 2753 this->ident = ident; |
2754 this->enclosingtry = NULL; | 2754 this->enclosingtryfinally = NULL; |
2755 } | 2755 } |
2756 | 2756 |
2757 Statement *ContinueStatement::syntaxCopy() | 2757 Statement *ContinueStatement::syntaxCopy() |
2758 { | 2758 { |
2759 ContinueStatement *s = new ContinueStatement(loc, ident); | 2759 ContinueStatement *s = new ContinueStatement(loc, ident); |
2760 return s; | 2760 return s; |
2761 } | 2761 } |
2762 | 2762 |
2763 Statement *ContinueStatement::semantic(Scope *sc) | 2763 Statement *ContinueStatement::semantic(Scope *sc) |
2764 { | 2764 { |
2765 enclosingtry = sc->tfOfTry; | 2765 enclosingtryfinally = sc->tfOfTry; |
2766 //printf("ContinueStatement::semantic() %p\n", this); | 2766 //printf("ContinueStatement::semantic() %p\n", this); |
2767 if (ident) | 2767 if (ident) |
2768 { | 2768 { |
2769 Scope *scx; | 2769 Scope *scx; |
2770 FuncDeclaration *thisfunc = sc->func; | 2770 FuncDeclaration *thisfunc = sc->func; |
3193 TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody) | 3193 TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody) |
3194 : Statement(loc) | 3194 : Statement(loc) |
3195 { | 3195 { |
3196 this->body = body; | 3196 this->body = body; |
3197 this->finalbody = finalbody; | 3197 this->finalbody = finalbody; |
3198 this->enclosingtry = NULL; | 3198 this->enclosingtryfinally = NULL; |
3199 } | 3199 } |
3200 | 3200 |
3201 Statement *TryFinallyStatement::syntaxCopy() | 3201 Statement *TryFinallyStatement::syntaxCopy() |
3202 { | 3202 { |
3203 TryFinallyStatement *s = new TryFinallyStatement(loc, | 3203 TryFinallyStatement *s = new TryFinallyStatement(loc, |
3207 | 3207 |
3208 Statement *TryFinallyStatement::semantic(Scope *sc) | 3208 Statement *TryFinallyStatement::semantic(Scope *sc) |
3209 { | 3209 { |
3210 //printf("TryFinallyStatement::semantic()\n"); | 3210 //printf("TryFinallyStatement::semantic()\n"); |
3211 | 3211 |
3212 enclosingtry = sc->tfOfTry; | 3212 enclosingtryfinally = sc->tfOfTry; |
3213 sc->tfOfTry = this; | 3213 sc->tfOfTry = this; |
3214 body = body->semantic(sc); | 3214 body = body->semantic(sc); |
3215 sc->tfOfTry = enclosingtry; | 3215 sc->tfOfTry = enclosingtryfinally; |
3216 | 3216 |
3217 sc = sc->push(); | 3217 sc = sc->push(); |
3218 sc->tf = this; | 3218 sc->tf = this; |
3219 sc->sbreak = NULL; | 3219 sc->sbreak = NULL; |
3220 sc->scontinue = NULL; // no break or continue out of finally block | 3220 sc->scontinue = NULL; // no break or continue out of finally block |
3445 : Statement(loc) | 3445 : Statement(loc) |
3446 { | 3446 { |
3447 this->ident = ident; | 3447 this->ident = ident; |
3448 this->label = NULL; | 3448 this->label = NULL; |
3449 this->tf = NULL; | 3449 this->tf = NULL; |
3450 this->enclosingtry = NULL; | 3450 this->enclosingtryfinally = NULL; |
3451 } | 3451 } |
3452 | 3452 |
3453 Statement *GotoStatement::syntaxCopy() | 3453 Statement *GotoStatement::syntaxCopy() |
3454 { | 3454 { |
3455 GotoStatement *s = new GotoStatement(loc, ident); | 3455 GotoStatement *s = new GotoStatement(loc, ident); |
3459 Statement *GotoStatement::semantic(Scope *sc) | 3459 Statement *GotoStatement::semantic(Scope *sc) |
3460 { FuncDeclaration *fd = sc->parent->isFuncDeclaration(); | 3460 { FuncDeclaration *fd = sc->parent->isFuncDeclaration(); |
3461 | 3461 |
3462 //printf("GotoStatement::semantic()\n"); | 3462 //printf("GotoStatement::semantic()\n"); |
3463 tf = sc->tf; | 3463 tf = sc->tf; |
3464 enclosingtry = sc->tfOfTry; | 3464 enclosingtryfinally = sc->tfOfTry; |
3465 label = fd->searchLabel(ident); | 3465 label = fd->searchLabel(ident); |
3466 if (!label->statement && sc->fes) | 3466 if (!label->statement && sc->fes) |
3467 { | 3467 { |
3468 /* Either the goto label is forward referenced or it | 3468 /* Either the goto label is forward referenced or it |
3469 * is in the function that the enclosing foreach is in. | 3469 * is in the function that the enclosing foreach is in. |
3503 : Statement(loc) | 3503 : Statement(loc) |
3504 { | 3504 { |
3505 this->ident = ident; | 3505 this->ident = ident; |
3506 this->statement = statement; | 3506 this->statement = statement; |
3507 this->tf = NULL; | 3507 this->tf = NULL; |
3508 this->enclosingtry = NULL; | 3508 this->enclosingtryfinally = NULL; |
3509 this->lblock = NULL; | 3509 this->lblock = NULL; |
3510 this->isReturnLabel = 0; | 3510 this->isReturnLabel = 0; |
3511 this->llvmBB = NULL; | 3511 this->llvmBB = NULL; |
3512 } | 3512 } |
3513 | 3513 |
3526 if (ls->statement) | 3526 if (ls->statement) |
3527 error("Label '%s' already defined", ls->toChars()); | 3527 error("Label '%s' already defined", ls->toChars()); |
3528 else | 3528 else |
3529 ls->statement = this; | 3529 ls->statement = this; |
3530 tf = sc->tf; | 3530 tf = sc->tf; |
3531 enclosingtry = sc->tfOfTry; | 3531 enclosingtryfinally = sc->tfOfTry; |
3532 sc = sc->push(); | 3532 sc = sc->push(); |
3533 sc->scopesym = sc->enclosing->scopesym; | 3533 sc->scopesym = sc->enclosing->scopesym; |
3534 sc->callSuper |= CSXlabel; | 3534 sc->callSuper |= CSXlabel; |
3535 sc->slabel = this; | 3535 sc->slabel = this; |
3536 if (statement) | 3536 if (statement) |