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