Mercurial > projects > ldc
annotate dmd/mtype.c @ 1541:1e7a09548e67
Target.addPassesToEmitFile takes a formatted_raw_ostream now
Build fix for LLVM r75670
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Tue, 14 Jul 2009 23:06:31 +0200 |
parents | 05c235309d6f |
children | def7a1d494fd |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3 // Copyright (c) 1999-2009 by Digital Mars |
159 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
11 #define __C99FEATURES__ 1 // Needed on Solaris for NaN and more |
159 | 12 #define __USE_ISOC99 1 // so signbit() gets defined |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
13 |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
14 #if (defined (__SVR4) && defined (__sun)) |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
15 #include <alloca.h> |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
16 #endif |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
17 |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
18 #ifdef __DMC__ |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
19 #include <math.h> |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
20 #else |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
21 #include <cmath> |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
22 #endif |
159 | 23 |
24 #include <stdio.h> | |
25 #include <assert.h> | |
26 #include <float.h> | |
27 | |
28 #if _MSC_VER | |
29 #include <malloc.h> | |
30 #include <complex> | |
31 #include <limits> | |
32 #elif __DMC__ | |
33 #include <complex.h> | |
285
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
270
diff
changeset
|
34 #elif __MINGW32__ |
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
270
diff
changeset
|
35 #include <malloc.h> |
159 | 36 #endif |
37 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
38 #include "rmem.h" |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
39 #include "port.h" |
159 | 40 |
41 #include "dsymbol.h" | |
42 #include "mtype.h" | |
43 #include "scope.h" | |
44 #include "init.h" | |
45 #include "expression.h" | |
46 #include "attrib.h" | |
47 #include "declaration.h" | |
48 #include "template.h" | |
49 #include "id.h" | |
50 #include "enum.h" | |
51 #include "import.h" | |
52 #include "aggregate.h" | |
53 #include "hdrgen.h" | |
54 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
55 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
56 //#include "gen/tollvm.h" |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
57 Ir* Type::sir = NULL; |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
58 unsigned GetTypeAlignment(Ir* ir, Type* t); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
59 #endif |
1009
b1b23a64ad8c
Use LLVM alignment data instead of hand-picked.
Frits van Bommel <fvbommel wxs.nl>
parents:
1008
diff
changeset
|
60 |
159 | 61 FuncDeclaration *hasThis(Scope *sc); |
62 | |
63 | |
64 #define LOGDOTEXP 0 // log ::dotExp() | |
65 #define LOGDEFAULTINIT 0 // log ::defaultInit() | |
66 | |
67 // Allow implicit conversion of T[] to T* | |
68 #define IMPLICIT_ARRAY_TO_PTR global.params.useDeprecated | |
69 | |
70 /* These have default values for 32 bit code, they get | |
71 * adjusted for 64 bit code. | |
72 */ | |
73 | |
74 int PTRSIZE = 4; | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
75 |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
76 /* REALSIZE = size a real consumes in memory |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
77 * REALPAD = 'padding' added to the CPU real size to bring it up to REALSIZE |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
78 * REALALIGNSIZE = alignment for reals |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
79 */ |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
80 #if TARGET_OSX |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
81 int REALSIZE = 16; |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
82 int REALPAD = 6; |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
83 int REALALIGNSIZE = 16; |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
84 #elif TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS |
159 | 85 int REALSIZE = 12; |
86 int REALPAD = 2; | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
87 int REALALIGNSIZE = 4; |
159 | 88 #else |
89 int REALSIZE = 10; | |
90 int REALPAD = 0; | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
91 int REALALIGNSIZE = 2; |
159 | 92 #endif |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
93 |
159 | 94 int Tsize_t = Tuns32; |
95 int Tptrdiff_t = Tint32; | |
96 | |
1393
04177061f98d
Patch to allow compiling LDC with MinGW, by `mp4 / [1]jaffa` (slightly edited).
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
97 #if _WIN32 && !defined __MINGW32__ |
1257
7af860e4f403
Changes for mingw to compile properly
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1245
diff
changeset
|
98 static double zero = 0; |
7af860e4f403
Changes for mingw to compile properly
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1245
diff
changeset
|
99 double Port::nan = NAN; |
7af860e4f403
Changes for mingw to compile properly
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1245
diff
changeset
|
100 double Port::infinity = 1/zero; |
7af860e4f403
Changes for mingw to compile properly
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1245
diff
changeset
|
101 #endif |
7af860e4f403
Changes for mingw to compile properly
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1245
diff
changeset
|
102 |
159 | 103 /***************************** Type *****************************/ |
104 | |
105 ClassDeclaration *Type::typeinfo; | |
106 ClassDeclaration *Type::typeinfoclass; | |
107 ClassDeclaration *Type::typeinfointerface; | |
108 ClassDeclaration *Type::typeinfostruct; | |
109 ClassDeclaration *Type::typeinfotypedef; | |
110 ClassDeclaration *Type::typeinfopointer; | |
111 ClassDeclaration *Type::typeinfoarray; | |
112 ClassDeclaration *Type::typeinfostaticarray; | |
113 ClassDeclaration *Type::typeinfoassociativearray; | |
114 ClassDeclaration *Type::typeinfoenum; | |
115 ClassDeclaration *Type::typeinfofunction; | |
116 ClassDeclaration *Type::typeinfodelegate; | |
117 ClassDeclaration *Type::typeinfotypelist; | |
118 | |
119 Type *Type::tvoidptr; | |
120 Type *Type::basic[TMAX]; | |
121 unsigned char Type::mangleChar[TMAX]; | |
122 StringTable Type::stringtable; | |
123 | |
1245
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
124 #if IN_LLVM |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
125 StringTable Type::deco_stringtable; |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
126 #endif |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
127 |
159 | 128 |
129 Type::Type(TY ty, Type *next) | |
130 { | |
131 this->ty = ty; | |
132 this->mod = 0; | |
133 this->next = next; | |
134 this->deco = NULL; | |
336 | 135 #if DMDV2 |
159 | 136 this->cto = NULL; |
137 this->ito = NULL; | |
138 #endif | |
139 this->pto = NULL; | |
140 this->rto = NULL; | |
141 this->arrayof = NULL; | |
142 this->vtinfo = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
143 #if IN_DMD |
159 | 144 this->ctype = NULL; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
145 #endif |
1192
3251ce06c820
Started seperating type resolution from the rest of codegen again, the merge had too many regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1188
diff
changeset
|
146 |
3251ce06c820
Started seperating type resolution from the rest of codegen again, the merge had too many regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1188
diff
changeset
|
147 #if IN_LLVM |
3251ce06c820
Started seperating type resolution from the rest of codegen again, the merge had too many regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1188
diff
changeset
|
148 this->irtype = NULL; |
3251ce06c820
Started seperating type resolution from the rest of codegen again, the merge had too many regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1188
diff
changeset
|
149 #endif |
159 | 150 } |
151 | |
152 Type *Type::syntaxCopy() | |
153 { | |
154 print(); | |
155 fprintf(stdmsg, "ty = %d\n", ty); | |
156 assert(0); | |
157 return this; | |
158 } | |
159 | |
160 int Type::equals(Object *o) | |
161 { Type *t; | |
162 | |
163 t = (Type *)o; | |
164 //printf("Type::equals(%s, %s)\n", toChars(), t->toChars()); | |
165 if (this == o || | |
166 (t && deco == t->deco) && // deco strings are unique | |
167 deco != NULL) // and semantic() has been run | |
168 { | |
169 //printf("deco = '%s', t->deco = '%s'\n", deco, t->deco); | |
170 return 1; | |
171 } | |
172 //if (deco && t && t->deco) printf("deco = '%s', t->deco = '%s'\n", deco, t->deco); | |
173 return 0; | |
174 } | |
175 | |
176 char Type::needThisPrefix() | |
177 { | |
178 return 'M'; // name mangling prefix for functions needing 'this' | |
179 } | |
180 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
181 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
182 void Type::init(Ir* _sir) |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
183 #else |
159 | 184 void Type::init() |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
185 #endif |
159 | 186 { int i; |
187 int j; | |
188 | |
189 Lexer::initKeywords(); | |
190 | |
191 mangleChar[Tarray] = 'A'; | |
192 mangleChar[Tsarray] = 'G'; | |
193 mangleChar[Taarray] = 'H'; | |
194 mangleChar[Tpointer] = 'P'; | |
195 mangleChar[Treference] = 'R'; | |
196 mangleChar[Tfunction] = 'F'; | |
197 mangleChar[Tident] = 'I'; | |
198 mangleChar[Tclass] = 'C'; | |
199 mangleChar[Tstruct] = 'S'; | |
200 mangleChar[Tenum] = 'E'; | |
201 mangleChar[Ttypedef] = 'T'; | |
202 mangleChar[Tdelegate] = 'D'; | |
203 | |
204 mangleChar[Tnone] = 'n'; | |
205 mangleChar[Tvoid] = 'v'; | |
206 mangleChar[Tint8] = 'g'; | |
207 mangleChar[Tuns8] = 'h'; | |
208 mangleChar[Tint16] = 's'; | |
209 mangleChar[Tuns16] = 't'; | |
210 mangleChar[Tint32] = 'i'; | |
211 mangleChar[Tuns32] = 'k'; | |
212 mangleChar[Tint64] = 'l'; | |
213 mangleChar[Tuns64] = 'm'; | |
214 mangleChar[Tfloat32] = 'f'; | |
215 mangleChar[Tfloat64] = 'd'; | |
216 mangleChar[Tfloat80] = 'e'; | |
217 | |
218 mangleChar[Timaginary32] = 'o'; | |
219 mangleChar[Timaginary64] = 'p'; | |
220 mangleChar[Timaginary80] = 'j'; | |
221 mangleChar[Tcomplex32] = 'q'; | |
222 mangleChar[Tcomplex64] = 'r'; | |
223 mangleChar[Tcomplex80] = 'c'; | |
224 | |
225 mangleChar[Tbool] = 'b'; | |
226 mangleChar[Tascii] = 'a'; | |
227 mangleChar[Twchar] = 'u'; | |
228 mangleChar[Tdchar] = 'w'; | |
229 | |
230 mangleChar[Tbit] = '@'; | |
231 mangleChar[Tinstance] = '@'; | |
232 mangleChar[Terror] = '@'; | |
233 mangleChar[Ttypeof] = '@'; | |
234 mangleChar[Ttuple] = 'B'; | |
235 mangleChar[Tslice] = '@'; | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
236 mangleChar[Treturn] = '@'; |
159 | 237 |
238 for (i = 0; i < TMAX; i++) | |
239 { if (!mangleChar[i]) | |
240 fprintf(stdmsg, "ty = %d\n", i); | |
241 assert(mangleChar[i]); | |
242 } | |
243 | |
244 // Set basic types | |
245 static TY basetab[] = | |
246 { Tvoid, Tint8, Tuns8, Tint16, Tuns16, Tint32, Tuns32, Tint64, Tuns64, | |
247 Tfloat32, Tfloat64, Tfloat80, | |
248 Timaginary32, Timaginary64, Timaginary80, | |
249 Tcomplex32, Tcomplex64, Tcomplex80, | |
250 Tbit, Tbool, | |
251 Tascii, Twchar, Tdchar }; | |
252 | |
253 for (i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++) | |
254 basic[basetab[i]] = new TypeBasic(basetab[i]); | |
255 basic[Terror] = basic[Tint32]; | |
256 | |
257 tvoidptr = tvoid->pointerTo(); | |
258 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
259 // LDC |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
260 sir = _sir; |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
261 |
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
243
diff
changeset
|
262 // set size_t / ptrdiff_t types and pointer size |
159 | 263 if (global.params.is64bit) |
264 { | |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
265 Tsize_t = Tuns64; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
266 Tptrdiff_t = Tint64; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
267 PTRSIZE = 8; |
159 | 268 } |
269 else | |
270 { | |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
271 Tsize_t = Tuns32; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
272 Tptrdiff_t = Tint32; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
273 PTRSIZE = 4; |
243
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
274 } |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
275 |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
276 // set real size and padding |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
389
diff
changeset
|
277 if (global.params.cpu == ARCHx86) |
243
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
278 { |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
279 REALSIZE = 12; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
280 REALPAD = 2; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
281 } |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
282 else if (global.params.cpu == ARCHx86_64) |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
283 { |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
284 REALSIZE = 16; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
285 REALPAD = 6; |
243
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
286 } |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
287 else |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
288 { |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
289 REALSIZE = 8; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
290 REALPAD = 0; |
159 | 291 } |
292 } | |
293 | |
294 d_uns64 Type::size() | |
295 { | |
296 return size(0); | |
297 } | |
298 | |
299 d_uns64 Type::size(Loc loc) | |
300 { | |
301 error(loc, "no size for type %s", toChars()); | |
302 return 1; | |
303 } | |
304 | |
305 unsigned Type::alignsize() | |
306 { | |
307 return size(0); | |
308 } | |
309 | |
310 Type *Type::semantic(Loc loc, Scope *sc) | |
311 { | |
312 if (next) | |
313 next = next->semantic(loc,sc); | |
314 return merge(); | |
315 } | |
316 | |
317 Type *Type::pointerTo() | |
318 { | |
319 if (!pto) | |
320 { Type *t; | |
321 | |
322 t = new TypePointer(this); | |
323 pto = t->merge(); | |
324 } | |
325 return pto; | |
326 } | |
327 | |
328 Type *Type::referenceTo() | |
329 { | |
330 if (!rto) | |
331 { Type *t; | |
332 | |
333 t = new TypeReference(this); | |
334 rto = t->merge(); | |
335 } | |
336 return rto; | |
337 } | |
338 | |
339 Type *Type::arrayOf() | |
340 { | |
341 if (!arrayof) | |
342 { Type *t; | |
343 | |
344 t = new TypeDArray(this); | |
345 arrayof = t->merge(); | |
346 } | |
347 return arrayof; | |
348 } | |
349 | |
350 Dsymbol *Type::toDsymbol(Scope *sc) | |
351 { | |
352 return NULL; | |
353 } | |
354 | |
355 /******************************* | |
356 * If this is a shell around another type, | |
357 * get that other type. | |
358 */ | |
359 | |
360 Type *Type::toBasetype() | |
361 { | |
362 return this; | |
363 } | |
364 | |
365 /******************************** | |
366 * Name mangling. | |
367 */ | |
368 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
369 void Type::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 370 { |
371 buf->writeByte(mangleChar[ty]); | |
372 if (next) | |
373 { | |
374 assert(next != this); | |
375 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this->ty, next, next->ty); | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
376 next->toDecoBuffer(buf, mangle); |
159 | 377 } |
378 } | |
379 | |
380 /******************************** | |
381 * For pretty-printing a type. | |
382 */ | |
383 | |
384 char *Type::toChars() | |
385 { OutBuffer *buf; | |
386 HdrGenState hgs; | |
387 | |
388 buf = new OutBuffer(); | |
389 toCBuffer(buf, NULL, &hgs); | |
390 return buf->toChars(); | |
391 } | |
392 | |
393 void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) | |
394 { | |
395 toCBuffer2(buf, hgs, 0); | |
396 if (ident) | |
397 { buf->writeByte(' '); | |
398 buf->writestring(ident->toChars()); | |
399 } | |
400 } | |
401 | |
402 void Type::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
403 { | |
404 if (mod != this->mod) | |
405 { toCBuffer3(buf, hgs, mod); | |
406 return; | |
407 } | |
408 buf->writestring(toChars()); | |
409 } | |
410 | |
411 void Type::toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod) | |
412 { | |
413 if (mod != this->mod) | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
414 { const char *p; |
159 | 415 |
416 switch (this->mod) | |
417 { | |
418 case 0: | |
419 toCBuffer2(buf, hgs, this->mod); | |
420 break; | |
421 case MODconst: | |
422 p = "const("; | |
423 goto L1; | |
424 case MODinvariant: | |
425 p = "invariant("; | |
426 L1: buf->writestring(p); | |
427 toCBuffer2(buf, hgs, this->mod); | |
428 buf->writeByte(')'); | |
429 break; | |
430 default: | |
431 assert(0); | |
432 } | |
433 } | |
434 } | |
435 | |
436 | |
437 /************************************ | |
438 */ | |
439 | |
440 Type *Type::merge() | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
441 { |
159 | 442 //printf("merge(%s)\n", toChars()); |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
443 Type *t = this; |
159 | 444 assert(t); |
445 if (!deco) | |
446 { | |
447 if (next) | |
448 next = next->merge(); | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
449 |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
450 OutBuffer buf; |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
451 toDecoBuffer(&buf, false); |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
452 StringValue *sv = stringtable.update((char *)buf.data, buf.offset); |
159 | 453 if (sv->ptrvalue) |
454 { t = (Type *) sv->ptrvalue; | |
455 assert(t->deco); | |
456 //printf("old value, deco = '%s' %p\n", t->deco, t->deco); | |
457 } | |
458 else | |
459 { | |
460 sv->ptrvalue = this; | |
1245
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
461 |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
462 // we still need deco strings to be unique |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
463 // or Type::equals fails, which breaks a bunch of stuff, |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
464 // like covariant member function overloads. |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
465 OutBuffer mangle; |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
466 toDecoBuffer(&mangle, true); |
1245
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
467 StringValue* sv2 = deco_stringtable.update((char *)mangle.data, mangle.offset); |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
468 if (sv2->ptrvalue) |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
469 { Type* t2 = (Type *) sv2->ptrvalue; |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
470 assert(t2->deco); |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
471 deco = t2->deco; |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
472 } |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
473 else |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
474 { |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
475 sv2->ptrvalue = this; |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
476 deco = (char *)sv2->lstring.string; |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
477 } |
159 | 478 //printf("new value, deco = '%s' %p\n", t->deco, t->deco); |
479 } | |
480 } | |
481 return t; | |
482 } | |
483 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
484 /************************************* |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
485 * This version does a merge even if the deco is already computed. |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
486 * Necessary for types that have a deco, but are not merged. |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
487 */ |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
488 Type *Type::merge2() |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
489 { |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
490 //printf("merge2(%s)\n", toChars()); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
491 Type *t = this; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
492 assert(t); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
493 if (!t->deco) |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
494 return t->merge(); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
495 |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
496 StringValue *sv = deco_stringtable.lookup((char *)t->deco, strlen(t->deco)); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
497 if (sv && sv->ptrvalue) |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
498 { t = (Type *) sv->ptrvalue; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
499 assert(t->deco); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
500 } |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
501 else |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
502 assert(0); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
503 return t; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
504 } |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
505 |
159 | 506 int Type::isbit() |
507 { | |
508 return FALSE; | |
509 } | |
510 | |
511 int Type::isintegral() | |
512 { | |
513 return FALSE; | |
514 } | |
515 | |
516 int Type::isfloating() | |
517 { | |
518 return FALSE; | |
519 } | |
520 | |
521 int Type::isreal() | |
522 { | |
523 return FALSE; | |
524 } | |
525 | |
526 int Type::isimaginary() | |
527 { | |
528 return FALSE; | |
529 } | |
530 | |
531 int Type::iscomplex() | |
532 { | |
533 return FALSE; | |
534 } | |
535 | |
536 int Type::isscalar() | |
537 { | |
538 return FALSE; | |
539 } | |
540 | |
541 int Type::isunsigned() | |
542 { | |
543 return FALSE; | |
544 } | |
545 | |
546 ClassDeclaration *Type::isClassHandle() | |
547 { | |
548 return NULL; | |
549 } | |
550 | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
551 int Type::isscope() |
159 | 552 { |
553 return FALSE; | |
554 } | |
555 | |
556 int Type::isString() | |
557 { | |
558 return FALSE; | |
559 } | |
560 | |
561 int Type::checkBoolean() | |
562 { | |
563 return isscalar(); | |
564 } | |
565 | |
566 /********************************* | |
567 * Check type to see if it is based on a deprecated symbol. | |
568 */ | |
569 | |
570 void Type::checkDeprecated(Loc loc, Scope *sc) | |
571 { | |
572 Type *t; | |
573 Dsymbol *s; | |
574 | |
575 for (t = this; t; t = t->next) | |
576 { | |
577 s = t->toDsymbol(sc); | |
578 if (s) | |
579 s->checkDeprecated(loc, sc); | |
580 } | |
581 } | |
582 | |
583 | |
584 Expression *Type::defaultInit(Loc loc) | |
585 { | |
586 #if LOGDEFAULTINIT | |
587 printf("Type::defaultInit() '%s'\n", toChars()); | |
588 #endif | |
589 return NULL; | |
590 } | |
591 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
592 int Type::isZeroInit(Loc loc) |
159 | 593 { |
594 return 0; // assume not | |
595 } | |
596 | |
597 int Type::isBaseOf(Type *t, int *poffset) | |
598 { | |
599 return 0; // assume not | |
600 } | |
601 | |
602 /******************************** | |
603 * Determine if 'this' can be implicitly converted | |
604 * to type 'to'. | |
605 * Returns: | |
606 * 0 can't convert | |
607 * 1 can convert using implicit conversions | |
608 * 2 this and to are the same type | |
609 */ | |
610 | |
611 MATCH Type::implicitConvTo(Type *to) | |
612 { | |
613 //printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to); | |
614 //printf("\tthis->next=%p, to->next=%p\n", this->next, to->next); | |
615 if (this == to) | |
616 return MATCHexact; | |
617 // if (to->ty == Tvoid) | |
618 // return 1; | |
619 return MATCHnomatch; | |
620 } | |
621 | |
622 Expression *Type::getProperty(Loc loc, Identifier *ident) | |
623 { Expression *e; | |
624 | |
625 #if LOGDOTEXP | |
626 printf("Type::getProperty(type = '%s', ident = '%s')\n", toChars(), ident->toChars()); | |
627 #endif | |
628 if (ident == Id::__sizeof) | |
629 { | |
630 e = new IntegerExp(loc, size(loc), Type::tsize_t); | |
631 } | |
632 else if (ident == Id::size) | |
633 { | |
634 error(loc, ".size property should be replaced with .sizeof"); | |
635 e = new IntegerExp(loc, size(loc), Type::tsize_t); | |
636 } | |
637 else if (ident == Id::alignof) | |
638 { | |
639 e = new IntegerExp(loc, alignsize(), Type::tsize_t); | |
640 } | |
641 else if (ident == Id::typeinfo) | |
642 { | |
643 if (!global.params.useDeprecated) | |
644 error(loc, ".typeinfo deprecated, use typeid(type)"); | |
645 e = getTypeInfo(NULL); | |
646 } | |
647 else if (ident == Id::init) | |
648 { | |
649 if (ty == Tvoid) | |
650 error(loc, "void does not have an initializer"); | |
651 e = defaultInit(loc); | |
652 } | |
653 else if (ident == Id::mangleof) | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
654 { const char *s; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
655 if (!deco) |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
656 { s = toChars(); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
657 error(loc, "forward reference of type %s.mangleof", s); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
658 } |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
659 else |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
660 s = deco; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
661 e = new StringExp(loc, (char *)s, strlen(s), 'c'); |
159 | 662 Scope sc; |
663 e = e->semantic(&sc); | |
664 } | |
665 else if (ident == Id::stringof) | |
666 { char *s = toChars(); | |
667 e = new StringExp(loc, s, strlen(s), 'c'); | |
668 Scope sc; | |
669 e = e->semantic(&sc); | |
670 } | |
671 else | |
672 { | |
673 error(loc, "no property '%s' for type '%s'", ident->toChars(), toChars()); | |
674 e = new IntegerExp(loc, 1, Type::tint32); | |
675 } | |
676 return e; | |
677 } | |
678 | |
679 Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
680 { VarDeclaration *v = NULL; | |
681 | |
682 #if LOGDOTEXP | |
683 printf("Type::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
684 #endif | |
685 if (e->op == TOKdotvar) | |
686 { | |
687 DotVarExp *dv = (DotVarExp *)e; | |
688 v = dv->var->isVarDeclaration(); | |
689 } | |
690 else if (e->op == TOKvar) | |
691 { | |
692 VarExp *ve = (VarExp *)e; | |
693 v = ve->var->isVarDeclaration(); | |
694 } | |
695 if (v) | |
696 { | |
697 if (ident == Id::offset) | |
698 { | |
699 if (!global.params.useDeprecated) | |
700 error(e->loc, ".offset deprecated, use .offsetof"); | |
701 goto Loffset; | |
702 } | |
703 else if (ident == Id::offsetof) | |
704 { | |
705 Loffset: | |
706 if (v->storage_class & STCfield) | |
707 { | |
708 e = new IntegerExp(e->loc, v->offset, Type::tsize_t); | |
709 return e; | |
710 } | |
711 } | |
712 else if (ident == Id::init) | |
713 { | |
714 #if 0 | |
715 if (v->init) | |
716 { | |
717 if (v->init->isVoidInitializer()) | |
718 error(e->loc, "%s.init is void", v->toChars()); | |
719 else | |
720 { Loc loc = e->loc; | |
721 e = v->init->toExpression(); | |
722 if (e->op == TOKassign || e->op == TOKconstruct) | |
723 { | |
724 e = ((AssignExp *)e)->e2; | |
725 | |
726 /* Take care of case where we used a 0 | |
727 * to initialize the struct. | |
728 */ | |
729 if (e->type == Type::tint32 && | |
730 e->isBool(0) && | |
731 v->type->toBasetype()->ty == Tstruct) | |
732 { | |
733 e = v->type->defaultInit(loc); | |
734 } | |
735 } | |
736 e = e->optimize(WANTvalue | WANTinterpret); | |
737 // if (!e->isConst()) | |
738 // error(loc, ".init cannot be evaluated at compile time"); | |
739 } | |
740 return e; | |
741 } | |
742 #endif | |
743 Expression *ex = defaultInit(e->loc); | |
744 return ex; | |
745 } | |
746 } | |
747 if (ident == Id::typeinfo) | |
748 { | |
749 if (!global.params.useDeprecated) | |
750 error(e->loc, ".typeinfo deprecated, use typeid(type)"); | |
751 e = getTypeInfo(sc); | |
752 return e; | |
753 } | |
754 if (ident == Id::stringof) | |
755 { char *s = e->toChars(); | |
756 e = new StringExp(e->loc, s, strlen(s), 'c'); | |
757 Scope sc; | |
758 e = e->semantic(&sc); | |
759 return e; | |
760 } | |
761 return getProperty(e->loc, ident); | |
762 } | |
763 | |
764 unsigned Type::memalign(unsigned salign) | |
765 { | |
766 return salign; | |
767 } | |
768 | |
769 void Type::error(Loc loc, const char *format, ...) | |
770 { | |
771 va_list ap; | |
772 va_start(ap, format); | |
773 ::verror(loc, format, ap); | |
774 va_end( ap ); | |
775 } | |
776 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
777 void Type::warning(Loc loc, const char *format, ...) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
778 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
779 if (global.params.warnings && !global.gag) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
780 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
781 va_list ap; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
782 va_start(ap, format); |
1124
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
783 ::vwarning(loc, format, ap); |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
784 va_end( ap ); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
785 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
786 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
787 |
159 | 788 Identifier *Type::getTypeInfoIdent(int internal) |
789 { | |
790 // _init_10TypeInfo_%s | |
791 OutBuffer buf; | |
792 Identifier *id; | |
793 char *name; | |
794 int len; | |
795 | |
796 //toTypeInfoBuffer(&buf); | |
797 if (internal) | |
798 { buf.writeByte(mangleChar[ty]); | |
799 if (ty == Tarray) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
800 buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]); |
159 | 801 } |
802 else | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
803 toDecoBuffer(&buf, true); |
159 | 804 len = buf.offset; |
805 name = (char *)alloca(19 + sizeof(len) * 3 + len + 1); | |
806 buf.writeByte(0); | |
807 sprintf(name, "_D%dTypeInfo_%s6__initZ", 9 + len, buf.data); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
808 // LDC |
375
3c4460b988bd
Do not strip the leading underscore for typeinfo mangles on Windows.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
809 // it is not clear where the underscore that's stripped here is added back in |
3c4460b988bd
Do not strip the leading underscore for typeinfo mangles on Windows.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
810 // if (global.params.isWindows) |
3c4460b988bd
Do not strip the leading underscore for typeinfo mangles on Windows.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
811 // name++; // C mangling will add it back in |
159 | 812 //printf("name = %s\n", name); |
813 id = Lexer::idPool(name); | |
814 return id; | |
815 } | |
816 | |
817 TypeBasic *Type::isTypeBasic() | |
818 { | |
819 return NULL; | |
820 } | |
821 | |
822 | |
823 void Type::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
824 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
825 //printf("Type::resolve() %s, %d\n", toChars(), ty); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
826 Type *t = semantic(loc, sc); |
159 | 827 *pt = t; |
828 *pe = NULL; | |
829 *ps = NULL; | |
830 } | |
831 | |
832 /******************************* | |
833 * If one of the subtypes of this type is a TypeIdentifier, | |
834 * i.e. it's an unresolved type, return that type. | |
835 */ | |
836 | |
837 Type *Type::reliesOnTident() | |
838 { | |
839 if (!next) | |
840 return NULL; | |
841 else | |
842 return next->reliesOnTident(); | |
843 } | |
844 | |
845 /******************************** | |
846 * We've mistakenly parsed this as a type. | |
847 * Redo it as an Expression. | |
848 * NULL if cannot. | |
849 */ | |
850 | |
851 Expression *Type::toExpression() | |
852 { | |
853 return NULL; | |
854 } | |
855 | |
856 /*************************************** | |
857 * Return !=0 if type has pointers that need to | |
858 * be scanned by the GC during a collection cycle. | |
859 */ | |
860 | |
861 int Type::hasPointers() | |
862 { | |
863 return FALSE; | |
864 } | |
865 | |
866 /* ============================= TypeBasic =========================== */ | |
867 | |
868 TypeBasic::TypeBasic(TY ty) | |
869 : Type(ty, NULL) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
642
diff
changeset
|
870 { const char *c; |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
642
diff
changeset
|
871 const char *d; |
159 | 872 unsigned flags; |
873 | |
874 #define TFLAGSintegral 1 | |
875 #define TFLAGSfloating 2 | |
876 #define TFLAGSunsigned 4 | |
877 #define TFLAGSreal 8 | |
878 #define TFLAGSimaginary 0x10 | |
879 #define TFLAGScomplex 0x20 | |
880 | |
881 flags = 0; | |
882 switch (ty) | |
883 { | |
884 case Tvoid: d = Token::toChars(TOKvoid); | |
885 c = "void"; | |
886 break; | |
887 | |
888 case Tint8: d = Token::toChars(TOKint8); | |
889 c = "byte"; | |
890 flags |= TFLAGSintegral; | |
891 break; | |
892 | |
893 case Tuns8: d = Token::toChars(TOKuns8); | |
894 c = "ubyte"; | |
895 flags |= TFLAGSintegral | TFLAGSunsigned; | |
896 break; | |
897 | |
898 case Tint16: d = Token::toChars(TOKint16); | |
899 c = "short"; | |
900 flags |= TFLAGSintegral; | |
901 break; | |
902 | |
903 case Tuns16: d = Token::toChars(TOKuns16); | |
904 c = "ushort"; | |
905 flags |= TFLAGSintegral | TFLAGSunsigned; | |
906 break; | |
907 | |
908 case Tint32: d = Token::toChars(TOKint32); | |
909 c = "int"; | |
910 flags |= TFLAGSintegral; | |
911 break; | |
912 | |
913 case Tuns32: d = Token::toChars(TOKuns32); | |
914 c = "uint"; | |
915 flags |= TFLAGSintegral | TFLAGSunsigned; | |
916 break; | |
917 | |
918 case Tfloat32: d = Token::toChars(TOKfloat32); | |
919 c = "float"; | |
920 flags |= TFLAGSfloating | TFLAGSreal; | |
921 break; | |
922 | |
923 case Tint64: d = Token::toChars(TOKint64); | |
924 c = "long"; | |
925 flags |= TFLAGSintegral; | |
926 break; | |
927 | |
928 case Tuns64: d = Token::toChars(TOKuns64); | |
929 c = "ulong"; | |
930 flags |= TFLAGSintegral | TFLAGSunsigned; | |
931 break; | |
932 | |
933 case Tfloat64: d = Token::toChars(TOKfloat64); | |
934 c = "double"; | |
935 flags |= TFLAGSfloating | TFLAGSreal; | |
936 break; | |
937 | |
938 case Tfloat80: d = Token::toChars(TOKfloat80); | |
939 c = "real"; | |
940 flags |= TFLAGSfloating | TFLAGSreal; | |
941 break; | |
942 | |
943 case Timaginary32: d = Token::toChars(TOKimaginary32); | |
944 c = "ifloat"; | |
945 flags |= TFLAGSfloating | TFLAGSimaginary; | |
946 break; | |
947 | |
948 case Timaginary64: d = Token::toChars(TOKimaginary64); | |
949 c = "idouble"; | |
950 flags |= TFLAGSfloating | TFLAGSimaginary; | |
951 break; | |
952 | |
953 case Timaginary80: d = Token::toChars(TOKimaginary80); | |
954 c = "ireal"; | |
955 flags |= TFLAGSfloating | TFLAGSimaginary; | |
956 break; | |
957 | |
958 case Tcomplex32: d = Token::toChars(TOKcomplex32); | |
959 c = "cfloat"; | |
960 flags |= TFLAGSfloating | TFLAGScomplex; | |
961 break; | |
962 | |
963 case Tcomplex64: d = Token::toChars(TOKcomplex64); | |
964 c = "cdouble"; | |
965 flags |= TFLAGSfloating | TFLAGScomplex; | |
966 break; | |
967 | |
968 case Tcomplex80: d = Token::toChars(TOKcomplex80); | |
969 c = "creal"; | |
970 flags |= TFLAGSfloating | TFLAGScomplex; | |
971 break; | |
972 | |
973 | |
974 case Tbit: d = Token::toChars(TOKbit); | |
975 c = "bit"; | |
976 flags |= TFLAGSintegral | TFLAGSunsigned; | |
977 break; | |
978 | |
979 case Tbool: d = "bool"; | |
980 c = d; | |
981 flags |= TFLAGSintegral | TFLAGSunsigned; | |
982 break; | |
983 | |
984 case Tascii: d = Token::toChars(TOKchar); | |
985 c = "char"; | |
986 flags |= TFLAGSintegral | TFLAGSunsigned; | |
987 break; | |
988 | |
989 case Twchar: d = Token::toChars(TOKwchar); | |
990 c = "wchar"; | |
991 flags |= TFLAGSintegral | TFLAGSunsigned; | |
992 break; | |
993 | |
994 case Tdchar: d = Token::toChars(TOKdchar); | |
995 c = "dchar"; | |
996 flags |= TFLAGSintegral | TFLAGSunsigned; | |
997 break; | |
998 | |
999 default: assert(0); | |
1000 } | |
1001 this->dstring = d; | |
1002 this->cstring = c; | |
1003 this->flags = flags; | |
1004 merge(); | |
1005 } | |
1006 | |
1007 Type *TypeBasic::syntaxCopy() | |
1008 { | |
1009 // No semantic analysis done on basic types, no need to copy | |
1010 return this; | |
1011 } | |
1012 | |
1013 | |
1014 char *TypeBasic::toChars() | |
1015 { | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
642
diff
changeset
|
1016 return (char *)dstring; |
159 | 1017 } |
1018 | |
1019 void TypeBasic::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
1020 { | |
1021 //printf("TypeBasic::toCBuffer2(mod = %d, this->mod = %d)\n", mod, this->mod); | |
1022 if (mod != this->mod) | |
1023 { toCBuffer3(buf, hgs, mod); | |
1024 return; | |
1025 } | |
1026 buf->writestring(dstring); | |
1027 } | |
1028 | |
1029 d_uns64 TypeBasic::size(Loc loc) | |
1030 { unsigned size; | |
1031 | |
1032 //printf("TypeBasic::size()\n"); | |
1033 switch (ty) | |
1034 { | |
1035 case Tint8: | |
1036 case Tuns8: size = 1; break; | |
1037 case Tint16: | |
1038 case Tuns16: size = 2; break; | |
1039 case Tint32: | |
1040 case Tuns32: | |
1041 case Tfloat32: | |
1042 case Timaginary32: | |
1043 size = 4; break; | |
1044 case Tint64: | |
1045 case Tuns64: | |
1046 case Tfloat64: | |
1047 case Timaginary64: | |
1048 size = 8; break; | |
1049 case Tfloat80: | |
1050 case Timaginary80: | |
1051 size = REALSIZE; break; | |
1052 case Tcomplex32: | |
1053 size = 8; break; | |
1054 case Tcomplex64: | |
1055 size = 16; break; | |
1056 case Tcomplex80: | |
1057 size = REALSIZE * 2; break; | |
1058 | |
1059 case Tvoid: | |
1060 //size = Type::size(); // error message | |
1061 size = 1; | |
1062 break; | |
1063 | |
1064 case Tbit: size = 1; break; | |
1065 case Tbool: size = 1; break; | |
1066 case Tascii: size = 1; break; | |
1067 case Twchar: size = 2; break; | |
1068 case Tdchar: size = 4; break; | |
1069 | |
1070 default: | |
1071 assert(0); | |
1072 break; | |
1073 } | |
1074 //printf("TypeBasic::size() = %d\n", size); | |
1075 return size; | |
1076 } | |
1077 | |
1078 unsigned TypeBasic::alignsize() | |
1009
b1b23a64ad8c
Use LLVM alignment data instead of hand-picked.
Frits van Bommel <fvbommel wxs.nl>
parents:
1008
diff
changeset
|
1079 { |
1014
47f8b54f90b3
Fixed alignsize for void types. (it's one byte)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1009
diff
changeset
|
1080 if (ty == Tvoid) |
47f8b54f90b3
Fixed alignsize for void types. (it's one byte)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1009
diff
changeset
|
1081 return 1; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
1082 return GetTypeAlignment(sir, this); |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1083 #if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1084 case Tint64: |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1085 case Tuns64: |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1086 case Tfloat64: |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1087 case Timaginary64: |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1088 case Tcomplex32: |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1089 case Tcomplex64: |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1090 sz = 4; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1091 break; |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1092 #endif |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1093 |
159 | 1094 } |
1095 | |
1096 | |
1097 Expression *TypeBasic::getProperty(Loc loc, Identifier *ident) | |
1098 { | |
1099 Expression *e; | |
1100 d_int64 ivalue; | |
1101 #ifdef IN_GCC | |
1102 real_t fvalue; | |
1103 #else | |
1104 d_float80 fvalue; | |
1105 #endif | |
1106 | |
1107 //printf("TypeBasic::getProperty('%s')\n", ident->toChars()); | |
1108 if (ident == Id::max) | |
1109 { | |
1110 switch (ty) | |
1111 { | |
1112 case Tint8: ivalue = 0x7F; goto Livalue; | |
1113 case Tuns8: ivalue = 0xFF; goto Livalue; | |
1114 case Tint16: ivalue = 0x7FFFUL; goto Livalue; | |
1115 case Tuns16: ivalue = 0xFFFFUL; goto Livalue; | |
1116 case Tint32: ivalue = 0x7FFFFFFFUL; goto Livalue; | |
1117 case Tuns32: ivalue = 0xFFFFFFFFUL; goto Livalue; | |
1118 case Tint64: ivalue = 0x7FFFFFFFFFFFFFFFLL; goto Livalue; | |
1119 case Tuns64: ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue; | |
1120 case Tbit: ivalue = 1; goto Livalue; | |
1121 case Tbool: ivalue = 1; goto Livalue; | |
1122 case Tchar: ivalue = 0xFF; goto Livalue; | |
1123 case Twchar: ivalue = 0xFFFFUL; goto Livalue; | |
1124 case Tdchar: ivalue = 0x10FFFFUL; goto Livalue; | |
1125 | |
1126 case Tcomplex32: | |
1127 case Timaginary32: | |
1128 case Tfloat32: fvalue = FLT_MAX; goto Lfvalue; | |
1129 case Tcomplex64: | |
1130 case Timaginary64: | |
1131 case Tfloat64: fvalue = DBL_MAX; goto Lfvalue; | |
1132 case Tcomplex80: | |
1133 case Timaginary80: | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1134 case Tfloat80: fvalue = Port::ldbl_max; goto Lfvalue; |
159 | 1135 } |
1136 } | |
1137 else if (ident == Id::min) | |
1138 { | |
1139 switch (ty) | |
1140 { | |
1141 case Tint8: ivalue = -128; goto Livalue; | |
1142 case Tuns8: ivalue = 0; goto Livalue; | |
1143 case Tint16: ivalue = -32768; goto Livalue; | |
1144 case Tuns16: ivalue = 0; goto Livalue; | |
1145 case Tint32: ivalue = -2147483647L - 1; goto Livalue; | |
1146 case Tuns32: ivalue = 0; goto Livalue; | |
1147 case Tint64: ivalue = (-9223372036854775807LL-1LL); goto Livalue; | |
1148 case Tuns64: ivalue = 0; goto Livalue; | |
1149 case Tbit: ivalue = 0; goto Livalue; | |
1150 case Tbool: ivalue = 0; goto Livalue; | |
1151 case Tchar: ivalue = 0; goto Livalue; | |
1152 case Twchar: ivalue = 0; goto Livalue; | |
1153 case Tdchar: ivalue = 0; goto Livalue; | |
1154 | |
1155 case Tcomplex32: | |
1156 case Timaginary32: | |
1157 case Tfloat32: fvalue = FLT_MIN; goto Lfvalue; | |
1158 case Tcomplex64: | |
1159 case Timaginary64: | |
1160 case Tfloat64: fvalue = DBL_MIN; goto Lfvalue; | |
1161 case Tcomplex80: | |
1162 case Timaginary80: | |
1163 case Tfloat80: fvalue = LDBL_MIN; goto Lfvalue; | |
1164 } | |
1165 } | |
1166 else if (ident == Id::nan) | |
1167 { | |
1168 switch (ty) | |
1169 { | |
1170 case Tcomplex32: | |
1171 case Tcomplex64: | |
1172 case Tcomplex80: | |
1173 case Timaginary32: | |
1174 case Timaginary64: | |
1175 case Timaginary80: | |
1176 case Tfloat32: | |
1177 case Tfloat64: | |
1178 case Tfloat80: | |
1179 { | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1180 fvalue = Port::nan; |
159 | 1181 goto Lfvalue; |
1182 } | |
1183 } | |
1184 } | |
1185 else if (ident == Id::infinity) | |
1186 { | |
1187 switch (ty) | |
1188 { | |
1189 case Tcomplex32: | |
1190 case Tcomplex64: | |
1191 case Tcomplex80: | |
1192 case Timaginary32: | |
1193 case Timaginary64: | |
1194 case Timaginary80: | |
1195 case Tfloat32: | |
1196 case Tfloat64: | |
1197 case Tfloat80: | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1198 fvalue = Port::infinity; |
159 | 1199 goto Lfvalue; |
1200 } | |
1201 } | |
1202 else if (ident == Id::dig) | |
1203 { | |
1204 switch (ty) | |
1205 { | |
1206 case Tcomplex32: | |
1207 case Timaginary32: | |
1208 case Tfloat32: ivalue = FLT_DIG; goto Lint; | |
1209 case Tcomplex64: | |
1210 case Timaginary64: | |
1211 case Tfloat64: ivalue = DBL_DIG; goto Lint; | |
1212 case Tcomplex80: | |
1213 case Timaginary80: | |
1214 case Tfloat80: ivalue = LDBL_DIG; goto Lint; | |
1215 } | |
1216 } | |
1217 else if (ident == Id::epsilon) | |
1218 { | |
1219 switch (ty) | |
1220 { | |
1221 case Tcomplex32: | |
1222 case Timaginary32: | |
1223 case Tfloat32: fvalue = FLT_EPSILON; goto Lfvalue; | |
1224 case Tcomplex64: | |
1225 case Timaginary64: | |
1226 case Tfloat64: fvalue = DBL_EPSILON; goto Lfvalue; | |
1227 case Tcomplex80: | |
1228 case Timaginary80: | |
1229 case Tfloat80: fvalue = LDBL_EPSILON; goto Lfvalue; | |
1230 } | |
1231 } | |
1232 else if (ident == Id::mant_dig) | |
1233 { | |
1234 switch (ty) | |
1235 { | |
1236 case Tcomplex32: | |
1237 case Timaginary32: | |
1238 case Tfloat32: ivalue = FLT_MANT_DIG; goto Lint; | |
1239 case Tcomplex64: | |
1240 case Timaginary64: | |
1241 case Tfloat64: ivalue = DBL_MANT_DIG; goto Lint; | |
1242 case Tcomplex80: | |
1243 case Timaginary80: | |
1244 case Tfloat80: ivalue = LDBL_MANT_DIG; goto Lint; | |
1245 } | |
1246 } | |
1247 else if (ident == Id::max_10_exp) | |
1248 { | |
1249 switch (ty) | |
1250 { | |
1251 case Tcomplex32: | |
1252 case Timaginary32: | |
1253 case Tfloat32: ivalue = FLT_MAX_10_EXP; goto Lint; | |
1254 case Tcomplex64: | |
1255 case Timaginary64: | |
1256 case Tfloat64: ivalue = DBL_MAX_10_EXP; goto Lint; | |
1257 case Tcomplex80: | |
1258 case Timaginary80: | |
1259 case Tfloat80: ivalue = LDBL_MAX_10_EXP; goto Lint; | |
1260 } | |
1261 } | |
1262 else if (ident == Id::max_exp) | |
1263 { | |
1264 switch (ty) | |
1265 { | |
1266 case Tcomplex32: | |
1267 case Timaginary32: | |
1268 case Tfloat32: ivalue = FLT_MAX_EXP; goto Lint; | |
1269 case Tcomplex64: | |
1270 case Timaginary64: | |
1271 case Tfloat64: ivalue = DBL_MAX_EXP; goto Lint; | |
1272 case Tcomplex80: | |
1273 case Timaginary80: | |
1274 case Tfloat80: ivalue = LDBL_MAX_EXP; goto Lint; | |
1275 } | |
1276 } | |
1277 else if (ident == Id::min_10_exp) | |
1278 { | |
1279 switch (ty) | |
1280 { | |
1281 case Tcomplex32: | |
1282 case Timaginary32: | |
1283 case Tfloat32: ivalue = FLT_MIN_10_EXP; goto Lint; | |
1284 case Tcomplex64: | |
1285 case Timaginary64: | |
1286 case Tfloat64: ivalue = DBL_MIN_10_EXP; goto Lint; | |
1287 case Tcomplex80: | |
1288 case Timaginary80: | |
1289 case Tfloat80: ivalue = LDBL_MIN_10_EXP; goto Lint; | |
1290 } | |
1291 } | |
1292 else if (ident == Id::min_exp) | |
1293 { | |
1294 switch (ty) | |
1295 { | |
1296 case Tcomplex32: | |
1297 case Timaginary32: | |
1298 case Tfloat32: ivalue = FLT_MIN_EXP; goto Lint; | |
1299 case Tcomplex64: | |
1300 case Timaginary64: | |
1301 case Tfloat64: ivalue = DBL_MIN_EXP; goto Lint; | |
1302 case Tcomplex80: | |
1303 case Timaginary80: | |
1304 case Tfloat80: ivalue = LDBL_MIN_EXP; goto Lint; | |
1305 } | |
1306 } | |
1307 | |
1308 Ldefault: | |
1309 return Type::getProperty(loc, ident); | |
1310 | |
1311 Livalue: | |
1312 e = new IntegerExp(loc, ivalue, this); | |
1313 return e; | |
1314 | |
1315 Lfvalue: | |
1316 if (isreal() || isimaginary()) | |
1317 e = new RealExp(loc, fvalue, this); | |
1318 else | |
1319 { | |
1320 complex_t cvalue; | |
1321 | |
1322 #if __DMC__ | |
1323 //((real_t *)&cvalue)[0] = fvalue; | |
1324 //((real_t *)&cvalue)[1] = fvalue; | |
1325 cvalue = fvalue + fvalue * I; | |
1326 #else | |
1327 cvalue.re = fvalue; | |
1328 cvalue.im = fvalue; | |
1329 #endif | |
1330 //for (int i = 0; i < 20; i++) | |
1331 // printf("%02x ", ((unsigned char *)&cvalue)[i]); | |
1332 //printf("\n"); | |
1333 e = new ComplexExp(loc, cvalue, this); | |
1334 } | |
1335 return e; | |
1336 | |
1337 Lint: | |
1338 e = new IntegerExp(loc, ivalue, Type::tint32); | |
1339 return e; | |
1340 } | |
1341 | |
1342 Expression *TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
1343 { | |
1344 #if LOGDOTEXP | |
1345 printf("TypeBasic::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
1346 #endif | |
1347 Type *t; | |
1348 | |
1349 if (ident == Id::re) | |
1350 { | |
1351 switch (ty) | |
1352 { | |
1353 case Tcomplex32: t = tfloat32; goto L1; | |
1354 case Tcomplex64: t = tfloat64; goto L1; | |
1355 case Tcomplex80: t = tfloat80; goto L1; | |
1356 L1: | |
1357 e = e->castTo(sc, t); | |
1358 break; | |
1359 | |
1360 case Tfloat32: | |
1361 case Tfloat64: | |
1362 case Tfloat80: | |
1363 break; | |
1364 | |
1365 case Timaginary32: t = tfloat32; goto L2; | |
1366 case Timaginary64: t = tfloat64; goto L2; | |
1367 case Timaginary80: t = tfloat80; goto L2; | |
1368 L2: | |
1369 e = new RealExp(0, 0.0, t); | |
1370 break; | |
1371 | |
1372 default: | |
1373 return Type::getProperty(e->loc, ident); | |
1374 } | |
1375 } | |
1376 else if (ident == Id::im) | |
1377 { Type *t2; | |
1378 | |
1379 switch (ty) | |
1380 { | |
1381 case Tcomplex32: t = timaginary32; t2 = tfloat32; goto L3; | |
1382 case Tcomplex64: t = timaginary64; t2 = tfloat64; goto L3; | |
1383 case Tcomplex80: t = timaginary80; t2 = tfloat80; goto L3; | |
1384 L3: | |
1385 e = e->castTo(sc, t); | |
1386 e->type = t2; | |
1387 break; | |
1388 | |
1389 case Timaginary32: t = tfloat32; goto L4; | |
1390 case Timaginary64: t = tfloat64; goto L4; | |
1391 case Timaginary80: t = tfloat80; goto L4; | |
1392 L4: | |
1393 e->type = t; | |
1394 break; | |
1395 | |
1396 case Tfloat32: | |
1397 case Tfloat64: | |
1398 case Tfloat80: | |
1399 e = new RealExp(0, 0.0, this); | |
1400 break; | |
1401 | |
1402 default: | |
1403 return Type::getProperty(e->loc, ident); | |
1404 } | |
1405 } | |
1406 else | |
1407 { | |
1408 return Type::dotExp(sc, e, ident); | |
1409 } | |
1410 return e; | |
1411 } | |
1412 | |
1413 Expression *TypeBasic::defaultInit(Loc loc) | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1414 { dinteger_t value = 0; |
159 | 1415 |
1416 #if LOGDEFAULTINIT | |
1417 printf("TypeBasic::defaultInit() '%s'\n", toChars()); | |
1418 #endif | |
1419 switch (ty) | |
1420 { | |
591
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
585
diff
changeset
|
1421 case Tvoid: |
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
585
diff
changeset
|
1422 return new IntegerExp(loc, value, Type::tbool); |
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
585
diff
changeset
|
1423 |
159 | 1424 case Tchar: |
1425 value = 0xFF; | |
1426 break; | |
1427 | |
1428 case Twchar: | |
1429 case Tdchar: | |
1430 value = 0xFFFF; | |
1431 break; | |
1432 | |
1433 case Timaginary32: | |
1434 case Timaginary64: | |
1435 case Timaginary80: | |
1436 case Tfloat32: | |
1437 case Tfloat64: | |
1438 case Tfloat80: | |
1439 case Tcomplex32: | |
1440 case Tcomplex64: | |
1441 case Tcomplex80: | |
1442 return getProperty(loc, Id::nan); | |
1443 } | |
1444 return new IntegerExp(loc, value, this); | |
1445 } | |
1446 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
1447 int TypeBasic::isZeroInit(Loc loc) |
159 | 1448 { |
1449 switch (ty) | |
1450 { | |
1451 case Tchar: | |
1452 case Twchar: | |
1453 case Tdchar: | |
1454 case Timaginary32: | |
1455 case Timaginary64: | |
1456 case Timaginary80: | |
1457 case Tfloat32: | |
1458 case Tfloat64: | |
1459 case Tfloat80: | |
1460 case Tcomplex32: | |
1461 case Tcomplex64: | |
1462 case Tcomplex80: | |
1463 return 0; // no | |
1464 } | |
1465 return 1; // yes | |
1466 } | |
1467 | |
1468 int TypeBasic::isbit() | |
1469 { | |
1470 return (ty == Tbit); | |
1471 } | |
1472 | |
1473 int TypeBasic::isintegral() | |
1474 { | |
1475 //printf("TypeBasic::isintegral('%s') x%x\n", toChars(), flags); | |
1476 return flags & TFLAGSintegral; | |
1477 } | |
1478 | |
1479 int TypeBasic::isfloating() | |
1480 { | |
1481 return flags & TFLAGSfloating; | |
1482 } | |
1483 | |
1484 int TypeBasic::isreal() | |
1485 { | |
1486 return flags & TFLAGSreal; | |
1487 } | |
1488 | |
1489 int TypeBasic::isimaginary() | |
1490 { | |
1491 return flags & TFLAGSimaginary; | |
1492 } | |
1493 | |
1494 int TypeBasic::iscomplex() | |
1495 { | |
1496 return flags & TFLAGScomplex; | |
1497 } | |
1498 | |
1499 int TypeBasic::isunsigned() | |
1500 { | |
1501 return flags & TFLAGSunsigned; | |
1502 } | |
1503 | |
1504 int TypeBasic::isscalar() | |
1505 { | |
1506 return flags & (TFLAGSintegral | TFLAGSfloating); | |
1507 } | |
1508 | |
1509 MATCH TypeBasic::implicitConvTo(Type *to) | |
1510 { | |
1511 //printf("TypeBasic::implicitConvTo(%s) from %s\n", to->toChars(), toChars()); | |
1512 if (this == to) | |
1513 return MATCHexact; | |
1514 | |
1515 if (ty == Tvoid || to->ty == Tvoid) | |
1516 return MATCHnomatch; | |
1517 if (1 || global.params.Dversion == 1) | |
1518 { | |
1519 if (to->ty == Tbool) | |
1520 return MATCHnomatch; | |
1521 } | |
1522 else | |
1523 { | |
1524 if (ty == Tbool || to->ty == Tbool) | |
1525 return MATCHnomatch; | |
1526 } | |
1527 if (!to->isTypeBasic()) | |
1528 return MATCHnomatch; | |
1529 | |
1530 TypeBasic *tob = (TypeBasic *)to; | |
1531 if (flags & TFLAGSintegral) | |
1532 { | |
1533 // Disallow implicit conversion of integers to imaginary or complex | |
1534 if (tob->flags & (TFLAGSimaginary | TFLAGScomplex)) | |
1535 return MATCHnomatch; | |
1536 | |
1537 // If converting to integral | |
1538 if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral) | |
1539 { d_uns64 sz = size(0); | |
1540 d_uns64 tosz = tob->size(0); | |
1541 | |
1542 /* Can't convert to smaller size or, if same size, change sign | |
1543 */ | |
1544 if (sz > tosz) | |
1545 return MATCHnomatch; | |
1546 | |
1547 /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned) | |
1548 return MATCHnomatch;*/ | |
1549 } | |
1550 } | |
1551 else if (flags & TFLAGSfloating) | |
1552 { | |
1553 // Disallow implicit conversion of floating point to integer | |
1554 if (tob->flags & TFLAGSintegral) | |
1555 return MATCHnomatch; | |
1556 | |
1557 assert(tob->flags & TFLAGSfloating); | |
1558 | |
1559 // Disallow implicit conversion from complex to non-complex | |
1560 if (flags & TFLAGScomplex && !(tob->flags & TFLAGScomplex)) | |
1561 return MATCHnomatch; | |
1562 | |
1563 // Disallow implicit conversion of real or imaginary to complex | |
1564 if (flags & (TFLAGSreal | TFLAGSimaginary) && | |
1565 tob->flags & TFLAGScomplex) | |
1566 return MATCHnomatch; | |
1567 | |
1568 // Disallow implicit conversion to-from real and imaginary | |
1569 if ((flags & (TFLAGSreal | TFLAGSimaginary)) != | |
1570 (tob->flags & (TFLAGSreal | TFLAGSimaginary))) | |
1571 return MATCHnomatch; | |
1572 } | |
1573 return MATCHconvert; | |
1574 } | |
1575 | |
1576 TypeBasic *TypeBasic::isTypeBasic() | |
1577 { | |
1578 return (TypeBasic *)this; | |
1579 } | |
1580 | |
1581 /***************************** TypeArray *****************************/ | |
1582 | |
1583 TypeArray::TypeArray(TY ty, Type *next) | |
1584 : Type(ty, next) | |
1585 { | |
1586 } | |
1587 | |
1588 Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
1589 { | |
1590 Type *n = this->next->toBasetype(); // uncover any typedef's | |
1591 | |
1592 #if LOGDOTEXP | |
1593 printf("TypeArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
1594 #endif | |
1595 if (ident == Id::reverse && (n->ty == Tchar || n->ty == Twchar)) | |
1596 { | |
1597 Expression *ec; | |
1598 Expressions *arguments; | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1599 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1600 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1601 static FuncDeclaration *adReverseChar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1602 if(!adReverseChar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1603 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1604 Type* arrty = Type::tchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1605 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1606 adReverseChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseChar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1607 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1608 static FuncDeclaration *adReverseWchar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1609 if(!adReverseWchar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1610 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1611 Type* arrty = Type::twchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1612 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1613 adReverseWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseWchar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1614 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1615 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1616 if(n->ty == Twchar) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1617 ec = new VarExp(0, adReverseWchar_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1618 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1619 ec = new VarExp(0, adReverseChar_fd); |
159 | 1620 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1621 arguments = new Expressions(); | |
1622 arguments->push(e); | |
1623 e = new CallExp(e->loc, ec, arguments); | |
1624 e->type = next->arrayOf(); | |
1625 } | |
1626 else if (ident == Id::sort && (n->ty == Tchar || n->ty == Twchar)) | |
1627 { | |
1628 Expression *ec; | |
1629 Expressions *arguments; | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1630 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1631 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1632 static FuncDeclaration *adSortChar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1633 if(!adSortChar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1634 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1635 Type* arrty = Type::tchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1636 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1637 adSortChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortChar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1638 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1639 static FuncDeclaration *adSortWchar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1640 if(!adSortWchar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1641 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1642 Type* arrty = Type::twchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1643 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1644 adSortWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortWchar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1645 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1646 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1647 if(n->ty == Twchar) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1648 ec = new VarExp(0, adSortWchar_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1649 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1650 ec = new VarExp(0, adSortChar_fd); |
159 | 1651 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1652 arguments = new Expressions(); | |
1653 arguments->push(e); | |
1654 e = new CallExp(e->loc, ec, arguments); | |
1655 e->type = next->arrayOf(); | |
1656 } | |
1657 else if (ident == Id::reverse || ident == Id::dup) | |
1658 { | |
1659 Expression *ec; | |
1660 Expressions *arguments; | |
1661 int size = next->size(e->loc); | |
1662 int dup; | |
1663 | |
1664 assert(size); | |
1665 dup = (ident == Id::dup); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1666 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1667 static FuncDeclaration *adDup_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1668 if(!adDup_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1669 Arguments* args = new Arguments; |
378
d8234836b40f
Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents:
375
diff
changeset
|
1670 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1671 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1672 adDup_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adDup); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1673 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1674 static FuncDeclaration *adReverse_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1675 if(!adReverse_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1676 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1677 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
378
d8234836b40f
Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents:
375
diff
changeset
|
1678 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1679 adReverse_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adReverse); |
378
d8234836b40f
Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents:
375
diff
changeset
|
1680 } |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1681 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1682 if(dup) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1683 ec = new VarExp(0, adDup_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1684 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1685 ec = new VarExp(0, adReverse_fd); |
159 | 1686 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1687 arguments = new Expressions(); | |
1688 if (dup) | |
1689 arguments->push(getTypeInfo(sc)); | |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1690 |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1691 // LDC repaint array type to void[] |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1692 if (n->ty != Tvoid) { |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1693 e = new CastExp(e->loc, e, e->type); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1694 e->type = Type::tvoid->arrayOf(); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1695 } |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1696 arguments->push(e); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1697 |
159 | 1698 if (!dup) |
881
1c2faa8325d1
Fixed 64bit problem in mtype.c with _adReverse runtime call, fixes #161 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1699 arguments->push(new IntegerExp(0, size, Type::tsize_t)); |
159 | 1700 e = new CallExp(e->loc, ec, arguments); |
1701 e->type = next->arrayOf(); | |
1702 } | |
1703 else if (ident == Id::sort) | |
1704 { | |
1705 Expression *ec; | |
1706 Expressions *arguments; | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1707 bool isBit = (n->ty == Tbit); |
159 | 1708 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1709 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1710 static FuncDeclaration *adSort_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1711 if(!adSort_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1712 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1713 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1714 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1715 adSort_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSort"); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1716 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1717 static FuncDeclaration *adSortBit_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1718 if(!adSortBit_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1719 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1720 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1721 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1722 adSortBit_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSortBit"); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1723 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1724 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1725 if(isBit) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1726 ec = new VarExp(0, adSortBit_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1727 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1728 ec = new VarExp(0, adSort_fd); |
159 | 1729 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1730 arguments = new Expressions(); | |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1731 |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1732 // LDC repaint array type to void[] |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1733 if (n->ty != Tvoid) { |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1734 e = new CastExp(e->loc, e, e->type); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1735 e->type = Type::tvoid->arrayOf(); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1736 } |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1737 arguments->push(e); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1738 |
509
337554fd34f1
Fixed mini/missingti.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
489
diff
changeset
|
1739 if (next->ty != Tbit) |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1740 arguments->push(n->getTypeInfo(sc)); // LDC, we don't support the getInternalTypeInfo |
509
337554fd34f1
Fixed mini/missingti.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
489
diff
changeset
|
1741 // optimization arbitrarily, not yet at least... |
159 | 1742 e = new CallExp(e->loc, ec, arguments); |
1743 e->type = next->arrayOf(); | |
1744 } | |
1745 else | |
1746 { | |
1747 e = Type::dotExp(sc, e, ident); | |
1748 } | |
1749 return e; | |
1750 } | |
1751 | |
1752 | |
1753 /***************************** TypeSArray *****************************/ | |
1754 | |
1755 TypeSArray::TypeSArray(Type *t, Expression *dim) | |
1756 : TypeArray(Tsarray, t) | |
1757 { | |
1758 //printf("TypeSArray(%s)\n", dim->toChars()); | |
1759 this->dim = dim; | |
1760 } | |
1761 | |
1762 Type *TypeSArray::syntaxCopy() | |
1763 { | |
1764 Type *t = next->syntaxCopy(); | |
1765 Expression *e = dim->syntaxCopy(); | |
1766 t = new TypeSArray(t, e); | |
1767 return t; | |
1768 } | |
1769 | |
1770 d_uns64 TypeSArray::size(Loc loc) | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1771 { dinteger_t sz; |
159 | 1772 |
1773 if (!dim) | |
1774 return Type::size(loc); | |
1775 sz = dim->toInteger(); | |
1776 if (next->toBasetype()->ty == Tbit) // if array of bits | |
1777 { | |
1778 if (sz + 31 < sz) | |
1779 goto Loverflow; | |
1780 sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords | |
1781 } | |
1782 else | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1783 { dinteger_t n, n2; |
159 | 1784 |
1785 n = next->size(); | |
1786 n2 = n * sz; | |
1787 if (n && (n2 / n) != sz) | |
1788 goto Loverflow; | |
1789 sz = n2; | |
1790 } | |
1791 return sz; | |
1792 | |
1793 Loverflow: | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
1794 error(loc, "index %jd overflow for static array", sz); |
159 | 1795 return 1; |
1796 } | |
1797 | |
1798 unsigned TypeSArray::alignsize() | |
1799 { | |
1800 return next->alignsize(); | |
1801 } | |
1802 | |
1803 /************************** | |
1804 * This evaluates exp while setting length to be the number | |
1805 * of elements in the tuple t. | |
1806 */ | |
1807 Expression *semanticLength(Scope *sc, Type *t, Expression *exp) | |
1808 { | |
1809 if (t->ty == Ttuple) | |
1810 { ScopeDsymbol *sym = new ArrayScopeSymbol((TypeTuple *)t); | |
1811 sym->parent = sc->scopesym; | |
1812 sc = sc->push(sym); | |
1813 | |
1814 exp = exp->semantic(sc); | |
1815 | |
1816 sc->pop(); | |
1817 } | |
1818 else | |
1819 exp = exp->semantic(sc); | |
1820 return exp; | |
1821 } | |
1822 | |
1823 Expression *semanticLength(Scope *sc, TupleDeclaration *s, Expression *exp) | |
1824 { | |
1825 ScopeDsymbol *sym = new ArrayScopeSymbol(s); | |
1826 sym->parent = sc->scopesym; | |
1827 sc = sc->push(sym); | |
1828 | |
1829 exp = exp->semantic(sc); | |
1830 | |
1831 sc->pop(); | |
1832 return exp; | |
1833 } | |
1834 | |
1835 void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
1836 { | |
1837 //printf("TypeSArray::resolve() %s\n", toChars()); | |
1838 next->resolve(loc, sc, pe, pt, ps); | |
1839 //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt); | |
1840 if (*pe) | |
1841 { // It's really an index expression | |
1842 Expression *e; | |
1843 e = new IndexExp(loc, *pe, dim); | |
1844 *pe = e; | |
1845 } | |
1846 else if (*ps) | |
1847 { Dsymbol *s = *ps; | |
1848 TupleDeclaration *td = s->isTupleDeclaration(); | |
1849 if (td) | |
1850 { | |
1851 ScopeDsymbol *sym = new ArrayScopeSymbol(td); | |
1852 sym->parent = sc->scopesym; | |
1853 sc = sc->push(sym); | |
1854 | |
1855 dim = dim->semantic(sc); | |
1856 dim = dim->optimize(WANTvalue | WANTinterpret); | |
1857 uinteger_t d = dim->toUInteger(); | |
1858 | |
1859 sc = sc->pop(); | |
1860 | |
1861 if (d >= td->objects->dim) | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
1862 { error(loc, "tuple index %ju exceeds %u", d, td->objects->dim); |
159 | 1863 goto Ldefault; |
1864 } | |
1865 Object *o = (Object *)td->objects->data[(size_t)d]; | |
1866 if (o->dyncast() == DYNCAST_DSYMBOL) | |
1867 { | |
1868 *ps = (Dsymbol *)o; | |
1869 return; | |
1870 } | |
1871 if (o->dyncast() == DYNCAST_EXPRESSION) | |
1872 { | |
1873 *ps = NULL; | |
1874 *pe = (Expression *)o; | |
1875 return; | |
1876 } | |
1877 | |
1878 /* Create a new TupleDeclaration which | |
1879 * is a slice [d..d+1] out of the old one. | |
1880 * Do it this way because TemplateInstance::semanticTiargs() | |
1881 * can handle unresolved Objects this way. | |
1882 */ | |
1883 Objects *objects = new Objects; | |
1884 objects->setDim(1); | |
1885 objects->data[0] = o; | |
1886 | |
1887 TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects); | |
1888 *ps = tds; | |
1889 } | |
1890 else | |
1891 goto Ldefault; | |
1892 } | |
1893 else | |
1894 { | |
1895 Ldefault: | |
1896 Type::resolve(loc, sc, pe, pt, ps); | |
1897 } | |
1898 } | |
1899 | |
1900 Type *TypeSArray::semantic(Loc loc, Scope *sc) | |
1901 { | |
1902 //printf("TypeSArray::semantic() %s\n", toChars()); | |
1903 | |
1904 Type *t; | |
1905 Expression *e; | |
1906 Dsymbol *s; | |
1907 next->resolve(loc, sc, &e, &t, &s); | |
1908 if (dim && s && s->isTupleDeclaration()) | |
1909 { TupleDeclaration *sd = s->isTupleDeclaration(); | |
1910 | |
1911 dim = semanticLength(sc, sd, dim); | |
1912 dim = dim->optimize(WANTvalue | WANTinterpret); | |
1913 uinteger_t d = dim->toUInteger(); | |
1914 | |
1915 if (d >= sd->objects->dim) | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
1916 { error(loc, "tuple index %ju exceeds %u", d, sd->objects->dim); |
159 | 1917 return Type::terror; |
1918 } | |
1919 Object *o = (Object *)sd->objects->data[(size_t)d]; | |
1920 if (o->dyncast() != DYNCAST_TYPE) | |
1921 { error(loc, "%s is not a type", toChars()); | |
1922 return Type::terror; | |
1923 } | |
1924 t = (Type *)o; | |
1925 return t; | |
1926 } | |
1927 | |
1928 next = next->semantic(loc,sc); | |
1929 Type *tbn = next->toBasetype(); | |
1930 | |
1931 if (dim) | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1932 { dinteger_t n, n2; |
159 | 1933 |
1934 dim = semanticLength(sc, tbn, dim); | |
1935 | |
1936 dim = dim->optimize(WANTvalue | WANTinterpret); | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1937 if (sc && sc->parameterSpecialization && dim->op == TOKvar && |
159 | 1938 ((VarExp *)dim)->var->storage_class & STCtemplateparameter) |
1939 { | |
1940 /* It could be a template parameter N which has no value yet: | |
1941 * template Foo(T : T[N], size_t N); | |
1942 */ | |
1943 return this; | |
1944 } | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1945 dinteger_t d1 = dim->toInteger(); |
159 | 1946 dim = dim->castTo(sc, tsize_t); |
1947 dim = dim->optimize(WANTvalue); | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
1948 dinteger_t d2 = dim->toInteger(); |
159 | 1949 |
1950 if (d1 != d2) | |
1951 goto Loverflow; | |
1952 | |
1953 if (tbn->isintegral() || | |
1954 tbn->isfloating() || | |
1955 tbn->ty == Tpointer || | |
1956 tbn->ty == Tarray || | |
1957 tbn->ty == Tsarray || | |
1958 tbn->ty == Taarray || | |
1959 tbn->ty == Tclass) | |
1960 { | |
1961 /* Only do this for types that don't need to have semantic() | |
1962 * run on them for the size, since they may be forward referenced. | |
1963 */ | |
1964 n = tbn->size(loc); | |
1965 n2 = n * d2; | |
1966 if ((int)n2 < 0) | |
1967 goto Loverflow; | |
1968 if (n2 >= 0x1000000) // put a 'reasonable' limit on it | |
1969 goto Loverflow; | |
1970 if (n && n2 / n != d2) | |
1971 { | |
1972 Loverflow: | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1973 error(loc, "index %jd overflow for static array", d1); |
159 | 1974 dim = new IntegerExp(0, 1, tsize_t); |
1975 } | |
1976 } | |
1977 } | |
1978 switch (tbn->ty) | |
1979 { | |
1980 case Ttuple: | |
1981 { // Index the tuple to get the type | |
1982 assert(dim); | |
1983 TypeTuple *tt = (TypeTuple *)tbn; | |
1984 uinteger_t d = dim->toUInteger(); | |
1985 | |
1986 if (d >= tt->arguments->dim) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1987 { error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim); |
159 | 1988 return Type::terror; |
1989 } | |
1990 Argument *arg = (Argument *)tt->arguments->data[(size_t)d]; | |
1991 return arg->type; | |
1992 } | |
1993 case Tfunction: | |
1994 case Tnone: | |
1995 error(loc, "can't have array of %s", tbn->toChars()); | |
1996 tbn = next = tint32; | |
1997 break; | |
1998 } | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
1999 if (tbn->isscope()) |
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
2000 error(loc, "cannot have array of scope %s", tbn->toChars()); |
159 | 2001 return merge(); |
2002 } | |
2003 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2004 void TypeSArray::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 2005 { |
2006 buf->writeByte(mangleChar[ty]); | |
2007 if (dim) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
2008 buf->printf("%ju", dim->toInteger()); |
159 | 2009 if (next) |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2010 next->toDecoBuffer(buf, mangle); |
159 | 2011 } |
2012 | |
2013 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2014 { | |
2015 if (mod != this->mod) | |
2016 { toCBuffer3(buf, hgs, mod); | |
2017 return; | |
2018 } | |
2019 next->toCBuffer2(buf, hgs, this->mod); | |
2020 buf->printf("[%s]", dim->toChars()); | |
2021 } | |
2022 | |
2023 Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
2024 { | |
2025 #if LOGDOTEXP | |
2026 printf("TypeSArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2027 #endif | |
2028 if (ident == Id::length) | |
2029 { | |
2030 e = dim; | |
2031 } | |
2032 else if (ident == Id::ptr) | |
2033 { | |
2034 e = e->castTo(sc, next->pointerTo()); | |
2035 } | |
2036 else | |
2037 { | |
2038 e = TypeArray::dotExp(sc, e, ident); | |
2039 } | |
2040 return e; | |
2041 } | |
2042 | |
2043 int TypeSArray::isString() | |
2044 { | |
2045 TY nty = next->toBasetype()->ty; | |
2046 return nty == Tchar || nty == Twchar || nty == Tdchar; | |
2047 } | |
2048 | |
2049 unsigned TypeSArray::memalign(unsigned salign) | |
2050 { | |
2051 return next->memalign(salign); | |
2052 } | |
2053 | |
2054 MATCH TypeSArray::implicitConvTo(Type *to) | |
2055 { | |
2056 //printf("TypeSArray::implicitConvTo()\n"); | |
2057 | |
2058 // Allow implicit conversion of static array to pointer or dynamic array | |
2059 if ((IMPLICIT_ARRAY_TO_PTR && to->ty == Tpointer) && | |
2060 (to->next->ty == Tvoid || next->equals(to->next) | |
2061 /*|| to->next->isBaseOf(next)*/)) | |
2062 { | |
2063 return MATCHconvert; | |
2064 } | |
2065 if (to->ty == Tarray) | |
2066 { int offset = 0; | |
2067 | |
2068 if (next->equals(to->next) || | |
2069 (to->next->isBaseOf(next, &offset) && offset == 0) || | |
2070 to->next->ty == Tvoid) | |
2071 return MATCHconvert; | |
2072 } | |
2073 #if 0 | |
2074 if (to->ty == Tsarray) | |
2075 { | |
2076 TypeSArray *tsa = (TypeSArray *)to; | |
2077 | |
2078 if (next->equals(tsa->next) && dim->equals(tsa->dim)) | |
2079 { | |
2080 return MATCHconvert; | |
2081 } | |
2082 } | |
2083 #endif | |
2084 return Type::implicitConvTo(to); | |
2085 } | |
2086 | |
2087 Expression *TypeSArray::defaultInit(Loc loc) | |
2088 { | |
2089 #if LOGDEFAULTINIT | |
2090 printf("TypeSArray::defaultInit() '%s'\n", toChars()); | |
2091 #endif | |
2092 return next->defaultInit(loc); | |
2093 } | |
2094 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2095 int TypeSArray::isZeroInit(Loc loc) |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2096 { |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2097 return next->isZeroInit(loc); |
159 | 2098 } |
2099 | |
2100 | |
2101 Expression *TypeSArray::toExpression() | |
2102 { | |
2103 Expression *e = next->toExpression(); | |
2104 if (e) | |
2105 { Expressions *arguments = new Expressions(); | |
2106 arguments->push(dim); | |
2107 e = new ArrayExp(dim->loc, e, arguments); | |
2108 } | |
2109 return e; | |
2110 } | |
2111 | |
2112 int TypeSArray::hasPointers() | |
2113 { | |
2114 return next->hasPointers(); | |
2115 } | |
2116 | |
2117 /***************************** TypeDArray *****************************/ | |
2118 | |
2119 TypeDArray::TypeDArray(Type *t) | |
2120 : TypeArray(Tarray, t) | |
2121 { | |
2122 //printf("TypeDArray(t = %p)\n", t); | |
2123 } | |
2124 | |
2125 Type *TypeDArray::syntaxCopy() | |
2126 { | |
2127 Type *t = next->syntaxCopy(); | |
2128 if (t == next) | |
2129 t = this; | |
2130 else | |
2131 t = new TypeDArray(t); | |
2132 return t; | |
2133 } | |
2134 | |
2135 d_uns64 TypeDArray::size(Loc loc) | |
2136 { | |
2137 //printf("TypeDArray::size()\n"); | |
2138 return PTRSIZE * 2; | |
2139 } | |
2140 | |
2141 unsigned TypeDArray::alignsize() | |
2142 { | |
2143 // A DArray consists of two ptr-sized values, so align it on pointer size | |
2144 // boundary | |
2145 return PTRSIZE; | |
2146 } | |
2147 | |
2148 Type *TypeDArray::semantic(Loc loc, Scope *sc) | |
2149 { Type *tn = next; | |
2150 | |
2151 tn = next->semantic(loc,sc); | |
2152 Type *tbn = tn->toBasetype(); | |
2153 switch (tbn->ty) | |
2154 { | |
2155 case Tfunction: | |
2156 case Tnone: | |
2157 case Ttuple: | |
2158 error(loc, "can't have array of %s", tbn->toChars()); | |
2159 tn = next = tint32; | |
2160 break; | |
2161 } | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
2162 if (tn->isscope()) |
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
2163 error(loc, "cannot have array of scope %s", tn->toChars()); |
159 | 2164 if (next != tn) |
2165 //deco = NULL; // redo | |
2166 return tn->arrayOf(); | |
2167 return merge(); | |
2168 } | |
2169 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2170 void TypeDArray::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 2171 { |
2172 buf->writeByte(mangleChar[ty]); | |
2173 if (next) | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2174 next->toDecoBuffer(buf, mangle); |
159 | 2175 } |
2176 | |
2177 void TypeDArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2178 { | |
2179 if (mod != this->mod) | |
2180 { toCBuffer3(buf, hgs, mod); | |
2181 return; | |
2182 } | |
2183 next->toCBuffer2(buf, hgs, this->mod); | |
2184 buf->writestring("[]"); | |
2185 } | |
2186 | |
2187 Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
2188 { | |
2189 #if LOGDOTEXP | |
2190 printf("TypeDArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2191 #endif | |
2192 if (ident == Id::length) | |
2193 { | |
2194 if (e->op == TOKstring) | |
2195 { StringExp *se = (StringExp *)e; | |
2196 | |
2197 return new IntegerExp(se->loc, se->len, Type::tindex); | |
2198 } | |
2199 e = new ArrayLengthExp(e->loc, e); | |
2200 e->type = Type::tsize_t; | |
2201 return e; | |
2202 } | |
2203 else if (ident == Id::ptr) | |
2204 { | |
2205 e = e->castTo(sc, next->pointerTo()); | |
2206 return e; | |
2207 } | |
2208 else | |
2209 { | |
2210 e = TypeArray::dotExp(sc, e, ident); | |
2211 } | |
2212 return e; | |
2213 } | |
2214 | |
2215 int TypeDArray::isString() | |
2216 { | |
2217 TY nty = next->toBasetype()->ty; | |
2218 return nty == Tchar || nty == Twchar || nty == Tdchar; | |
2219 } | |
2220 | |
2221 MATCH TypeDArray::implicitConvTo(Type *to) | |
2222 { | |
2223 //printf("TypeDArray::implicitConvTo()\n"); | |
2224 | |
2225 // Allow implicit conversion of array to pointer | |
2226 if (IMPLICIT_ARRAY_TO_PTR && | |
2227 to->ty == Tpointer && | |
2228 (to->next->ty == Tvoid || next->equals(to->next) /*|| to->next->isBaseOf(next)*/)) | |
2229 { | |
2230 return MATCHconvert; | |
2231 } | |
2232 | |
2233 if (to->ty == Tarray) | |
2234 { int offset = 0; | |
2235 | |
2236 if ((to->next->isBaseOf(next, &offset) && offset == 0) || | |
2237 to->next->ty == Tvoid) | |
2238 return MATCHconvert; | |
2239 } | |
2240 return Type::implicitConvTo(to); | |
2241 } | |
2242 | |
2243 Expression *TypeDArray::defaultInit(Loc loc) | |
2244 { | |
2245 #if LOGDEFAULTINIT | |
2246 printf("TypeDArray::defaultInit() '%s'\n", toChars()); | |
2247 #endif | |
2248 Expression *e; | |
2249 e = new NullExp(loc); | |
2250 e->type = this; | |
2251 return e; | |
2252 } | |
2253 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2254 int TypeDArray::isZeroInit(Loc loc) |
159 | 2255 { |
2256 return 1; | |
2257 } | |
2258 | |
2259 int TypeDArray::checkBoolean() | |
2260 { | |
2261 return TRUE; | |
2262 } | |
2263 | |
2264 int TypeDArray::hasPointers() | |
2265 { | |
2266 return TRUE; | |
2267 } | |
2268 | |
2269 /***************************** TypeAArray *****************************/ | |
2270 | |
2271 TypeAArray::TypeAArray(Type *t, Type *index) | |
2272 : TypeArray(Taarray, t) | |
2273 { | |
2274 this->index = index; | |
2275 this->key = NULL; | |
2276 } | |
2277 | |
2278 Type *TypeAArray::syntaxCopy() | |
2279 { | |
2280 Type *t = next->syntaxCopy(); | |
2281 Type *ti = index->syntaxCopy(); | |
2282 if (t == next && ti == index) | |
2283 t = this; | |
2284 else | |
2285 t = new TypeAArray(t, ti); | |
2286 return t; | |
2287 } | |
2288 | |
2289 d_uns64 TypeAArray::size(Loc loc) | |
2290 { | |
2291 return PTRSIZE /* * 2*/; | |
2292 } | |
2293 | |
2294 | |
2295 Type *TypeAArray::semantic(Loc loc, Scope *sc) | |
2296 { | |
2297 //printf("TypeAArray::semantic() %s index->ty = %d\n", toChars(), index->ty); | |
2298 | |
2299 // Deal with the case where we thought the index was a type, but | |
2300 // in reality it was an expression. | |
2301 if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray) | |
2302 { | |
2303 Expression *e; | |
2304 Type *t; | |
2305 Dsymbol *s; | |
2306 | |
2307 index->resolve(loc, sc, &e, &t, &s); | |
2308 if (e) | |
2309 { // It was an expression - | |
2310 // Rewrite as a static array | |
2311 TypeSArray *tsa; | |
2312 | |
2313 tsa = new TypeSArray(next, e); | |
2314 return tsa->semantic(loc,sc); | |
2315 } | |
2316 else if (t) | |
2317 index = t; | |
2318 else | |
2319 index->error(loc, "index is not a type or an expression"); | |
2320 } | |
2321 else | |
2322 index = index->semantic(loc,sc); | |
2323 | |
2324 // Compute key type; the purpose of the key type is to | |
2325 // minimize the permutations of runtime library | |
2326 // routines as much as possible. | |
2327 key = index->toBasetype(); | |
2328 switch (key->ty) | |
2329 { | |
2330 #if 0 | |
2331 case Tint8: | |
2332 case Tuns8: | |
2333 case Tint16: | |
2334 case Tuns16: | |
2335 key = tint32; | |
2336 break; | |
2337 #endif | |
2338 | |
2339 case Tsarray: | |
2340 #if 0 | |
2341 // Convert to Tarray | |
2342 key = key->next->arrayOf(); | |
2343 #endif | |
2344 break; | |
2345 case Tbit: | |
2346 case Tbool: | |
2347 case Tfunction: | |
2348 case Tvoid: | |
2349 case Tnone: | |
2350 error(loc, "can't have associative array key of %s", key->toChars()); | |
2351 break; | |
2352 } | |
2353 next = next->semantic(loc,sc); | |
2354 switch (next->toBasetype()->ty) | |
2355 { | |
2356 case Tfunction: | |
2357 case Tnone: | |
2358 error(loc, "can't have associative array of %s", next->toChars()); | |
2359 break; | |
2360 } | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
2361 if (next->isscope()) |
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
2362 error(loc, "cannot have array of scope %s", next->toChars()); |
159 | 2363 |
2364 return merge(); | |
2365 } | |
2366 | |
336 | 2367 void TypeAArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) |
2368 { | |
2369 //printf("TypeAArray::resolve() %s\n", toChars()); | |
2370 | |
2371 // Deal with the case where we thought the index was a type, but | |
2372 // in reality it was an expression. | |
2373 if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray) | |
2374 { | |
2375 Expression *e; | |
2376 Type *t; | |
2377 Dsymbol *s; | |
2378 | |
2379 index->resolve(loc, sc, &e, &t, &s); | |
2380 if (e) | |
2381 { // It was an expression - | |
2382 // Rewrite as a static array | |
2383 | |
2384 TypeSArray *tsa = new TypeSArray(next, e); | |
2385 return tsa->resolve(loc, sc, pe, pt, ps); | |
2386 } | |
2387 else if (t) | |
2388 index = t; | |
2389 else | |
2390 index->error(loc, "index is not a type or an expression"); | |
2391 } | |
2392 Type::resolve(loc, sc, pe, pt, ps); | |
2393 } | |
2394 | |
2395 | |
159 | 2396 Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) |
2397 { | |
2398 #if LOGDOTEXP | |
2399 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2400 #endif | |
2401 if (ident == Id::length) | |
2402 { | |
2403 Expression *ec; | |
2404 Expressions *arguments; | |
2405 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2406 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2407 static FuncDeclaration *aaLen_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2408 if(!aaLen_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2409 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2410 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2411 aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2412 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2413 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2414 ec = new VarExp(0, aaLen_fd); |
159 | 2415 arguments = new Expressions(); |
2416 arguments->push(e); | |
2417 e = new CallExp(e->loc, ec, arguments); | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2418 e->type = aaLen_fd->type->next; |
159 | 2419 } |
2420 else if (ident == Id::keys) | |
2421 { | |
2422 Expression *ec; | |
2423 Expressions *arguments; | |
2424 int size = key->size(e->loc); | |
2425 | |
2426 assert(size); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2427 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2428 static FuncDeclaration *aaKeys_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2429 if(!aaKeys_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2430 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2431 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2432 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2433 aaKeys_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaKeys); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2434 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2435 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2436 ec = new VarExp(0, aaKeys_fd); |
159 | 2437 arguments = new Expressions(); |
2438 arguments->push(e); | |
2439 arguments->push(new IntegerExp(0, size, Type::tsize_t)); | |
2440 e = new CallExp(e->loc, ec, arguments); | |
2441 e->type = index->arrayOf(); | |
2442 } | |
2443 else if (ident == Id::values) | |
2444 { | |
2445 Expression *ec; | |
2446 Expressions *arguments; | |
2447 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2448 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2449 static FuncDeclaration *aaValues_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2450 if(!aaValues_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2451 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2452 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2453 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2454 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2455 aaValues_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaValues); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2456 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2457 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2458 ec = new VarExp(0, aaValues_fd); |
159 | 2459 arguments = new Expressions(); |
2460 arguments->push(e); | |
2461 size_t keysize = key->size(e->loc); | |
771
bfabbac8e705
Fixed 64bit problem with aaValues runtime calls (assumed 32bits)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
742
diff
changeset
|
2462 keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1); |
159 | 2463 arguments->push(new IntegerExp(0, keysize, Type::tsize_t)); |
2464 arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t)); | |
2465 e = new CallExp(e->loc, ec, arguments); | |
2466 e->type = next->arrayOf(); | |
2467 } | |
2468 else if (ident == Id::rehash) | |
2469 { | |
2470 Expression *ec; | |
2471 Expressions *arguments; | |
2472 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2473 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2474 static FuncDeclaration *aaRehash_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2475 if(!aaRehash_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2476 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2477 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2478 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2479 aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2480 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2481 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2482 ec = new VarExp(0, aaRehash_fd); |
159 | 2483 arguments = new Expressions(); |
2484 arguments->push(e->addressOf(sc)); | |
975
067bb8f19c36
Fix #217. getInternalTypeInfo doesn't work with LDC.
Christian Kamm <kamm incasoftware de>
parents:
938
diff
changeset
|
2485 arguments->push(key->getTypeInfo(sc)); // LDC doesn't support getInternalTypeInfo, see above |
159 | 2486 e = new CallExp(e->loc, ec, arguments); |
2487 e->type = this; | |
2488 } | |
2489 else | |
2490 { | |
2491 e = Type::dotExp(sc, e, ident); | |
2492 } | |
2493 return e; | |
2494 } | |
2495 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2496 void TypeAArray::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 2497 { |
2498 buf->writeByte(mangleChar[ty]); | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2499 index->toDecoBuffer(buf, mangle); |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2500 next->toDecoBuffer(buf, mangle); |
159 | 2501 } |
2502 | |
2503 void TypeAArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2504 { | |
2505 if (mod != this->mod) | |
2506 { toCBuffer3(buf, hgs, mod); | |
2507 return; | |
2508 } | |
2509 next->toCBuffer2(buf, hgs, this->mod); | |
2510 buf->writeByte('['); | |
2511 index->toCBuffer2(buf, hgs, 0); | |
2512 buf->writeByte(']'); | |
2513 } | |
2514 | |
2515 Expression *TypeAArray::defaultInit(Loc loc) | |
2516 { | |
2517 #if LOGDEFAULTINIT | |
2518 printf("TypeAArray::defaultInit() '%s'\n", toChars()); | |
2519 #endif | |
2520 Expression *e; | |
2521 e = new NullExp(loc); | |
2522 e->type = this; | |
2523 return e; | |
2524 } | |
2525 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2526 int TypeAArray::isZeroInit(Loc loc) |
211
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2527 { |
846
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
2528 return TRUE; |
211
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2529 } |
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2530 |
159 | 2531 int TypeAArray::checkBoolean() |
2532 { | |
2533 return TRUE; | |
2534 } | |
2535 | |
2536 int TypeAArray::hasPointers() | |
2537 { | |
2538 return TRUE; | |
2539 } | |
2540 | |
2541 /***************************** TypePointer *****************************/ | |
2542 | |
2543 TypePointer::TypePointer(Type *t) | |
2544 : Type(Tpointer, t) | |
2545 { | |
2546 } | |
2547 | |
2548 Type *TypePointer::syntaxCopy() | |
2549 { | |
2550 Type *t = next->syntaxCopy(); | |
2551 if (t == next) | |
2552 t = this; | |
2553 else | |
2554 t = new TypePointer(t); | |
2555 return t; | |
2556 } | |
2557 | |
2558 Type *TypePointer::semantic(Loc loc, Scope *sc) | |
2559 { | |
2560 //printf("TypePointer::semantic()\n"); | |
2561 Type *n = next->semantic(loc, sc); | |
2562 switch (n->toBasetype()->ty) | |
2563 { | |
2564 case Ttuple: | |
2565 error(loc, "can't have pointer to %s", n->toChars()); | |
2566 n = tint32; | |
2567 break; | |
2568 } | |
2569 if (n != next) | |
2570 deco = NULL; | |
2571 next = n; | |
2572 return merge(); | |
2573 } | |
2574 | |
2575 | |
2576 d_uns64 TypePointer::size(Loc loc) | |
2577 { | |
2578 return PTRSIZE; | |
2579 } | |
2580 | |
2581 void TypePointer::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2582 { | |
2583 //printf("TypePointer::toCBuffer2() next = %d\n", next->ty); | |
2584 if (mod != this->mod) | |
2585 { toCBuffer3(buf, hgs, mod); | |
2586 return; | |
2587 } | |
2588 next->toCBuffer2(buf, hgs, this->mod); | |
2589 if (next->ty != Tfunction) | |
2590 buf->writeByte('*'); | |
2591 } | |
2592 | |
2593 MATCH TypePointer::implicitConvTo(Type *to) | |
2594 { | |
2595 //printf("TypePointer::implicitConvTo()\n"); | |
2596 | |
2597 if (this == to) | |
2598 return MATCHexact; | |
2599 if (to->ty == Tpointer && to->next) | |
2600 { | |
2601 if (to->next->ty == Tvoid) | |
2602 return MATCHconvert; | |
2603 | |
2604 #if 0 | |
2605 if (to->next->isBaseOf(next)) | |
2606 return MATCHconvert; | |
2607 #endif | |
2608 | |
2609 if (next->ty == Tfunction && to->next->ty == Tfunction) | |
2610 { TypeFunction *tf; | |
2611 TypeFunction *tfto; | |
2612 | |
2613 tf = (TypeFunction *)(next); | |
2614 tfto = (TypeFunction *)(to->next); | |
2615 return tfto->equals(tf) ? MATCHexact : MATCHnomatch; | |
2616 } | |
2617 } | |
2618 // if (to->ty == Tvoid) | |
2619 // return MATCHconvert; | |
2620 return MATCHnomatch; | |
2621 } | |
2622 | |
2623 int TypePointer::isscalar() | |
2624 { | |
2625 return TRUE; | |
2626 } | |
2627 | |
2628 Expression *TypePointer::defaultInit(Loc loc) | |
2629 { | |
2630 #if LOGDEFAULTINIT | |
2631 printf("TypePointer::defaultInit() '%s'\n", toChars()); | |
2632 #endif | |
2633 Expression *e; | |
2634 e = new NullExp(loc); | |
2635 e->type = this; | |
2636 return e; | |
2637 } | |
2638 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2639 int TypePointer::isZeroInit(Loc loc) |
159 | 2640 { |
2641 return 1; | |
2642 } | |
2643 | |
2644 int TypePointer::hasPointers() | |
2645 { | |
2646 return TRUE; | |
2647 } | |
2648 | |
2649 | |
2650 /***************************** TypeReference *****************************/ | |
2651 | |
2652 TypeReference::TypeReference(Type *t) | |
2653 : Type(Treference, t) | |
2654 { | |
2655 if (t->ty == Tbit) | |
2656 error(0,"cannot make reference to a bit"); | |
2657 // BUG: what about references to static arrays? | |
2658 } | |
2659 | |
2660 Type *TypeReference::syntaxCopy() | |
2661 { | |
2662 Type *t = next->syntaxCopy(); | |
2663 if (t == next) | |
2664 t = this; | |
2665 else | |
2666 t = new TypeReference(t); | |
2667 return t; | |
2668 } | |
2669 | |
2670 d_uns64 TypeReference::size(Loc loc) | |
2671 { | |
2672 return PTRSIZE; | |
2673 } | |
2674 | |
2675 void TypeReference::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2676 { | |
2677 if (mod != this->mod) | |
2678 { toCBuffer3(buf, hgs, mod); | |
2679 return; | |
2680 } | |
2681 next->toCBuffer2(buf, hgs, this->mod); | |
2682 buf->writeByte('&'); | |
2683 } | |
2684 | |
2685 Expression *TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
2686 { | |
2687 #if LOGDOTEXP | |
2688 printf("TypeReference::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2689 #endif | |
2690 | |
2691 // References just forward things along | |
2692 return next->dotExp(sc, e, ident); | |
2693 } | |
2694 | |
2695 Expression *TypeReference::defaultInit(Loc loc) | |
2696 { | |
2697 #if LOGDEFAULTINIT | |
2698 printf("TypeReference::defaultInit() '%s'\n", toChars()); | |
2699 #endif | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
2700 Expression *e = new NullExp(loc); |
159 | 2701 e->type = this; |
2702 return e; | |
2703 } | |
2704 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2705 int TypeReference::isZeroInit(Loc loc) |
159 | 2706 { |
2707 return 1; | |
2708 } | |
2709 | |
2710 | |
2711 /***************************** TypeFunction *****************************/ | |
2712 | |
2713 TypeFunction::TypeFunction(Arguments *parameters, Type *treturn, int varargs, enum LINK linkage) | |
2714 : Type(Tfunction, treturn) | |
2715 { | |
2716 //if (!treturn) *(char*)0=0; | |
2717 // assert(treturn); | |
2718 this->parameters = parameters; | |
2719 this->varargs = varargs; | |
2720 this->linkage = linkage; | |
2721 this->inuse = 0; | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2722 |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2723 #if IN_LLVM |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2724 this->funcdecl = NULL; |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2725 #endif |
159 | 2726 } |
2727 | |
2728 Type *TypeFunction::syntaxCopy() | |
2729 { | |
2730 Type *treturn = next ? next->syntaxCopy() : NULL; | |
2731 Arguments *params = Argument::arraySyntaxCopy(parameters); | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
211
diff
changeset
|
2732 TypeFunction *t = new TypeFunction(params, treturn, varargs, linkage); |
159 | 2733 return t; |
2734 } | |
2735 | |
2736 /******************************* | |
2737 * Returns: | |
2738 * 0 types are distinct | |
2739 * 1 this is covariant with t | |
2740 * 2 arguments match as far as overloading goes, | |
2741 * but types are not covariant | |
2742 * 3 cannot determine covariance because of forward references | |
2743 */ | |
2744 | |
2745 int Type::covariant(Type *t) | |
2746 { | |
2747 #if 0 | |
2748 printf("Type::covariant(t = %s) %s\n", t->toChars(), toChars()); | |
2749 printf("deco = %p, %p\n", deco, t->deco); | |
2750 printf("ty = %d\n", next->ty); | |
2751 #endif | |
2752 | |
2753 int inoutmismatch = 0; | |
2754 | |
2755 if (equals(t)) | |
2756 goto Lcovariant; | |
2757 if (ty != Tfunction || t->ty != Tfunction) | |
2758 goto Ldistinct; | |
2759 | |
2760 { | |
2761 TypeFunction *t1 = (TypeFunction *)this; | |
2762 TypeFunction *t2 = (TypeFunction *)t; | |
2763 | |
2764 if (t1->varargs != t2->varargs) | |
2765 goto Ldistinct; | |
2766 | |
2767 if (t1->parameters && t2->parameters) | |
2768 { | |
2769 size_t dim = Argument::dim(t1->parameters); | |
2770 if (dim != Argument::dim(t2->parameters)) | |
2771 goto Ldistinct; | |
2772 | |
2773 for (size_t i = 0; i < dim; i++) | |
2774 { Argument *arg1 = Argument::getNth(t1->parameters, i); | |
2775 Argument *arg2 = Argument::getNth(t2->parameters, i); | |
2776 | |
2777 if (!arg1->type->equals(arg2->type)) | |
2778 goto Ldistinct; | |
2779 if (arg1->storageClass != arg2->storageClass) | |
2780 inoutmismatch = 1; | |
2781 } | |
2782 } | |
2783 else if (t1->parameters != t2->parameters) | |
2784 goto Ldistinct; | |
2785 | |
2786 // The argument lists match | |
2787 if (inoutmismatch) | |
2788 goto Lnotcovariant; | |
2789 if (t1->linkage != t2->linkage) | |
2790 goto Lnotcovariant; | |
2791 | |
2792 Type *t1n = t1->next; | |
2793 Type *t2n = t2->next; | |
2794 | |
2795 if (t1n->equals(t2n)) | |
2796 goto Lcovariant; | |
2797 if (t1n->ty != Tclass || t2n->ty != Tclass) | |
2798 goto Lnotcovariant; | |
2799 | |
2800 // If t1n is forward referenced: | |
2801 ClassDeclaration *cd = ((TypeClass *)t1n)->sym; | |
2802 if (!cd->baseClass && cd->baseclasses.dim && !cd->isInterfaceDeclaration()) | |
2803 { | |
2804 return 3; | |
2805 } | |
2806 | |
2807 if (t1n->implicitConvTo(t2n)) | |
2808 goto Lcovariant; | |
2809 goto Lnotcovariant; | |
2810 } | |
2811 | |
2812 Lcovariant: | |
2813 //printf("\tcovaraint: 1\n"); | |
2814 return 1; | |
2815 | |
2816 Ldistinct: | |
2817 //printf("\tcovaraint: 0\n"); | |
2818 return 0; | |
2819 | |
2820 Lnotcovariant: | |
2821 //printf("\tcovaraint: 2\n"); | |
2822 return 2; | |
2823 } | |
2824 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2825 void TypeFunction::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 2826 { unsigned char mc; |
2827 | |
2828 //printf("TypeFunction::toDecoBuffer() this = %p %s\n", this, toChars()); | |
2829 //static int nest; if (++nest == 50) *(char*)0=0; | |
2830 if (inuse) | |
2831 { inuse = 2; // flag error to caller | |
2832 return; | |
2833 } | |
2834 inuse++; | |
2835 switch (linkage) | |
2836 { | |
2837 case LINKd: mc = 'F'; break; | |
2838 case LINKc: mc = 'U'; break; | |
2839 case LINKwindows: mc = 'W'; break; | |
2840 case LINKpascal: mc = 'V'; break; | |
2841 case LINKcpp: mc = 'R'; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2842 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2843 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2844 case LINKintrinsic: mc = 'Q'; break; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2845 |
159 | 2846 default: |
2847 assert(0); | |
2848 } | |
2849 buf->writeByte(mc); | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2850 |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2851 // LDC: if we're not producing a mangle string, add the this |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2852 // type to prevent merging different member function |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2853 if (!mangle && funcdecl) |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2854 { |
1282
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2855 if (funcdecl->needThis()) |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2856 { |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2857 AggregateDeclaration* ad = funcdecl->isMember2(); |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2858 buf->writeByte('M'); |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2859 ad->type->toDecoBuffer(buf, false); |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2860 } |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2861 /* BUG This causes problems with delegate types |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2862 On the other hand, the llvm type for nested functions *is* different |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2863 so not doing anything here may be lead to bugs! |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2864 A sane solution would be DtoType(Dsymbol)... |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2865 if (funcdecl->isNested()) |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2866 { |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2867 buf->writeByte('M'); |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2868 if (funcdecl->toParent2() && funcdecl->toParent2()->isFuncDeclaration()) |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2869 { |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2870 FuncDeclaration* fd = funcdecl->toParent2()->isFuncDeclaration(); |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2871 fd->type->toDecoBuffer(buf, false); |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2872 } |
680b4df0ea36
Commit workaround for TypeFunction comparing issue.
Christian Kamm <kamm incasoftware de>
parents:
1257
diff
changeset
|
2873 }*/ |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2874 } |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2875 |
159 | 2876 // Write argument types |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2877 Argument::argsToDecoBuffer(buf, parameters, mangle); |
159 | 2878 //if (buf->data[buf->offset - 1] == '@') halt(); |
2879 buf->writeByte('Z' - varargs); // mark end of arg list | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
2880 next->toDecoBuffer(buf, mangle); |
159 | 2881 inuse--; |
2882 } | |
2883 | |
2884 void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) | |
2885 { | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2886 const char *p = NULL; |
159 | 2887 |
2888 if (inuse) | |
2889 { inuse = 2; // flag error to caller | |
2890 return; | |
2891 } | |
2892 inuse++; | |
2893 if (next && (!ident || ident->toHChars2() == ident->toChars())) | |
2894 next->toCBuffer2(buf, hgs, 0); | |
2895 if (hgs->ddoc != 1) | |
2896 { | |
2897 switch (linkage) | |
2898 { | |
2899 case LINKd: p = NULL; break; | |
2900 case LINKc: p = "C "; break; | |
2901 case LINKwindows: p = "Windows "; break; | |
2902 case LINKpascal: p = "Pascal "; break; | |
2903 case LINKcpp: p = "C++ "; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2904 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2905 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2906 case LINKintrinsic: p = "Intrinsic"; break; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2907 |
159 | 2908 default: |
2909 assert(0); | |
2910 } | |
2911 } | |
2912 | |
2913 if (!hgs->hdrgen && p) | |
2914 buf->writestring(p); | |
2915 if (ident) | |
2916 { buf->writeByte(' '); | |
2917 buf->writestring(ident->toHChars2()); | |
2918 } | |
2919 Argument::argsToCBuffer(buf, hgs, parameters, varargs); | |
2920 inuse--; | |
2921 } | |
2922 | |
2923 void TypeFunction::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2924 { | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
2925 const char *p = NULL; |
159 | 2926 |
2927 if (inuse) | |
2928 { inuse = 2; // flag error to caller | |
2929 return; | |
2930 } | |
2931 inuse++; | |
2932 if (next) | |
2933 next->toCBuffer2(buf, hgs, 0); | |
2934 if (hgs->ddoc != 1) | |
2935 { | |
2936 switch (linkage) | |
2937 { | |
2938 case LINKd: p = NULL; break; | |
2939 case LINKc: p = "C "; break; | |
2940 case LINKwindows: p = "Windows "; break; | |
2941 case LINKpascal: p = "Pascal "; break; | |
2942 case LINKcpp: p = "C++ "; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2943 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2944 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2945 case LINKintrinsic: p = "Intrinsic"; break; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2946 |
159 | 2947 default: |
2948 assert(0); | |
2949 } | |
2950 } | |
2951 | |
2952 if (!hgs->hdrgen && p) | |
2953 buf->writestring(p); | |
2954 buf->writestring(" function"); | |
2955 Argument::argsToCBuffer(buf, hgs, parameters, varargs); | |
2956 inuse--; | |
2957 } | |
2958 | |
2959 Type *TypeFunction::semantic(Loc loc, Scope *sc) | |
2960 { | |
2961 if (deco) // if semantic() already run | |
2962 { | |
2963 //printf("already done\n"); | |
2964 return this; | |
2965 } | |
2966 //printf("TypeFunction::semantic() this = %p\n", this); | |
2967 | |
2968 TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction)); | |
2969 memcpy(tf, this, sizeof(TypeFunction)); | |
2970 if (parameters) | |
2971 { tf->parameters = (Arguments *)parameters->copy(); | |
2972 for (size_t i = 0; i < parameters->dim; i++) | |
2973 { Argument *arg = (Argument *)parameters->data[i]; | |
2974 Argument *cpy = (Argument *)mem.malloc(sizeof(Argument)); | |
2975 memcpy(cpy, arg, sizeof(Argument)); | |
2976 tf->parameters->data[i] = (void *)cpy; | |
2977 } | |
2978 } | |
2979 | |
2980 tf->linkage = sc->linkage; | |
2981 if (!tf->next) | |
2982 { | |
2983 assert(global.errors); | |
2984 tf->next = tvoid; | |
2985 } | |
2986 tf->next = tf->next->semantic(loc,sc); | |
2987 if (tf->next->toBasetype()->ty == Tsarray) | |
2988 { error(loc, "functions cannot return static array %s", tf->next->toChars()); | |
2989 tf->next = Type::terror; | |
2990 } | |
2991 if (tf->next->toBasetype()->ty == Tfunction) | |
2992 { error(loc, "functions cannot return a function"); | |
2993 tf->next = Type::terror; | |
2994 } | |
2995 if (tf->next->toBasetype()->ty == Ttuple) | |
2996 { error(loc, "functions cannot return a tuple"); | |
2997 tf->next = Type::terror; | |
2998 } | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
2999 if (tf->next->isscope() && !(sc->flags & SCOPEctor)) |
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
3000 error(loc, "functions cannot return scope %s", tf->next->toChars()); |
159 | 3001 |
3002 if (tf->parameters) | |
3003 { size_t dim = Argument::dim(tf->parameters); | |
3004 | |
3005 for (size_t i = 0; i < dim; i++) | |
3006 { Argument *arg = Argument::getNth(tf->parameters, i); | |
3007 Type *t; | |
3008 | |
3009 tf->inuse++; | |
3010 arg->type = arg->type->semantic(loc,sc); | |
3011 if (tf->inuse == 1) tf->inuse--; | |
780
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3012 |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3013 // each function needs its own copy of a tuple arg, since |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3014 // they mustn't share arg flags like inreg, ... |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3015 if (arg->type->ty == Ttuple) { |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3016 arg->type = arg->type->syntaxCopy(); |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3017 tf->inuse++; |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3018 arg->type = arg->type->semantic(loc,sc); |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3019 if (tf->inuse == 1) tf->inuse--; |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3020 } |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
3021 |
159 | 3022 t = arg->type->toBasetype(); |
3023 | |
3024 if (arg->storageClass & (STCout | STCref | STClazy)) | |
3025 { | |
3026 if (t->ty == Tsarray) | |
3027 error(loc, "cannot have out or ref parameter of type %s", t->toChars()); | |
3028 } | |
3029 if (!(arg->storageClass & STClazy) && t->ty == Tvoid) | |
3030 error(loc, "cannot have parameter of type %s", arg->type->toChars()); | |
3031 | |
3032 if (arg->defaultArg) | |
3033 { | |
3034 arg->defaultArg = arg->defaultArg->semantic(sc); | |
3035 arg->defaultArg = resolveProperties(sc, arg->defaultArg); | |
3036 arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type); | |
3037 } | |
3038 | |
3039 /* If arg turns out to be a tuple, the number of parameters may | |
3040 * change. | |
3041 */ | |
3042 if (t->ty == Ttuple) | |
3043 { dim = Argument::dim(tf->parameters); | |
3044 i--; | |
3045 } | |
3046 } | |
3047 } | |
3048 tf->deco = tf->merge()->deco; | |
3049 | |
3050 if (tf->inuse) | |
3051 { error(loc, "recursive type"); | |
3052 tf->inuse = 0; | |
3053 return terror; | |
3054 } | |
3055 | |
3056 if (tf->varargs == 1 && tf->linkage != LINKd && Argument::dim(tf->parameters) == 0) | |
3057 error(loc, "variadic functions with non-D linkage must have at least one parameter"); | |
3058 | |
3059 /* Don't return merge(), because arg identifiers and default args | |
3060 * can be different | |
3061 * even though the types match | |
3062 */ | |
3063 return tf; | |
3064 } | |
3065 | |
3066 /******************************** | |
3067 * 'args' are being matched to function 'this' | |
3068 * Determine match level. | |
3069 * Returns: | |
3070 * MATCHxxxx | |
3071 */ | |
3072 | |
3073 int TypeFunction::callMatch(Expressions *args) | |
3074 { | |
3075 //printf("TypeFunction::callMatch()\n"); | |
3076 int match = MATCHexact; // assume exact match | |
3077 | |
3078 size_t nparams = Argument::dim(parameters); | |
3079 size_t nargs = args ? args->dim : 0; | |
3080 if (nparams == nargs) | |
3081 ; | |
3082 else if (nargs > nparams) | |
3083 { | |
3084 if (varargs == 0) | |
3085 goto Nomatch; // too many args; no match | |
3086 match = MATCHconvert; // match ... with a "conversion" match level | |
3087 } | |
3088 | |
3089 for (size_t u = 0; u < nparams; u++) | |
3090 { int m; | |
3091 Expression *arg; | |
3092 | |
3093 // BUG: what about out and ref? | |
3094 | |
3095 Argument *p = Argument::getNth(parameters, u); | |
3096 assert(p); | |
3097 if (u >= nargs) | |
3098 { | |
3099 if (p->defaultArg) | |
3100 continue; | |
3101 if (varargs == 2 && u + 1 == nparams) | |
3102 goto L1; | |
3103 goto Nomatch; // not enough arguments | |
3104 } | |
3105 arg = (Expression *)args->data[u]; | |
3106 assert(arg); | |
3107 if (p->storageClass & STClazy && p->type->ty == Tvoid && arg->type->ty != Tvoid) | |
3108 m = MATCHconvert; | |
3109 else | |
3110 m = arg->implicitConvTo(p->type); | |
3111 //printf("\tm = %d\n", m); | |
3112 if (m == MATCHnomatch) // if no match | |
3113 { | |
3114 L1: | |
3115 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
3116 { Type *tb = p->type->toBasetype(); | |
3117 TypeSArray *tsa; | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1192
diff
changeset
|
3118 dinteger_t sz; |
159 | 3119 |
3120 switch (tb->ty) | |
3121 { | |
3122 case Tsarray: | |
3123 tsa = (TypeSArray *)tb; | |
3124 sz = tsa->dim->toInteger(); | |
3125 if (sz != nargs - u) | |
3126 goto Nomatch; | |
3127 case Tarray: | |
3128 for (; u < nargs; u++) | |
3129 { | |
3130 arg = (Expression *)args->data[u]; | |
3131 assert(arg); | |
3132 #if 1 | |
3133 /* If lazy array of delegates, | |
3134 * convert arg(s) to delegate(s) | |
3135 */ | |
3136 Type *tret = p->isLazyArray(); | |
3137 if (tret) | |
3138 { | |
3139 if (tb->next->equals(arg->type)) | |
3140 { m = MATCHexact; | |
3141 } | |
3142 else | |
3143 { | |
3144 m = arg->implicitConvTo(tret); | |
3145 if (m == MATCHnomatch) | |
3146 { | |
3147 if (tret->toBasetype()->ty == Tvoid) | |
3148 m = MATCHconvert; | |
3149 } | |
3150 } | |
3151 } | |
3152 else | |
3153 m = arg->implicitConvTo(tb->next); | |
3154 #else | |
3155 m = arg->implicitConvTo(tb->next); | |
3156 #endif | |
3157 if (m == 0) | |
3158 goto Nomatch; | |
3159 if (m < match) | |
3160 match = m; | |
3161 } | |
3162 goto Ldone; | |
3163 | |
3164 case Tclass: | |
3165 // Should see if there's a constructor match? | |
3166 // Or just leave it ambiguous? | |
3167 goto Ldone; | |
3168 | |
3169 default: | |
3170 goto Nomatch; | |
3171 } | |
3172 } | |
3173 goto Nomatch; | |
3174 } | |
3175 if (m < match) | |
3176 match = m; // pick worst match | |
3177 } | |
3178 | |
3179 Ldone: | |
3180 //printf("match = %d\n", match); | |
3181 return match; | |
3182 | |
3183 Nomatch: | |
3184 //printf("no match\n"); | |
3185 return MATCHnomatch; | |
3186 } | |
3187 | |
3188 Type *TypeFunction::reliesOnTident() | |
3189 { | |
3190 if (parameters) | |
3191 { | |
3192 for (size_t i = 0; i < parameters->dim; i++) | |
3193 { Argument *arg = (Argument *)parameters->data[i]; | |
3194 Type *t = arg->type->reliesOnTident(); | |
3195 if (t) | |
3196 return t; | |
3197 } | |
3198 } | |
3199 return next->reliesOnTident(); | |
3200 } | |
3201 | |
3202 /***************************** TypeDelegate *****************************/ | |
3203 | |
3204 TypeDelegate::TypeDelegate(Type *t) | |
3205 : Type(Tfunction, t) | |
3206 { | |
3207 ty = Tdelegate; | |
3208 } | |
3209 | |
3210 Type *TypeDelegate::syntaxCopy() | |
3211 { | |
3212 Type *t = next->syntaxCopy(); | |
3213 if (t == next) | |
3214 t = this; | |
3215 else | |
3216 t = new TypeDelegate(t); | |
3217 return t; | |
3218 } | |
3219 | |
3220 Type *TypeDelegate::semantic(Loc loc, Scope *sc) | |
3221 { | |
3222 if (deco) // if semantic() already run | |
3223 { | |
3224 //printf("already done\n"); | |
3225 return this; | |
3226 } | |
3227 next = next->semantic(loc,sc); | |
3228 return merge(); | |
3229 } | |
3230 | |
3231 d_uns64 TypeDelegate::size(Loc loc) | |
3232 { | |
3233 return PTRSIZE * 2; | |
3234 } | |
3235 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3236 // LDC added, no reason to align to 2*PTRSIZE |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3237 unsigned TypeDelegate::alignsize() |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3238 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3239 // A Delegate consists of two ptr values, so align it on pointer size |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3240 // boundary |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3241 return PTRSIZE; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3242 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3243 |
159 | 3244 void TypeDelegate::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
3245 { | |
3246 if (mod != this->mod) | |
3247 { toCBuffer3(buf, hgs, mod); | |
3248 return; | |
3249 } | |
3250 TypeFunction *tf = (TypeFunction *)next; | |
3251 | |
3252 tf->next->toCBuffer2(buf, hgs, 0); | |
3253 buf->writestring(" delegate"); | |
3254 Argument::argsToCBuffer(buf, hgs, tf->parameters, tf->varargs); | |
3255 } | |
3256 | |
3257 Expression *TypeDelegate::defaultInit(Loc loc) | |
3258 { | |
3259 #if LOGDEFAULTINIT | |
3260 printf("TypeDelegate::defaultInit() '%s'\n", toChars()); | |
3261 #endif | |
3262 Expression *e; | |
3263 e = new NullExp(loc); | |
3264 e->type = this; | |
3265 return e; | |
3266 } | |
3267 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
3268 int TypeDelegate::isZeroInit(Loc loc) |
159 | 3269 { |
3270 return 1; | |
3271 } | |
3272 | |
3273 int TypeDelegate::checkBoolean() | |
3274 { | |
3275 return TRUE; | |
3276 } | |
3277 | |
3278 Expression *TypeDelegate::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
3279 { | |
3280 #if LOGDOTEXP | |
3281 printf("TypeDelegate::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
3282 #endif | |
3283 if (ident == Id::ptr) | |
3284 { | |
599
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
591
diff
changeset
|
3285 e = new GEPExp(e->loc, e, ident, 0); |
159 | 3286 e->type = tvoidptr; |
3287 return e; | |
3288 } | |
3289 else if (ident == Id::funcptr) | |
3290 { | |
599
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
591
diff
changeset
|
3291 e = new GEPExp(e->loc, e, ident, 1); |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
591
diff
changeset
|
3292 e->type = tvoidptr; |
159 | 3293 return e; |
3294 } | |
3295 else | |
3296 { | |
3297 e = Type::dotExp(sc, e, ident); | |
3298 } | |
3299 return e; | |
3300 } | |
3301 | |
3302 int TypeDelegate::hasPointers() | |
3303 { | |
3304 return TRUE; | |
3305 } | |
3306 | |
3307 | |
3308 | |
3309 /***************************** TypeQualified *****************************/ | |
3310 | |
3311 TypeQualified::TypeQualified(TY ty, Loc loc) | |
3312 : Type(ty, NULL) | |
3313 { | |
3314 this->loc = loc; | |
3315 } | |
3316 | |
3317 void TypeQualified::syntaxCopyHelper(TypeQualified *t) | |
3318 { | |
3319 //printf("TypeQualified::syntaxCopyHelper(%s) %s\n", t->toChars(), toChars()); | |
3320 idents.setDim(t->idents.dim); | |
3321 for (int i = 0; i < idents.dim; i++) | |
3322 { | |
3323 Identifier *id = (Identifier *)t->idents.data[i]; | |
3324 if (id->dyncast() == DYNCAST_DSYMBOL) | |
3325 { | |
3326 TemplateInstance *ti = (TemplateInstance *)id; | |
3327 | |
3328 ti = (TemplateInstance *)ti->syntaxCopy(NULL); | |
3329 id = (Identifier *)ti; | |
3330 } | |
3331 idents.data[i] = id; | |
3332 } | |
3333 } | |
3334 | |
3335 | |
3336 void TypeQualified::addIdent(Identifier *ident) | |
3337 { | |
3338 idents.push(ident); | |
3339 } | |
3340 | |
3341 void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs) | |
3342 { | |
3343 int i; | |
3344 | |
3345 for (i = 0; i < idents.dim; i++) | |
3346 { Identifier *id = (Identifier *)idents.data[i]; | |
3347 | |
3348 buf->writeByte('.'); | |
3349 | |
3350 if (id->dyncast() == DYNCAST_DSYMBOL) | |
3351 { | |
3352 TemplateInstance *ti = (TemplateInstance *)id; | |
3353 ti->toCBuffer(buf, hgs); | |
3354 } | |
3355 else | |
3356 buf->writestring(id->toChars()); | |
3357 } | |
3358 } | |
3359 | |
3360 d_uns64 TypeQualified::size(Loc loc) | |
3361 { | |
3362 error(this->loc, "size of type %s is not known", toChars()); | |
3363 return 1; | |
3364 } | |
3365 | |
3366 /************************************* | |
3367 * Takes an array of Identifiers and figures out if | |
3368 * it represents a Type or an Expression. | |
3369 * Output: | |
3370 * if expression, *pe is set | |
3371 * if type, *pt is set | |
3372 */ | |
3373 | |
3374 void TypeQualified::resolveHelper(Loc loc, Scope *sc, | |
3375 Dsymbol *s, Dsymbol *scopesym, | |
3376 Expression **pe, Type **pt, Dsymbol **ps) | |
3377 { | |
3378 Identifier *id = NULL; | |
3379 int i; | |
3380 VarDeclaration *v; | |
3381 EnumMember *em; | |
3382 TupleDeclaration *td; | |
3383 Type *t; | |
3384 Expression *e; | |
3385 | |
3386 #if 0 | |
3387 printf("TypeQualified::resolveHelper(sc = %p, idents = '%s')\n", sc, toChars()); | |
3388 if (scopesym) | |
3389 printf("\tscopesym = '%s'\n", scopesym->toChars()); | |
3390 #endif | |
3391 *pe = NULL; | |
3392 *pt = NULL; | |
3393 *ps = NULL; | |
3394 if (s) | |
3395 { | |
3396 //printf("\t1: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | |
336 | 3397 s->checkDeprecated(loc, sc); // check for deprecated aliases |
159 | 3398 s = s->toAlias(); |
3399 //printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | |
3400 for (i = 0; i < idents.dim; i++) | |
3401 { Dsymbol *sm; | |
3402 | |
3403 id = (Identifier *)idents.data[i]; | |
3404 sm = s->searchX(loc, sc, id); | |
3405 //printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | |
3406 //printf("getType = '%s'\n", s->getType()->toChars()); | |
3407 if (!sm) | |
3408 { | |
3409 v = s->isVarDeclaration(); | |
3410 if (v && id == Id::length) | |
3411 { | |
1499
df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
Christian Kamm <kamm incasoftware de>
parents:
1393
diff
changeset
|
3412 if (v->isSameAsInitializer() && v->getExpInitializer()) |
159 | 3413 { e = v->getExpInitializer()->exp; |
3414 } | |
3415 else | |
3416 e = new VarExp(loc, v); | |
3417 t = e->type; | |
3418 if (!t) | |
3419 goto Lerror; | |
3420 goto L3; | |
3421 } | |
3422 t = s->getType(); | |
3423 if (!t && s->isDeclaration()) | |
3424 t = s->isDeclaration()->type; | |
3425 if (t) | |
3426 { | |
3427 sm = t->toDsymbol(sc); | |
3428 if (sm) | |
3429 { sm = sm->search(loc, id, 0); | |
3430 if (sm) | |
3431 goto L2; | |
3432 } | |
3433 //e = t->getProperty(loc, id); | |
3434 e = new TypeExp(loc, t); | |
3435 e = t->dotExp(sc, e, id); | |
3436 i++; | |
3437 L3: | |
3438 for (; i < idents.dim; i++) | |
3439 { | |
3440 id = (Identifier *)idents.data[i]; | |
3441 //printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type); | |
3442 e = e->type->dotExp(sc, e, id); | |
3443 } | |
3444 *pe = e; | |
3445 } | |
3446 else | |
3447 Lerror: | |
3448 error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars()); | |
3449 return; | |
3450 } | |
3451 L2: | |
3452 s = sm->toAlias(); | |
3453 } | |
3454 | |
3455 v = s->isVarDeclaration(); | |
3456 if (v) | |
3457 { | |
3458 // It's not a type, it's an expression | |
1499
df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
Christian Kamm <kamm incasoftware de>
parents:
1393
diff
changeset
|
3459 if (v->isSameAsInitializer() && v->getExpInitializer()) |
159 | 3460 { |
3461 ExpInitializer *ei = v->getExpInitializer(); | |
3462 assert(ei); | |
3463 *pe = ei->exp->copy(); // make copy so we can change loc | |
3464 (*pe)->loc = loc; | |
3465 } | |
3466 else | |
3467 { | |
3468 #if 0 | |
3469 WithScopeSymbol *withsym; | |
3470 if (scopesym && (withsym = scopesym->isWithScopeSymbol()) != NULL) | |
3471 { | |
3472 // Same as wthis.ident | |
3473 e = new VarExp(loc, withsym->withstate->wthis); | |
3474 e = new DotIdExp(loc, e, ident); | |
3475 //assert(0); // BUG: should handle this | |
3476 } | |
3477 else | |
3478 #endif | |
3479 *pe = new VarExp(loc, v); | |
3480 } | |
3481 return; | |
3482 } | |
3483 em = s->isEnumMember(); | |
3484 if (em) | |
3485 { | |
3486 // It's not a type, it's an expression | |
3487 *pe = em->value->copy(); | |
3488 return; | |
3489 } | |
3490 | |
3491 L1: | |
3492 t = s->getType(); | |
3493 if (!t) | |
3494 { | |
3495 // If the symbol is an import, try looking inside the import | |
3496 Import *si; | |
3497 | |
3498 si = s->isImport(); | |
3499 if (si) | |
3500 { | |
3501 s = si->search(loc, s->ident, 0); | |
3502 if (s && s != si) | |
3503 goto L1; | |
3504 s = si; | |
3505 } | |
3506 *ps = s; | |
3507 return; | |
3508 } | |
3509 if (t->ty == Tinstance && t != this && !t->deco) | |
3510 { error(loc, "forward reference to '%s'", t->toChars()); | |
3511 return; | |
3512 } | |
3513 | |
3514 if (t != this) | |
3515 { | |
3516 if (t->reliesOnTident()) | |
3517 { | |
3518 Scope *scx; | |
3519 | |
3520 for (scx = sc; 1; scx = scx->enclosing) | |
3521 { | |
3522 if (!scx) | |
3523 { error(loc, "forward reference to '%s'", t->toChars()); | |
3524 return; | |
3525 } | |
3526 if (scx->scopesym == scopesym) | |
3527 break; | |
3528 } | |
3529 t = t->semantic(loc, scx); | |
3530 //((TypeIdentifier *)t)->resolve(loc, scx, pe, &t, ps); | |
3531 } | |
3532 } | |
3533 if (t->ty == Ttuple) | |
772
cd7da2ba14d1
Fix bug reported by downs. Related to delegate types within tuple template parameters.
Christian Kamm <kamm incasoftware de>
parents:
771
diff
changeset
|
3534 *pt = t; |
159 | 3535 else |
3536 *pt = t->merge(); | |
3537 } | |
3538 if (!s) | |
3539 { | |
3540 error(loc, "identifier '%s' is not defined", toChars()); | |
3541 } | |
3542 } | |
3543 | |
3544 /***************************** TypeIdentifier *****************************/ | |
3545 | |
3546 TypeIdentifier::TypeIdentifier(Loc loc, Identifier *ident) | |
3547 : TypeQualified(Tident, loc) | |
3548 { | |
3549 this->ident = ident; | |
3550 } | |
3551 | |
3552 | |
3553 Type *TypeIdentifier::syntaxCopy() | |
3554 { | |
3555 TypeIdentifier *t; | |
3556 | |
3557 t = new TypeIdentifier(loc, ident); | |
3558 t->syntaxCopyHelper(this); | |
3559 return t; | |
3560 } | |
3561 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
3562 void TypeIdentifier::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 3563 { unsigned len; |
3564 char *name; | |
3565 | |
3566 name = ident->toChars(); | |
3567 len = strlen(name); | |
3568 buf->printf("%c%d%s", mangleChar[ty], len, name); | |
3569 //buf->printf("%c%s", mangleChar[ty], name); | |
3570 } | |
3571 | |
3572 void TypeIdentifier::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3573 { | |
3574 if (mod != this->mod) | |
3575 { toCBuffer3(buf, hgs, mod); | |
3576 return; | |
3577 } | |
3578 buf->writestring(this->ident->toChars()); | |
3579 toCBuffer2Helper(buf, hgs); | |
3580 } | |
3581 | |
3582 /************************************* | |
3583 * Takes an array of Identifiers and figures out if | |
3584 * it represents a Type or an Expression. | |
3585 * Output: | |
3586 * if expression, *pe is set | |
3587 * if type, *pt is set | |
3588 */ | |
3589 | |
3590 void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
3591 { Dsymbol *s; | |
3592 Dsymbol *scopesym; | |
3593 | |
3594 //printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars()); | |
3595 s = sc->search(loc, ident, &scopesym); | |
3596 resolveHelper(loc, sc, s, scopesym, pe, pt, ps); | |
3597 } | |
3598 | |
3599 /***************************************** | |
3600 * See if type resolves to a symbol, if so, | |
3601 * return that symbol. | |
3602 */ | |
3603 | |
3604 Dsymbol *TypeIdentifier::toDsymbol(Scope *sc) | |
3605 { | |
3606 //printf("TypeIdentifier::toDsymbol('%s')\n", toChars()); | |
3607 if (!sc) | |
3608 return NULL; | |
3609 //printf("ident = '%s'\n", ident->toChars()); | |
3610 | |
3611 Dsymbol *scopesym; | |
3612 Dsymbol *s = sc->search(loc, ident, &scopesym); | |
3613 if (s) | |
3614 { | |
3615 for (int i = 0; i < idents.dim; i++) | |
3616 { | |
3617 Identifier *id = (Identifier *)idents.data[i]; | |
3618 s = s->searchX(loc, sc, id); | |
3619 if (!s) // failed to find a symbol | |
3620 { //printf("\tdidn't find a symbol\n"); | |
3621 break; | |
3622 } | |
3623 } | |
3624 } | |
3625 return s; | |
3626 } | |
3627 | |
3628 Type *TypeIdentifier::semantic(Loc loc, Scope *sc) | |
3629 { | |
3630 Type *t; | |
3631 Expression *e; | |
3632 Dsymbol *s; | |
3633 | |
3634 //printf("TypeIdentifier::semantic(%s)\n", toChars()); | |
3635 resolve(loc, sc, &e, &t, &s); | |
3636 if (t) | |
3637 { | |
3638 //printf("\tit's a type %d, %s, %s\n", t->ty, t->toChars(), t->deco); | |
3639 | |
3640 if (t->ty == Ttypedef) | |
3641 { TypeTypedef *tt = (TypeTypedef *)t; | |
3642 | |
3643 if (tt->sym->sem == 1) | |
3644 error(loc, "circular reference of typedef %s", tt->toChars()); | |
3645 } | |
3646 } | |
3647 else | |
3648 { | |
3649 #ifdef DEBUG | |
3650 if (!global.gag) | |
3651 printf("1: "); | |
3652 #endif | |
3653 if (s) | |
3654 { | |
3655 s->error(loc, "is used as a type"); | |
3656 } | |
3657 else | |
3658 error(loc, "%s is used as a type", toChars()); | |
3659 t = tvoid; | |
3660 } | |
3661 //t->print(); | |
3662 return t; | |
3663 } | |
3664 | |
3665 Type *TypeIdentifier::reliesOnTident() | |
3666 { | |
3667 return this; | |
3668 } | |
3669 | |
3670 Expression *TypeIdentifier::toExpression() | |
3671 { | |
3672 Expression *e = new IdentifierExp(loc, ident); | |
3673 for (int i = 0; i < idents.dim; i++) | |
3674 { | |
3675 Identifier *id = (Identifier *)idents.data[i]; | |
3676 e = new DotIdExp(loc, e, id); | |
3677 } | |
3678 | |
3679 return e; | |
3680 } | |
3681 | |
3682 /***************************** TypeInstance *****************************/ | |
3683 | |
3684 TypeInstance::TypeInstance(Loc loc, TemplateInstance *tempinst) | |
3685 : TypeQualified(Tinstance, loc) | |
3686 { | |
3687 this->tempinst = tempinst; | |
3688 } | |
3689 | |
3690 Type *TypeInstance::syntaxCopy() | |
3691 { | |
3692 //printf("TypeInstance::syntaxCopy() %s, %d\n", toChars(), idents.dim); | |
3693 TypeInstance *t; | |
3694 | |
3695 t = new TypeInstance(loc, (TemplateInstance *)tempinst->syntaxCopy(NULL)); | |
3696 t->syntaxCopyHelper(this); | |
3697 return t; | |
3698 } | |
3699 | |
3700 | |
3701 void TypeInstance::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3702 { | |
3703 if (mod != this->mod) | |
3704 { toCBuffer3(buf, hgs, mod); | |
3705 return; | |
3706 } | |
3707 tempinst->toCBuffer(buf, hgs); | |
3708 toCBuffer2Helper(buf, hgs); | |
3709 } | |
3710 | |
3711 void TypeInstance::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
3712 { | |
3713 // Note close similarity to TypeIdentifier::resolve() | |
3714 | |
3715 Dsymbol *s; | |
3716 | |
3717 *pe = NULL; | |
3718 *pt = NULL; | |
3719 *ps = NULL; | |
3720 | |
3721 #if 0 | |
3722 if (!idents.dim) | |
3723 { | |
3724 error(loc, "template instance '%s' has no identifier", toChars()); | |
3725 return; | |
3726 } | |
3727 #endif | |
3728 //id = (Identifier *)idents.data[0]; | |
3729 //printf("TypeInstance::resolve(sc = %p, idents = '%s')\n", sc, id->toChars()); | |
3730 s = tempinst; | |
3731 if (s) | |
3732 s->semantic(sc); | |
3733 resolveHelper(loc, sc, s, NULL, pe, pt, ps); | |
3734 //printf("pt = '%s'\n", (*pt)->toChars()); | |
3735 } | |
3736 | |
3737 Type *TypeInstance::semantic(Loc loc, Scope *sc) | |
3738 { | |
3739 Type *t; | |
3740 Expression *e; | |
3741 Dsymbol *s; | |
3742 | |
3743 //printf("TypeInstance::semantic(%s)\n", toChars()); | |
3744 | |
3745 if (sc->parameterSpecialization) | |
3746 { | |
3747 unsigned errors = global.errors; | |
3748 global.gag++; | |
3749 | |
3750 resolve(loc, sc, &e, &t, &s); | |
3751 | |
3752 global.gag--; | |
3753 if (errors != global.errors) | |
3754 { if (global.gag == 0) | |
3755 global.errors = errors; | |
3756 return this; | |
3757 } | |
3758 } | |
3759 else | |
3760 resolve(loc, sc, &e, &t, &s); | |
3761 | |
3762 if (!t) | |
3763 { | |
3764 #ifdef DEBUG | |
3765 printf("2: "); | |
3766 #endif | |
3767 error(loc, "%s is used as a type", toChars()); | |
3768 t = tvoid; | |
3769 } | |
3770 return t; | |
3771 } | |
3772 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3773 Dsymbol *TypeInstance::toDsymbol(Scope *sc) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3774 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3775 Type *t; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3776 Expression *e; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3777 Dsymbol *s; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3778 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3779 //printf("TypeInstance::semantic(%s)\n", toChars()); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3780 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3781 if (sc->parameterSpecialization) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3782 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3783 unsigned errors = global.errors; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3784 global.gag++; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3785 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3786 resolve(loc, sc, &e, &t, &s); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3787 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3788 global.gag--; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3789 if (errors != global.errors) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3790 { if (global.gag == 0) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3791 global.errors = errors; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3792 return NULL; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3793 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3794 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3795 else |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3796 resolve(loc, sc, &e, &t, &s); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3797 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3798 return s; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3799 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3800 |
159 | 3801 |
3802 /***************************** TypeTypeof *****************************/ | |
3803 | |
3804 TypeTypeof::TypeTypeof(Loc loc, Expression *exp) | |
3805 : TypeQualified(Ttypeof, loc) | |
3806 { | |
3807 this->exp = exp; | |
3808 } | |
3809 | |
3810 Type *TypeTypeof::syntaxCopy() | |
3811 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3812 //printf("TypeTypeof::syntaxCopy() %s\n", toChars()); |
159 | 3813 TypeTypeof *t; |
3814 | |
3815 t = new TypeTypeof(loc, exp->syntaxCopy()); | |
3816 t->syntaxCopyHelper(this); | |
3817 return t; | |
3818 } | |
3819 | |
3820 Dsymbol *TypeTypeof::toDsymbol(Scope *sc) | |
3821 { | |
3822 Type *t; | |
3823 | |
336 | 3824 t = semantic(loc, sc); |
159 | 3825 if (t == this) |
3826 return NULL; | |
3827 return t->toDsymbol(sc); | |
3828 } | |
3829 | |
3830 void TypeTypeof::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3831 { | |
3832 if (mod != this->mod) | |
3833 { toCBuffer3(buf, hgs, mod); | |
3834 return; | |
3835 } | |
3836 buf->writestring("typeof("); | |
3837 exp->toCBuffer(buf, hgs); | |
3838 buf->writeByte(')'); | |
3839 toCBuffer2Helper(buf, hgs); | |
3840 } | |
3841 | |
3842 Type *TypeTypeof::semantic(Loc loc, Scope *sc) | |
3843 { Expression *e; | |
3844 Type *t; | |
3845 | |
3846 //printf("TypeTypeof::semantic() %p\n", this); | |
3847 | |
3848 //static int nest; if (++nest == 50) *(char*)0=0; | |
3849 | |
3850 #if 0 | |
3851 /* Special case for typeof(this) and typeof(super) since both | |
3852 * should work even if they are not inside a non-static member function | |
3853 */ | |
3854 if (exp->op == TOKthis || exp->op == TOKsuper) | |
3855 { | |
3856 // Find enclosing struct or class | |
3857 for (Dsymbol *s = sc->parent; 1; s = s->parent) | |
3858 { | |
3859 ClassDeclaration *cd; | |
3860 StructDeclaration *sd; | |
3861 | |
3862 if (!s) | |
3863 { | |
3864 error(loc, "%s is not in a struct or class scope", exp->toChars()); | |
3865 goto Lerr; | |
3866 } | |
3867 cd = s->isClassDeclaration(); | |
3868 if (cd) | |
3869 { | |
3870 if (exp->op == TOKsuper) | |
3871 { | |
3872 cd = cd->baseClass; | |
3873 if (!cd) | |
3874 { error(loc, "class %s has no 'super'", s->toChars()); | |
3875 goto Lerr; | |
3876 } | |
3877 } | |
3878 t = cd->type; | |
3879 break; | |
3880 } | |
3881 sd = s->isStructDeclaration(); | |
3882 if (sd) | |
3883 { | |
3884 if (exp->op == TOKsuper) | |
3885 { | |
3886 error(loc, "struct %s has no 'super'", sd->toChars()); | |
3887 goto Lerr; | |
3888 } | |
3889 t = sd->type->pointerTo(); | |
3890 break; | |
3891 } | |
3892 } | |
3893 } | |
3894 else | |
3895 #endif | |
3896 { | |
3897 sc->intypeof++; | |
3898 exp = exp->semantic(sc); | |
3899 sc->intypeof--; | |
336 | 3900 if (exp->op == TOKtype) |
3901 { | |
3902 error(loc, "argument %s to typeof is not an expression", exp->toChars()); | |
3903 } | |
159 | 3904 t = exp->type; |
3905 if (!t) | |
3906 { | |
3907 error(loc, "expression (%s) has no type", exp->toChars()); | |
3908 goto Lerr; | |
3909 } | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
3910 if (t->ty == Ttypeof) |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
3911 error(loc, "forward reference to %s", toChars()); |
159 | 3912 } |
3913 | |
3914 if (idents.dim) | |
3915 { | |
3916 Dsymbol *s = t->toDsymbol(sc); | |
3917 for (size_t i = 0; i < idents.dim; i++) | |
3918 { | |
3919 if (!s) | |
3920 break; | |
3921 Identifier *id = (Identifier *)idents.data[i]; | |
3922 s = s->searchX(loc, sc, id); | |
3923 } | |
3924 if (s) | |
3925 { | |
3926 t = s->getType(); | |
3927 if (!t) | |
3928 { error(loc, "%s is not a type", s->toChars()); | |
3929 goto Lerr; | |
3930 } | |
3931 } | |
3932 else | |
3933 { error(loc, "cannot resolve .property for %s", toChars()); | |
3934 goto Lerr; | |
3935 } | |
3936 } | |
3937 return t; | |
3938 | |
3939 Lerr: | |
3940 return tvoid; | |
3941 } | |
3942 | |
3943 d_uns64 TypeTypeof::size(Loc loc) | |
3944 { | |
3945 if (exp->type) | |
3946 return exp->type->size(loc); | |
3947 else | |
3948 return TypeQualified::size(loc); | |
3949 } | |
3950 | |
3951 | |
3952 | |
3953 /***************************** TypeEnum *****************************/ | |
3954 | |
3955 TypeEnum::TypeEnum(EnumDeclaration *sym) | |
3956 : Type(Tenum, NULL) | |
3957 { | |
3958 this->sym = sym; | |
3959 } | |
3960 | |
3961 char *TypeEnum::toChars() | |
3962 { | |
3963 return sym->toChars(); | |
3964 } | |
3965 | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3966 Type *TypeEnum::syntaxCopy() |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3967 { |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3968 return this; |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3969 } |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3970 |
159 | 3971 Type *TypeEnum::semantic(Loc loc, Scope *sc) |
3972 { | |
3973 sym->semantic(sc); | |
3974 return merge(); | |
3975 } | |
3976 | |
3977 d_uns64 TypeEnum::size(Loc loc) | |
3978 { | |
3979 if (!sym->memtype) | |
3980 { | |
3981 error(loc, "enum %s is forward referenced", sym->toChars()); | |
3982 return 4; | |
3983 } | |
3984 return sym->memtype->size(loc); | |
3985 } | |
3986 | |
3987 unsigned TypeEnum::alignsize() | |
3988 { | |
3989 if (!sym->memtype) | |
3990 { | |
3991 #ifdef DEBUG | |
3992 printf("1: "); | |
3993 #endif | |
3994 error(0, "enum %s is forward referenced", sym->toChars()); | |
3995 return 4; | |
3996 } | |
3997 return sym->memtype->alignsize(); | |
3998 } | |
3999 | |
4000 Dsymbol *TypeEnum::toDsymbol(Scope *sc) | |
4001 { | |
4002 return sym; | |
4003 } | |
4004 | |
4005 Type *TypeEnum::toBasetype() | |
4006 { | |
4007 if (!sym->memtype) | |
4008 { | |
4009 #ifdef DEBUG | |
4010 printf("2: "); | |
4011 #endif | |
4012 error(sym->loc, "enum %s is forward referenced", sym->toChars()); | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4013 return terror; |
159 | 4014 } |
4015 return sym->memtype->toBasetype(); | |
4016 } | |
4017 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
4018 void TypeEnum::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 4019 { char *name; |
4020 | |
4021 name = sym->mangle(); | |
4022 // if (name[0] == '_' && name[1] == 'D') | |
4023 // name += 2; | |
4024 buf->printf("%c%s", mangleChar[ty], name); | |
4025 } | |
4026 | |
4027 void TypeEnum::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4028 { | |
4029 if (mod != this->mod) | |
4030 { toCBuffer3(buf, hgs, mod); | |
4031 return; | |
4032 } | |
4033 buf->writestring(sym->toChars()); | |
4034 } | |
4035 | |
4036 Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4037 { | |
4038 EnumMember *m; | |
4039 Dsymbol *s; | |
4040 Expression *em; | |
4041 | |
4042 #if LOGDOTEXP | |
4043 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e->toChars(), ident->toChars(), toChars()); | |
4044 #endif | |
4045 if (!sym->symtab) | |
4046 goto Lfwd; | |
4047 s = sym->symtab->lookup(ident); | |
4048 if (!s) | |
4049 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4050 if (ident == Id::max || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4051 ident == Id::min || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4052 ident == Id::init || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4053 ident == Id::stringof || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4054 !sym->memtype |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4055 ) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4056 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4057 return getProperty(e->loc, ident); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4058 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
4059 return sym->memtype->dotExp(sc, e, ident); |
159 | 4060 } |
4061 m = s->isEnumMember(); | |
4062 em = m->value->copy(); | |
4063 em->loc = e->loc; | |
4064 return em; | |
4065 | |
4066 Lfwd: | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4067 error(e->loc, "forward reference of enum %s.%s", toChars(), ident->toChars()); |
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4068 return new IntegerExp(0, 0, Type::terror); |
159 | 4069 } |
4070 | |
4071 Expression *TypeEnum::getProperty(Loc loc, Identifier *ident) | |
4072 { Expression *e; | |
4073 | |
4074 if (ident == Id::max) | |
4075 { | |
4076 if (!sym->symtab) | |
4077 goto Lfwd; | |
4078 e = new IntegerExp(0, sym->maxval, this); | |
4079 } | |
4080 else if (ident == Id::min) | |
4081 { | |
4082 if (!sym->symtab) | |
4083 goto Lfwd; | |
4084 e = new IntegerExp(0, sym->minval, this); | |
4085 } | |
4086 else if (ident == Id::init) | |
4087 { | |
4088 if (!sym->symtab) | |
4089 goto Lfwd; | |
4090 e = defaultInit(loc); | |
4091 } | |
846
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4092 else if (ident == Id::stringof) |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4093 { char *s = toChars(); |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4094 e = new StringExp(loc, s, strlen(s), 'c'); |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4095 Scope sc; |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4096 e = e->semantic(&sc); |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4097 } |
159 | 4098 else |
4099 { | |
4100 if (!sym->memtype) | |
4101 goto Lfwd; | |
4102 e = sym->memtype->getProperty(loc, ident); | |
4103 } | |
4104 return e; | |
4105 | |
4106 Lfwd: | |
4107 error(loc, "forward reference of %s.%s", toChars(), ident->toChars()); | |
4108 return new IntegerExp(0, 0, this); | |
4109 } | |
4110 | |
4111 int TypeEnum::isintegral() | |
4112 { | |
4113 return 1; | |
4114 } | |
4115 | |
4116 int TypeEnum::isfloating() | |
4117 { | |
4118 return 0; | |
4119 } | |
4120 | |
4121 int TypeEnum::isunsigned() | |
4122 { | |
4123 return sym->memtype->isunsigned(); | |
4124 } | |
4125 | |
4126 int TypeEnum::isscalar() | |
4127 { | |
4128 return 1; | |
4129 //return sym->memtype->isscalar(); | |
4130 } | |
4131 | |
4132 MATCH TypeEnum::implicitConvTo(Type *to) | |
4133 { MATCH m; | |
4134 | |
4135 //printf("TypeEnum::implicitConvTo()\n"); | |
4136 if (this->equals(to)) | |
4137 m = MATCHexact; // exact match | |
4138 else if (sym->memtype->implicitConvTo(to)) | |
4139 m = MATCHconvert; // match with conversions | |
4140 else | |
4141 m = MATCHnomatch; // no match | |
4142 return m; | |
4143 } | |
4144 | |
4145 Expression *TypeEnum::defaultInit(Loc loc) | |
4146 { | |
4147 #if LOGDEFAULTINIT | |
4148 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
4149 #endif | |
4150 // Initialize to first member of enum | |
4151 Expression *e; | |
4152 e = new IntegerExp(loc, sym->defaultval, this); | |
4153 return e; | |
4154 } | |
4155 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4156 int TypeEnum::isZeroInit(Loc loc) |
159 | 4157 { |
4158 return (sym->defaultval == 0); | |
4159 } | |
4160 | |
4161 int TypeEnum::hasPointers() | |
4162 { | |
4163 return toBasetype()->hasPointers(); | |
4164 } | |
4165 | |
4166 /***************************** TypeTypedef *****************************/ | |
4167 | |
4168 TypeTypedef::TypeTypedef(TypedefDeclaration *sym) | |
4169 : Type(Ttypedef, NULL) | |
4170 { | |
4171 this->sym = sym; | |
4172 } | |
4173 | |
4174 Type *TypeTypedef::syntaxCopy() | |
4175 { | |
4176 return this; | |
4177 } | |
4178 | |
4179 char *TypeTypedef::toChars() | |
4180 { | |
4181 return sym->toChars(); | |
4182 } | |
4183 | |
4184 Type *TypeTypedef::semantic(Loc loc, Scope *sc) | |
4185 { | |
4186 //printf("TypeTypedef::semantic(%s), sem = %d\n", toChars(), sym->sem); | |
4187 sym->semantic(sc); | |
4188 return merge(); | |
4189 } | |
4190 | |
4191 d_uns64 TypeTypedef::size(Loc loc) | |
4192 { | |
4193 return sym->basetype->size(loc); | |
4194 } | |
4195 | |
4196 unsigned TypeTypedef::alignsize() | |
4197 { | |
4198 return sym->basetype->alignsize(); | |
4199 } | |
4200 | |
4201 Dsymbol *TypeTypedef::toDsymbol(Scope *sc) | |
4202 { | |
4203 return sym; | |
4204 } | |
4205 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
4206 void TypeTypedef::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 4207 { unsigned len; |
4208 char *name; | |
4209 | |
4210 name = sym->mangle(); | |
4211 // if (name[0] == '_' && name[1] == 'D') | |
4212 // name += 2; | |
4213 //len = strlen(name); | |
4214 //buf->printf("%c%d%s", mangleChar[ty], len, name); | |
4215 buf->printf("%c%s", mangleChar[ty], name); | |
4216 } | |
4217 | |
4218 void TypeTypedef::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4219 { | |
4220 //printf("TypeTypedef::toCBuffer2() '%s'\n", sym->toChars()); | |
4221 if (mod != this->mod) | |
4222 { toCBuffer3(buf, hgs, mod); | |
4223 return; | |
4224 } | |
4225 buf->writestring(sym->toChars()); | |
4226 } | |
4227 | |
4228 Expression *TypeTypedef::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4229 { | |
4230 #if LOGDOTEXP | |
4231 printf("TypeTypedef::dotExp(e = '%s', ident = '%s') '%s'\n", e->toChars(), ident->toChars(), toChars()); | |
4232 #endif | |
4233 if (ident == Id::init) | |
4234 { | |
4235 return Type::dotExp(sc, e, ident); | |
4236 } | |
4237 return sym->basetype->dotExp(sc, e, ident); | |
4238 } | |
4239 | |
4240 Expression *TypeTypedef::getProperty(Loc loc, Identifier *ident) | |
4241 { | |
4242 if (ident == Id::init) | |
4243 { | |
4244 return Type::getProperty(loc, ident); | |
4245 } | |
4246 return sym->basetype->getProperty(loc, ident); | |
4247 } | |
4248 | |
4249 int TypeTypedef::isbit() | |
4250 { | |
4251 return sym->basetype->isbit(); | |
4252 } | |
4253 | |
4254 int TypeTypedef::isintegral() | |
4255 { | |
4256 //printf("TypeTypedef::isintegral()\n"); | |
4257 //printf("sym = '%s'\n", sym->toChars()); | |
4258 //printf("basetype = '%s'\n", sym->basetype->toChars()); | |
4259 return sym->basetype->isintegral(); | |
4260 } | |
4261 | |
4262 int TypeTypedef::isfloating() | |
4263 { | |
4264 return sym->basetype->isfloating(); | |
4265 } | |
4266 | |
4267 int TypeTypedef::isreal() | |
4268 { | |
4269 return sym->basetype->isreal(); | |
4270 } | |
4271 | |
4272 int TypeTypedef::isimaginary() | |
4273 { | |
4274 return sym->basetype->isimaginary(); | |
4275 } | |
4276 | |
4277 int TypeTypedef::iscomplex() | |
4278 { | |
4279 return sym->basetype->iscomplex(); | |
4280 } | |
4281 | |
4282 int TypeTypedef::isunsigned() | |
4283 { | |
4284 return sym->basetype->isunsigned(); | |
4285 } | |
4286 | |
4287 int TypeTypedef::isscalar() | |
4288 { | |
4289 return sym->basetype->isscalar(); | |
4290 } | |
4291 | |
4292 int TypeTypedef::checkBoolean() | |
4293 { | |
4294 return sym->basetype->checkBoolean(); | |
4295 } | |
4296 | |
4297 Type *TypeTypedef::toBasetype() | |
4298 { | |
4299 if (sym->inuse) | |
4300 { | |
4301 sym->error("circular definition"); | |
4302 sym->basetype = Type::terror; | |
4303 return Type::terror; | |
4304 } | |
4305 sym->inuse = 1; | |
4306 Type *t = sym->basetype->toBasetype(); | |
4307 sym->inuse = 0; | |
4308 return t; | |
4309 } | |
4310 | |
4311 MATCH TypeTypedef::implicitConvTo(Type *to) | |
4312 { MATCH m; | |
4313 | |
4314 //printf("TypeTypedef::implicitConvTo()\n"); | |
4315 if (this->equals(to)) | |
4316 m = MATCHexact; // exact match | |
4317 else if (sym->basetype->implicitConvTo(to)) | |
4318 m = MATCHconvert; // match with conversions | |
4319 else | |
4320 m = MATCHnomatch; // no match | |
4321 return m; | |
4322 } | |
4323 | |
4324 Expression *TypeTypedef::defaultInit(Loc loc) | |
4325 { Expression *e; | |
4326 Type *bt; | |
4327 | |
4328 #if LOGDEFAULTINIT | |
4329 printf("TypeTypedef::defaultInit() '%s'\n", toChars()); | |
4330 #endif | |
4331 if (sym->init) | |
4332 { | |
4333 //sym->init->toExpression()->print(); | |
4334 return sym->init->toExpression(); | |
4335 } | |
4336 bt = sym->basetype; | |
4337 e = bt->defaultInit(loc); | |
4338 e->type = this; | |
4339 while (bt->ty == Tsarray) | |
4340 { | |
4341 e->type = bt->next; | |
4342 bt = bt->next->toBasetype(); | |
4343 } | |
4344 return e; | |
4345 } | |
4346 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4347 int TypeTypedef::isZeroInit(Loc loc) |
159 | 4348 { |
4349 if (sym->init) | |
4350 { | |
4351 if (sym->init->isVoidInitializer()) | |
4352 return 1; // initialize voids to 0 | |
4353 Expression *e = sym->init->toExpression(); | |
4354 if (e && e->isBool(FALSE)) | |
4355 return 1; | |
4356 return 0; // assume not | |
4357 } | |
4358 if (sym->inuse) | |
4359 { | |
4360 sym->error("circular definition"); | |
4361 sym->basetype = Type::terror; | |
4362 } | |
4363 sym->inuse = 1; | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4364 int result = sym->basetype->isZeroInit(loc); |
159 | 4365 sym->inuse = 0; |
4366 return result; | |
4367 } | |
4368 | |
4369 int TypeTypedef::hasPointers() | |
4370 { | |
4371 return toBasetype()->hasPointers(); | |
4372 } | |
4373 | |
4374 /***************************** TypeStruct *****************************/ | |
4375 | |
4376 TypeStruct::TypeStruct(StructDeclaration *sym) | |
4377 : Type(Tstruct, NULL) | |
4378 { | |
4379 this->sym = sym; | |
1029
4d366a75d95f
Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
4380 |
4d366a75d95f
Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
4381 // LDC |
4d366a75d95f
Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
4382 this->unaligned = 0; |
159 | 4383 } |
4384 | |
4385 char *TypeStruct::toChars() | |
4386 { | |
4387 //printf("sym.parent: %s, deco = %s\n", sym->parent->toChars(), deco); | |
4388 TemplateInstance *ti = sym->parent->isTemplateInstance(); | |
4389 if (ti && ti->toAlias() == sym) | |
4390 return ti->toChars(); | |
4391 return sym->toChars(); | |
4392 } | |
4393 | |
4394 Type *TypeStruct::syntaxCopy() | |
4395 { | |
4396 return this; | |
4397 } | |
4398 | |
4399 Type *TypeStruct::semantic(Loc loc, Scope *sc) | |
4400 { | |
4401 //printf("TypeStruct::semantic('%s')\n", sym->toChars()); | |
4402 | |
4403 /* Cannot do semantic for sym because scope chain may not | |
4404 * be right. | |
4405 */ | |
4406 //sym->semantic(sc); | |
4407 | |
4408 return merge(); | |
4409 } | |
4410 | |
4411 d_uns64 TypeStruct::size(Loc loc) | |
4412 { | |
4413 return sym->size(loc); | |
4414 } | |
4415 | |
4416 unsigned TypeStruct::alignsize() | |
4417 { unsigned sz; | |
4418 | |
4419 sym->size(0); // give error for forward references | |
4420 sz = sym->alignsize; | |
4421 if (sz > sym->structalign) | |
4422 sz = sym->structalign; | |
4423 return sz; | |
4424 } | |
4425 | |
4426 Dsymbol *TypeStruct::toDsymbol(Scope *sc) | |
4427 { | |
4428 return sym; | |
4429 } | |
4430 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
4431 void TypeStruct::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 4432 { unsigned len; |
4433 char *name; | |
4434 | |
4435 name = sym->mangle(); | |
4436 //printf("TypeStruct::toDecoBuffer('%s') = '%s'\n", toChars(), name); | |
4437 // if (name[0] == '_' && name[1] == 'D') | |
4438 // name += 2; | |
4439 //len = strlen(name); | |
4440 //buf->printf("%c%d%s", mangleChar[ty], len, name); | |
4441 buf->printf("%c%s", mangleChar[ty], name); | |
4442 } | |
4443 | |
4444 void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4445 { | |
4446 if (mod != this->mod) | |
4447 { toCBuffer3(buf, hgs, mod); | |
4448 return; | |
4449 } | |
4450 TemplateInstance *ti = sym->parent->isTemplateInstance(); | |
4451 if (ti && ti->toAlias() == sym) | |
4452 buf->writestring(ti->toChars()); | |
4453 else | |
4454 buf->writestring(sym->toChars()); | |
4455 } | |
4456 | |
4457 Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4458 { unsigned offset; | |
4459 | |
4460 Expression *b; | |
4461 VarDeclaration *v; | |
4462 Dsymbol *s; | |
4463 DotVarExp *de; | |
4464 Declaration *d; | |
4465 | |
4466 #if LOGDOTEXP | |
4467 printf("TypeStruct::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
4468 #endif | |
4469 if (!sym->members) | |
4470 { | |
4471 error(e->loc, "struct %s is forward referenced", sym->toChars()); | |
4472 return new IntegerExp(e->loc, 0, Type::tint32); | |
4473 } | |
4474 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4475 /* If e.tupleof |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4476 */ |
159 | 4477 if (ident == Id::tupleof) |
4478 { | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4479 /* Create a TupleExp out of the fields of the struct e: |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4480 * (e.field0, e.field1, e.field2, ...) |
159 | 4481 */ |
336 | 4482 e = e->semantic(sc); // do this before turning on noaccesscheck |
159 | 4483 Expressions *exps = new Expressions; |
4484 exps->reserve(sym->fields.dim); | |
4485 for (size_t i = 0; i < sym->fields.dim; i++) | |
4486 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; | |
4487 Expression *fe = new DotVarExp(e->loc, e, v); | |
4488 exps->push(fe); | |
4489 } | |
4490 e = new TupleExp(e->loc, exps); | |
336 | 4491 sc = sc->push(); |
4492 sc->noaccesscheck = 1; | |
159 | 4493 e = e->semantic(sc); |
336 | 4494 sc->pop(); |
159 | 4495 return e; |
4496 } | |
4497 | |
4498 if (e->op == TOKdotexp) | |
4499 { DotExp *de = (DotExp *)e; | |
4500 | |
4501 if (de->e1->op == TOKimport) | |
4502 { | |
4503 ScopeExp *se = (ScopeExp *)de->e1; | |
4504 | |
4505 s = se->sds->search(e->loc, ident, 0); | |
4506 e = de->e1; | |
4507 goto L1; | |
4508 } | |
4509 } | |
4510 | |
4511 s = sym->search(e->loc, ident, 0); | |
4512 L1: | |
4513 if (!s) | |
4514 { | |
4515 //return getProperty(e->loc, ident); | |
4516 return Type::dotExp(sc, e, ident); | |
4517 } | |
336 | 4518 if (!s->isFuncDeclaration()) // because of overloading |
4519 s->checkDeprecated(e->loc, sc); | |
159 | 4520 s = s->toAlias(); |
4521 | |
4522 v = s->isVarDeclaration(); | |
1499
df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
Christian Kamm <kamm incasoftware de>
parents:
1393
diff
changeset
|
4523 if (v && v->isSameAsInitializer() && v->type->toBasetype()->ty != Tsarray) |
159 | 4524 { ExpInitializer *ei = v->getExpInitializer(); |
4525 | |
4526 if (ei) | |
4527 { e = ei->exp->copy(); // need to copy it if it's a StringExp | |
4528 e = e->semantic(sc); | |
4529 return e; | |
4530 } | |
4531 } | |
4532 | |
4533 if (s->getType()) | |
4534 { | |
4535 //return new DotTypeExp(e->loc, e, s); | |
4536 return new TypeExp(e->loc, s->getType()); | |
4537 } | |
4538 | |
4539 EnumMember *em = s->isEnumMember(); | |
4540 if (em) | |
4541 { | |
4542 assert(em->value); | |
4543 return em->value->copy(); | |
4544 } | |
4545 | |
4546 TemplateMixin *tm = s->isTemplateMixin(); | |
4547 if (tm) | |
4548 { Expression *de; | |
4549 | |
4550 de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm)); | |
4551 de->type = e->type; | |
4552 return de; | |
4553 } | |
4554 | |
4555 TemplateDeclaration *td = s->isTemplateDeclaration(); | |
4556 if (td) | |
4557 { | |
4558 e = new DotTemplateExp(e->loc, e, td); | |
4559 e->semantic(sc); | |
4560 return e; | |
4561 } | |
4562 | |
4563 TemplateInstance *ti = s->isTemplateInstance(); | |
4564 if (ti) | |
4565 { if (!ti->semanticdone) | |
4566 ti->semantic(sc); | |
4567 s = ti->inst->toAlias(); | |
4568 if (!s->isTemplateInstance()) | |
4569 goto L1; | |
4570 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); | |
4571 de->type = e->type; | |
4572 return de; | |
4573 } | |
4574 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4575 Import *timp = s->isImport(); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4576 if (timp) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4577 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4578 e = new DsymbolExp(e->loc, s); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4579 e = e->semantic(sc); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4580 return e; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4581 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4582 |
159 | 4583 d = s->isDeclaration(); |
4584 #ifdef DEBUG | |
4585 if (!d) | |
4586 printf("d = %s '%s'\n", s->kind(), s->toChars()); | |
4587 #endif | |
4588 assert(d); | |
4589 | |
4590 if (e->op == TOKtype) | |
4591 { FuncDeclaration *fd = sc->func; | |
4592 | |
4593 if (d->needThis() && fd && fd->vthis) | |
4594 { | |
4595 e = new DotVarExp(e->loc, new ThisExp(e->loc), d); | |
4596 e = e->semantic(sc); | |
4597 return e; | |
4598 } | |
4599 if (d->isTupleDeclaration()) | |
4600 { | |
4601 e = new TupleExp(e->loc, d->isTupleDeclaration()); | |
4602 e = e->semantic(sc); | |
4603 return e; | |
4604 } | |
4605 return new VarExp(e->loc, d); | |
4606 } | |
4607 | |
4608 if (d->isDataseg()) | |
4609 { | |
4610 // (e, d) | |
4611 VarExp *ve; | |
4612 | |
4613 accessCheck(e->loc, sc, e, d); | |
4614 ve = new VarExp(e->loc, d); | |
4615 e = new CommaExp(e->loc, e, ve); | |
4616 e->type = d->type; | |
4617 return e; | |
4618 } | |
4619 | |
4620 if (v) | |
4621 { | |
4622 if (v->toParent() != sym) | |
4623 sym->error(e->loc, "'%s' is not a member", v->toChars()); | |
4624 | |
4625 // *(&e + offset) | |
4626 accessCheck(e->loc, sc, e, d); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4627 #if 0 |
159 | 4628 b = new AddrExp(e->loc, e); |
4629 b->type = e->type->pointerTo(); | |
4630 b = new AddExp(e->loc, b, new IntegerExp(e->loc, v->offset, Type::tint32)); | |
4631 b->type = v->type->pointerTo(); | |
4632 e = new PtrExp(e->loc, b); | |
4633 e->type = v->type; | |
4634 return e; | |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
509
diff
changeset
|
4635 #endif |
159 | 4636 } |
4637 | |
4638 de = new DotVarExp(e->loc, e, d); | |
4639 return de->semantic(sc); | |
4640 } | |
4641 | |
4642 unsigned TypeStruct::memalign(unsigned salign) | |
4643 { | |
4644 sym->size(0); // give error for forward references | |
4645 return sym->structalign; | |
4646 } | |
4647 | |
4648 Expression *TypeStruct::defaultInit(Loc loc) | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
4649 { Declaration *d; |
159 | 4650 |
4651 #if LOGDEFAULTINIT | |
4652 printf("TypeStruct::defaultInit() '%s'\n", toChars()); | |
4653 #endif | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
4654 d = new StaticStructInitDeclaration(sym->loc, sym); |
159 | 4655 assert(d); |
4656 d->type = this; | |
4657 return new VarExp(sym->loc, d); | |
4658 } | |
4659 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
4660 int TypeStruct::isZeroInit(Loc loc) |
159 | 4661 { |
4662 return sym->zeroInit; | |
4663 } | |
4664 | |
4665 int TypeStruct::checkBoolean() | |
4666 { | |
4667 return FALSE; | |
4668 } | |
4669 | |
4670 int TypeStruct::hasPointers() | |
4671 { | |
4672 StructDeclaration *s = sym; | |
4673 | |
4674 sym->size(0); // give error for forward references | |
4675 if (s->members) | |
4676 { | |
4677 for (size_t i = 0; i < s->members->dim; i++) | |
4678 { | |
4679 Dsymbol *sm = (Dsymbol *)s->members->data[i]; | |
4680 if (sm->hasPointers()) | |
4681 return TRUE; | |
4682 } | |
4683 } | |
4684 return FALSE; | |
4685 } | |
4686 | |
4687 | |
4688 /***************************** TypeClass *****************************/ | |
4689 | |
4690 TypeClass::TypeClass(ClassDeclaration *sym) | |
4691 : Type(Tclass, NULL) | |
4692 { | |
4693 this->sym = sym; | |
4694 } | |
4695 | |
4696 char *TypeClass::toChars() | |
4697 { | |
4698 return sym->toPrettyChars(); | |
4699 } | |
4700 | |
4701 Type *TypeClass::syntaxCopy() | |
4702 { | |
4703 return this; | |
4704 } | |
4705 | |
4706 Type *TypeClass::semantic(Loc loc, Scope *sc) | |
4707 { | |
4708 //printf("TypeClass::semantic(%s)\n", sym->toChars()); | |
4709 if (sym->scope) | |
4710 sym->semantic(sym->scope); | |
4711 return merge(); | |
4712 } | |
4713 | |
4714 d_uns64 TypeClass::size(Loc loc) | |
4715 { | |
4716 return PTRSIZE; | |
4717 } | |
4718 | |
4719 Dsymbol *TypeClass::toDsymbol(Scope *sc) | |
4720 { | |
4721 return sym; | |
4722 } | |
4723 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
4724 void TypeClass::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 4725 { unsigned len; |
4726 char *name; | |
4727 | |
4728 name = sym->mangle(); | |
4729 // if (name[0] == '_' && name[1] == 'D') | |
4730 // name += 2; | |
4731 //printf("TypeClass::toDecoBuffer('%s') = '%s'\n", toChars(), name); | |
4732 //len = strlen(name); | |
4733 //buf->printf("%c%d%s", mangleChar[ty], len, name); | |
4734 buf->printf("%c%s", mangleChar[ty], name); | |
4735 } | |
4736 | |
4737 void TypeClass::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4738 { | |
4739 if (mod != this->mod) | |
4740 { toCBuffer3(buf, hgs, mod); | |
4741 return; | |
4742 } | |
4743 buf->writestring(sym->toChars()); | |
4744 } | |
4745 | |
4746 Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4747 { unsigned offset; | |
4748 | |
4749 Expression *b; | |
4750 VarDeclaration *v; | |
4751 Dsymbol *s; | |
4752 DotVarExp *de; | |
4753 Declaration *d; | |
4754 | |
4755 #if LOGDOTEXP | |
4756 printf("TypeClass::dotExp(e='%s', ident='%s')\n", e->toChars(), ident->toChars()); | |
4757 #endif | |
4758 | |
4759 if (e->op == TOKdotexp) | |
4760 { DotExp *de = (DotExp *)e; | |
4761 | |
4762 if (de->e1->op == TOKimport) | |
4763 { | |
4764 ScopeExp *se = (ScopeExp *)de->e1; | |
4765 | |
4766 s = se->sds->search(e->loc, ident, 0); | |
4767 e = de->e1; | |
4768 goto L1; | |
4769 } | |
4770 } | |
4771 | |
4772 if (ident == Id::tupleof) | |
4773 { | |
4774 /* Create a TupleExp | |
4775 */ | |
336 | 4776 e = e->semantic(sc); // do this before turning on noaccesscheck |
159 | 4777 Expressions *exps = new Expressions; |
4778 exps->reserve(sym->fields.dim); | |
4779 for (size_t i = 0; i < sym->fields.dim; i++) | |
4780 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; | |
4781 Expression *fe = new DotVarExp(e->loc, e, v); | |
4782 exps->push(fe); | |
4783 } | |
4784 e = new TupleExp(e->loc, exps); | |
336 | 4785 sc = sc->push(); |
4786 sc->noaccesscheck = 1; | |
159 | 4787 e = e->semantic(sc); |
336 | 4788 sc->pop(); |
159 | 4789 return e; |
4790 } | |
4791 | |
4792 s = sym->search(e->loc, ident, 0); | |
4793 L1: | |
4794 if (!s) | |
4795 { | |
4796 // See if it's a base class | |
4797 ClassDeclaration *cbase; | |
4798 for (cbase = sym->baseClass; cbase; cbase = cbase->baseClass) | |
4799 { | |
4800 if (cbase->ident->equals(ident)) | |
4801 { | |
4802 e = new DotTypeExp(0, e, cbase); | |
4803 return e; | |
4804 } | |
4805 } | |
4806 | |
4807 if (ident == Id::classinfo) | |
4808 { | |
4809 Type *t; | |
4810 | |
4811 assert(ClassDeclaration::classinfo); | |
4812 t = ClassDeclaration::classinfo->type; | |
4813 if (e->op == TOKtype || e->op == TOKdottype) | |
4814 { | |
4815 /* For type.classinfo, we know the classinfo | |
4816 * at compile time. | |
4817 */ | |
4818 if (!sym->vclassinfo) | |
4819 sym->vclassinfo = new ClassInfoDeclaration(sym); | |
4820 e = new VarExp(e->loc, sym->vclassinfo); | |
4821 e = e->addressOf(sc); | |
4822 e->type = t; // do this so we don't get redundant dereference | |
4823 } | |
4824 else | |
4825 { | |
4826 /* For class objects, the classinfo reference is the first | |
4827 * entry in the vtbl[] | |
4828 */ | |
4829 #if IN_LLVM | |
4830 | |
4831 Type* ct; | |
4832 if (sym->isInterfaceDeclaration()) { | |
4833 ct = t->pointerTo()->pointerTo()->pointerTo(); | |
4834 } | |
4835 else { | |
4836 ct = t->pointerTo()->pointerTo(); | |
4837 } | |
4838 | |
4839 e = e->castTo(sc, ct); | |
4840 e = new PtrExp(e->loc, e); | |
4841 e->type = ct->next; | |
4842 e = new PtrExp(e->loc, e); | |
4843 e->type = ct->next->next; | |
4844 | |
4845 if (sym->isInterfaceDeclaration()) | |
4846 { | |
4847 if (sym->isCOMinterface()) | |
4848 { /* COM interface vtbl[]s are different in that the | |
4849 * first entry is always pointer to QueryInterface(). | |
4850 * We can't get a .classinfo for it. | |
4851 */ | |
4852 error(e->loc, "no .classinfo for COM interface objects"); | |
4853 } | |
4854 /* For an interface, the first entry in the vtbl[] | |
4855 * is actually a pointer to an instance of struct Interface. | |
4856 * The first member of Interface is the .classinfo, | |
4857 * so add an extra pointer indirection. | |
4858 */ | |
4859 e = new PtrExp(e->loc, e); | |
4860 e->type = ct->next->next->next; | |
4861 } | |
336 | 4862 } |
159 | 4863 |
4864 #else | |
4865 | |
4866 e = new PtrExp(e->loc, e); | |
4867 e->type = t->pointerTo(); | |
4868 if (sym->isInterfaceDeclaration()) | |
4869 { | |
4870 if (sym->isCOMinterface()) | |
4871 { /* COM interface vtbl[]s are different in that the | |
4872 * first entry is always pointer to QueryInterface(). | |
4873 * We can't get a .classinfo for it. | |
4874 */ | |
4875 error(e->loc, "no .classinfo for COM interface objects"); | |
4876 } | |
4877 /* For an interface, the first entry in the vtbl[] | |
4878 * is actually a pointer to an instance of struct Interface. | |
4879 * The first member of Interface is the .classinfo, | |
4880 * so add an extra pointer indirection. | |
4881 */ | |
4882 e->type = e->type->pointerTo(); | |
4883 e = new PtrExp(e->loc, e); | |
4884 e->type = t->pointerTo(); | |
4885 } | |
4886 e = new PtrExp(e->loc, e, t); | |
336 | 4887 } |
4888 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
4889 #endif // !LDC |
336 | 4890 |
4891 return e; | |
4892 } | |
4893 | |
4894 if (ident == Id::__vptr) | |
4895 { /* The pointer to the vtbl[] | |
4896 * *cast(void***)e | |
4897 */ | |
4898 e = e->castTo(sc, tvoidptr->pointerTo()->pointerTo()); | |
4899 e = new PtrExp(e->loc, e); | |
4900 e = e->semantic(sc); | |
4901 return e; | |
4902 } | |
4903 | |
4904 if (ident == Id::__monitor) | |
4905 { /* The handle to the monitor (call it a void*) | |
4906 * *(cast(void**)e + 1) | |
4907 */ | |
4908 e = e->castTo(sc, tvoidptr->pointerTo()); | |
4909 e = new AddExp(e->loc, e, new IntegerExp(1)); | |
4910 e = new PtrExp(e->loc, e); | |
4911 e = e->semantic(sc); | |
159 | 4912 return e; |
4913 } | |
4914 | |
4915 if (ident == Id::typeinfo) | |
4916 { | |
4917 if (!global.params.useDeprecated) | |
4918 error(e->loc, ".typeinfo deprecated, use typeid(type)"); | |
4919 return getTypeInfo(sc); | |
4920 } | |
4921 if (ident == Id::outer && sym->vthis) | |
4922 { | |
4923 s = sym->vthis; | |
4924 } | |
4925 else | |
4926 { | |
4927 //return getProperty(e->loc, ident); | |
4928 return Type::dotExp(sc, e, ident); | |
4929 } | |
4930 } | |
336 | 4931 if (!s->isFuncDeclaration()) // because of overloading |
4932 s->checkDeprecated(e->loc, sc); | |
159 | 4933 s = s->toAlias(); |
4934 v = s->isVarDeclaration(); | |
1499
df11cdec45a2
Another shot at fixing the issues with (constant) struct literals and their addresses. See DMD2682, #218, #324.
Christian Kamm <kamm incasoftware de>
parents:
1393
diff
changeset
|
4935 if (v && v->isSameAsInitializer() && v->type->toBasetype()->ty != Tsarray) |
159 | 4936 { ExpInitializer *ei = v->getExpInitializer(); |
4937 | |
4938 if (ei) | |
4939 { e = ei->exp->copy(); // need to copy it if it's a StringExp | |
4940 e = e->semantic(sc); | |
4941 return e; | |
4942 } | |
4943 } | |
4944 | |
4945 if (s->getType()) | |
4946 { | |
4947 // if (e->op == TOKtype) | |
4948 return new TypeExp(e->loc, s->getType()); | |
4949 // return new DotTypeExp(e->loc, e, s); | |
4950 } | |
4951 | |
4952 EnumMember *em = s->isEnumMember(); | |
4953 if (em) | |
4954 { | |
4955 assert(em->value); | |
4956 return em->value->copy(); | |
4957 } | |
4958 | |
4959 TemplateMixin *tm = s->isTemplateMixin(); | |
4960 if (tm) | |
4961 { Expression *de; | |
4962 | |
4963 de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm)); | |
4964 de->type = e->type; | |
4965 return de; | |
4966 } | |
4967 | |
4968 TemplateDeclaration *td = s->isTemplateDeclaration(); | |
4969 if (td) | |
4970 { | |
4971 e = new DotTemplateExp(e->loc, e, td); | |
4972 e->semantic(sc); | |
4973 return e; | |
4974 } | |
4975 | |
4976 TemplateInstance *ti = s->isTemplateInstance(); | |
4977 if (ti) | |
4978 { if (!ti->semanticdone) | |
4979 ti->semantic(sc); | |
4980 s = ti->inst->toAlias(); | |
4981 if (!s->isTemplateInstance()) | |
4982 goto L1; | |
4983 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); | |
4984 de->type = e->type; | |
4985 return de; | |
4986 } | |
4987 | |
4988 d = s->isDeclaration(); | |
4989 if (!d) | |
4990 { | |
4991 e->error("%s.%s is not a declaration", e->toChars(), ident->toChars()); | |
4992 return new IntegerExp(e->loc, 1, Type::tint32); | |
4993 } | |
4994 | |
4995 if (e->op == TOKtype) | |
4996 { | |
4997 VarExp *ve; | |
4998 | |
4999 if (d->needThis() && (hasThis(sc) || !d->isFuncDeclaration())) | |
5000 { | |
5001 if (sc->func) | |
5002 { | |
5003 ClassDeclaration *thiscd; | |
5004 thiscd = sc->func->toParent()->isClassDeclaration(); | |
5005 | |
5006 if (thiscd) | |
5007 { | |
5008 ClassDeclaration *cd = e->type->isClassHandle(); | |
5009 | |
5010 if (cd == thiscd) | |
5011 { | |
5012 e = new ThisExp(e->loc); | |
5013 e = new DotTypeExp(e->loc, e, cd); | |
5014 de = new DotVarExp(e->loc, e, d); | |
5015 e = de->semantic(sc); | |
5016 return e; | |
5017 } | |
5018 else if ((!cd || !cd->isBaseOf(thiscd, NULL)) && | |
5019 !d->isFuncDeclaration()) | |
5020 e->error("'this' is required, but %s is not a base class of %s", e->type->toChars(), thiscd->toChars()); | |
5021 } | |
5022 } | |
5023 | |
5024 de = new DotVarExp(e->loc, new ThisExp(e->loc), d); | |
5025 e = de->semantic(sc); | |
5026 return e; | |
5027 } | |
5028 else if (d->isTupleDeclaration()) | |
5029 { | |
5030 e = new TupleExp(e->loc, d->isTupleDeclaration()); | |
5031 e = e->semantic(sc); | |
5032 return e; | |
5033 } | |
5034 else | |
5035 ve = new VarExp(e->loc, d); | |
5036 return ve; | |
5037 } | |
5038 | |
5039 if (d->isDataseg()) | |
5040 { | |
5041 // (e, d) | |
5042 VarExp *ve; | |
5043 | |
5044 accessCheck(e->loc, sc, e, d); | |
5045 ve = new VarExp(e->loc, d); | |
5046 e = new CommaExp(e->loc, e, ve); | |
5047 e->type = d->type; | |
5048 return e; | |
5049 } | |
5050 | |
5051 if (d->parent && d->toParent()->isModule()) | |
5052 { | |
5053 // (e, d) | |
5054 VarExp *ve; | |
5055 | |
5056 ve = new VarExp(e->loc, d); | |
5057 e = new CommaExp(e->loc, e, ve); | |
5058 e->type = d->type; | |
5059 return e; | |
5060 } | |
5061 | |
5062 de = new DotVarExp(e->loc, e, d); | |
5063 return de->semantic(sc); | |
5064 } | |
5065 | |
5066 ClassDeclaration *TypeClass::isClassHandle() | |
5067 { | |
5068 return sym; | |
5069 } | |
5070 | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
5071 int TypeClass::isscope() |
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
5072 { |
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1499
diff
changeset
|
5073 return sym->isscope; |
159 | 5074 } |
5075 | |
5076 int TypeClass::isBaseOf(Type *t, int *poffset) | |
5077 { | |
5078 if (t->ty == Tclass) | |
5079 { ClassDeclaration *cd; | |
5080 | |
5081 cd = ((TypeClass *)t)->sym; | |
5082 if (sym->isBaseOf(cd, poffset)) | |
5083 return 1; | |
5084 } | |
5085 return 0; | |
5086 } | |
5087 | |
5088 MATCH TypeClass::implicitConvTo(Type *to) | |
5089 { | |
5090 //printf("TypeClass::implicitConvTo('%s')\n", to->toChars()); | |
5091 if (this == to) | |
5092 return MATCHexact; | |
5093 | |
5094 ClassDeclaration *cdto = to->isClassHandle(); | |
5095 if (cdto && cdto->isBaseOf(sym, NULL)) | |
5096 { //printf("is base\n"); | |
5097 return MATCHconvert; | |
5098 } | |
5099 | |
5100 if (global.params.Dversion == 1) | |
5101 { | |
5102 // Allow conversion to (void *) | |
5103 if (to->ty == Tpointer && to->next->ty == Tvoid) | |
5104 return MATCHconvert; | |
5105 } | |
5106 | |
5107 return MATCHnomatch; | |
5108 } | |
5109 | |
5110 Expression *TypeClass::defaultInit(Loc loc) | |
5111 { | |
5112 #if LOGDEFAULTINIT | |
5113 printf("TypeClass::defaultInit() '%s'\n", toChars()); | |
5114 #endif | |
5115 Expression *e; | |
5116 e = new NullExp(loc); | |
5117 e->type = this; | |
5118 return e; | |
5119 } | |
5120 | |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1282
diff
changeset
|
5121 int TypeClass::isZeroInit(Loc loc) |
159 | 5122 { |
5123 return 1; | |
5124 } | |
5125 | |
5126 int TypeClass::checkBoolean() | |
5127 { | |
5128 return TRUE; | |
5129 } | |
5130 | |
5131 int TypeClass::hasPointers() | |
5132 { | |
5133 return TRUE; | |
5134 } | |
5135 | |
5136 /***************************** TypeTuple *****************************/ | |
5137 | |
5138 TypeTuple::TypeTuple(Arguments *arguments) | |
5139 : Type(Ttuple, NULL) | |
5140 { | |
5141 //printf("TypeTuple(this = %p)\n", this); | |
5142 this->arguments = arguments; | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5143 //printf("TypeTuple() %s\n", toChars()); |
159 | 5144 #ifdef DEBUG |
5145 if (arguments) | |
5146 { | |
5147 for (size_t i = 0; i < arguments->dim; i++) | |
5148 { | |
5149 Argument *arg = (Argument *)arguments->data[i]; | |
5150 assert(arg && arg->type); | |
5151 } | |
5152 } | |
5153 #endif | |
5154 } | |
5155 | |
5156 /**************** | |
5157 * Form TypeTuple from the types of the expressions. | |
5158 * Assume exps[] is already tuple expanded. | |
5159 */ | |
5160 | |
5161 TypeTuple::TypeTuple(Expressions *exps) | |
5162 : Type(Ttuple, NULL) | |
5163 { | |
5164 Arguments *arguments = new Arguments; | |
5165 if (exps) | |
5166 { | |
5167 arguments->setDim(exps->dim); | |
5168 for (size_t i = 0; i < exps->dim; i++) | |
5169 { Expression *e = (Expression *)exps->data[i]; | |
5170 if (e->type->ty == Ttuple) | |
5171 e->error("cannot form tuple of tuples"); | |
5172 Argument *arg = new Argument(STCin, e->type, NULL, NULL); | |
5173 arguments->data[i] = (void *)arg; | |
5174 } | |
5175 } | |
5176 this->arguments = arguments; | |
5177 } | |
5178 | |
5179 Type *TypeTuple::syntaxCopy() | |
5180 { | |
5181 Arguments *args = Argument::arraySyntaxCopy(arguments); | |
5182 Type *t = new TypeTuple(args); | |
5183 return t; | |
5184 } | |
5185 | |
5186 Type *TypeTuple::semantic(Loc loc, Scope *sc) | |
5187 { | |
5188 //printf("TypeTuple::semantic(this = %p)\n", this); | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5189 //printf("TypeTuple::semantic() %s\n", toChars()); |
159 | 5190 if (!deco) |
5191 deco = merge()->deco; | |
5192 | |
5193 /* Don't return merge(), because a tuple with one type has the | |
5194 * same deco as that type. | |
5195 */ | |
5196 return this; | |
5197 } | |
5198 | |
5199 int TypeTuple::equals(Object *o) | |
5200 { Type *t; | |
5201 | |
5202 t = (Type *)o; | |
5203 //printf("TypeTuple::equals(%s, %s)\n", toChars(), t->toChars()); | |
5204 if (this == t) | |
5205 { | |
5206 return 1; | |
5207 } | |
5208 if (t->ty == Ttuple) | |
5209 { TypeTuple *tt = (TypeTuple *)t; | |
5210 | |
5211 if (arguments->dim == tt->arguments->dim) | |
5212 { | |
5213 for (size_t i = 0; i < tt->arguments->dim; i++) | |
5214 { Argument *arg1 = (Argument *)arguments->data[i]; | |
5215 Argument *arg2 = (Argument *)tt->arguments->data[i]; | |
5216 | |
5217 if (!arg1->type->equals(arg2->type)) | |
5218 return 0; | |
5219 } | |
5220 return 1; | |
5221 } | |
5222 } | |
5223 return 0; | |
5224 } | |
5225 | |
5226 Type *TypeTuple::reliesOnTident() | |
5227 { | |
5228 if (arguments) | |
5229 { | |
5230 for (size_t i = 0; i < arguments->dim; i++) | |
5231 { | |
5232 Argument *arg = (Argument *)arguments->data[i]; | |
5233 Type *t = arg->type->reliesOnTident(); | |
5234 if (t) | |
5235 return t; | |
5236 } | |
5237 } | |
5238 return NULL; | |
5239 } | |
5240 | |
5241 void TypeTuple::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
5242 { | |
5243 Argument::argsToCBuffer(buf, hgs, arguments, 0); | |
5244 } | |
5245 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
5246 void TypeTuple::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 5247 { |
5248 //printf("TypeTuple::toDecoBuffer() this = %p\n", this); | |
5249 OutBuffer buf2; | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
5250 Argument::argsToDecoBuffer(&buf2, arguments, mangle); |
159 | 5251 unsigned len = buf2.offset; |
5252 buf->printf("%c%d%.*s", mangleChar[ty], len, len, (char *)buf2.extractData()); | |
5253 } | |
5254 | |
5255 Expression *TypeTuple::getProperty(Loc loc, Identifier *ident) | |
5256 { Expression *e; | |
5257 | |
5258 #if LOGDOTEXP | |
5259 printf("TypeTuple::getProperty(type = '%s', ident = '%s')\n", toChars(), ident->toChars()); | |
5260 #endif | |
5261 if (ident == Id::length) | |
5262 { | |
5263 e = new IntegerExp(loc, arguments->dim, Type::tsize_t); | |
5264 } | |
5265 else | |
5266 { | |
5267 error(loc, "no property '%s' for tuple '%s'", ident->toChars(), toChars()); | |
5268 e = new IntegerExp(loc, 1, Type::tint32); | |
5269 } | |
5270 return e; | |
5271 } | |
5272 | |
5273 /***************************** TypeSlice *****************************/ | |
5274 | |
5275 /* This is so we can slice a TypeTuple */ | |
5276 | |
5277 TypeSlice::TypeSlice(Type *next, Expression *lwr, Expression *upr) | |
5278 : Type(Tslice, next) | |
5279 { | |
5280 //printf("TypeSlice[%s .. %s]\n", lwr->toChars(), upr->toChars()); | |
5281 this->lwr = lwr; | |
5282 this->upr = upr; | |
5283 } | |
5284 | |
5285 Type *TypeSlice::syntaxCopy() | |
5286 { | |
5287 Type *t = new TypeSlice(next->syntaxCopy(), lwr->syntaxCopy(), upr->syntaxCopy()); | |
5288 return t; | |
5289 } | |
5290 | |
5291 Type *TypeSlice::semantic(Loc loc, Scope *sc) | |
5292 { | |
5293 //printf("TypeSlice::semantic() %s\n", toChars()); | |
5294 next = next->semantic(loc, sc); | |
5295 //printf("next: %s\n", next->toChars()); | |
5296 | |
5297 Type *tbn = next->toBasetype(); | |
5298 if (tbn->ty != Ttuple) | |
5299 { error(loc, "can only slice tuple types, not %s", tbn->toChars()); | |
5300 return Type::terror; | |
5301 } | |
5302 TypeTuple *tt = (TypeTuple *)tbn; | |
5303 | |
5304 lwr = semanticLength(sc, tbn, lwr); | |
5305 lwr = lwr->optimize(WANTvalue); | |
5306 uinteger_t i1 = lwr->toUInteger(); | |
5307 | |
5308 upr = semanticLength(sc, tbn, upr); | |
5309 upr = upr->optimize(WANTvalue); | |
5310 uinteger_t i2 = upr->toUInteger(); | |
5311 | |
5312 if (!(i1 <= i2 && i2 <= tt->arguments->dim)) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5313 { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, tt->arguments->dim); |
159 | 5314 return Type::terror; |
5315 } | |
5316 | |
5317 Arguments *args = new Arguments; | |
5318 args->reserve(i2 - i1); | |
5319 for (size_t i = i1; i < i2; i++) | |
5320 { Argument *arg = (Argument *)tt->arguments->data[i]; | |
5321 args->push(arg); | |
5322 } | |
5323 | |
5324 return new TypeTuple(args); | |
5325 } | |
5326 | |
5327 void TypeSlice::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
5328 { | |
5329 next->resolve(loc, sc, pe, pt, ps); | |
5330 if (*pe) | |
5331 { // It's really a slice expression | |
5332 Expression *e; | |
5333 e = new SliceExp(loc, *pe, lwr, upr); | |
5334 *pe = e; | |
5335 } | |
5336 else if (*ps) | |
5337 { Dsymbol *s = *ps; | |
5338 TupleDeclaration *td = s->isTupleDeclaration(); | |
5339 if (td) | |
5340 { | |
5341 /* It's a slice of a TupleDeclaration | |
5342 */ | |
5343 ScopeDsymbol *sym = new ArrayScopeSymbol(td); | |
5344 sym->parent = sc->scopesym; | |
5345 sc = sc->push(sym); | |
5346 | |
5347 lwr = lwr->semantic(sc); | |
5348 lwr = lwr->optimize(WANTvalue); | |
5349 uinteger_t i1 = lwr->toUInteger(); | |
5350 | |
5351 upr = upr->semantic(sc); | |
5352 upr = upr->optimize(WANTvalue); | |
5353 uinteger_t i2 = upr->toUInteger(); | |
5354 | |
5355 sc = sc->pop(); | |
5356 | |
5357 if (!(i1 <= i2 && i2 <= td->objects->dim)) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5358 { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, td->objects->dim); |
159 | 5359 goto Ldefault; |
5360 } | |
5361 | |
5362 if (i1 == 0 && i2 == td->objects->dim) | |
5363 { | |
5364 *ps = td; | |
5365 return; | |
5366 } | |
5367 | |
5368 /* Create a new TupleDeclaration which | |
5369 * is a slice [i1..i2] out of the old one. | |
5370 */ | |
5371 Objects *objects = new Objects; | |
5372 objects->setDim(i2 - i1); | |
5373 for (size_t i = 0; i < objects->dim; i++) | |
5374 { | |
5375 objects->data[i] = td->objects->data[(size_t)i1 + i]; | |
5376 } | |
5377 | |
5378 TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects); | |
5379 *ps = tds; | |
5380 } | |
5381 else | |
5382 goto Ldefault; | |
5383 } | |
5384 else | |
5385 { | |
5386 Ldefault: | |
5387 Type::resolve(loc, sc, pe, pt, ps); | |
5388 } | |
5389 } | |
5390 | |
5391 void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
5392 { | |
5393 if (mod != this->mod) | |
5394 { toCBuffer3(buf, hgs, mod); | |
5395 return; | |
5396 } | |
5397 next->toCBuffer2(buf, hgs, this->mod); | |
5398 | |
5399 buf->printf("[%s .. ", lwr->toChars()); | |
5400 buf->printf("%s]", upr->toChars()); | |
5401 } | |
5402 | |
5403 /***************************** Argument *****************************/ | |
5404 | |
5405 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg) | |
5406 { | |
5407 this->type = type; | |
5408 this->ident = ident; | |
5409 this->storageClass = storageClass; | |
5410 this->defaultArg = defaultArg; | |
5411 } | |
5412 | |
5413 Argument *Argument::syntaxCopy() | |
5414 { | |
5415 Argument *a = new Argument(storageClass, | |
5416 type ? type->syntaxCopy() : NULL, | |
5417 ident, | |
5418 defaultArg ? defaultArg->syntaxCopy() : NULL); | |
5419 return a; | |
5420 } | |
5421 | |
5422 Arguments *Argument::arraySyntaxCopy(Arguments *args) | |
5423 { Arguments *a = NULL; | |
5424 | |
5425 if (args) | |
5426 { | |
5427 a = new Arguments(); | |
5428 a->setDim(args->dim); | |
5429 for (size_t i = 0; i < a->dim; i++) | |
5430 { Argument *arg = (Argument *)args->data[i]; | |
5431 | |
5432 arg = arg->syntaxCopy(); | |
5433 a->data[i] = (void *)arg; | |
5434 } | |
5435 } | |
5436 return a; | |
5437 } | |
5438 | |
5439 char *Argument::argsTypesToChars(Arguments *args, int varargs) | |
5440 { OutBuffer *buf; | |
5441 | |
5442 buf = new OutBuffer(); | |
5443 | |
5444 buf->writeByte('('); | |
5445 if (args) | |
5446 { int i; | |
5447 OutBuffer argbuf; | |
5448 HdrGenState hgs; | |
5449 | |
5450 for (i = 0; i < args->dim; i++) | |
5451 { Argument *arg; | |
5452 | |
5453 if (i) | |
5454 buf->writeByte(','); | |
5455 arg = (Argument *)args->data[i]; | |
5456 argbuf.reset(); | |
5457 arg->type->toCBuffer2(&argbuf, &hgs, 0); | |
5458 buf->write(&argbuf); | |
5459 } | |
5460 if (varargs) | |
5461 { | |
5462 if (i && varargs == 1) | |
5463 buf->writeByte(','); | |
5464 buf->writestring("..."); | |
5465 } | |
5466 } | |
5467 buf->writeByte(')'); | |
5468 | |
5469 return buf->toChars(); | |
5470 } | |
5471 | |
5472 void Argument::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Arguments *arguments, int varargs) | |
5473 { | |
5474 buf->writeByte('('); | |
5475 if (arguments) | |
5476 { int i; | |
5477 OutBuffer argbuf; | |
5478 | |
5479 for (i = 0; i < arguments->dim; i++) | |
5480 { Argument *arg; | |
5481 | |
5482 if (i) | |
5483 buf->writestring(", "); | |
5484 arg = (Argument *)arguments->data[i]; | |
5485 if (arg->storageClass & STCout) | |
5486 buf->writestring("out "); | |
5487 else if (arg->storageClass & STCref) | |
5488 buf->writestring((global.params.Dversion == 1) | |
5489 ? (char *)"inout " : (char *)"ref "); | |
5490 else if (arg->storageClass & STClazy) | |
5491 buf->writestring("lazy "); | |
5492 argbuf.reset(); | |
5493 arg->type->toCBuffer(&argbuf, arg->ident, hgs); | |
5494 if (arg->defaultArg) | |
5495 { | |
5496 argbuf.writestring(" = "); | |
5497 arg->defaultArg->toCBuffer(&argbuf, hgs); | |
5498 } | |
5499 buf->write(&argbuf); | |
5500 } | |
5501 if (varargs) | |
5502 { | |
5503 if (i && varargs == 1) | |
5504 buf->writeByte(','); | |
5505 buf->writestring("..."); | |
5506 } | |
5507 } | |
5508 buf->writeByte(')'); | |
5509 } | |
5510 | |
5511 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
5512 void Argument::argsToDecoBuffer(OutBuffer *buf, Arguments *arguments, bool mangle) |
159 | 5513 { |
5514 //printf("Argument::argsToDecoBuffer()\n"); | |
5515 | |
5516 // Write argument types | |
5517 if (arguments) | |
5518 { | |
5519 size_t dim = Argument::dim(arguments); | |
5520 for (size_t i = 0; i < dim; i++) | |
5521 { | |
5522 Argument *arg = Argument::getNth(arguments, i); | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
5523 arg->toDecoBuffer(buf, mangle); |
159 | 5524 } |
5525 } | |
5526 } | |
5527 | |
5528 /**************************************************** | |
5529 * Determine if parameter is a lazy array of delegates. | |
5530 * If so, return the return type of those delegates. | |
5531 * If not, return NULL. | |
5532 */ | |
5533 | |
5534 Type *Argument::isLazyArray() | |
5535 { | |
5536 // if (inout == Lazy) | |
5537 { | |
5538 Type *tb = type->toBasetype(); | |
5539 if (tb->ty == Tsarray || tb->ty == Tarray) | |
5540 { | |
5541 Type *tel = tb->next->toBasetype(); | |
5542 if (tel->ty == Tdelegate) | |
5543 { | |
5544 TypeDelegate *td = (TypeDelegate *)tel; | |
5545 TypeFunction *tf = (TypeFunction *)td->next; | |
5546 | |
5547 if (!tf->varargs && Argument::dim(tf->parameters) == 0) | |
5548 { | |
5549 return tf->next; // return type of delegate | |
5550 } | |
5551 } | |
5552 } | |
5553 } | |
5554 return NULL; | |
5555 } | |
5556 | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
5557 void Argument::toDecoBuffer(OutBuffer *buf, bool mangle) |
159 | 5558 { |
5559 switch (storageClass & (STCin | STCout | STCref | STClazy)) | |
5560 { case 0: | |
5561 case STCin: | |
5562 break; | |
5563 case STCout: | |
5564 buf->writeByte('J'); | |
5565 break; | |
5566 case STCref: | |
5567 buf->writeByte('K'); | |
5568 break; | |
5569 case STClazy: | |
5570 buf->writeByte('L'); | |
5571 break; | |
5572 default: | |
5573 #ifdef DEBUG | |
5574 halt(); | |
5575 #endif | |
5576 assert(0); | |
5577 } | |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1195
diff
changeset
|
5578 type->toDecoBuffer(buf, mangle); |
159 | 5579 } |
5580 | |
5581 /*************************************** | |
5582 * Determine number of arguments, folding in tuples. | |
5583 */ | |
5584 | |
5585 size_t Argument::dim(Arguments *args) | |
5586 { | |
5587 size_t n = 0; | |
5588 if (args) | |
5589 { | |
5590 for (size_t i = 0; i < args->dim; i++) | |
5591 { Argument *arg = (Argument *)args->data[i]; | |
5592 Type *t = arg->type->toBasetype(); | |
5593 | |
5594 if (t->ty == Ttuple) | |
5595 { TypeTuple *tu = (TypeTuple *)t; | |
5596 n += dim(tu->arguments); | |
5597 } | |
5598 else | |
5599 n++; | |
5600 } | |
5601 } | |
5602 return n; | |
5603 } | |
5604 | |
5605 /*************************************** | |
5606 * Get nth Argument, folding in tuples. | |
5607 * Returns: | |
5608 * Argument* nth Argument | |
5609 * NULL not found, *pn gets incremented by the number | |
5610 * of Arguments | |
5611 */ | |
5612 | |
5613 Argument *Argument::getNth(Arguments *args, size_t nth, size_t *pn) | |
5614 { | |
5615 if (!args) | |
5616 return NULL; | |
5617 | |
5618 size_t n = 0; | |
5619 for (size_t i = 0; i < args->dim; i++) | |
5620 { Argument *arg = (Argument *)args->data[i]; | |
5621 Type *t = arg->type->toBasetype(); | |
5622 | |
5623 if (t->ty == Ttuple) | |
5624 { TypeTuple *tu = (TypeTuple *)t; | |
5625 arg = getNth(tu->arguments, nth - n, &n); | |
5626 if (arg) | |
5627 return arg; | |
5628 } | |
5629 else if (n == nth) | |
5630 return arg; | |
5631 else | |
5632 n++; | |
5633 } | |
5634 | |
5635 if (pn) | |
5636 *pn += n; | |
5637 return NULL; | |
5638 } |