Mercurial > projects > ddmd
diff dmd/StructInitializer.d @ 56:51605de93870
TupleExp.optimize
UnrolledLoopStatement.ctor
UnrolledLoopStatement.semantic
UnrolledLoopStatement.blockExit
OrOrExp.checkSideEffect
FuncExp.syntaxCopy
FuncLiteralDeclaration.syntaxCopy
WhileStatement.hasBreak
StructInitializer.toExpression
StructLiteralExp.ctor
StructLiteralExp.optimize
BinExp.commonSemanticAssign
ModAssignExp.opId
Argument.isLazyArray
CommaExp.implicitConvTo
CommaExp.castTo
TypeClass.isBaseOf
createTypeInfoArray
TypeTuple.getTypeInfoDeclaration
TypeInfoTupleDeclaration.ctor
TypeNext.constConv
XorExp.implicitConvTo
TemplateParameter.isTemplateValueParameter
author | korDen |
---|---|
date | Sat, 21 Aug 2010 14:16:53 +0400 |
parents | b7d29f613539 |
children | f708f0452e81 |
line wrap: on
line diff
--- a/dmd/StructInitializer.d Sat Aug 21 13:28:16 2010 +0400 +++ b/dmd/StructInitializer.d Sat Aug 21 14:16:53 2010 +0400 @@ -4,6 +4,8 @@ import dmd.TOK; import dmd.FuncLiteralDeclaration; import dmd.TypeFunction; +import dmd.StructDeclaration; +import dmd.StructLiteralExp; import dmd.ArrayTypes; import dmd.Array; import dmd.Loc; @@ -170,9 +172,44 @@ return this; } + /*************************************** + * This works by transforming a struct initializer into + * a struct literal. In the future, the two should be the + * same thing. + */ Expression toExpression() { - assert(false); + Expression e; + + //printf("StructInitializer.toExpression() %s\n", toChars()); + if (!ad) // if fwd referenced + { + return null; + } + StructDeclaration sd = ad.isStructDeclaration(); + if (!sd) + return null; + Expressions elements = new Expressions(); + for (size_t i = 0; i < value.dim; i++) + { + if (field.data[i]) + goto Lno; + Initializer iz = cast(Initializer)value.data[i]; + if (!iz) + goto Lno; + Expression ex = iz.toExpression(); + if (!ex) + goto Lno; + elements.push(cast(void*)ex); + } + e = new StructLiteralExp(loc, sd, elements); + e.type = sd.type; + return e; + + Lno: + delete elements; + //error(loc, "struct initializers as expressions are not allowed"); + return null; } void toCBuffer(OutBuffer buf, HdrGenState* hgs)