Mercurial > projects > ldc
comparison dmd/expression.c @ 1103:b30fe7e1dbb9
- Updated to DMD frontend 1.041.
- Removed dmd/inifile.c , it's not under a free license, replaced with libconfig based config file.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Thu, 12 Mar 2009 20:37:27 +0100 |
parents | 39cf8fa483fd |
children | 0d38fa5a0b46 |
comparison
equal
deleted
inserted
replaced
1102:ae950bd712d3 | 1103:b30fe7e1dbb9 |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2008 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. |
9 // See the included readme.txt for details. | 9 // See the included readme.txt for details. |
10 | 10 |
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <ctype.h> | 13 #include <ctype.h> |
14 #include <math.h> | |
14 #include <assert.h> | 15 #include <assert.h> |
15 #if _MSC_VER | 16 #if _MSC_VER |
16 #include <complex> | 17 #include <complex> |
17 #else | 18 #else |
18 #endif | 19 #endif |
19 #include <math.h> | |
20 | 20 |
21 #if _WIN32 && __DMC__ | 21 #if _WIN32 && __DMC__ |
22 extern "C" char * __cdecl __locale_decpoint; | 22 extern "C" char * __cdecl __locale_decpoint; |
23 #endif | 23 #endif |
24 | 24 |
41 | 41 |
42 #ifdef __APPLE__ | 42 #ifdef __APPLE__ |
43 #define integer_t dmd_integer_t | 43 #define integer_t dmd_integer_t |
44 #endif | 44 #endif |
45 | 45 |
46 #if IN_GCC || IN_LLVM | 46 #include "rmem.h" |
47 #include "mem.h" | |
48 #elif _WIN32 | |
49 #include "..\root\mem.h" | |
50 #elif POSIX | |
51 #include "../root/mem.h" | |
52 #endif | |
53 | 47 |
54 //#include "port.h" | 48 //#include "port.h" |
55 #include "mtype.h" | 49 #include "mtype.h" |
56 #include "init.h" | 50 #include "init.h" |
57 #include "expression.h" | 51 #include "expression.h" |
558 assert(arguments); | 552 assert(arguments); |
559 size_t nargs = arguments ? arguments->dim : 0; | 553 size_t nargs = arguments ? arguments->dim : 0; |
560 size_t nparams = Argument::dim(tf->parameters); | 554 size_t nparams = Argument::dim(tf->parameters); |
561 | 555 |
562 if (nargs > nparams && tf->varargs == 0) | 556 if (nargs > nparams && tf->varargs == 0) |
563 error(loc, "expected %"PRIuSIZE" arguments, not %"PRIuSIZE, nparams, nargs); | 557 error(loc, "expected %zu arguments, not %zu", nparams, nargs); |
564 | 558 |
565 n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams) | 559 n = (nargs > nparams) ? nargs : nparams; // n = max(nargs, nparams) |
566 | 560 |
567 int done = 0; | 561 int done = 0; |
568 for (size_t i = 0; i < n; i++) | 562 for (size_t i = 0; i < n; i++) |
583 { | 577 { |
584 if (!p->defaultArg) | 578 if (!p->defaultArg) |
585 { | 579 { |
586 if (tf->varargs == 2 && i + 1 == nparams) | 580 if (tf->varargs == 2 && i + 1 == nparams) |
587 goto L2; | 581 goto L2; |
588 error(loc, "expected %"PRIuSIZE" arguments, not %"PRIuSIZE, nparams, nargs); | 582 error(loc, "expected %zu arguments, not %zu", nparams, nargs); |
589 break; | 583 break; |
590 } | 584 } |
591 arg = p->defaultArg; | 585 arg = p->defaultArg; |
592 #if DMDV2 | 586 #if DMDV2 |
593 if (arg->op == TOKdefault) | 587 if (arg->op == TOKdefault) |
605 { | 599 { |
606 //printf("\t\tvarargs == 2, p->type = '%s'\n", p->type->toChars()); | 600 //printf("\t\tvarargs == 2, p->type = '%s'\n", p->type->toChars()); |
607 if (arg->implicitConvTo(p->type)) | 601 if (arg->implicitConvTo(p->type)) |
608 { | 602 { |
609 if (nargs != nparams) | 603 if (nargs != nparams) |
610 error(loc, "expected %"PRIuSIZE" arguments, not %"PRIuSIZE, nparams, nargs); | 604 error(loc, "expected %zu arguments, not %zu", nparams, nargs); |
611 goto L1; | 605 goto L1; |
612 } | 606 } |
613 L2: | 607 L2: |
614 Type *tb = p->type->toBasetype(); | 608 Type *tb = p->type->toBasetype(); |
615 Type *tret = p->isLazyArray(); | 609 Type *tret = p->isLazyArray(); |
963 va_start(ap, format); | 957 va_start(ap, format); |
964 ::verror(loc, format, ap); | 958 ::verror(loc, format, ap); |
965 va_end( ap ); | 959 va_end( ap ); |
966 } | 960 } |
967 | 961 |
962 void Expression::warning(const char *format, ...) | |
963 { | |
964 if (global.params.warnings && !global.gag) | |
965 { | |
966 fprintf(stdmsg, "warning - "); | |
967 va_list ap; | |
968 va_start(ap, format); | |
969 ::warning(loc, format, ap); | |
970 va_end( ap ); | |
971 } | |
972 } | |
973 | |
968 void Expression::rvalue() | 974 void Expression::rvalue() |
969 { | 975 { |
970 if (type && type->toBasetype()->ty == Tvoid) | 976 if (type && type->toBasetype()->ty == Tvoid) |
971 { error("expression %s is void and has no value", toChars()); | 977 { error("expression %s is void and has no value", toChars()); |
972 #if 0 | 978 #if 0 |
1317 { | 1323 { |
1318 #if 1 | 1324 #if 1 |
1319 return Expression::toChars(); | 1325 return Expression::toChars(); |
1320 #else | 1326 #else |
1321 static char buffer[sizeof(value) * 3 + 1]; | 1327 static char buffer[sizeof(value) * 3 + 1]; |
1322 sprintf(buffer, "%lld", value); | 1328 |
1329 sprintf(buffer, "%jd", value); | |
1323 return buffer; | 1330 return buffer; |
1324 #endif | 1331 #endif |
1325 } | 1332 } |
1326 | 1333 |
1327 integer_t IntegerExp::toInteger() | 1334 integer_t IntegerExp::toInteger() |
1499 L3: | 1506 L3: |
1500 buf->printf("%du", (unsigned)v); | 1507 buf->printf("%du", (unsigned)v); |
1501 break; | 1508 break; |
1502 | 1509 |
1503 case Tint64: | 1510 case Tint64: |
1504 buf->printf("%lldL", v); | 1511 buf->printf("%jdL", v); |
1505 break; | 1512 break; |
1506 | 1513 |
1507 case Tuns64: | 1514 case Tuns64: |
1508 buf->printf("%lluLU", v); | 1515 buf->printf("%juLU", v); |
1509 break; | 1516 break; |
1510 | 1517 |
1511 case Tbit: | 1518 case Tbit: |
1512 case Tbool: | 1519 case Tbool: |
1513 buf->writestring((char *)(v ? "true" : "false")); | 1520 buf->writestring((char *)(v ? "true" : "false")); |
1532 } | 1539 } |
1533 break; | 1540 break; |
1534 } | 1541 } |
1535 } | 1542 } |
1536 else if (v & 0x8000000000000000LL) | 1543 else if (v & 0x8000000000000000LL) |
1537 buf->printf("0x%llx", v); | 1544 buf->printf("0x%jx", v); |
1538 else | 1545 else |
1539 buf->printf("%lld", v); | 1546 buf->printf("%jd", v); |
1540 } | 1547 } |
1541 | 1548 |
1542 void IntegerExp::toMangleBuffer(OutBuffer *buf) | 1549 void IntegerExp::toMangleBuffer(OutBuffer *buf) |
1543 { | 1550 { |
1544 if ((sinteger_t)value < 0) | 1551 if ((sinteger_t)value < 0) |
1545 buf->printf("N%lld", -value); | 1552 buf->printf("N%jd", -value); |
1546 else | 1553 else |
1547 buf->printf("%lld", value); | 1554 buf->printf("%jd", value); |
1548 } | 1555 } |
1549 | 1556 |
1550 /******************************** RealExp **************************/ | 1557 /******************************** RealExp **************************/ |
1551 | 1558 |
1552 RealExp::RealExp(Loc loc, real_t value, Type *type) | 1559 RealExp::RealExp(Loc loc, real_t value, Type *type) |
1615 * Regard +0 and -0 as different. | 1622 * Regard +0 and -0 as different. |
1616 */ | 1623 */ |
1617 | 1624 |
1618 int RealEquals(real_t x1, real_t x2) | 1625 int RealEquals(real_t x1, real_t x2) |
1619 { | 1626 { |
1627 #if __APPLE__ | |
1628 return (__inline_isnan(x1) && __inline_isnan(x2)) || | |
1629 #else | |
1620 return // special case nans | 1630 return // special case nans |
1621 (isnan(x1) && isnan(x2)) || | 1631 (isnan(x1) && isnan(x2)) || |
1632 #endif | |
1622 // and zero, in order to distinguish +0 from -0 | 1633 // and zero, in order to distinguish +0 from -0 |
1623 (x1 == 0 && x2 == 0 && 1./x1 == 1./x2) || | 1634 (x1 == 0 && x2 == 0 && 1./x1 == 1./x2) || |
1624 // otherwise just compare | 1635 // otherwise just compare |
1625 (x1 != 0. && x1 == x2); | 1636 (x1 != 0. && x1 == x2); |
1626 } | 1637 } |
1721 * INF => INF | 1732 * INF => INF |
1722 * -0X1.1BC18BA997B95P+79 => N11BC18BA997B95P79 | 1733 * -0X1.1BC18BA997B95P+79 => N11BC18BA997B95P79 |
1723 * 0X1.9P+2 => 19P2 | 1734 * 0X1.9P+2 => 19P2 |
1724 */ | 1735 */ |
1725 | 1736 |
1737 #if __APPLE__ | |
1738 if (__inline_isnan(value)) | |
1739 #else | |
1726 if (isnan(value)) | 1740 if (isnan(value)) |
1741 #endif | |
1727 buf->writestring("NAN"); // no -NAN bugs | 1742 buf->writestring("NAN"); // no -NAN bugs |
1728 else | 1743 else |
1729 { | 1744 { |
1730 char buffer[32]; | 1745 char buffer[32]; |
1731 int n = sprintf(buffer, "%LA", value); | 1746 int n = sprintf(buffer, "%LA", value); |
3857 //var->semantic(sc); | 3872 //var->semantic(sc); |
3858 if (!type) | 3873 if (!type) |
3859 type = var->type->pointerTo(); | 3874 type = var->type->pointerTo(); |
3860 VarDeclaration *v = var->isVarDeclaration(); | 3875 VarDeclaration *v = var->isVarDeclaration(); |
3861 if (v) | 3876 if (v) |
3862 { | 3877 v->checkNestedReference(sc, loc); |
3863 v->checkNestedReference(sc, loc); | |
3864 } | |
3865 return this; | 3878 return this; |
3866 } | 3879 } |
3867 | 3880 |
3868 int SymOffExp::isBool(int result) | 3881 int SymOffExp::isBool(int result) |
3869 { | 3882 { |
7227 } | 7240 } |
7228 e = e->semantic(sc); | 7241 e = e->semantic(sc); |
7229 } | 7242 } |
7230 else | 7243 else |
7231 { | 7244 { |
7232 error("string slice [%llu .. %llu] is out of bounds", i1, i2); | 7245 error("string slice [%ju .. %ju] is out of bounds", i1, i2); |
7233 e = e1; | 7246 e = e1; |
7234 } | 7247 } |
7235 return e; | 7248 return e; |
7236 } | 7249 } |
7237 | 7250 |
7238 type = t->nextOf()->arrayOf(); | 7251 if (t->ty == Tarray) |
7252 type = e1->type; | |
7253 else | |
7254 type = t->nextOf()->arrayOf(); | |
7239 return e; | 7255 return e; |
7240 | 7256 |
7241 Lerror: | 7257 Lerror: |
7242 char *s; | 7258 char *s; |
7243 if (t->ty == Tvoid) | 7259 if (t->ty == Tvoid) |
7608 else | 7624 else |
7609 e = new TypeExp(e1->loc, Argument::getNth(tup->arguments, (size_t)index)->type); | 7625 e = new TypeExp(e1->loc, Argument::getNth(tup->arguments, (size_t)index)->type); |
7610 } | 7626 } |
7611 else | 7627 else |
7612 { | 7628 { |
7613 error("array index [%llu] is outside array bounds [0 .. %"PRIuSIZE"]", | 7629 error("array index [%ju] is outside array bounds [0 .. %zu]", |
7614 index, length); | 7630 index, length); |
7615 e = e1; | 7631 e = e1; |
7616 } | 7632 } |
7617 break; | 7633 break; |
7618 } | 7634 } |
7619 | 7635 |
7620 default: | 7636 default: |