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