Mercurial > projects > ldc
diff dmd/constfold.c @ 35:3cfcb944304e trunk
[svn r39] * Updated to DMD 1.022 with the exception of:
Bugzilla 278: dmd.conf search path doesn't work
This fix was causing crashes for me :/ So for it's the old behaviour
author | lindquist |
---|---|
date | Tue, 09 Oct 2007 06:21:30 +0200 |
parents | 788401029ecf |
children | 2b72433d5c8c |
line wrap: on
line diff
--- a/dmd/constfold.c Tue Oct 09 02:50:00 2007 +0200 +++ b/dmd/constfold.c Tue Oct 09 06:21:30 2007 +0200 @@ -733,6 +733,36 @@ } } } + else if (e1->op == TOKarrayliteral && e2->op == TOKstring) + { // Swap operands and use common code + Expression *e = e1; + e1 = e2; + e2 = e; + goto Lsa; + } + else if (e1->op == TOKstring && e2->op == TOKarrayliteral) + { + Lsa: + StringExp *es1 = (StringExp *)e1; + ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; + size_t dim1 = es1->len; + size_t dim2 = es2->elements ? es2->elements->dim : 0; + if (dim1 != dim2) + cmp = 0; + else + { + for (size_t i = 0; i < dim1; i++) + { + uinteger_t c = es1->charAt(i); + Expression *ee2 = (Expression *)es2->elements->data[i]; + if (ee2->isConst() != 1) + return EXP_CANT_INTERPRET; + cmp = (c == ee2->toInteger()); + if (cmp == 0) + break; + } + } + } else if (e1->op == TOKstructliteral && e2->op == TOKstructliteral) { StructLiteralExp *es1 = (StructLiteralExp *)e1; StructLiteralExp *es2 = (StructLiteralExp *)e2; @@ -1132,26 +1162,7 @@ if (i >= es1->len) e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); else - { integer_t value; - - switch (es1->sz) - { - case 1: - value = ((unsigned char *)es1->string)[i]; - break; - - case 2: - value = ((unsigned short *)es1->string)[i]; - break; - - case 4: - value = ((unsigned int *)es1->string)[i]; - break; - - default: - assert(0); - break; - } + { unsigned value = es1->charAt(i); e = new IntegerExp(loc, value, type); } }