comparison dmd/constfold.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 b30fe7e1dbb9
children 6bae1c30480f
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.
553 553
554 Expression *Shr(Type *type, Expression *e1, Expression *e2) 554 Expression *Shr(Type *type, Expression *e1, Expression *e2)
555 { Expression *e; 555 { Expression *e;
556 Loc loc = e1->loc; 556 Loc loc = e1->loc;
557 unsigned count; 557 unsigned count;
558 integer_t value; 558 dinteger_t value;
559 559
560 value = e1->toInteger(); 560 value = e1->toInteger();
561 count = e2->toInteger(); 561 count = e2->toInteger();
562 switch (e1->type->toBasetype()->ty) 562 switch (e1->type->toBasetype()->ty)
563 { 563 {
602 602
603 Expression *Ushr(Type *type, Expression *e1, Expression *e2) 603 Expression *Ushr(Type *type, Expression *e1, Expression *e2)
604 { Expression *e; 604 { Expression *e;
605 Loc loc = e1->loc; 605 Loc loc = e1->loc;
606 unsigned count; 606 unsigned count;
607 integer_t value; 607 dinteger_t value;
608 608
609 value = e1->toInteger(); 609 value = e1->toInteger();
610 count = e2->toInteger(); 610 count = e2->toInteger();
611 switch (e1->type->toBasetype()->ty) 611 switch (e1->type->toBasetype()->ty)
612 { 612 {
885 885
886 886
887 Expression *Cmp(enum TOK op, Type *type, Expression *e1, Expression *e2) 887 Expression *Cmp(enum TOK op, Type *type, Expression *e1, Expression *e2)
888 { Expression *e; 888 { Expression *e;
889 Loc loc = e1->loc; 889 Loc loc = e1->loc;
890 integer_t n; 890 dinteger_t n;
891 real_t r1; 891 real_t r1;
892 real_t r2; 892 real_t r2;
893 893
894 if (e1->type->isreal()) 894 if (e1->type->isreal())
895 { 895 {
1056 if (tb->ty == Tbool) 1056 if (tb->ty == Tbool)
1057 e = new IntegerExp(loc, e1->toInteger() != 0, type); 1057 e = new IntegerExp(loc, e1->toInteger() != 0, type);
1058 else if (type->isintegral()) 1058 else if (type->isintegral())
1059 { 1059 {
1060 if (e1->type->isfloating()) 1060 if (e1->type->isfloating())
1061 { integer_t result; 1061 { dinteger_t result;
1062 real_t r = e1->toReal(); 1062 real_t r = e1->toReal();
1063 1063
1064 switch (type->toBasetype()->ty) 1064 switch (type->toBasetype()->ty)
1065 { 1065 {
1066 case Tint8: result = (d_int8)r; break; 1066 case Tint8: result = (d_int8)r; break;
1249 uinteger_t iupr = upr->toInteger(); 1249 uinteger_t iupr = upr->toInteger();
1250 1250
1251 if (iupr > es1->len || ilwr > iupr) 1251 if (iupr > es1->len || ilwr > iupr)
1252 e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr); 1252 e1->error("string slice [%ju .. %ju] is out of bounds", ilwr, iupr);
1253 else 1253 else
1254 { integer_t value; 1254 { dinteger_t value;
1255 void *s; 1255 void *s;
1256 size_t len = iupr - ilwr; 1256 size_t len = iupr - ilwr;
1257 int sz = es1->sz; 1257 int sz = es1->sz;
1258 StringExp *es; 1258 StringExp *es;
1259 1259
1315 // Create a StringExp 1315 // Create a StringExp
1316 void *s; 1316 void *s;
1317 StringExp *es; 1317 StringExp *es;
1318 size_t len = 1; 1318 size_t len = 1;
1319 int sz = tn->size(); 1319 int sz = tn->size();
1320 integer_t v = e->toInteger(); 1320 dinteger_t v = e->toInteger();
1321 1321
1322 s = mem.malloc((len + 1) * sz); 1322 s = mem.malloc((len + 1) * sz);
1323 memcpy((unsigned char *)s, &v, sz); 1323 memcpy((unsigned char *)s, &v, sz);
1324 1324
1325 // Add terminating 0 1325 // Add terminating 0
1382 StringExp *es1 = (StringExp *)e1; 1382 StringExp *es1 = (StringExp *)e1;
1383 StringExp *es; 1383 StringExp *es;
1384 Type *t; 1384 Type *t;
1385 size_t len = es1->len + 1; 1385 size_t len = es1->len + 1;
1386 int sz = es1->sz; 1386 int sz = es1->sz;
1387 integer_t v = e2->toInteger(); 1387 dinteger_t v = e2->toInteger();
1388 1388
1389 s = mem.malloc((len + 1) * sz); 1389 s = mem.malloc((len + 1) * sz);
1390 memcpy(s, es1->string, es1->len * sz); 1390 memcpy(s, es1->string, es1->len * sz);
1391 memcpy((unsigned char *)s + es1->len * sz, &v, sz); 1391 memcpy((unsigned char *)s + es1->len * sz, &v, sz);
1392 1392
1407 StringExp *es2 = (StringExp *)e2; 1407 StringExp *es2 = (StringExp *)e2;
1408 StringExp *es; 1408 StringExp *es;
1409 Type *t; 1409 Type *t;
1410 size_t len = 1 + es2->len; 1410 size_t len = 1 + es2->len;
1411 int sz = es2->sz; 1411 int sz = es2->sz;
1412 integer_t v = e1->toInteger(); 1412 dinteger_t v = e1->toInteger();
1413 1413
1414 s = mem.malloc((len + 1) * sz); 1414 s = mem.malloc((len + 1) * sz);
1415 memcpy((unsigned char *)s, &v, sz); 1415 memcpy((unsigned char *)s, &v, sz);
1416 memcpy((unsigned char *)s + sz, es2->string, es2->len * sz); 1416 memcpy((unsigned char *)s + sz, es2->string, es2->len * sz);
1417 1417