Mercurial > projects > ldc
comparison dmd/optimize.c @ 1195:e961851fb8be
Merged DMD 1.042.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Fri, 03 Apr 2009 17:59:34 +0200 |
parents | ab186e535e72 |
children | 8026319762be |
comparison
equal
deleted
inserted
replaced
1194:1853dcd9b944 | 1195:e961851fb8be |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2007 by Digital Mars | 3 // Copyright (c) 1999-2009 by Digital Mars |
4 // All Rights Reserved | 4 // All Rights Reserved |
5 // written by Walter Bright | 5 // written by Walter Bright |
6 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
7 // License for redistribution is by either the Artistic License | 7 // License for redistribution is by either the Artistic License |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | 8 // in artistic.txt, or the GNU General Public License in gnu.txt. |
224 { // Convert &array[n] to &array+n | 224 { // Convert &array[n] to &array+n |
225 IndexExp *ae = (IndexExp *)e1; | 225 IndexExp *ae = (IndexExp *)e1; |
226 | 226 |
227 if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar) | 227 if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar) |
228 { | 228 { |
229 integer_t index = ae->e2->toInteger(); | 229 dinteger_t index = ae->e2->toInteger(); |
230 VarExp *ve = (VarExp *)ae->e1; | 230 VarExp *ve = (VarExp *)ae->e1; |
231 if (ve->type->ty == Tsarray && ve->type->next->ty != Tbit | 231 if (ve->type->ty == Tsarray && ve->type->next->ty != Tbit |
232 && !ve->var->isImportedSymbol()) | 232 && !ve->var->isImportedSymbol()) |
233 { | 233 { |
234 TypeSArray *ts = (TypeSArray *)ve->type; | 234 TypeSArray *ts = (TypeSArray *)ve->type; |
235 integer_t dim = ts->dim->toInteger(); | 235 dinteger_t dim = ts->dim->toInteger(); |
236 if (index < 0 || index >= dim) | 236 if (index < 0 || index >= dim) |
237 error("array index %jd is out of bounds [0..%jd]", index, dim); | 237 error("array index %jd is out of bounds [0..%jd]", index, dim); |
238 e = new SymOffExp(loc, ve->var, index * ts->next->size()); | 238 e = new SymOffExp(loc, ve->var, index * ts->next->size()); |
239 e->type = type; | 239 e->type = type; |
240 return e; | 240 return e; |
416 e2 = e2->optimize(result); | 416 e2 = e2->optimize(result); |
417 if (op == TOKshlass || op == TOKshrass || op == TOKushrass) | 417 if (op == TOKshlass || op == TOKshrass || op == TOKushrass) |
418 { | 418 { |
419 if (e2->isConst() == 1) | 419 if (e2->isConst() == 1) |
420 { | 420 { |
421 integer_t i2 = e2->toInteger(); | 421 dinteger_t i2 = e2->toInteger(); |
422 d_uns64 sz = e1->type->size() * 8; | 422 d_uns64 sz = e1->type->size() * 8; |
423 if (i2 < 0 || i2 > sz) | 423 if (i2 < 0 || i2 > sz) |
424 { error("shift assign by %jd is outside the range 0..%zu", i2, sz); | 424 { error("shift assign by %jd is outside the range 0..%zu", i2, sz); |
425 e2 = new IntegerExp(0); | 425 e2 = new IntegerExp(0); |
426 } | 426 } |
511 | 511 |
512 e->e1 = e->e1->optimize(result); | 512 e->e1 = e->e1->optimize(result); |
513 e->e2 = e->e2->optimize(result); | 513 e->e2 = e->e2->optimize(result); |
514 if (e->e2->isConst() == 1) | 514 if (e->e2->isConst() == 1) |
515 { | 515 { |
516 integer_t i2 = e->e2->toInteger(); | 516 dinteger_t i2 = e->e2->toInteger(); |
517 d_uns64 sz = e->e1->type->size() * 8; | 517 d_uns64 sz = e->e1->type->size() * 8; |
518 if (i2 < 0 || i2 > sz) | 518 if (i2 < 0 || i2 > sz) |
519 { e->error("shift by %jd is outside the range 0..%zu", i2, sz); | 519 { e->error("shift by %jd is outside the range 0..%zu", i2, sz); |
520 e->e2 = new IntegerExp(0); | 520 e->e2 = new IntegerExp(0); |
521 } | 521 } |