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