comparison dmd/mtype.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 3251ce06c820
children 79758fd2f48a
comparison
equal deleted inserted replaced
1194:1853dcd9b944 1195:e961851fb8be
23 23
24 #include <stdio.h> 24 #include <stdio.h>
25 #include <assert.h> 25 #include <assert.h>
26 #include <float.h> 26 #include <float.h>
27 27
28 #ifdef __DMC__
29 #include <fp.h>
30 #endif
31
32 #if _MSC_VER 28 #if _MSC_VER
33 #include <malloc.h> 29 #include <malloc.h>
34 #include <complex> 30 #include <complex>
35 #include <limits> 31 #include <limits>
36 #elif __DMC__ 32 #elif __DMC__
37 #include <complex.h> 33 #include <complex.h>
38 #elif __MINGW32__ 34 #elif __MINGW32__
39 #include <malloc.h> 35 #include <malloc.h>
40 #else
41 //#define signbit 56
42 #endif 36 #endif
43 37
44 #if __GNUC__
45 #if !(defined (__SVR4) && defined (__sun))
46 #include <bits/nan.h>
47 #include <bits/mathdef.h>
48 #endif
49 #endif
50 static double zero = 0;
51
52 #include "rmem.h" 38 #include "rmem.h"
39 #include "port.h"
53 40
54 #include "dsymbol.h" 41 #include "dsymbol.h"
55 #include "mtype.h" 42 #include "mtype.h"
56 #include "scope.h" 43 #include "scope.h"
57 #include "init.h" 44 #include "init.h"
83 /* These have default values for 32 bit code, they get 70 /* These have default values for 32 bit code, they get
84 * adjusted for 64 bit code. 71 * adjusted for 64 bit code.
85 */ 72 */
86 73
87 int PTRSIZE = 4; 74 int PTRSIZE = 4;
88 #if IN_LLVM 75 #if TARGET_OSX
89 int REALSIZE = 8; 76 int REALSIZE = 16;
90 int REALPAD = 0; 77 int REALPAD = 6;
91 #elif TARGET_LINUX 78 int REALALIGNSIZE = 16;
79 #elif TARGET_LINUX || TARGET_FREEBSD
92 int REALSIZE = 12; 80 int REALSIZE = 12;
93 int REALPAD = 2; 81 int REALPAD = 2;
82 int REALALIGNSIZE = 4;
94 #else 83 #else
95 int REALSIZE = 10; 84 int REALSIZE = 10;
96 int REALPAD = 0; 85 int REALPAD = 0;
86 int REALALIGNSIZE = 2;
97 #endif 87 #endif
98 int Tsize_t = Tuns32; 88 int Tsize_t = Tuns32;
99 int Tptrdiff_t = Tint32; 89 int Tptrdiff_t = Tint32;
100 90
101 /***************************** Type *****************************/ 91 /***************************** Type *****************************/
1117 case Timaginary80: 1107 case Timaginary80:
1118 case Tfloat32: 1108 case Tfloat32:
1119 case Tfloat64: 1109 case Tfloat64:
1120 case Tfloat80: 1110 case Tfloat80:
1121 { 1111 {
1122 #if IN_GCC 1112 fvalue = Port::nan;
1123 // mode doesn't matter, will be converted in RealExp anyway
1124 fvalue = real_t::getnan(real_t::LongDouble);
1125 #elif __GNUC__
1126 // gcc nan's have the sign bit set by default, so turn it off
1127 // Need the volatile to prevent gcc from doing incorrect
1128 // constant folding.
1129 volatile d_float80 foo;
1130 foo = NAN;
1131 if (std::signbit(foo)) // signbit sometimes, not always, set
1132 foo = -foo; // turn off sign bit
1133 fvalue = foo;
1134 #elif _MSC_VER
1135 unsigned long nan[2]= { 0xFFFFFFFF, 0x7FFFFFFF };
1136 fvalue = *(double*)nan;
1137 #else
1138 fvalue = NAN;
1139 #endif
1140 goto Lfvalue; 1113 goto Lfvalue;
1141 } 1114 }
1142 } 1115 }
1143 } 1116 }
1144 else if (ident == Id::infinity) 1117 else if (ident == Id::infinity)
1152 case Timaginary64: 1125 case Timaginary64:
1153 case Timaginary80: 1126 case Timaginary80:
1154 case Tfloat32: 1127 case Tfloat32:
1155 case Tfloat64: 1128 case Tfloat64:
1156 case Tfloat80: 1129 case Tfloat80:
1157 #if IN_GCC 1130 fvalue = Port::infinity;
1158 fvalue = real_t::getinfinity();
1159 #elif __GNUC__
1160 fvalue = 1 / zero;
1161 #elif _MSC_VER
1162 fvalue = std::numeric_limits<long double>::infinity();
1163 #else
1164 fvalue = INFINITY;
1165 #endif
1166 goto Lfvalue; 1131 goto Lfvalue;
1167 } 1132 }
1168 } 1133 }
1169 else if (ident == Id::dig) 1134 else if (ident == Id::dig)
1170 { 1135 {
1376 } 1341 }
1377 return e; 1342 return e;
1378 } 1343 }
1379 1344
1380 Expression *TypeBasic::defaultInit(Loc loc) 1345 Expression *TypeBasic::defaultInit(Loc loc)
1381 { integer_t value = 0; 1346 { dinteger_t value = 0;
1382 1347
1383 #if LOGDEFAULTINIT 1348 #if LOGDEFAULTINIT
1384 printf("TypeBasic::defaultInit() '%s'\n", toChars()); 1349 printf("TypeBasic::defaultInit() '%s'\n", toChars());
1385 #endif 1350 #endif
1386 switch (ty) 1351 switch (ty)
1733 t = new TypeSArray(t, e); 1698 t = new TypeSArray(t, e);
1734 return t; 1699 return t;
1735 } 1700 }
1736 1701
1737 d_uns64 TypeSArray::size(Loc loc) 1702 d_uns64 TypeSArray::size(Loc loc)
1738 { integer_t sz; 1703 { dinteger_t sz;
1739 1704
1740 if (!dim) 1705 if (!dim)
1741 return Type::size(loc); 1706 return Type::size(loc);
1742 sz = dim->toInteger(); 1707 sz = dim->toInteger();
1743 if (next->toBasetype()->ty == Tbit) // if array of bits 1708 if (next->toBasetype()->ty == Tbit) // if array of bits
1745 if (sz + 31 < sz) 1710 if (sz + 31 < sz)
1746 goto Loverflow; 1711 goto Loverflow;
1747 sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords 1712 sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords
1748 } 1713 }
1749 else 1714 else
1750 { integer_t n, n2; 1715 { dinteger_t n, n2;
1751 1716
1752 n = next->size(); 1717 n = next->size();
1753 n2 = n * sz; 1718 n2 = n * sz;
1754 if (n && (n2 / n) != sz) 1719 if (n && (n2 / n) != sz)
1755 goto Loverflow; 1720 goto Loverflow;
1894 1859
1895 next = next->semantic(loc,sc); 1860 next = next->semantic(loc,sc);
1896 Type *tbn = next->toBasetype(); 1861 Type *tbn = next->toBasetype();
1897 1862
1898 if (dim) 1863 if (dim)
1899 { integer_t n, n2; 1864 { dinteger_t n, n2;
1900 1865
1901 dim = semanticLength(sc, tbn, dim); 1866 dim = semanticLength(sc, tbn, dim);
1902 1867
1903 dim = dim->optimize(WANTvalue | WANTinterpret); 1868 dim = dim->optimize(WANTvalue | WANTinterpret);
1904 if (sc && sc->parameterSpecialization && dim->op == TOKvar && 1869 if (sc && sc->parameterSpecialization && dim->op == TOKvar &&
1907 /* It could be a template parameter N which has no value yet: 1872 /* It could be a template parameter N which has no value yet:
1908 * template Foo(T : T[N], size_t N); 1873 * template Foo(T : T[N], size_t N);
1909 */ 1874 */
1910 return this; 1875 return this;
1911 } 1876 }
1912 integer_t d1 = dim->toInteger(); 1877 dinteger_t d1 = dim->toInteger();
1913 dim = dim->castTo(sc, tsize_t); 1878 dim = dim->castTo(sc, tsize_t);
1914 dim = dim->optimize(WANTvalue); 1879 dim = dim->optimize(WANTvalue);
1915 integer_t d2 = dim->toInteger(); 1880 dinteger_t d2 = dim->toInteger();
1916 1881
1917 if (d1 != d2) 1882 if (d1 != d2)
1918 goto Loverflow; 1883 goto Loverflow;
1919 1884
1920 if (tbn->isintegral() || 1885 if (tbn->isintegral() ||
3050 { 3015 {
3051 L1: 3016 L1:
3052 if (varargs == 2 && u + 1 == nparams) // if last varargs param 3017 if (varargs == 2 && u + 1 == nparams) // if last varargs param
3053 { Type *tb = p->type->toBasetype(); 3018 { Type *tb = p->type->toBasetype();
3054 TypeSArray *tsa; 3019 TypeSArray *tsa;
3055 integer_t sz; 3020 dinteger_t sz;
3056 3021
3057 switch (tb->ty) 3022 switch (tb->ty)
3058 { 3023 {
3059 case Tsarray: 3024 case Tsarray:
3060 tsa = (TypeSArray *)tb; 3025 tsa = (TypeSArray *)tb;