comparison dmd/constfold.c @ 717:a26b0c5d5942

Merged DMD 1.036. Improved comments a little in the runtime source code.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 22 Oct 2008 17:06:17 +0200
parents 50383e476c7e
children 6dcab994ddc3
comparison
equal deleted inserted replaced
716:b654bb98d31d 717:a26b0c5d5942
1295 */ 1295 */
1296 Expression *Cat(Type *type, Expression *e1, Expression *e2) 1296 Expression *Cat(Type *type, Expression *e1, Expression *e2)
1297 { Expression *e = EXP_CANT_INTERPRET; 1297 { Expression *e = EXP_CANT_INTERPRET;
1298 Loc loc = e1->loc; 1298 Loc loc = e1->loc;
1299 Type *t; 1299 Type *t;
1300 Type *t1 = e1->type->toBasetype();
1301 Type *t2 = e2->type->toBasetype();
1300 1302
1301 //printf("Cat(e1 = %s, e2 = %s)\n", e1->toChars(), e2->toChars()); 1303 //printf("Cat(e1 = %s, e2 = %s)\n", e1->toChars(), e2->toChars());
1302 1304
1303 if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral)) 1305 if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral))
1304 { e = e2; 1306 { e = e2;
1435 e = es1; 1437 e = es1;
1436 1438
1437 if (type->toBasetype()->ty == Tsarray) 1439 if (type->toBasetype()->ty == Tsarray)
1438 { 1440 {
1439 e->type = new TypeSArray(e1->type->toBasetype()->next, new IntegerExp(0, es1->elements->dim, Type::tindex)); 1441 e->type = new TypeSArray(e1->type->toBasetype()->next, new IntegerExp(0, es1->elements->dim, Type::tindex));
1442 e->type = e->type->semantic(loc, NULL);
1443 }
1444 else
1445 e->type = type;
1446 }
1447 else if (e1->op == TOKarrayliteral && e2->op == TOKnull &&
1448 t1->nextOf()->equals(t2->nextOf()))
1449 {
1450 e = e1;
1451 goto L3;
1452 }
1453 else if (e1->op == TOKnull && e2->op == TOKarrayliteral &&
1454 t1->nextOf()->equals(t2->nextOf()))
1455 {
1456 e = e2;
1457 L3:
1458 // Concatenate the array with null
1459 ArrayLiteralExp *es = (ArrayLiteralExp *)e;
1460
1461 es = new ArrayLiteralExp(es->loc, (Expressions *)es->elements->copy());
1462 e = es;
1463
1464 if (type->toBasetype()->ty == Tsarray)
1465 {
1466 e->type = new TypeSArray(t1->nextOf(), new IntegerExp(loc, es->elements->dim, Type::tindex));
1440 e->type = e->type->semantic(loc, NULL); 1467 e->type = e->type->semantic(loc, NULL);
1441 } 1468 }
1442 else 1469 else
1443 e->type = type; 1470 e->type = type;
1444 } 1471 }