comparison dmd/statement.c @ 309:d59c363fccad trunk

[svn r330] Implemented synchronized statements. Changed the tryfinally handlers to a more generalized EnclosingHandler. Changed ClassInfoS to be mutable so they can be used as locks. Added new BB after throw ala return/break etc.
author lindquist
date Sat, 28 Jun 2008 11:37:53 +0200
parents 2b72433d5c8c
children d20cf0dec9c1
comparison
equal deleted inserted replaced
308:6b62e8cdf970 309:d59c363fccad
558 558
559 UnrolledLoopStatement::UnrolledLoopStatement(Loc loc, Statements *s) 559 UnrolledLoopStatement::UnrolledLoopStatement(Loc loc, Statements *s)
560 : Statement(loc) 560 : Statement(loc)
561 { 561 {
562 statements = s; 562 statements = s;
563 enclosingtryfinally = NULL; 563 enclosinghandler = NULL;
564 } 564 }
565 565
566 Statement *UnrolledLoopStatement::syntaxCopy() 566 Statement *UnrolledLoopStatement::syntaxCopy()
567 { 567 {
568 Statements *a = new Statements(); 568 Statements *a = new Statements();
580 580
581 Statement *UnrolledLoopStatement::semantic(Scope *sc) 581 Statement *UnrolledLoopStatement::semantic(Scope *sc)
582 { 582 {
583 //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc); 583 //printf("UnrolledLoopStatement::semantic(this = %p, sc = %p)\n", this, sc);
584 584
585 enclosingtryfinally = sc->tfOfTry; 585 enclosinghandler = sc->tfOfTry;
586 586
587 sc->noctor++; 587 sc->noctor++;
588 Scope *scd = sc->push(); 588 Scope *scd = sc->push();
589 scd->sbreak = this; 589 scd->sbreak = this;
590 scd->scontinue = this; 590 scd->scontinue = this;
771 WhileStatement::WhileStatement(Loc loc, Expression *c, Statement *b) 771 WhileStatement::WhileStatement(Loc loc, Expression *c, Statement *b)
772 : Statement(loc) 772 : Statement(loc)
773 { 773 {
774 condition = c; 774 condition = c;
775 body = b; 775 body = b;
776 enclosingtryfinally = NULL; 776 enclosinghandler = NULL;
777 } 777 }
778 778
779 Statement *WhileStatement::syntaxCopy() 779 Statement *WhileStatement::syntaxCopy()
780 { 780 {
781 WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body ? body->syntaxCopy() : NULL); 781 WhileStatement *s = new WhileStatement(loc, condition->syntaxCopy(), body ? body->syntaxCopy() : NULL);
806 Statement *si = new IfStatement(loc, condition, sw, NULL); 806 Statement *si = new IfStatement(loc, condition, sw, NULL);
807 return si->semantic(sc); 807 return si->semantic(sc);
808 } 808 }
809 #endif 809 #endif
810 810
811 enclosingtryfinally = sc->tfOfTry; 811 enclosinghandler = sc->tfOfTry;
812 812
813 condition = condition->semantic(sc); 813 condition = condition->semantic(sc);
814 condition = resolveProperties(sc, condition); 814 condition = resolveProperties(sc, condition);
815 condition = condition->optimize(WANTvalue); 815 condition = condition->optimize(WANTvalue);
816 condition = condition->checkToBoolean(); 816 condition = condition->checkToBoolean();
873 DoStatement::DoStatement(Loc loc, Statement *b, Expression *c) 873 DoStatement::DoStatement(Loc loc, Statement *b, Expression *c)
874 : Statement(loc) 874 : Statement(loc)
875 { 875 {
876 body = b; 876 body = b;
877 condition = c; 877 condition = c;
878 enclosingtryfinally = NULL; 878 enclosinghandler = NULL;
879 } 879 }
880 880
881 Statement *DoStatement::syntaxCopy() 881 Statement *DoStatement::syntaxCopy()
882 { 882 {
883 DoStatement *s = new DoStatement(loc, body ? body->syntaxCopy() : NULL, condition->syntaxCopy()); 883 DoStatement *s = new DoStatement(loc, body ? body->syntaxCopy() : NULL, condition->syntaxCopy());
885 } 885 }
886 886
887 887
888 Statement *DoStatement::semantic(Scope *sc) 888 Statement *DoStatement::semantic(Scope *sc)
889 { 889 {
890 enclosingtryfinally = sc->tfOfTry; 890 enclosinghandler = sc->tfOfTry;
891 891
892 sc->noctor++; 892 sc->noctor++;
893 if (body) 893 if (body)
894 body = body->semanticScope(sc, this, this); 894 body = body->semanticScope(sc, this, this);
895 sc->noctor--; 895 sc->noctor--;
949 { 949 {
950 this->init = init; 950 this->init = init;
951 this->condition = condition; 951 this->condition = condition;
952 this->increment = increment; 952 this->increment = increment;
953 this->body = body; 953 this->body = body;
954 this->enclosingtryfinally = NULL; 954 this->enclosinghandler = NULL;
955 } 955 }
956 956
957 Statement *ForStatement::syntaxCopy() 957 Statement *ForStatement::syntaxCopy()
958 { 958 {
959 Statement *i = NULL; 959 Statement *i = NULL;
969 return s; 969 return s;
970 } 970 }
971 971
972 Statement *ForStatement::semantic(Scope *sc) 972 Statement *ForStatement::semantic(Scope *sc)
973 { 973 {
974 enclosingtryfinally = sc->tfOfTry; 974 enclosinghandler = sc->tfOfTry;
975 975
976 ScopeDsymbol *sym = new ScopeDsymbol(); 976 ScopeDsymbol *sym = new ScopeDsymbol();
977 sym->parent = sc->scopesym; 977 sym->parent = sc->scopesym;
978 sc = sc->push(sym); 978 sc = sc->push(sym);
979 if (init) 979 if (init)
1083 { 1083 {
1084 this->op = op; 1084 this->op = op;
1085 this->arguments = arguments; 1085 this->arguments = arguments;
1086 this->aggr = aggr; 1086 this->aggr = aggr;
1087 this->body = body; 1087 this->body = body;
1088 this->enclosingtryfinally = NULL; 1088 this->enclosinghandler = NULL;
1089 1089
1090 this->key = NULL; 1090 this->key = NULL;
1091 this->value = NULL; 1091 this->value = NULL;
1092 1092
1093 this->func = NULL; 1093 this->func = NULL;
1112 TypeAArray *taa = NULL; 1112 TypeAArray *taa = NULL;
1113 1113
1114 Type *tn = NULL; 1114 Type *tn = NULL;
1115 Type *tnv = NULL; 1115 Type *tnv = NULL;
1116 1116
1117 enclosingtryfinally = sc->tfOfTry; 1117 enclosinghandler = sc->tfOfTry;
1118 1118
1119 func = sc->func; 1119 func = sc->func;
1120 if (func->fes) 1120 if (func->fes)
1121 func = func->fes->func; 1121 func = func->fes->func;
1122 1122
1979 body = b; 1979 body = b;
1980 sdefault = NULL; 1980 sdefault = NULL;
1981 cases = NULL; 1981 cases = NULL;
1982 hasNoDefault = 0; 1982 hasNoDefault = 0;
1983 // LLVMDC 1983 // LLVMDC
1984 enclosingtryfinally = NULL; 1984 enclosinghandler = NULL;
1985 } 1985 }
1986 1986
1987 Statement *SwitchStatement::syntaxCopy() 1987 Statement *SwitchStatement::syntaxCopy()
1988 { 1988 {
1989 SwitchStatement *s = new SwitchStatement(loc, 1989 SwitchStatement *s = new SwitchStatement(loc,
1994 Statement *SwitchStatement::semantic(Scope *sc) 1994 Statement *SwitchStatement::semantic(Scope *sc)
1995 { 1995 {
1996 //printf("SwitchStatement::semantic(%p)\n", this); 1996 //printf("SwitchStatement::semantic(%p)\n", this);
1997 assert(!cases); // ensure semantic() is only run once 1997 assert(!cases); // ensure semantic() is only run once
1998 1998
1999 enclosingtryfinally = sc->tfOfTry; 1999 enclosinghandler = sc->tfOfTry;
2000 2000
2001 condition = condition->semantic(sc); 2001 condition = condition->semantic(sc);
2002 condition = resolveProperties(sc, condition); 2002 condition = resolveProperties(sc, condition);
2003 if (condition->type->isString()) 2003 if (condition->type->isString())
2004 { 2004 {
2282 2282
2283 GotoDefaultStatement::GotoDefaultStatement(Loc loc) 2283 GotoDefaultStatement::GotoDefaultStatement(Loc loc)
2284 : Statement(loc) 2284 : Statement(loc)
2285 { 2285 {
2286 sw = NULL; 2286 sw = NULL;
2287 enclosingtryfinally = NULL; 2287 enclosinghandler = NULL;
2288 } 2288 }
2289 2289
2290 Statement *GotoDefaultStatement::syntaxCopy() 2290 Statement *GotoDefaultStatement::syntaxCopy()
2291 { 2291 {
2292 GotoDefaultStatement *s = new GotoDefaultStatement(loc); 2292 GotoDefaultStatement *s = new GotoDefaultStatement(loc);
2293 return s; 2293 return s;
2294 } 2294 }
2295 2295
2296 Statement *GotoDefaultStatement::semantic(Scope *sc) 2296 Statement *GotoDefaultStatement::semantic(Scope *sc)
2297 { 2297 {
2298 enclosingtryfinally = sc->tfOfTry; 2298 enclosinghandler = sc->tfOfTry;
2299 sw = sc->sw; 2299 sw = sc->sw;
2300 if (!sw) 2300 if (!sw)
2301 error("goto default not in switch statement"); 2301 error("goto default not in switch statement");
2302 return this; 2302 return this;
2303 } 2303 }
2317 GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp) 2317 GotoCaseStatement::GotoCaseStatement(Loc loc, Expression *exp)
2318 : Statement(loc) 2318 : Statement(loc)
2319 { 2319 {
2320 cs = NULL; 2320 cs = NULL;
2321 this->exp = exp; 2321 this->exp = exp;
2322 enclosingtryfinally = NULL; 2322 enclosinghandler = NULL;
2323 sw = NULL; 2323 sw = NULL;
2324 } 2324 }
2325 2325
2326 Statement *GotoCaseStatement::syntaxCopy() 2326 Statement *GotoCaseStatement::syntaxCopy()
2327 { 2327 {
2330 return s; 2330 return s;
2331 } 2331 }
2332 2332
2333 Statement *GotoCaseStatement::semantic(Scope *sc) 2333 Statement *GotoCaseStatement::semantic(Scope *sc)
2334 { 2334 {
2335 enclosingtryfinally = sc->tfOfTry; 2335 enclosinghandler = sc->tfOfTry;
2336 if (exp) 2336 if (exp)
2337 exp = exp->semantic(sc); 2337 exp = exp->semantic(sc);
2338 2338
2339 if (!sc->sw) 2339 if (!sc->sw)
2340 error("goto case not in switch statement"); 2340 error("goto case not in switch statement");
2389 2389
2390 ReturnStatement::ReturnStatement(Loc loc, Expression *exp) 2390 ReturnStatement::ReturnStatement(Loc loc, Expression *exp)
2391 : Statement(loc) 2391 : Statement(loc)
2392 { 2392 {
2393 this->exp = exp; 2393 this->exp = exp;
2394 this->enclosingtryfinally = NULL; 2394 this->enclosinghandler = NULL;
2395 } 2395 }
2396 2396
2397 Statement *ReturnStatement::syntaxCopy() 2397 Statement *ReturnStatement::syntaxCopy()
2398 { 2398 {
2399 Expression *e = NULL; 2399 Expression *e = NULL;
2404 } 2404 }
2405 2405
2406 Statement *ReturnStatement::semantic(Scope *sc) 2406 Statement *ReturnStatement::semantic(Scope *sc)
2407 { 2407 {
2408 //printf("ReturnStatement::semantic() %s\n", toChars()); 2408 //printf("ReturnStatement::semantic() %s\n", toChars());
2409 this->enclosingtryfinally = sc->tfOfTry; 2409 this->enclosinghandler = sc->tfOfTry;
2410 2410
2411 FuncDeclaration *fd = sc->parent->isFuncDeclaration(); 2411 FuncDeclaration *fd = sc->parent->isFuncDeclaration();
2412 Scope *scx = sc; 2412 Scope *scx = sc;
2413 int implicit0 = 0; 2413 int implicit0 = 0;
2414 2414
2665 2665
2666 BreakStatement::BreakStatement(Loc loc, Identifier *ident) 2666 BreakStatement::BreakStatement(Loc loc, Identifier *ident)
2667 : Statement(loc) 2667 : Statement(loc)
2668 { 2668 {
2669 this->ident = ident; 2669 this->ident = ident;
2670 this->enclosingtryfinally = NULL; 2670 this->enclosinghandler = NULL;
2671 } 2671 }
2672 2672
2673 Statement *BreakStatement::syntaxCopy() 2673 Statement *BreakStatement::syntaxCopy()
2674 { 2674 {
2675 BreakStatement *s = new BreakStatement(loc, ident); 2675 BreakStatement *s = new BreakStatement(loc, ident);
2676 return s; 2676 return s;
2677 } 2677 }
2678 2678
2679 Statement *BreakStatement::semantic(Scope *sc) 2679 Statement *BreakStatement::semantic(Scope *sc)
2680 { 2680 {
2681 enclosingtryfinally = sc->tfOfTry; 2681 enclosinghandler = sc->tfOfTry;
2682 // If: 2682 // If:
2683 // break Identifier; 2683 // break Identifier;
2684 if (ident) 2684 if (ident)
2685 { 2685 {
2686 Scope *scx; 2686 Scope *scx;
2759 2759
2760 ContinueStatement::ContinueStatement(Loc loc, Identifier *ident) 2760 ContinueStatement::ContinueStatement(Loc loc, Identifier *ident)
2761 : Statement(loc) 2761 : Statement(loc)
2762 { 2762 {
2763 this->ident = ident; 2763 this->ident = ident;
2764 this->enclosingtryfinally = NULL; 2764 this->enclosinghandler = NULL;
2765 } 2765 }
2766 2766
2767 Statement *ContinueStatement::syntaxCopy() 2767 Statement *ContinueStatement::syntaxCopy()
2768 { 2768 {
2769 ContinueStatement *s = new ContinueStatement(loc, ident); 2769 ContinueStatement *s = new ContinueStatement(loc, ident);
2770 return s; 2770 return s;
2771 } 2771 }
2772 2772
2773 Statement *ContinueStatement::semantic(Scope *sc) 2773 Statement *ContinueStatement::semantic(Scope *sc)
2774 { 2774 {
2775 enclosingtryfinally = sc->tfOfTry; 2775 enclosinghandler = sc->tfOfTry;
2776 //printf("ContinueStatement::semantic() %p\n", this); 2776 //printf("ContinueStatement::semantic() %p\n", this);
2777 if (ident) 2777 if (ident)
2778 { 2778 {
2779 Scope *scx; 2779 Scope *scx;
2780 FuncDeclaration *thisfunc = sc->func; 2780 FuncDeclaration *thisfunc = sc->func;
2864 : Statement(loc) 2864 : Statement(loc)
2865 { 2865 {
2866 this->exp = exp; 2866 this->exp = exp;
2867 this->body = body; 2867 this->body = body;
2868 this->esync = NULL; 2868 this->esync = NULL;
2869 // LLVMDC
2870 this->llsync = NULL;
2869 } 2871 }
2870 2872
2871 SynchronizedStatement::SynchronizedStatement(Loc loc, elem *esync, Statement *body) 2873 SynchronizedStatement::SynchronizedStatement(Loc loc, elem *esync, Statement *body)
2872 : Statement(loc) 2874 : Statement(loc)
2873 { 2875 {
2874 this->exp = NULL; 2876 this->exp = NULL;
2875 this->body = body; 2877 this->body = body;
2876 this->esync = esync; 2878 this->esync = esync;
2879 // LLVMDC
2880 this->llsync = NULL;
2877 } 2881 }
2878 2882
2879 Statement *SynchronizedStatement::syntaxCopy() 2883 Statement *SynchronizedStatement::syntaxCopy()
2880 { 2884 {
2881 Expression *e = exp ? exp->syntaxCopy() : NULL; 2885 Expression *e = exp ? exp->syntaxCopy() : NULL;
2900 exp = new CastExp(loc, exp, t); 2904 exp = new CastExp(loc, exp, t);
2901 exp = exp->semantic(sc); 2905 exp = exp->semantic(sc);
2902 } 2906 }
2903 } 2907 }
2904 if (body) 2908 if (body)
2905 body = body->semantic(sc); 2909 {
2910 enclosinghandler = sc->tfOfTry;
2911 sc->tfOfTry = new EnclosingSynchro(this);
2912 body = body->semantic(sc);
2913 sc->tfOfTry = enclosinghandler;
2914 }
2906 return this; 2915 return this;
2907 } 2916 }
2908 2917
2909 int SynchronizedStatement::hasBreak() 2918 int SynchronizedStatement::hasBreak()
2910 { 2919 {
3203 TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody) 3212 TryFinallyStatement::TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody)
3204 : Statement(loc) 3213 : Statement(loc)
3205 { 3214 {
3206 this->body = body; 3215 this->body = body;
3207 this->finalbody = finalbody; 3216 this->finalbody = finalbody;
3208 this->enclosingtryfinally = NULL; 3217 this->enclosinghandler = NULL;
3209 } 3218 }
3210 3219
3211 Statement *TryFinallyStatement::syntaxCopy() 3220 Statement *TryFinallyStatement::syntaxCopy()
3212 { 3221 {
3213 TryFinallyStatement *s = new TryFinallyStatement(loc, 3222 TryFinallyStatement *s = new TryFinallyStatement(loc,
3217 3226
3218 Statement *TryFinallyStatement::semantic(Scope *sc) 3227 Statement *TryFinallyStatement::semantic(Scope *sc)
3219 { 3228 {
3220 //printf("TryFinallyStatement::semantic()\n"); 3229 //printf("TryFinallyStatement::semantic()\n");
3221 3230
3222 enclosingtryfinally = sc->tfOfTry; 3231 enclosinghandler = sc->tfOfTry;
3223 sc->tfOfTry = this; 3232 sc->tfOfTry = new EnclosingTryFinally(this);
3224 body = body->semantic(sc); 3233 body = body->semantic(sc);
3225 sc->tfOfTry = enclosingtryfinally; 3234 sc->tfOfTry = enclosinghandler;
3226 3235
3227 sc = sc->push(); 3236 sc = sc->push();
3228 sc->tf = this; 3237 sc->tf = this;
3229 sc->sbreak = NULL; 3238 sc->sbreak = NULL;
3230 sc->scontinue = NULL; // no break or continue out of finally block 3239 sc->scontinue = NULL; // no break or continue out of finally block
3397 3406
3398 VolatileStatement::VolatileStatement(Loc loc, Statement *statement) 3407 VolatileStatement::VolatileStatement(Loc loc, Statement *statement)
3399 : Statement(loc) 3408 : Statement(loc)
3400 { 3409 {
3401 this->statement = statement; 3410 this->statement = statement;
3411 this->enclosinghandler = NULL;
3402 } 3412 }
3403 3413
3404 Statement *VolatileStatement::syntaxCopy() 3414 Statement *VolatileStatement::syntaxCopy()
3405 { 3415 {
3406 VolatileStatement *s = new VolatileStatement(loc, 3416 VolatileStatement *s = new VolatileStatement(loc,
3408 return s; 3418 return s;
3409 } 3419 }
3410 3420
3411 Statement *VolatileStatement::semantic(Scope *sc) 3421 Statement *VolatileStatement::semantic(Scope *sc)
3412 { 3422 {
3413 statement = statement ? statement->semantic(sc) : NULL; 3423 if (statement)
3424 {
3425 enclosinghandler = sc->tfOfTry;
3426 sc->tfOfTry = new EnclosingVolatile(this);
3427 statement = statement->semantic(sc);
3428 sc->tfOfTry = enclosinghandler;
3429 }
3414 return this; 3430 return this;
3415 } 3431 }
3416 3432
3417 Statements *VolatileStatement::flatten(Scope *sc) 3433 Statements *VolatileStatement::flatten(Scope *sc)
3418 { 3434 {
3455 : Statement(loc) 3471 : Statement(loc)
3456 { 3472 {
3457 this->ident = ident; 3473 this->ident = ident;
3458 this->label = NULL; 3474 this->label = NULL;
3459 this->tf = NULL; 3475 this->tf = NULL;
3460 this->enclosingtryfinally = NULL; 3476 this->enclosinghandler = NULL;
3461 } 3477 }
3462 3478
3463 Statement *GotoStatement::syntaxCopy() 3479 Statement *GotoStatement::syntaxCopy()
3464 { 3480 {
3465 GotoStatement *s = new GotoStatement(loc, ident); 3481 GotoStatement *s = new GotoStatement(loc, ident);
3469 Statement *GotoStatement::semantic(Scope *sc) 3485 Statement *GotoStatement::semantic(Scope *sc)
3470 { FuncDeclaration *fd = sc->parent->isFuncDeclaration(); 3486 { FuncDeclaration *fd = sc->parent->isFuncDeclaration();
3471 3487
3472 //printf("GotoStatement::semantic()\n"); 3488 //printf("GotoStatement::semantic()\n");
3473 tf = sc->tf; 3489 tf = sc->tf;
3474 enclosingtryfinally = sc->tfOfTry; 3490 enclosinghandler = sc->tfOfTry;
3475 label = fd->searchLabel(ident); 3491 label = fd->searchLabel(ident);
3476 if (!label->statement && sc->fes) 3492 if (!label->statement && sc->fes)
3477 { 3493 {
3478 /* Either the goto label is forward referenced or it 3494 /* Either the goto label is forward referenced or it
3479 * is in the function that the enclosing foreach is in. 3495 * is in the function that the enclosing foreach is in.
3513 : Statement(loc) 3529 : Statement(loc)
3514 { 3530 {
3515 this->ident = ident; 3531 this->ident = ident;
3516 this->statement = statement; 3532 this->statement = statement;
3517 this->tf = NULL; 3533 this->tf = NULL;
3518 this->enclosingtryfinally = NULL; 3534 this->enclosinghandler = NULL;
3519 this->lblock = NULL; 3535 this->lblock = NULL;
3520 this->isReturnLabel = 0; 3536 this->isReturnLabel = 0;
3521 this->llvmBB = NULL; 3537 this->llvmBB = NULL;
3522 this->asmLabel = false; 3538 this->asmLabel = false;
3523 } 3539 }
3537 if (ls->statement) 3553 if (ls->statement)
3538 error("Label '%s' already defined", ls->toChars()); 3554 error("Label '%s' already defined", ls->toChars());
3539 else 3555 else
3540 ls->statement = this; 3556 ls->statement = this;
3541 tf = sc->tf; 3557 tf = sc->tf;
3542 enclosingtryfinally = sc->tfOfTry; 3558 enclosinghandler = sc->tfOfTry;
3543 sc = sc->push(); 3559 sc = sc->push();
3544 sc->scopesym = sc->enclosing->scopesym; 3560 sc->scopesym = sc->enclosing->scopesym;
3545 sc->callSuper |= CSXlabel; 3561 sc->callSuper |= CSXlabel;
3546 sc->slabel = this; 3562 sc->slabel = this;
3547 if (statement) 3563 if (statement)