Mercurial > projects > ldc
comparison dmd2/optimize.c @ 1577:e4f7b5d9c68a
DMD 2.032 Merge.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 08 Sep 2009 10:07:56 +0100 |
parents | 54b3c1394d62 |
children |
comparison
equal
deleted
inserted
replaced
1576:4551475bc6b6 | 1577:e4f7b5d9c68a |
---|---|
84 { | 84 { |
85 v->inuse++; | 85 v->inuse++; |
86 e = ei->syntaxCopy(); | 86 e = ei->syntaxCopy(); |
87 e = e->semantic(v->scope); | 87 e = e->semantic(v->scope); |
88 e = e->implicitCastTo(v->scope, v->type); | 88 e = e->implicitCastTo(v->scope, v->type); |
89 // enabling this line causes test22 in test suite to fail | |
90 //ei->type = e->type; | |
89 v->scope = NULL; | 91 v->scope = NULL; |
90 v->inuse--; | 92 v->inuse--; |
91 } | 93 } |
92 else if (!ei->type) | 94 else if (!ei->type) |
93 { | 95 { |
424 } | 426 } |
425 | 427 |
426 return this; | 428 return this; |
427 } | 429 } |
428 | 430 |
431 Expression *NewExp::optimize(int result) | |
432 { | |
433 if (thisexp) | |
434 thisexp = thisexp->optimize(WANTvalue); | |
435 | |
436 // Optimize parameters | |
437 if (newargs) | |
438 { | |
439 for (size_t i = 0; i < newargs->dim; i++) | |
440 { Expression *e = (Expression *)newargs->data[i]; | |
441 | |
442 e = e->optimize(WANTvalue); | |
443 newargs->data[i] = (void *)e; | |
444 } | |
445 } | |
446 | |
447 if (arguments) | |
448 { | |
449 for (size_t i = 0; i < arguments->dim; i++) | |
450 { Expression *e = (Expression *)arguments->data[i]; | |
451 | |
452 e = e->optimize(WANTvalue); | |
453 arguments->data[i] = (void *)e; | |
454 } | |
455 } | |
456 return this; | |
457 } | |
458 | |
429 Expression *CallExp::optimize(int result) | 459 Expression *CallExp::optimize(int result) |
430 { | 460 { |
431 //printf("CallExp::optimize(result = %d) %s\n", result, toChars()); | 461 //printf("CallExp::optimize(result = %d) %s\n", result, toChars()); |
432 Expression *e = this; | 462 Expression *e = this; |
463 | |
464 // Optimize parameters | |
465 if (arguments) | |
466 { | |
467 for (size_t i = 0; i < arguments->dim; i++) | |
468 { Expression *e = (Expression *)arguments->data[i]; | |
469 | |
470 e = e->optimize(WANTvalue); | |
471 arguments->data[i] = (void *)e; | |
472 } | |
473 } | |
433 | 474 |
434 e1 = e1->optimize(result); | 475 e1 = e1->optimize(result); |
435 if (e1->op == TOKvar) | 476 if (e1->op == TOKvar) |
436 { | 477 { |
437 FuncDeclaration *fd = ((VarExp *)e1)->var->isFuncDeclaration(); | 478 FuncDeclaration *fd = ((VarExp *)e1)->var->isFuncDeclaration(); |
790 //printf("IdentityExp::optimize(result = %d) %s\n", result, toChars()); | 831 //printf("IdentityExp::optimize(result = %d) %s\n", result, toChars()); |
791 e1 = e1->optimize(WANTvalue | (result & WANTinterpret)); | 832 e1 = e1->optimize(WANTvalue | (result & WANTinterpret)); |
792 e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); | 833 e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); |
793 e = this; | 834 e = this; |
794 | 835 |
795 if (this->e1->isConst() && this->e2->isConst()) | 836 if ((this->e1->isConst() && this->e2->isConst()) || |
837 (this->e1->op == TOKnull && this->e2->op == TOKnull)) | |
796 { | 838 { |
797 e = Identity(op, type, this->e1, this->e2); | 839 e = Identity(op, type, this->e1, this->e2); |
798 } | 840 } |
799 return e; | 841 return e; |
800 } | 842 } |