Mercurial > projects > ldc
diff dmd/interpret.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 | fb2e6707ad17 |
children | 44b145be2ef5 |
line wrap: on
line diff
--- a/dmd/interpret.c Wed Jan 06 15:18:23 2010 -0300 +++ b/dmd/interpret.c Wed Jan 06 15:18:23 2010 -0300 @@ -1516,24 +1516,6 @@ /******************************** - * Necessary because defaultInit() for a struct is a VarExp, not a StructLiteralExp. - */ -StructLiteralExp *createDefaultInitStructLiteral(Loc loc, StructDeclaration *sym) -{ - Expressions *structelems = new Expressions(); - structelems->setDim(sym->fields.dim); - for (size_t j = 0; j < structelems->dim; j++) - { - structelems->data[j] = ((VarDeclaration *)(sym->fields.data[j]))->type->defaultInit(); - } - StructLiteralExp *structinit = new StructLiteralExp(loc, sym, structelems); - // Why doesn't the StructLiteralExp constructor do this, when - // sym->type != NULL ? - structinit->type = sym->type; - return structinit; -} - -/******************************** * Add v to the istate list, unless it already exists there. */ void addVarToInterstate(InterState *istate, VarDeclaration *v) @@ -1592,7 +1574,7 @@ } else if (v && v->value && (v->value->op==TOKindex || v->value->op == TOKdotvar)) { - // It is no longer be a TOKvar, eg when a[4] is passed by ref. + // It is no longer a TOKvar, eg when a[4] is passed by ref. e1 = v->value; } } @@ -1634,7 +1616,7 @@ */ if (v->type->toBasetype()->ty == Tstruct && e2->op == TOKint64) { - e2 = v->type->defaultInit(); + e2 = v->type->defaultInitLiteral(); } e2 = Cast(v->type, v->type, e2); } @@ -1960,8 +1942,7 @@ if (telem->ty != Tstruct) { return EXP_CANT_INTERPRET; } // Create a default struct literal... - StructDeclaration *sym = ((TypeStruct *)telem)->sym; - StructLiteralExp *structinit = createDefaultInitStructLiteral(v->loc, sym); + Expression *structinit = telem->defaultInitLiteral(v->loc); // ... and use to create a blank array literal size_t dim = ((TypeSArray *)t)->dim->toInteger(); @@ -2642,10 +2623,15 @@ if (v) { e = se->getField(type, v->offset); if (!e) + { + error("couldn't find field %s in %s", v->toChars(), type->toChars()); e = EXP_CANT_INTERPRET; + } return e; } - } else error("%s.%s is not yet implemented at compile time", ex->toChars(), var->toChars()); + } + else + error("%s.%s is not yet implemented at compile time", ex->toChars(), var->toChars()); } #if LOG