Mercurial > projects > ldc
comparison dmd/expression.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 | 79758fd2f48a |
comparison
equal
deleted
inserted
replaced
1194:1853dcd9b944 | 1195:e961851fb8be |
---|---|
30 | 30 |
31 #ifdef __APPLE__ | 31 #ifdef __APPLE__ |
32 #ifndef isnan | 32 #ifndef isnan |
33 int isnan(double); | 33 int isnan(double); |
34 #endif | 34 #endif |
35 #endif | |
36 | |
37 #if IN_GCC | |
38 // Issues with using -include total.h (defines integer_t) and then complex.h fails... | |
39 #undef integer_t | |
40 #endif | |
41 | |
42 #ifdef __APPLE__ | |
43 #define integer_t dmd_integer_t | |
44 #endif | 35 #endif |
45 | 36 |
46 #include "rmem.h" | 37 #include "rmem.h" |
47 | 38 |
48 //#include "port.h" | 39 //#include "port.h" |
698 if (tb->ty == Tsarray) | 689 if (tb->ty == Tsarray) |
699 { | 690 { |
700 arg = arg->checkToPointer(); | 691 arg = arg->checkToPointer(); |
701 } | 692 } |
702 #endif | 693 #endif |
703 | |
704 #if DMDV2 | 694 #if DMDV2 |
705 if (tb->ty == Tstruct && !(p->storageClass & (STCref | STCout))) | 695 if (tb->ty == Tstruct && !(p->storageClass & (STCref | STCout))) |
706 { | 696 { |
707 arg = callCpCtor(loc, sc, arg); | 697 arg = callCpCtor(loc, sc, arg); |
708 } | 698 } |
998 else | 988 else |
999 e1 = e2; | 989 e1 = e2; |
1000 return e1; | 990 return e1; |
1001 } | 991 } |
1002 | 992 |
1003 integer_t Expression::toInteger() | 993 dinteger_t Expression::toInteger() |
1004 { | 994 { |
1005 //printf("Expression %s\n", Token::toChars(op)); | 995 //printf("Expression %s\n", Token::toChars(op)); |
1006 error("Integer constant expression expected instead of %s", toChars()); | 996 error("Integer constant expression expected instead of %s", toChars()); |
1007 return 0; | 997 return 0; |
1008 } | 998 } |
1287 return a; | 1277 return a; |
1288 } | 1278 } |
1289 | 1279 |
1290 /******************************** IntegerExp **************************/ | 1280 /******************************** IntegerExp **************************/ |
1291 | 1281 |
1292 IntegerExp::IntegerExp(Loc loc, integer_t value, Type *type) | 1282 IntegerExp::IntegerExp(Loc loc, dinteger_t value, Type *type) |
1293 : Expression(loc, TOKint64, sizeof(IntegerExp)) | 1283 : Expression(loc, TOKint64, sizeof(IntegerExp)) |
1294 { | 1284 { |
1295 //printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type->toChars() : ""); | 1285 //printf("IntegerExp(value = %lld, type = '%s')\n", value, type ? type->toChars() : ""); |
1296 if (type && !type->isscalar()) | 1286 if (type && !type->isscalar()) |
1297 { | 1287 { |
1301 } | 1291 } |
1302 this->type = type; | 1292 this->type = type; |
1303 this->value = value; | 1293 this->value = value; |
1304 } | 1294 } |
1305 | 1295 |
1306 IntegerExp::IntegerExp(integer_t value) | 1296 IntegerExp::IntegerExp(dinteger_t value) |
1307 : Expression(0, TOKint64, sizeof(IntegerExp)) | 1297 : Expression(0, TOKint64, sizeof(IntegerExp)) |
1308 { | 1298 { |
1309 this->type = Type::tint32; | 1299 this->type = Type::tint32; |
1310 this->value = value; | 1300 this->value = value; |
1311 } | 1301 } |
1331 sprintf(buffer, "%jd", value); | 1321 sprintf(buffer, "%jd", value); |
1332 return buffer; | 1322 return buffer; |
1333 #endif | 1323 #endif |
1334 } | 1324 } |
1335 | 1325 |
1336 integer_t IntegerExp::toInteger() | 1326 dinteger_t IntegerExp::toInteger() |
1337 { Type *t; | 1327 { Type *t; |
1338 | 1328 |
1339 t = type; | 1329 t = type; |
1340 while (t) | 1330 while (t) |
1341 { | 1331 { |
1353 case Tdchar: | 1343 case Tdchar: |
1354 case Tuns32: value = (d_uns32) value; break; | 1344 case Tuns32: value = (d_uns32) value; break; |
1355 case Tint64: value = (d_int64) value; break; | 1345 case Tint64: value = (d_int64) value; break; |
1356 case Tuns64: value = (d_uns64) value; break; | 1346 case Tuns64: value = (d_uns64) value; break; |
1357 case Tpointer: | 1347 case Tpointer: |
1358 // FIXME: Other pointer widths than 32 and 64? | |
1359 if (PTRSIZE == 4) | 1348 if (PTRSIZE == 4) |
1360 value = (d_uns32) value; | 1349 value = (d_uns32) value; |
1361 else | 1350 else if (PTRSIZE == 8) |
1362 value = (d_uns64) value; | 1351 value = (d_uns64) value; |
1352 else | |
1353 assert(0); | |
1363 break; | 1354 break; |
1364 | 1355 |
1365 case Tenum: | 1356 case Tenum: |
1366 { | 1357 { |
1367 TypeEnum *te = (TypeEnum *)t; | 1358 TypeEnum *te = (TypeEnum *)t; |
1421 Expression *IntegerExp::semantic(Scope *sc) | 1412 Expression *IntegerExp::semantic(Scope *sc) |
1422 { | 1413 { |
1423 if (!type) | 1414 if (!type) |
1424 { | 1415 { |
1425 // Determine what the type of this number is | 1416 // Determine what the type of this number is |
1426 integer_t number = value; | 1417 dinteger_t number = value; |
1427 | 1418 |
1428 if (number & 0x8000000000000000LL) | 1419 if (number & 0x8000000000000000LL) |
1429 type = Type::tuns64; | 1420 type = Type::tuns64; |
1430 else if (number & 0xFFFFFFFF80000000LL) | 1421 else if (number & 0xFFFFFFFF80000000LL) |
1431 type = Type::tint64; | 1422 type = Type::tint64; |
1449 return this; | 1440 return this; |
1450 } | 1441 } |
1451 | 1442 |
1452 void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | 1443 void IntegerExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
1453 { | 1444 { |
1454 integer_t v = toInteger(); | 1445 dinteger_t v = toInteger(); |
1455 | 1446 |
1456 if (type) | 1447 if (type) |
1457 { Type *t = type; | 1448 { Type *t = type; |
1458 | 1449 |
1459 L1: | 1450 L1: |
1518 case Tint64: | 1509 case Tint64: |
1519 buf->printf("%jdL", v); | 1510 buf->printf("%jdL", v); |
1520 break; | 1511 break; |
1521 | 1512 |
1522 case Tuns64: | 1513 case Tuns64: |
1523 L4: | 1514 L4: |
1524 buf->printf("%juLU", v); | 1515 buf->printf("%juLU", v); |
1525 break; | 1516 break; |
1526 | 1517 |
1527 case Tbit: | 1518 case Tbit: |
1528 case Tbool: | 1519 case Tbool: |
1531 | 1522 |
1532 case Tpointer: | 1523 case Tpointer: |
1533 buf->writestring("cast("); | 1524 buf->writestring("cast("); |
1534 buf->writestring(t->toChars()); | 1525 buf->writestring(t->toChars()); |
1535 buf->writeByte(')'); | 1526 buf->writeByte(')'); |
1536 // FIXME: Other pointer widths than 32 and 64? | |
1537 if (PTRSIZE == 4) | 1527 if (PTRSIZE == 4) |
1538 goto L3; | 1528 goto L3; |
1539 else | 1529 else if (PTRSIZE == 8) |
1540 goto L4; | 1530 goto L4; |
1531 else | |
1532 assert(0); | |
1541 | 1533 |
1542 default: | 1534 default: |
1543 /* This can happen if errors, such as | 1535 /* This can happen if errors, such as |
1544 * the type is painted on like in fromConstInitializer(). | 1536 * the type is painted on like in fromConstInitializer(). |
1545 */ | 1537 */ |
1590 #endif | 1582 #endif |
1591 assert(strlen(buffer) < sizeof(buffer)); | 1583 assert(strlen(buffer) < sizeof(buffer)); |
1592 return mem.strdup(buffer); | 1584 return mem.strdup(buffer); |
1593 } | 1585 } |
1594 | 1586 |
1595 integer_t RealExp::toInteger() | 1587 dinteger_t RealExp::toInteger() |
1596 { | 1588 { |
1597 #ifdef IN_GCC | 1589 #ifdef IN_GCC |
1598 return toReal().toInt(); | 1590 return toReal().toInt(); |
1599 #else | 1591 #else |
1600 return (sinteger_t) toReal(); | 1592 return (sinteger_t) toReal(); |
1815 assert(strlen(buffer) < sizeof(buffer)); | 1807 assert(strlen(buffer) < sizeof(buffer)); |
1816 #endif | 1808 #endif |
1817 return mem.strdup(buffer); | 1809 return mem.strdup(buffer); |
1818 } | 1810 } |
1819 | 1811 |
1820 integer_t ComplexExp::toInteger() | 1812 dinteger_t ComplexExp::toInteger() |
1821 { | 1813 { |
1822 #ifdef IN_GCC | 1814 #ifdef IN_GCC |
1823 return (sinteger_t) toReal().toInt(); | 1815 return (sinteger_t) toReal().toInt(); |
1824 #else | 1816 #else |
1825 return (sinteger_t) toReal(); | 1817 return (sinteger_t) toReal(); |
2161 return dte->semantic(sc); | 2153 return dte->semantic(sc); |
2162 } | 2154 } |
2163 imp = s->isImport(); | 2155 imp = s->isImport(); |
2164 if (imp) | 2156 if (imp) |
2165 { | 2157 { |
2166 ScopeExp *ie; | 2158 if (!imp->pkg) |
2167 | 2159 { error("forward reference of import %s", imp->toChars()); |
2168 ie = new ScopeExp(loc, imp->pkg); | 2160 return this; |
2161 } | |
2162 ScopeExp *ie = new ScopeExp(loc, imp->pkg); | |
2169 return ie->semantic(sc); | 2163 return ie->semantic(sc); |
2170 } | 2164 } |
2171 pkg = s->isPackage(); | 2165 pkg = s->isPackage(); |
2172 if (pkg) | 2166 if (pkg) |
2173 { | 2167 { |
3648 error("no constructor for %s", cd->toChars()); | 3642 error("no constructor for %s", cd->toChars()); |
3649 } | 3643 } |
3650 | 3644 |
3651 if (cd->aggNew) | 3645 if (cd->aggNew) |
3652 { | 3646 { |
3653 // Prepend the size_t size argument to newargs[] | 3647 // Prepend the size argument to newargs[] |
3654 Expression *e = new IntegerExp(loc, cd->size(loc), Type::tsize_t); | 3648 Expression *e = new IntegerExp(loc, cd->size(loc), Type::tsize_t); |
3655 if (!newargs) | 3649 if (!newargs) |
3656 newargs = new Expressions(); | 3650 newargs = new Expressions(); |
3657 newargs->shift(e); | 3651 newargs->shift(e); |
3658 | 3652 |
4317 return fd->toChars(); | 4311 return fd->toChars(); |
4318 } | 4312 } |
4319 | 4313 |
4320 void FuncExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | 4314 void FuncExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
4321 { | 4315 { |
4322 buf->writestring(fd->toChars()); | 4316 fd->toCBuffer(buf, hgs); |
4317 //buf->writestring(fd->toChars()); | |
4323 } | 4318 } |
4324 | 4319 |
4325 | 4320 |
4326 /******************************** DeclarationExp **************************/ | 4321 /******************************** DeclarationExp **************************/ |
4327 | 4322 |
7591 #if 0 // Don't do now, because it might be short-circuit evaluated | 7586 #if 0 // Don't do now, because it might be short-circuit evaluated |
7592 // Do compile time array bounds checking if possible | 7587 // Do compile time array bounds checking if possible |
7593 e2 = e2->optimize(WANTvalue); | 7588 e2 = e2->optimize(WANTvalue); |
7594 if (e2->op == TOKint64) | 7589 if (e2->op == TOKint64) |
7595 { | 7590 { |
7596 integer_t index = e2->toInteger(); | 7591 dinteger_t index = e2->toInteger(); |
7597 integer_t length = tsa->dim->toInteger(); | 7592 dinteger_t length = tsa->dim->toInteger(); |
7598 if (index < 0 || index >= length) | 7593 if (index < 0 || index >= length) |
7599 error("array index [%lld] is outside array bounds [0 .. %lld]", | 7594 error("array index [%lld] is outside array bounds [0 .. %lld]", |
7600 index, length); | 7595 index, length); |
7601 } | 7596 } |
7602 #endif | 7597 #endif |