Mercurial > projects > ldc
annotate dmd/attrib.c @ 797:340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Fixed function literals in static initializers.
Changed alignment of delegates from 2*PTRSIZE to just PTRSIZE.
Changed errors to go to stderr instead of stdout.
Fairly major rewriting of struct/union/class handling, STILL A BIT BUGGY !!!
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sat, 29 Nov 2008 21:25:43 +0100 |
parents | 661384d6a936 |
children | 7d16ce7ad19d |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
336 | 3 // Copyright (c) 1999-2008 by Digital Mars |
159 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <assert.h> | |
14 | |
15 #if _WIN32 || IN_GCC || IN_LLVM | |
16 #include "mem.h" | |
571
cbd6c8073a32
Changed all '#if linux || __APPLE__' to '#if POSIX' so we can support other platforms too, thanx for the suggestion anders.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
535
diff
changeset
|
17 #elif POSIX |
159 | 18 #include "../root/mem.h" |
19 #endif | |
20 | |
21 #include "init.h" | |
22 #include "declaration.h" | |
23 #include "attrib.h" | |
24 #include "cond.h" | |
25 #include "scope.h" | |
26 #include "id.h" | |
27 #include "expression.h" | |
28 #include "dsymbol.h" | |
29 #include "aggregate.h" | |
30 #include "module.h" | |
31 #include "parse.h" | |
32 #include "template.h" | |
33 | |
34 #include "../gen/enums.h" | |
35 #include "../gen/logger.h" | |
36 | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
571
diff
changeset
|
37 extern void obj_includelib(const char *name); |
336 | 38 void obj_startaddress(Symbol *s); |
159 | 39 |
40 | |
41 /********************************* AttribDeclaration ****************************/ | |
42 | |
43 AttribDeclaration::AttribDeclaration(Array *decl) | |
44 : Dsymbol() | |
45 { | |
46 this->decl = decl; | |
47 } | |
48 | |
49 Array *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd) | |
50 { | |
51 return decl; | |
52 } | |
53 | |
54 int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
55 { | |
56 int m = 0; | |
57 Array *d = include(sc, sd); | |
58 | |
59 if (d) | |
60 { | |
336 | 61 for (unsigned i = 0; i < d->dim; i++) |
62 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 63 m |= s->addMember(sc, sd, m | memnum); |
64 } | |
65 } | |
66 return m; | |
67 } | |
68 | |
69 void AttribDeclaration::semantic(Scope *sc) | |
70 { | |
71 Array *d = include(sc, NULL); | |
72 | |
336 | 73 //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); |
159 | 74 if (d) |
75 { | |
76 for (unsigned i = 0; i < d->dim; i++) | |
77 { | |
78 Dsymbol *s = (Dsymbol *)d->data[i]; | |
79 | |
80 s->semantic(sc); | |
81 } | |
82 } | |
83 } | |
84 | |
85 void AttribDeclaration::semantic2(Scope *sc) | |
86 { | |
87 Array *d = include(sc, NULL); | |
88 | |
89 if (d) | |
90 { | |
336 | 91 for (unsigned i = 0; i < d->dim; i++) |
92 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 93 s->semantic2(sc); |
94 } | |
95 } | |
96 } | |
97 | |
98 void AttribDeclaration::semantic3(Scope *sc) | |
99 { | |
100 Array *d = include(sc, NULL); | |
101 | |
102 if (d) | |
103 { | |
336 | 104 for (unsigned i = 0; i < d->dim; i++) |
105 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 106 s->semantic3(sc); |
107 } | |
108 } | |
109 } | |
110 | |
111 void AttribDeclaration::inlineScan() | |
112 { | |
113 Array *d = include(NULL, NULL); | |
114 | |
115 if (d) | |
116 { | |
336 | 117 for (unsigned i = 0; i < d->dim; i++) |
118 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 119 //printf("AttribDeclaration::inlineScan %s\n", s->toChars()); |
120 s->inlineScan(); | |
121 } | |
122 } | |
123 } | |
124 | |
125 void AttribDeclaration::addComment(unsigned char *comment) | |
126 { | |
127 if (comment) | |
128 { | |
129 Array *d = include(NULL, NULL); | |
130 | |
131 if (d) | |
132 { | |
336 | 133 for (unsigned i = 0; i < d->dim; i++) |
134 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 135 //printf("AttribDeclaration::addComment %s\n", s->toChars()); |
136 s->addComment(comment); | |
137 } | |
138 } | |
139 } | |
140 } | |
141 | |
142 void AttribDeclaration::emitComment(Scope *sc) | |
143 { | |
144 //printf("AttribDeclaration::emitComment(sc = %p)\n", sc); | |
145 | |
146 /* If generating doc comment, skip this because if we're inside | |
147 * a template, then include(NULL, NULL) will fail. | |
148 */ | |
149 // if (sc->docbuf) | |
150 // return; | |
151 | |
152 Array *d = include(NULL, NULL); | |
153 | |
154 if (d) | |
155 { | |
336 | 156 for (unsigned i = 0; i < d->dim; i++) |
157 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 158 //printf("AttribDeclaration::emitComment %s\n", s->toChars()); |
159 s->emitComment(sc); | |
160 } | |
161 } | |
162 } | |
163 | |
336 | 164 void AttribDeclaration::toObjFile(int multiobj) |
159 | 165 { |
166 Array *d = include(NULL, NULL); | |
167 | |
168 if (d) | |
169 { | |
336 | 170 for (unsigned i = 0; i < d->dim; i++) |
171 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
172 s->toObjFile(multiobj); | |
159 | 173 } |
174 } | |
175 } | |
176 | |
177 int AttribDeclaration::cvMember(unsigned char *p) | |
178 { | |
179 int nwritten = 0; | |
180 int n; | |
181 Array *d = include(NULL, NULL); | |
182 | |
183 if (d) | |
184 { | |
336 | 185 for (unsigned i = 0; i < d->dim; i++) |
186 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 187 n = s->cvMember(p); |
188 if (p) | |
189 p += n; | |
190 nwritten += n; | |
191 } | |
192 } | |
193 return nwritten; | |
194 } | |
195 | |
196 int AttribDeclaration::hasPointers() | |
197 { | |
198 Array *d = include(NULL, NULL); | |
199 | |
200 if (d) | |
201 { | |
202 for (size_t i = 0; i < d->dim; i++) | |
203 { | |
204 Dsymbol *s = (Dsymbol *)d->data[i]; | |
205 if (s->hasPointers()) | |
206 return 1; | |
207 } | |
208 } | |
209 return 0; | |
210 } | |
211 | |
336 | 212 const char *AttribDeclaration::kind() |
159 | 213 { |
214 return "attribute"; | |
215 } | |
216 | |
217 int AttribDeclaration::oneMember(Dsymbol **ps) | |
218 { | |
219 Array *d = include(NULL, NULL); | |
220 | |
221 return Dsymbol::oneMembers(d, ps); | |
222 } | |
223 | |
224 void AttribDeclaration::checkCtorConstInit() | |
225 { | |
226 Array *d = include(NULL, NULL); | |
227 | |
228 if (d) | |
229 { | |
336 | 230 for (unsigned i = 0; i < d->dim; i++) |
231 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 232 s->checkCtorConstInit(); |
233 } | |
234 } | |
235 } | |
236 | |
237 /**************************************** | |
238 */ | |
239 | |
240 void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses) | |
336 | 241 { |
159 | 242 Array *d = include(NULL, NULL); |
243 | |
244 if (d) | |
245 { | |
336 | 246 for (unsigned i = 0; i < d->dim; i++) |
247 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
159 | 248 s->addLocalClass(aclasses); |
249 } | |
250 } | |
251 } | |
252 | |
253 | |
254 void AttribDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
255 { | |
256 if (decl) | |
257 { | |
258 buf->writenl(); | |
259 buf->writeByte('{'); | |
260 buf->writenl(); | |
261 for (unsigned i = 0; i < decl->dim; i++) | |
262 { | |
263 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
264 | |
265 buf->writestring(" "); | |
266 s->toCBuffer(buf, hgs); | |
267 } | |
268 buf->writeByte('}'); | |
269 } | |
270 else | |
271 buf->writeByte(';'); | |
272 buf->writenl(); | |
273 } | |
274 | |
275 /************************* StorageClassDeclaration ****************************/ | |
276 | |
277 StorageClassDeclaration::StorageClassDeclaration(unsigned stc, Array *decl) | |
278 : AttribDeclaration(decl) | |
279 { | |
280 this->stc = stc; | |
281 } | |
282 | |
283 Dsymbol *StorageClassDeclaration::syntaxCopy(Dsymbol *s) | |
284 { | |
285 StorageClassDeclaration *scd; | |
286 | |
287 assert(!s); | |
288 scd = new StorageClassDeclaration(stc, Dsymbol::arraySyntaxCopy(decl)); | |
289 return scd; | |
290 } | |
291 | |
292 void StorageClassDeclaration::semantic(Scope *sc) | |
293 { | |
294 if (decl) | |
295 { unsigned stc_save = sc->stc; | |
296 | |
297 if (stc & (STCauto | STCscope | STCstatic | STCextern)) | |
298 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern); | |
299 sc->stc |= stc; | |
300 for (unsigned i = 0; i < decl->dim; i++) | |
301 { | |
302 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
303 | |
304 s->semantic(sc); | |
305 } | |
306 sc->stc = stc_save; | |
307 } | |
308 else | |
309 sc->stc = stc; | |
310 } | |
311 | |
312 void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
313 { | |
314 struct SCstring | |
315 { | |
316 int stc; | |
317 enum TOK tok; | |
318 }; | |
319 | |
320 static SCstring table[] = | |
321 { | |
322 { STCauto, TOKauto }, | |
323 { STCscope, TOKscope }, | |
324 { STCstatic, TOKstatic }, | |
325 { STCextern, TOKextern }, | |
326 { STCconst, TOKconst }, | |
327 { STCfinal, TOKfinal }, | |
328 { STCabstract, TOKabstract }, | |
329 { STCsynchronized, TOKsynchronized }, | |
330 { STCdeprecated, TOKdeprecated }, | |
331 { STCoverride, TOKoverride }, | |
332 }; | |
333 | |
334 int written = 0; | |
335 for (int i = 0; i < sizeof(table)/sizeof(table[0]); i++) | |
336 { | |
337 if (stc & table[i].stc) | |
338 { | |
339 if (written) | |
340 buf->writeByte(' '); | |
341 written = 1; | |
342 buf->writestring(Token::toChars(table[i].tok)); | |
343 } | |
344 } | |
345 | |
346 AttribDeclaration::toCBuffer(buf, hgs); | |
347 } | |
348 | |
349 /********************************* LinkDeclaration ****************************/ | |
350 | |
351 LinkDeclaration::LinkDeclaration(enum LINK p, Array *decl) | |
352 : AttribDeclaration(decl) | |
353 { | |
354 //printf("LinkDeclaration(linkage = %d, decl = %p)\n", p, decl); | |
355 linkage = p; | |
356 } | |
357 | |
358 Dsymbol *LinkDeclaration::syntaxCopy(Dsymbol *s) | |
359 { | |
360 LinkDeclaration *ld; | |
361 | |
362 assert(!s); | |
363 ld = new LinkDeclaration(linkage, Dsymbol::arraySyntaxCopy(decl)); | |
364 return ld; | |
365 } | |
366 | |
367 void LinkDeclaration::semantic(Scope *sc) | |
368 { | |
369 //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); | |
370 if (decl) | |
371 { enum LINK linkage_save = sc->linkage; | |
372 | |
373 sc->linkage = linkage; | |
374 for (unsigned i = 0; i < decl->dim; i++) | |
375 { | |
376 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
377 | |
378 s->semantic(sc); | |
379 } | |
380 sc->linkage = linkage_save; | |
381 } | |
382 else | |
383 { | |
384 sc->linkage = linkage; | |
385 } | |
386 } | |
387 | |
388 void LinkDeclaration::semantic3(Scope *sc) | |
389 { | |
390 //printf("LinkDeclaration::semantic3(linkage = %d, decl = %p)\n", linkage, decl); | |
391 if (decl) | |
392 { enum LINK linkage_save = sc->linkage; | |
393 | |
394 sc->linkage = linkage; | |
395 for (unsigned i = 0; i < decl->dim; i++) | |
396 { | |
397 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
398 | |
399 s->semantic3(sc); | |
400 } | |
401 sc->linkage = linkage_save; | |
402 } | |
403 else | |
404 { | |
405 sc->linkage = linkage; | |
406 } | |
407 } | |
408 | |
409 void LinkDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
410 { char *p; | |
411 | |
412 switch (linkage) | |
413 { | |
414 case LINKd: p = "D"; break; | |
415 case LINKc: p = "C"; break; | |
416 case LINKcpp: p = "C++"; break; | |
417 case LINKwindows: p = "Windows"; break; | |
418 case LINKpascal: p = "Pascal"; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
419 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
420 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
421 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:
716
diff
changeset
|
422 |
159 | 423 default: |
424 assert(0); | |
425 break; | |
426 } | |
427 buf->writestring("extern ("); | |
428 buf->writestring(p); | |
429 buf->writestring(") "); | |
430 AttribDeclaration::toCBuffer(buf, hgs); | |
431 } | |
432 | |
433 char *LinkDeclaration::toChars() | |
434 { | |
435 return "extern ()"; | |
436 } | |
437 | |
438 /********************************* ProtDeclaration ****************************/ | |
439 | |
440 ProtDeclaration::ProtDeclaration(enum PROT p, Array *decl) | |
441 : AttribDeclaration(decl) | |
442 { | |
443 protection = p; | |
444 //printf("decl = %p\n", decl); | |
445 } | |
446 | |
447 Dsymbol *ProtDeclaration::syntaxCopy(Dsymbol *s) | |
448 { | |
449 ProtDeclaration *pd; | |
450 | |
451 assert(!s); | |
452 pd = new ProtDeclaration(protection, Dsymbol::arraySyntaxCopy(decl)); | |
453 return pd; | |
454 } | |
455 | |
456 void ProtDeclaration::semantic(Scope *sc) | |
457 { | |
458 if (decl) | |
459 { enum PROT protection_save = sc->protection; | |
460 int explicitProtection_save = sc->explicitProtection; | |
461 | |
462 sc->protection = protection; | |
463 sc->explicitProtection = 1; | |
464 for (unsigned i = 0; i < decl->dim; i++) | |
465 { | |
466 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
467 | |
468 s->semantic(sc); | |
469 } | |
470 sc->protection = protection_save; | |
471 sc->explicitProtection = explicitProtection_save; | |
472 } | |
473 else | |
474 { sc->protection = protection; | |
475 sc->explicitProtection = 1; | |
476 } | |
477 } | |
478 | |
479 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
480 { char *p; | |
481 | |
482 switch (protection) | |
483 { | |
484 case PROTprivate: p = "private"; break; | |
485 case PROTpackage: p = "package"; break; | |
486 case PROTprotected: p = "protected"; break; | |
487 case PROTpublic: p = "public"; break; | |
488 case PROTexport: p = "export"; break; | |
489 default: | |
490 assert(0); | |
491 break; | |
492 } | |
493 buf->writestring(p); | |
494 AttribDeclaration::toCBuffer(buf, hgs); | |
495 } | |
496 | |
497 /********************************* AlignDeclaration ****************************/ | |
498 | |
710
20a5180f2e80
Make align(n), n != 1 an error.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
499 AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl) |
159 | 500 : AttribDeclaration(decl) |
501 { | |
710
20a5180f2e80
Make align(n), n != 1 an error.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
502 this->loc = loc; |
159 | 503 salign = sa; |
504 } | |
505 | |
506 Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s) | |
507 { | |
508 AlignDeclaration *ad; | |
509 | |
510 assert(!s); | |
710
20a5180f2e80
Make align(n), n != 1 an error.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
511 ad = new AlignDeclaration(loc, salign, Dsymbol::arraySyntaxCopy(decl)); |
159 | 512 return ad; |
513 } | |
514 | |
515 void AlignDeclaration::semantic(Scope *sc) | |
516 { | |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
517 // LDC |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
518 // we only support packed structs, as from the spec: align(1) struct Packed { ... } |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
519 // other alignments are simply ignored. my tests show this is what llvm-gcc does too ... |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
520 |
159 | 521 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); |
522 if (decl) | |
523 { unsigned salign_save = sc->structalign; | |
524 | |
525 for (unsigned i = 0; i < decl->dim; i++) | |
526 { | |
527 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
528 | |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
529 if (s->isStructDeclaration() && salign == 1) |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
530 { |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
531 sc->structalign = salign; |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
532 s->semantic(sc); |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
533 sc->structalign = salign_save; |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
534 } |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
535 else |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
536 { |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
537 s->semantic(sc); |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
538 } |
159 | 539 } |
540 sc->structalign = salign_save; | |
541 } | |
542 else | |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
543 assert(0 && "what kind of align use triggers this?"); |
159 | 544 } |
545 | |
546 | |
547 void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
548 { | |
549 buf->printf("align (%d)", salign); | |
550 AttribDeclaration::toCBuffer(buf, hgs); | |
551 } | |
552 | |
553 /********************************* AnonDeclaration ****************************/ | |
554 | |
555 AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl) | |
556 : AttribDeclaration(decl) | |
557 { | |
558 this->loc = loc; | |
559 this->isunion = isunion; | |
560 this->scope = NULL; | |
561 this->sem = 0; | |
562 } | |
563 | |
564 Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) | |
565 { | |
566 AnonDeclaration *ad; | |
567 | |
568 assert(!s); | |
569 ad = new AnonDeclaration(loc, isunion, Dsymbol::arraySyntaxCopy(decl)); | |
570 return ad; | |
571 } | |
572 | |
573 void AnonDeclaration::semantic(Scope *sc) | |
574 { | |
575 //printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this); | |
576 | |
577 Scope *scx = NULL; | |
578 if (scope) | |
579 { sc = scope; | |
580 scx = scope; | |
581 scope = NULL; | |
582 } | |
583 | |
584 assert(sc->parent); | |
585 | |
586 Dsymbol *parent = sc->parent->pastMixin(); | |
587 AggregateDeclaration *ad = parent->isAggregateDeclaration(); | |
588 | |
589 if (!ad || (!ad->isStructDeclaration() && !ad->isClassDeclaration())) | |
590 { | |
591 error("can only be a part of an aggregate"); | |
592 return; | |
593 } | |
594 | |
595 if (decl) | |
596 { | |
597 AnonymousAggregateDeclaration aad; | |
598 int adisunion; | |
599 | |
600 if (sc->anonAgg) | |
601 { ad = sc->anonAgg; | |
602 adisunion = sc->inunion; | |
603 } | |
604 else | |
605 adisunion = ad->isUnionDeclaration() != NULL; | |
606 | |
607 // printf("\tsc->anonAgg = %p\n", sc->anonAgg); | |
608 // printf("\tad = %p\n", ad); | |
609 // printf("\taad = %p\n", &aad); | |
610 | |
611 sc = sc->push(); | |
612 sc->anonAgg = &aad; | |
613 sc->stc &= ~(STCauto | STCscope | STCstatic); | |
614 sc->inunion = isunion; | |
615 sc->offset = 0; | |
616 sc->flags = 0; | |
617 aad.structalign = sc->structalign; | |
618 aad.parent = ad; | |
619 for (unsigned i = 0; i < decl->dim; i++) | |
620 { | |
621 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
622 | |
623 s->semantic(sc); | |
624 if (isunion) | |
625 sc->offset = 0; | |
626 if (aad.sizeok == 2) | |
627 { | |
628 break; | |
629 } | |
630 } | |
631 sc = sc->pop(); | |
632 | |
633 // If failed due to forward references, unwind and try again later | |
634 if (aad.sizeok == 2) | |
635 { | |
636 ad->sizeok = 2; | |
637 //printf("\tsetting ad->sizeok %p to 2\n", ad); | |
638 if (!sc->anonAgg) | |
639 { | |
640 scope = scx ? scx : new Scope(*sc); | |
641 scope->setNoFree(); | |
642 scope->module->addDeferredSemantic(this); | |
643 } | |
644 //printf("\tforward reference %p\n", this); | |
645 return; | |
646 } | |
647 if (sem == 0) | |
648 { Module::dprogress++; | |
649 sem = 1; | |
650 //printf("\tcompleted %p\n", this); | |
651 } | |
652 else | |
653 ;//printf("\talready completed %p\n", this); | |
654 | |
655 // 0 sized structs are set to 1 byte | |
656 if (aad.structsize == 0) | |
657 { | |
658 aad.structsize = 1; | |
659 aad.alignsize = 1; | |
660 } | |
661 | |
662 // Align size of anonymous aggregate | |
663 //printf("aad.structalign = %d, aad.alignsize = %d, sc->offset = %d\n", aad.structalign, aad.alignsize, sc->offset); | |
664 ad->alignmember(aad.structalign, aad.alignsize, &sc->offset); | |
665 //ad->structsize = sc->offset; | |
666 //printf("sc->offset = %d\n", sc->offset); | |
667 | |
668 // Add members of aad to ad | |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
669 //printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars()); |
159 | 670 for (unsigned i = 0; i < aad.fields.dim; i++) |
671 { | |
672 VarDeclaration *v = (VarDeclaration *)aad.fields.data[i]; | |
673 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
674 // LDC |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
675 v->offset2 = sc->offset; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
676 |
159 | 677 v->offset += sc->offset; |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
678 |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
679 // LDC |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
680 if (!v->anonDecl) |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
681 v->anonDecl = this; |
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
682 |
159 | 683 ad->fields.push(v); |
684 } | |
685 | |
686 // Add size of aad to ad | |
687 if (adisunion) | |
688 { | |
689 if (aad.structsize > ad->structsize) | |
690 ad->structsize = aad.structsize; | |
691 sc->offset = 0; | |
692 } | |
693 else | |
694 { | |
695 ad->structsize = sc->offset + aad.structsize; | |
696 sc->offset = ad->structsize; | |
697 } | |
698 | |
699 if (ad->alignsize < aad.alignsize) | |
700 ad->alignsize = aad.alignsize; | |
701 } | |
702 } | |
703 | |
704 | |
705 void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
706 { | |
707 buf->printf(isunion ? "union" : "struct"); | |
708 buf->writestring("\n{\n"); | |
709 if (decl) | |
710 { | |
711 for (unsigned i = 0; i < decl->dim; i++) | |
712 { | |
713 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
714 | |
715 //buf->writestring(" "); | |
716 s->toCBuffer(buf, hgs); | |
717 } | |
718 } | |
719 buf->writestring("}\n"); | |
720 } | |
721 | |
336 | 722 const char *AnonDeclaration::kind() |
159 | 723 { |
724 return (char *)(isunion ? "anonymous union" : "anonymous struct"); | |
725 } | |
726 | |
727 /********************************* PragmaDeclaration ****************************/ | |
728 | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
729 static bool parseStringExp(Expression* e, std::string& res) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
730 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
731 StringExp *s = NULL; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
732 |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
733 e = e->optimize(WANTvalue); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
734 if (e->op == TOKstring && (s = (StringExp *)e)) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
735 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
736 char* str = (char*)s->string; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
737 res = str; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
738 return true; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
739 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
740 return false; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
741 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
742 |
159 | 743 PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl) |
744 : AttribDeclaration(decl) | |
745 { | |
746 this->loc = loc; | |
747 this->ident = ident; | |
748 this->args = args; | |
749 } | |
750 | |
751 Dsymbol *PragmaDeclaration::syntaxCopy(Dsymbol *s) | |
752 { | |
753 PragmaDeclaration *pd; | |
754 | |
755 assert(!s); | |
756 pd = new PragmaDeclaration(loc, ident, | |
757 Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl)); | |
758 return pd; | |
759 } | |
760 | |
761 void PragmaDeclaration::semantic(Scope *sc) | |
762 { // Should be merged with PragmaStatement | |
763 | |
764 #if IN_LLVM | |
765 int llvm_internal = 0; | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
766 std::string arg1str; |
159 | 767 |
768 #endif | |
769 | |
770 //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); | |
771 if (ident == Id::msg) | |
772 { | |
773 if (args) | |
774 { | |
775 for (size_t i = 0; i < args->dim; i++) | |
776 { | |
777 Expression *e = (Expression *)args->data[i]; | |
778 | |
779 e = e->semantic(sc); | |
780 e = e->optimize(WANTvalue | WANTinterpret); | |
781 if (e->op == TOKstring) | |
782 { | |
783 StringExp *se = (StringExp *)e; | |
794
661384d6a936
Fix warnings on x86-64. By fvbommel.
Christian Kamm <kamm incasoftware de>
parents:
737
diff
changeset
|
784 fprintf(stdmsg, "%.*s", (int)se->len, (char*)se->string); |
159 | 785 } |
786 else | |
787 error("string expected for message, not '%s'", e->toChars()); | |
788 } | |
789 fprintf(stdmsg, "\n"); | |
790 } | |
791 goto Lnodecl; | |
792 } | |
793 else if (ident == Id::lib) | |
794 { | |
795 if (!args || args->dim != 1) | |
796 error("string expected for library name"); | |
797 else | |
798 { | |
799 Expression *e = (Expression *)args->data[0]; | |
800 | |
801 e = e->semantic(sc); | |
802 e = e->optimize(WANTvalue | WANTinterpret); | |
803 args->data[0] = (void *)e; | |
804 if (e->op != TOKstring) | |
805 error("string expected for library name, not '%s'", e->toChars()); | |
806 else if (global.params.verbose) | |
807 { | |
808 StringExp *se = (StringExp *)e; | |
809 char *name = (char *)mem.malloc(se->len + 1); | |
810 memcpy(name, se->string, se->len); | |
811 name[se->len] = 0; | |
812 printf("library %s\n", name); | |
813 mem.free(name); | |
814 } | |
815 } | |
816 goto Lnodecl; | |
817 } | |
818 #if IN_GCC | |
819 else if (ident == Id::GNU_asm) | |
820 { | |
821 if (! args || args->dim != 2) | |
822 error("identifier and string expected for asm name"); | |
823 else | |
824 { | |
825 Expression *e; | |
826 Declaration *d = NULL; | |
827 StringExp *s = NULL; | |
828 | |
829 e = (Expression *)args->data[0]; | |
830 e = e->semantic(sc); | |
831 if (e->op == TOKvar) | |
832 { | |
833 d = ((VarExp *)e)->var; | |
834 if (! d->isFuncDeclaration() && ! d->isVarDeclaration()) | |
835 d = NULL; | |
836 } | |
837 if (!d) | |
838 error("first argument of GNU_asm must be a function or variable declaration"); | |
839 | |
840 e = (Expression *)args->data[1]; | |
841 e = e->semantic(sc); | |
842 e = e->optimize(WANTvalue); | |
843 if (e->op == TOKstring && ((StringExp *)e)->sz == 1) | |
844 s = ((StringExp *)e); | |
845 else | |
846 error("second argument of GNU_asm must be a char string"); | |
847 | |
848 if (d && s) | |
849 d->c_ident = Lexer::idPool((char*) s->string); | |
850 } | |
851 goto Lnodecl; | |
852 } | |
853 #endif | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
854 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
855 // LDC |
159 | 856 #if IN_LLVM |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
857 |
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
|
858 // pragma(intrinsic, "string") { funcdecl(s) } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
859 else if (ident == Id::intrinsic) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
860 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
861 Expression* expr = (Expression *)args->data[0]; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
862 expr = expr->semantic(sc); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
863 if (!args || args->dim != 1 || !parseStringExp(expr, arg1str)) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
864 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
865 error("requires exactly 1 string literal parameter"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
866 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
867 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
868 llvm_internal = LLVMintrinsic; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
869 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
870 |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
871 // pragma(notypeinfo) { typedecl(s) } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
872 else if (ident == Id::no_typeinfo) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
873 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
874 if (args && args->dim > 0) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
875 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
876 error("takes no parameters"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
877 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
878 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
879 llvm_internal = LLVMno_typeinfo; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
880 } |
159 | 881 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
882 // pragma(nomoduleinfo) ; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
883 else if (ident == Id::no_moduleinfo) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
884 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
885 if (args && args->dim > 0) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
886 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
887 error("takes no parameters"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
888 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
889 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
890 llvm_internal = LLVMno_moduleinfo; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
891 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
892 |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
893 // pragma(alloca) { funcdecl(s) } |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
894 else if (ident == Id::Alloca) |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
895 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
896 if (args && args->dim > 0) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
897 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
898 error("takes no parameters"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
899 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
900 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
901 llvm_internal = LLVMalloca; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
902 } |
159 | 903 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
904 // pragma(va_start) { templdecl(s) } |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
905 else if (ident == Id::vastart) |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
906 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
907 if (args && args->dim > 0) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
908 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
909 error("takes no parameters"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
910 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
911 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
912 llvm_internal = LLVMva_start; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
913 } |
159 | 914 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
915 // pragma(va_copy) { funcdecl(s) } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
916 else if (ident == Id::vacopy) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
917 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
918 if (args && args->dim > 0) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
919 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
920 error("takes no parameters"); |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
921 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
922 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
923 llvm_internal = LLVMva_copy; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
924 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
925 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
926 // pragma(va_end) { funcdecl(s) } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
927 else if (ident == Id::vaend) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
928 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
929 if (args && args->dim > 0) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
930 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
931 error("takes no parameters"); |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
932 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
933 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
934 llvm_internal = LLVMva_end; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
935 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
936 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
937 // pragma(va_arg) { templdecl(s) } |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
938 else if (ident == Id::vaarg) |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
939 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
940 if (args && args->dim > 0) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
941 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
942 error("takes no parameters"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
943 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
944 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
945 llvm_internal = LLVMva_arg; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
946 } |
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
|
947 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
948 // pragma(ldc, "string") { templdecl(s) } |
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
949 else if (ident == Id::ldc) |
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
|
950 { |
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
|
951 Expression* expr = (Expression *)args->data[0]; |
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
|
952 expr = expr->semantic(sc); |
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
|
953 if (!args || args->dim != 1 || !parseStringExp(expr, arg1str)) |
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
|
954 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
955 error("requires exactly 1 string literal parameter"); |
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
|
956 fatal(); |
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
|
957 } |
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
|
958 else if (arg1str == "verbose") |
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
|
959 { |
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
|
960 sc->module->llvmForceLogging = true; |
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
|
961 } |
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
|
962 else |
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
|
963 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
964 error("command '%s' invalid"); |
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
|
965 fatal(); |
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
|
966 } |
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
|
967 } |
159 | 968 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
969 #endif // LDC |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
970 |
159 | 971 else if (global.params.ignoreUnsupportedPragmas) |
972 { | |
973 if (global.params.verbose) | |
974 { | |
975 /* Print unrecognized pragmas | |
976 */ | |
977 printf("pragma %s", ident->toChars()); | |
978 if (args) | |
979 { | |
980 for (size_t i = 0; i < args->dim; i++) | |
981 { | |
982 Expression *e = (Expression *)args->data[i]; | |
983 e = e->semantic(sc); | |
984 e = e->optimize(WANTvalue | WANTinterpret); | |
985 if (i == 0) | |
986 printf(" ("); | |
987 else | |
988 printf(","); | |
989 printf("%s", e->toChars()); | |
990 } | |
991 if (args->dim) | |
992 printf(")"); | |
993 } | |
994 printf("\n"); | |
995 } | |
996 goto Lnodecl; | |
997 } | |
998 else | |
999 error("unrecognized pragma(%s)", ident->toChars()); | |
1000 | |
1001 if (decl) | |
1002 { | |
1003 for (unsigned i = 0; i < decl->dim; i++) | |
1004 { | |
1005 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1006 | |
1007 s->semantic(sc); | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1008 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1009 // LDC |
159 | 1010 #if IN_LLVM |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1011 |
159 | 1012 if (llvm_internal) |
1013 { | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1014 if (s->llvmInternal) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1015 { |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1016 error("multiple LDC specific pragmas not allowed not affect the same declaration ('%s' at '%s')", s->toChars(), s->loc.toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1017 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1018 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1019 switch(llvm_internal) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1020 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1021 case LLVMintrinsic: |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1022 if (FuncDeclaration* fd = s->isFuncDeclaration()) |
159 | 1023 { |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1024 fd->llvmInternal = llvm_internal; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1025 fd->intrinsicName = arg1str; |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
1026 fd->linkage = LINKintrinsic; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
1027 ((TypeFunction*)fd->type)->linkage = LINKintrinsic; |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1028 } |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1029 else if (TemplateDeclaration* td = s->isTemplateDeclaration()) |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1030 { |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1031 td->llvmInternal = llvm_internal; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1032 td->intrinsicName = arg1str; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1033 } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1034 else |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1035 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1036 error("only allowed on function declarations"); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1037 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1038 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1039 break; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1040 |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1041 case LLVMva_start: |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1042 case LLVMva_arg: |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1043 if (TemplateDeclaration* td = s->isTemplateDeclaration()) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1044 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1045 if (td->parameters->dim != 1) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1046 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1047 error("the '%s' pragma template must have exactly one template parameter", ident->toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1048 fatal(); |
159 | 1049 } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1050 else if (!td->onemember) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1051 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1052 error("the '%s' pragma template must have exactly one member", ident->toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1053 fatal(); |
159 | 1054 } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1055 else if (td->overnext || td->overroot) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1056 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1057 error("the '%s' pragma template must not be overloaded", ident->toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1058 fatal(); |
159 | 1059 } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1060 td->llvmInternal = llvm_internal; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1061 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1062 else |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1063 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1064 error("the '%s' pragma is only allowed on template declarations", ident->toChars()); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1065 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1066 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1067 break; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1068 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1069 case LLVMva_copy: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1070 case LLVMva_end: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1071 if (FuncDeclaration* fd = s->isFuncDeclaration()) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1072 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1073 fd->llvmInternal = llvm_internal; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1074 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1075 else |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1076 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1077 error("the '%s' pragma is only allowed on function declarations", ident->toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1078 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1079 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1080 break; |
159 | 1081 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1082 case LLVMno_typeinfo: |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1083 s->llvmInternal = llvm_internal; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1084 break; |
159 | 1085 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1086 case LLVMalloca: |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1087 if (FuncDeclaration* fd = s->isFuncDeclaration()) |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1088 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1089 fd->llvmInternal = llvm_internal; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1090 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1091 else |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1092 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1093 error("the '%s' pragma must only be used on function declarations of type 'void* function(uint nbytes)'", ident->toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1094 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1095 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1096 break; |
159 | 1097 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1098 default: |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1099 warning("the LDC specific pragma '%s' is not yet implemented, ignoring", ident->toChars()); |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1100 } |
159 | 1101 } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1102 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1103 #endif // LDC |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1104 |
159 | 1105 } |
1106 } | |
1107 return; | |
1108 | |
1109 Lnodecl: | |
1110 if (decl) | |
1111 error("pragma is missing closing ';'"); | |
1112 } | |
1113 | |
1114 int PragmaDeclaration::oneMember(Dsymbol **ps) | |
1115 { | |
1116 *ps = NULL; | |
1117 return TRUE; | |
1118 } | |
1119 | |
336 | 1120 const char *PragmaDeclaration::kind() |
159 | 1121 { |
1122 return "pragma"; | |
1123 } | |
1124 | |
336 | 1125 void PragmaDeclaration::toObjFile(int multiobj) |
159 | 1126 { |
1127 if (ident == Id::lib) | |
1128 { | |
1129 assert(args && args->dim == 1); | |
1130 | |
1131 Expression *e = (Expression *)args->data[0]; | |
1132 | |
1133 assert(e->op == TOKstring); | |
1134 | |
1135 StringExp *se = (StringExp *)e; | |
1136 char *name = (char *)mem.malloc(se->len + 1); | |
1137 memcpy(name, se->string, se->len); | |
1138 name[se->len] = 0; | |
1139 obj_includelib(name); | |
1140 } | |
336 | 1141 AttribDeclaration::toObjFile(multiobj); |
159 | 1142 } |
1143 | |
1144 void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1145 { | |
1146 buf->printf("pragma(%s", ident->toChars()); | |
1147 if (args) | |
1148 { | |
1149 for (size_t i = 0; i < args->dim; i++) | |
1150 { | |
1151 Expression *e = (Expression *)args->data[i]; | |
1152 | |
1153 buf->writestring(", "); | |
1154 e->toCBuffer(buf, hgs); | |
1155 } | |
1156 } | |
1157 buf->writestring(")"); | |
1158 AttribDeclaration::toCBuffer(buf, hgs); | |
1159 } | |
1160 | |
1161 | |
1162 /********************************* ConditionalDeclaration ****************************/ | |
1163 | |
1164 ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl) | |
1165 : AttribDeclaration(decl) | |
1166 { | |
1167 //printf("ConditionalDeclaration::ConditionalDeclaration()\n"); | |
1168 this->condition = condition; | |
1169 this->elsedecl = elsedecl; | |
1170 } | |
1171 | |
1172 Dsymbol *ConditionalDeclaration::syntaxCopy(Dsymbol *s) | |
1173 { | |
1174 ConditionalDeclaration *dd; | |
1175 | |
1176 assert(!s); | |
1177 dd = new ConditionalDeclaration(condition->syntaxCopy(), | |
1178 Dsymbol::arraySyntaxCopy(decl), | |
1179 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1180 return dd; | |
1181 } | |
1182 | |
1183 | |
1184 int ConditionalDeclaration::oneMember(Dsymbol **ps) | |
1185 { | |
1186 //printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc); | |
1187 if (condition->inc) | |
1188 { | |
1189 Array *d = condition->include(NULL, NULL) ? decl : elsedecl; | |
1190 return Dsymbol::oneMembers(d, ps); | |
1191 } | |
1192 *ps = NULL; | |
1193 return TRUE; | |
1194 } | |
1195 | |
1196 void ConditionalDeclaration::emitComment(Scope *sc) | |
1197 { | |
1198 //printf("ConditionalDeclaration::emitComment(sc = %p)\n", sc); | |
1199 if (condition->inc) | |
1200 { | |
1201 AttribDeclaration::emitComment(sc); | |
1202 } | |
1203 } | |
1204 | |
1205 // Decide if 'then' or 'else' code should be included | |
1206 | |
1207 Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd) | |
1208 { | |
1209 //printf("ConditionalDeclaration::include()\n"); | |
1210 assert(condition); | |
1211 return condition->include(sc, sd) ? decl : elsedecl; | |
1212 } | |
1213 | |
1214 | |
1215 void ConditionalDeclaration::addComment(unsigned char *comment) | |
1216 { | |
1217 /* Because addComment is called by the parser, if we called | |
1218 * include() it would define a version before it was used. | |
1219 * But it's no problem to drill down to both decl and elsedecl, | |
1220 * so that's the workaround. | |
1221 */ | |
1222 | |
1223 if (comment) | |
1224 { | |
1225 Array *d = decl; | |
1226 | |
1227 for (int j = 0; j < 2; j++) | |
1228 { | |
1229 if (d) | |
1230 { | |
1231 for (unsigned i = 0; i < d->dim; i++) | |
1232 { Dsymbol *s; | |
1233 | |
1234 s = (Dsymbol *)d->data[i]; | |
1235 //printf("ConditionalDeclaration::addComment %s\n", s->toChars()); | |
1236 s->addComment(comment); | |
1237 } | |
1238 } | |
1239 d = elsedecl; | |
1240 } | |
1241 } | |
1242 } | |
1243 | |
1244 void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1245 { | |
1246 condition->toCBuffer(buf, hgs); | |
1247 if (decl || elsedecl) | |
1248 { | |
1249 buf->writenl(); | |
1250 buf->writeByte('{'); | |
1251 buf->writenl(); | |
1252 if (decl) | |
1253 { | |
1254 for (unsigned i = 0; i < decl->dim; i++) | |
1255 { | |
1256 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1257 | |
1258 buf->writestring(" "); | |
1259 s->toCBuffer(buf, hgs); | |
1260 } | |
1261 } | |
1262 buf->writeByte('}'); | |
1263 if (elsedecl) | |
1264 { | |
1265 buf->writenl(); | |
1266 buf->writestring("else"); | |
1267 buf->writenl(); | |
1268 buf->writeByte('{'); | |
1269 buf->writenl(); | |
1270 for (unsigned i = 0; i < elsedecl->dim; i++) | |
1271 { | |
1272 Dsymbol *s = (Dsymbol *)elsedecl->data[i]; | |
1273 | |
1274 buf->writestring(" "); | |
1275 s->toCBuffer(buf, hgs); | |
1276 } | |
1277 buf->writeByte('}'); | |
1278 } | |
1279 } | |
1280 else | |
1281 buf->writeByte(':'); | |
1282 buf->writenl(); | |
1283 } | |
1284 | |
1285 /***************************** StaticIfDeclaration ****************************/ | |
1286 | |
1287 StaticIfDeclaration::StaticIfDeclaration(Condition *condition, | |
1288 Array *decl, Array *elsedecl) | |
1289 : ConditionalDeclaration(condition, decl, elsedecl) | |
1290 { | |
1291 //printf("StaticIfDeclaration::StaticIfDeclaration()\n"); | |
1292 sd = NULL; | |
1293 addisdone = 0; | |
1294 } | |
1295 | |
1296 | |
1297 Dsymbol *StaticIfDeclaration::syntaxCopy(Dsymbol *s) | |
1298 { | |
1299 StaticIfDeclaration *dd; | |
1300 | |
1301 assert(!s); | |
1302 dd = new StaticIfDeclaration(condition->syntaxCopy(), | |
1303 Dsymbol::arraySyntaxCopy(decl), | |
1304 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1305 return dd; | |
1306 } | |
1307 | |
1308 | |
1309 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1310 { | |
336 | 1311 //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); |
159 | 1312 /* This is deferred until semantic(), so that |
1313 * expressions in the condition can refer to declarations | |
1314 * in the same scope, such as: | |
1315 * | |
1316 * template Foo(int i) | |
1317 * { | |
1318 * const int j = i + 1; | |
1319 * static if (j == 3) | |
1320 * const int k; | |
1321 * } | |
1322 */ | |
1323 this->sd = sd; | |
1324 int m = 0; | |
1325 | |
1326 if (memnum == 0) | |
1327 { m = AttribDeclaration::addMember(sc, sd, memnum); | |
1328 addisdone = 1; | |
1329 } | |
1330 return m; | |
1331 } | |
1332 | |
1333 | |
1334 void StaticIfDeclaration::semantic(Scope *sc) | |
1335 { | |
1336 Array *d = include(sc, sd); | |
1337 | |
336 | 1338 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); |
159 | 1339 if (d) |
1340 { | |
1341 if (!addisdone) | |
1342 { AttribDeclaration::addMember(sc, sd, 1); | |
1343 addisdone = 1; | |
1344 } | |
1345 | |
1346 for (unsigned i = 0; i < d->dim; i++) | |
1347 { | |
1348 Dsymbol *s = (Dsymbol *)d->data[i]; | |
1349 | |
1350 s->semantic(sc); | |
1351 } | |
1352 } | |
1353 } | |
1354 | |
336 | 1355 const char *StaticIfDeclaration::kind() |
159 | 1356 { |
1357 return "static if"; | |
1358 } | |
1359 | |
1360 | |
1361 /***************************** CompileDeclaration *****************************/ | |
1362 | |
1363 CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp) | |
1364 : AttribDeclaration(NULL) | |
1365 { | |
336 | 1366 this->loc = loc; |
159 | 1367 this->exp = exp; |
1368 this->sd = NULL; | |
336 | 1369 this->compiled = 0; |
159 | 1370 } |
1371 | |
1372 Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *s) | |
1373 { | |
1374 //printf("CompileDeclaration::syntaxCopy('%s')\n", toChars()); | |
1375 CompileDeclaration *sc = new CompileDeclaration(loc, exp->syntaxCopy()); | |
1376 return sc; | |
1377 } | |
1378 | |
1379 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1380 { | |
336 | 1381 //printf("CompileDeclaration::addMember(sc = %p)\n", sc); |
159 | 1382 this->sd = sd; |
336 | 1383 if (memnum == 0) |
1384 { /* No members yet, so parse the mixin now | |
1385 */ | |
1386 compileIt(sc); | |
1387 memnum |= AttribDeclaration::addMember(sc, sd, memnum); | |
1388 compiled = 1; | |
1389 } | |
159 | 1390 return memnum; |
1391 } | |
1392 | |
336 | 1393 void CompileDeclaration::compileIt(Scope *sc) |
1394 { | |
1395 //printf("CompileDeclaration::compileIt()\n"); | |
1396 exp = exp->semantic(sc); | |
1397 exp = resolveProperties(sc, exp); | |
1398 exp = exp->optimize(WANTvalue | WANTinterpret); | |
1399 if (exp->op != TOKstring) | |
1400 { exp->error("argument to mixin must be a string, not (%s)", exp->toChars()); | |
1401 } | |
1402 else | |
1403 { | |
1404 StringExp *se = (StringExp *)exp; | |
1405 se = se->toUTF8(sc); | |
1406 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); | |
1407 p.loc = loc; | |
1408 p.nextToken(); | |
1409 decl = p.parseDeclDefs(0); | |
1410 if (p.token.value != TOKeof) | |
1411 exp->error("incomplete mixin declaration (%s)", se->toChars()); | |
1412 } | |
1413 } | |
1414 | |
159 | 1415 void CompileDeclaration::semantic(Scope *sc) |
1416 { | |
1417 //printf("CompileDeclaration::semantic()\n"); | |
336 | 1418 |
1419 if (!compiled) | |
1420 { | |
1421 compileIt(sc); | |
1422 AttribDeclaration::addMember(sc, sd, 0); | |
1423 compiled = 1; | |
159 | 1424 } |
1425 AttribDeclaration::semantic(sc); | |
1426 } | |
1427 | |
1428 void CompileDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1429 { | |
1430 buf->writestring("mixin("); | |
1431 exp->toCBuffer(buf, hgs); | |
1432 buf->writestring(");"); | |
1433 buf->writenl(); | |
1434 } |