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