Mercurial > projects > ldc
comparison dmd/mtype.c @ 1627:e83f0778c260
Merge DMD r321: bugzilla 3575 CTFE: member structs not initialized correctly
---
dmd/expression.c | 4 +---
dmd/interpret.c | 32 +++++++++-----------------------
dmd/mtype.c | 48 +++++++++++++++++++++++++++++++++++++++++++-----
dmd/mtype.h | 2 ++
4 files changed, 55 insertions(+), 31 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:23 -0300 |
parents | 8fa4ab3dcc88 |
children | 44b145be2ef5 |
comparison
equal
deleted
inserted
replaced
1626:8fa4ab3dcc88 | 1627:e83f0778c260 |
---|---|
567 * Check type to see if it is based on a deprecated symbol. | 567 * Check type to see if it is based on a deprecated symbol. |
568 */ | 568 */ |
569 | 569 |
570 void Type::checkDeprecated(Loc loc, Scope *sc) | 570 void Type::checkDeprecated(Loc loc, Scope *sc) |
571 { | 571 { |
572 Type *t; | 572 for (Type *t = this; t; t = t->next) |
573 Dsymbol *s; | 573 { |
574 | 574 Dsymbol *s = t->toDsymbol(sc); |
575 for (t = this; t; t = t->next) | |
576 { | |
577 s = t->toDsymbol(sc); | |
578 if (s) | 575 if (s) |
579 s->checkDeprecated(loc, sc); | 576 s->checkDeprecated(loc, sc); |
580 } | 577 } |
581 } | 578 } |
582 | 579 |
585 { | 582 { |
586 #if LOGDEFAULTINIT | 583 #if LOGDEFAULTINIT |
587 printf("Type::defaultInit() '%s'\n", toChars()); | 584 printf("Type::defaultInit() '%s'\n", toChars()); |
588 #endif | 585 #endif |
589 return NULL; | 586 return NULL; |
587 } | |
588 | |
589 /*************************************** | |
590 * Use when we prefer the default initializer to be a literal, | |
591 * rather than a global immutable variable. | |
592 */ | |
593 Expression *Type::defaultInitLiteral(Loc loc) | |
594 { | |
595 #if LOGDEFAULTINIT | |
596 printf("Type::defaultInitLiteral() '%s'\n", toChars()); | |
597 #endif | |
598 return defaultInit(loc); | |
590 } | 599 } |
591 | 600 |
592 int Type::isZeroInit(Loc loc) | 601 int Type::isZeroInit(Loc loc) |
593 { | 602 { |
594 return 0; // assume not | 603 return 0; // assume not |
4705 assert(d); | 4714 assert(d); |
4706 d->type = this; | 4715 d->type = this; |
4707 return new VarExp(sym->loc, d); | 4716 return new VarExp(sym->loc, d); |
4708 } | 4717 } |
4709 | 4718 |
4719 /*************************************** | |
4720 * Use when we prefer the default initializer to be a literal, | |
4721 * rather than a global immutable variable. | |
4722 */ | |
4723 Expression *TypeStruct::defaultInitLiteral(Loc loc) | |
4724 { | |
4725 #if LOGDEFAULTINIT | |
4726 printf("TypeStruct::defaultInitLiteral() '%s'\n", toChars()); | |
4727 #endif | |
4728 Expressions *structelems = new Expressions(); | |
4729 structelems->setDim(sym->fields.dim); | |
4730 for (size_t j = 0; j < structelems->dim; j++) | |
4731 { | |
4732 VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]); | |
4733 Expression *e; | |
4734 if (vd->init) | |
4735 e = vd->init->toExpression(); | |
4736 else | |
4737 e = vd->type->defaultInitLiteral(); | |
4738 structelems->data[j] = e; | |
4739 } | |
4740 StructLiteralExp *structinit = new StructLiteralExp(loc, (StructDeclaration *)sym, structelems); | |
4741 // Why doesn't the StructLiteralExp constructor do this, when | |
4742 // sym->type != NULL ? | |
4743 structinit->type = sym->type; | |
4744 return structinit; | |
4745 } | |
4746 | |
4747 | |
4710 int TypeStruct::isZeroInit(Loc loc) | 4748 int TypeStruct::isZeroInit(Loc loc) |
4711 { | 4749 { |
4712 return sym->zeroInit; | 4750 return sym->zeroInit; |
4713 } | 4751 } |
4714 | 4752 |