Mercurial > projects > ldc
comparison dmd/inline.c @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | d9c5f5a43403 |
children | 44b145be2ef5 |
comparison
equal
deleted
inserted
replaced
1586:7f728c52e63c | 1587:def7a1d494fd |
---|---|
1 | 1 |
2 // Copyright (c) 1999-2008 by Digital Mars | 2 // Copyright (c) 1999-2009 by Digital Mars |
3 // All Rights Reserved | 3 // All Rights Reserved |
4 // written by Walter Bright | 4 // written by Walter Bright |
5 // http://www.digitalmars.com | 5 // http://www.digitalmars.com |
6 // License for redistribution is by either the Artistic License | 6 // License for redistribution is by either the Artistic License |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | 7 // in artistic.txt, or the GNU General Public License in gnu.txt. |
868 init = init->inlineScan(iss); | 868 init = init->inlineScan(iss); |
869 if (condition) | 869 if (condition) |
870 condition = condition->inlineScan(iss); | 870 condition = condition->inlineScan(iss); |
871 if (increment) | 871 if (increment) |
872 increment = increment->inlineScan(iss); | 872 increment = increment->inlineScan(iss); |
873 body = body->inlineScan(iss); | 873 if (body) |
874 body = body->inlineScan(iss); | |
874 return this; | 875 return this; |
875 } | 876 } |
876 | 877 |
877 | 878 |
878 Statement *ForeachStatement::inlineScan(InlineScanState *iss) | 879 Statement *ForeachStatement::inlineScan(InlineScanState *iss) |
1070 { | 1071 { |
1071 ExpInitializer *ie = vd->init->isExpInitializer(); | 1072 ExpInitializer *ie = vd->init->isExpInitializer(); |
1072 | 1073 |
1073 if (ie) | 1074 if (ie) |
1074 { | 1075 { |
1076 #if DMDV2 | |
1077 if (vd->type) | |
1078 { Type *tb = vd->type->toBasetype(); | |
1079 if (tb->ty == Tstruct) | |
1080 { StructDeclaration *sd = ((TypeStruct *)tb)->sym; | |
1081 if (sd->cpctor) | |
1082 { /* The problem here is that if the initializer is a | |
1083 * function call that returns a struct S with a cpctor: | |
1084 * S s = foo(); | |
1085 * the postblit is done by the return statement in foo() | |
1086 * in s2ir.c, the intermediate code generator. | |
1087 * But, if foo() is inlined and now the code looks like: | |
1088 * S s = x; | |
1089 * the postblit is not there, because such assignments | |
1090 * are rewritten as s.cpctor(&x) by the front end. | |
1091 * So, the inlining won't get the postblit called. | |
1092 * Work around by not inlining these cases. | |
1093 * A proper fix would be to move all the postblit | |
1094 * additions to the front end. | |
1095 */ | |
1096 return; | |
1097 } | |
1098 } | |
1099 } | |
1100 #endif | |
1075 ie->exp = ie->exp->inlineScan(iss); | 1101 ie->exp = ie->exp->inlineScan(iss); |
1076 } | 1102 } |
1077 } | 1103 } |
1078 } | 1104 } |
1079 } | 1105 } |
1403 { | 1429 { |
1404 VarDeclaration *vthis; | 1430 VarDeclaration *vthis; |
1405 ExpInitializer *ei; | 1431 ExpInitializer *ei; |
1406 VarExp *ve; | 1432 VarExp *ve; |
1407 | 1433 |
1434 #if STRUCTTHISREF | |
1435 if (ethis->type->ty == Tpointer) | |
1436 { Type *t = ethis->type->nextOf(); | |
1437 ethis = new PtrExp(ethis->loc, ethis); | |
1438 ethis->type = t; | |
1439 } | |
1440 ei = new ExpInitializer(ethis->loc, ethis); | |
1441 | |
1442 vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei); | |
1443 if (ethis->type->ty != Tclass) | |
1444 vthis->storage_class = STCref; | |
1445 else | |
1446 vthis->storage_class = STCin; | |
1447 #else | |
1408 if (ethis->type->ty != Tclass && ethis->type->ty != Tpointer) | 1448 if (ethis->type->ty != Tclass && ethis->type->ty != Tpointer) |
1409 { | 1449 { |
1410 ethis = ethis->addressOf(NULL); | 1450 ethis = ethis->addressOf(NULL); |
1411 } | 1451 } |
1412 | 1452 |
1413 ei = new ExpInitializer(ethis->loc, ethis); | 1453 ei = new ExpInitializer(ethis->loc, ethis); |
1414 | 1454 |
1415 vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei); | 1455 vthis = new VarDeclaration(ethis->loc, ethis->type, Id::This, ei); |
1416 vthis->storage_class = STCin; | 1456 vthis->storage_class = STCin; |
1457 #endif | |
1417 vthis->linkage = LINKd; | 1458 vthis->linkage = LINKd; |
1418 vthis->parent = iss->fd; | 1459 vthis->parent = iss->fd; |
1419 | 1460 |
1420 ve = new VarExp(vthis->loc, vthis); | 1461 ve = new VarExp(vthis->loc, vthis); |
1421 ve->type = vthis->type; | 1462 ve->type = vthis->type; |
1422 | 1463 |
1423 ei->exp = new AssignExp(vthis->loc, ve, ethis); | 1464 ei->exp = new AssignExp(vthis->loc, ve, ethis); |
1424 ei->exp->type = ve->type; | 1465 ei->exp->type = ve->type; |
1466 #if STRUCTTHISREF | |
1467 if (ethis->type->ty != Tclass) | |
1468 { /* This is a reference initialization, not a simple assignment. | |
1469 */ | |
1470 ei->exp->op = TOKconstruct; | |
1471 } | |
1472 #endif | |
1425 | 1473 |
1426 ids.vthis = vthis; | 1474 ids.vthis = vthis; |
1427 } | 1475 } |
1428 | 1476 |
1429 // Set up parameters | 1477 // Set up parameters |