comparison dmd/optimize.c @ 875:330f999ade44

Merged DMD 1.038
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 06 Jan 2009 16:33:51 +0100
parents 870652a9af23
children d8c44f1e08e1
comparison
equal deleted inserted replaced
874:2ddee23bd70e 875:330f999ade44
276 return this; 276 return this;
277 } 277 }
278 278
279 Expression *DotVarExp::optimize(int result) 279 Expression *DotVarExp::optimize(int result)
280 { 280 {
281 e1 = e1->optimize(result); 281 //printf("DotVarExp::optimize(result = x%x) %s\n", result, toChars());
282 282 e1 = e1->optimize(result);
283 // Constant fold structliteral.member 283
284 #if DMDV2
285 if (e1->op == TOKvar)
286 { VarExp *ve = (VarExp *)e1;
287 VarDeclaration *v = ve->var->isVarDeclaration();
288 Expression *e = expandVar(result, v);
289 if (e && e->op == TOKstructliteral)
290 { StructLiteralExp *sle = (StructLiteralExp *)e;
291 VarDeclaration *vf = var->isVarDeclaration();
292 if (vf)
293 {
294 e = sle->getField(type, vf->offset);
295 if (e != EXP_CANT_INTERPRET)
296 return e;
297 }
298 }
299 }
300 else
301 #endif
284 if (e1->op == TOKstructliteral) 302 if (e1->op == TOKstructliteral)
285 { StructLiteralExp *se = (StructLiteralExp *)e1; 303 { StructLiteralExp *sle = (StructLiteralExp *)e1;
286 304 VarDeclaration *vf = var->isVarDeclaration();
287 VarDeclaration* v; 305 if (vf)
288 if (v = var->isVarDeclaration()) 306 {
289 { 307 Expression *e = sle->getField(type, vf->offset);
290 Expression *e = se->getField(type, v->offset); 308 if (e != EXP_CANT_INTERPRET)
291 if (!e) 309 return e;
292 e = EXP_CANT_INTERPRET;
293 return e;
294 } 310 }
295 } 311 }
296 312
297 return this; 313 return this;
298 } 314 }
320 Expression *CastExp::optimize(int result) 336 Expression *CastExp::optimize(int result)
321 { 337 {
322 //printf("CastExp::optimize(result = %d) %s\n", result, toChars()); 338 //printf("CastExp::optimize(result = %d) %s\n", result, toChars());
323 //printf("from %s to %s\n", type->toChars(), to->toChars()); 339 //printf("from %s to %s\n", type->toChars(), to->toChars());
324 //printf("from %s\n", type->toChars()); 340 //printf("from %s\n", type->toChars());
341 //printf("e1->type %s\n", e1->type->toChars());
325 //printf("type = %p\n", type); 342 //printf("type = %p\n", type);
326 assert(type); 343 assert(type);
327 enum TOK op1 = e1->op; 344 enum TOK op1 = e1->op;
328 345
329 e1 = e1->optimize(result); 346 e1 = e1->optimize(result);