Mercurial > projects > ldc
comparison dmd/func.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 | b28a57f4b530 |
comparison
equal
deleted
inserted
replaced
1137:45d73f0a9b43 | 1141:f99a3b393c03 |
---|---|
680 sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated | STCfinal); | 680 sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated | STCfinal); |
681 sc2->protection = PROTpublic; | 681 sc2->protection = PROTpublic; |
682 sc2->explicitProtection = 0; | 682 sc2->explicitProtection = 0; |
683 sc2->structalign = 8; | 683 sc2->structalign = 8; |
684 sc2->incontract = 0; | 684 sc2->incontract = 0; |
685 sc2->tf = NULL; | 685 sc2->enclosingFinally = NULL; |
686 sc2->tfOfTry = NULL; | 686 sc2->enclosingScopeExit = NULL; |
687 sc2->noctor = 0; | 687 sc2->noctor = 0; |
688 | 688 |
689 // Declare 'this' | 689 // Declare 'this' |
690 ad = isThis(); | 690 ad = isThis(); |
691 if (ad) | 691 if (ad) |
1241 a->push(s); | 1241 a->push(s); |
1242 } | 1242 } |
1243 } | 1243 } |
1244 | 1244 |
1245 fbody = new CompoundStatement(0, a); | 1245 fbody = new CompoundStatement(0, a); |
1246 | |
1247 // wrap body of synchronized functions in a synchronized statement | |
1248 if (isSynchronized()) | |
1249 { | |
1250 ClassDeclaration *cd = parent->isClassDeclaration(); | |
1251 if (!cd) | |
1252 error("synchronized function %s must be a member of a class", toChars()); | |
1253 | |
1254 Expression *sync; | |
1255 if (isStatic()) | |
1256 { | |
1257 // static member functions synchronize on classinfo | |
1258 // (the expression passed doesn't matter) | |
1259 sync = cd->type->dotExp(sc2, new DollarExp(loc), Id::classinfo); | |
1260 } | |
1261 else | |
1262 { | |
1263 // non-static member functions synchronize on this | |
1264 sync = new VarExp(loc, vthis); | |
1265 } | |
1266 | |
1267 // is is ok to not rerun semantic on the whole fbody here; only the enclosingScopeExit | |
1268 // value will differ and as it is impossible to goto out of this synchronized statement, | |
1269 // that should not lead to errors | |
1270 SynchronizedStatement* s = new SynchronizedStatement(loc, sync, NULL); | |
1271 s->semantic(sc2); | |
1272 s->body = fbody; | |
1273 | |
1274 a = new Statements; | |
1275 a->push(s); | |
1276 fbody = new CompoundStatement(0, a); | |
1277 } | |
1246 } | 1278 } |
1247 | 1279 |
1248 sc2->callSuper = 0; | 1280 sc2->callSuper = 0; |
1249 sc2->pop(); | 1281 sc2->pop(); |
1250 } | 1282 } |