comparison dmd/init.c @ 19:788401029ecf trunk

[svn r23] * Updated to DMD 1.021
author lindquist
date Thu, 04 Oct 2007 03:42:56 +0200
parents c53b6e3fe49a
children 5825d48b27d1
comparison
equal deleted inserted replaced
18:c05ef76f1c20 19:788401029ecf
233 } 233 }
234 return this; 234 return this;
235 } 235 }
236 236
237 237
238 /***************************************
239 * This works by transforming a struct initializer into
240 * a struct literal. In the future, the two should be the
241 * same thing.
242 */
238 Expression *StructInitializer::toExpression() 243 Expression *StructInitializer::toExpression()
239 { 244 { Expression *e;
240 return NULL; // cannot do it 245
246 //printf("StructInitializer::toExpression() %s\n", toChars());
247 if (!ad) // if fwd referenced
248 {
249 return NULL;
250 }
251 StructDeclaration *sd = ad->isStructDeclaration();
252 if (!sd)
253 return NULL;
254 Expressions *elements = new Expressions();
255 for (size_t i = 0; i < value.dim; i++)
256 {
257 if (field.data[i])
258 goto Lno;
259 Initializer *iz = (Initializer *)value.data[i];
260 if (!iz)
261 goto Lno;
262 Expression *ex = iz->toExpression();
263 if (!ex)
264 goto Lno;
265 elements->push(ex);
266 }
267 e = new StructLiteralExp(loc, sd, elements);
268 e->type = sd->type;
269 return e;
270
271 Lno:
272 delete elements;
273 //error(loc, "struct initializers as expressions are not allowed");
274 return NULL;
241 } 275 }
242 276
243 277
244 void StructInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 278 void StructInitializer::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
245 { 279 {