Mercurial > projects > ldc
diff 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 |
line wrap: on
line diff
--- a/dmd/mtype.c Wed Jan 06 15:18:23 2010 -0300 +++ b/dmd/mtype.c Wed Jan 06 15:18:23 2010 -0300 @@ -569,12 +569,9 @@ void Type::checkDeprecated(Loc loc, Scope *sc) { - Type *t; - Dsymbol *s; - - for (t = this; t; t = t->next) + for (Type *t = this; t; t = t->next) { - s = t->toDsymbol(sc); + Dsymbol *s = t->toDsymbol(sc); if (s) s->checkDeprecated(loc, sc); } @@ -589,6 +586,18 @@ return NULL; } +/*************************************** + * Use when we prefer the default initializer to be a literal, + * rather than a global immutable variable. + */ +Expression *Type::defaultInitLiteral(Loc loc) +{ +#if LOGDEFAULTINIT + printf("Type::defaultInitLiteral() '%s'\n", toChars()); +#endif + return defaultInit(loc); +} + int Type::isZeroInit(Loc loc) { return 0; // assume not @@ -4707,6 +4716,35 @@ return new VarExp(sym->loc, d); } +/*************************************** + * Use when we prefer the default initializer to be a literal, + * rather than a global immutable variable. + */ +Expression *TypeStruct::defaultInitLiteral(Loc loc) +{ +#if LOGDEFAULTINIT + printf("TypeStruct::defaultInitLiteral() '%s'\n", toChars()); +#endif + Expressions *structelems = new Expressions(); + structelems->setDim(sym->fields.dim); + for (size_t j = 0; j < structelems->dim; j++) + { + VarDeclaration *vd = (VarDeclaration *)(sym->fields.data[j]); + Expression *e; + if (vd->init) + e = vd->init->toExpression(); + else + e = vd->type->defaultInitLiteral(); + structelems->data[j] = e; + } + StructLiteralExp *structinit = new StructLiteralExp(loc, (StructDeclaration *)sym, structelems); + // Why doesn't the StructLiteralExp constructor do this, when + // sym->type != NULL ? + structinit->type = sym->type; + return structinit; +} + + int TypeStruct::isZeroInit(Loc loc) { return sym->zeroInit;