Mercurial > projects > ldc
diff dmd/constfold.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 | 3cfcb944304e |
line wrap: on
line diff
--- a/dmd/constfold.c Thu Oct 04 01:47:53 2007 +0200 +++ b/dmd/constfold.c Thu Oct 04 03:42:56 2007 +0200 @@ -668,7 +668,35 @@ assert(op == TOKequal || op == TOKnotequal); - if (e1->op == TOKstring && e2->op == TOKstring) + if (e1->op == TOKnull) + { + if (e2->op == TOKnull) + cmp = 1; + else if (e2->op == TOKstring) + { StringExp *es2 = (StringExp *)e2; + cmp = (0 == es2->len); + } + else if (e2->op == TOKarrayliteral) + { ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; + cmp = !es2->elements || (0 == es2->elements->dim); + } + else + return EXP_CANT_INTERPRET; + } + else if (e2->op == TOKnull) + { + if (e1->op == TOKstring) + { StringExp *es1 = (StringExp *)e1; + cmp = (0 == es1->len); + } + else if (e1->op == TOKarrayliteral) + { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; + cmp = !es1->elements || (0 == es1->elements->dim); + } + else + return EXP_CANT_INTERPRET; + } + else if (e1->op == TOKstring && e2->op == TOKstring) { StringExp *es1 = (StringExp *)e1; StringExp *es2 = (StringExp *)e2; @@ -792,7 +820,11 @@ Loc loc = e1->loc; int cmp; - if (e1->op == TOKsymoff && e2->op == TOKsymoff) + if (e1->op == TOKnull && e2->op == TOKnull) + { + cmp = 1; + } + else if (e1->op == TOKsymoff && e2->op == TOKsymoff) { SymOffExp *es1 = (SymOffExp *)e1; SymOffExp *es2 = (SymOffExp *)e2; @@ -1051,7 +1083,7 @@ } else { - error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); + error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars()); e = new IntegerExp(loc, 0, type); } return e; @@ -1245,11 +1277,11 @@ //printf("Cat(e1 = %s, e2 = %s)\n", e1->toChars(), e2->toChars()); - if (e1->op == TOKnull && e2->op == TOKint64) + if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral)) { e = e2; goto L2; } - else if (e1->op == TOKint64 && e2->op == TOKnull) + else if ((e1->op == TOKint64 || e1->op == TOKstructliteral) && e2->op == TOKnull) { e = e1; L2: Type *tn = e->type->toBasetype(); @@ -1381,7 +1413,7 @@ e->type = type; } else if (e1->op == TOKarrayliteral && - e1->type->toBasetype()->next->equals(e2->type)) + e1->type->toBasetype()->nextOf()->equals(e2->type)) { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; @@ -1398,7 +1430,7 @@ e->type = type; } else if (e2->op == TOKarrayliteral && - e2->type->toBasetype()->next->equals(e1->type)) + e2->type->toBasetype()->nextOf()->equals(e1->type)) { ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; @@ -1425,7 +1457,7 @@ t = e2->type; L1: Type *tb = t->toBasetype(); - if (tb->ty == Tarray && tb->next->equals(e->type)) + if (tb->ty == Tarray && tb->nextOf()->equals(e->type)) { Expressions *expressions = new Expressions(); expressions->push(e); e = new ArrayLiteralExp(loc, expressions);