Mercurial > projects > ldc
annotate dmd/attrib.c @ 645:bb8d73e29324
Adjust dmain catch to print exception trace info.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 04 Oct 2008 13:35:27 +0200 |
parents | cbd6c8073a32 |
children | 50383e476c7e |
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 | |
37 extern void obj_includelib(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; | |
419 default: | |
420 assert(0); | |
421 break; | |
422 } | |
423 buf->writestring("extern ("); | |
424 buf->writestring(p); | |
425 buf->writestring(") "); | |
426 AttribDeclaration::toCBuffer(buf, hgs); | |
427 } | |
428 | |
429 char *LinkDeclaration::toChars() | |
430 { | |
431 return "extern ()"; | |
432 } | |
433 | |
434 /********************************* ProtDeclaration ****************************/ | |
435 | |
436 ProtDeclaration::ProtDeclaration(enum PROT p, Array *decl) | |
437 : AttribDeclaration(decl) | |
438 { | |
439 protection = p; | |
440 //printf("decl = %p\n", decl); | |
441 } | |
442 | |
443 Dsymbol *ProtDeclaration::syntaxCopy(Dsymbol *s) | |
444 { | |
445 ProtDeclaration *pd; | |
446 | |
447 assert(!s); | |
448 pd = new ProtDeclaration(protection, Dsymbol::arraySyntaxCopy(decl)); | |
449 return pd; | |
450 } | |
451 | |
452 void ProtDeclaration::semantic(Scope *sc) | |
453 { | |
454 if (decl) | |
455 { enum PROT protection_save = sc->protection; | |
456 int explicitProtection_save = sc->explicitProtection; | |
457 | |
458 sc->protection = protection; | |
459 sc->explicitProtection = 1; | |
460 for (unsigned i = 0; i < decl->dim; i++) | |
461 { | |
462 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
463 | |
464 s->semantic(sc); | |
465 } | |
466 sc->protection = protection_save; | |
467 sc->explicitProtection = explicitProtection_save; | |
468 } | |
469 else | |
470 { sc->protection = protection; | |
471 sc->explicitProtection = 1; | |
472 } | |
473 } | |
474 | |
475 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
476 { char *p; | |
477 | |
478 switch (protection) | |
479 { | |
480 case PROTprivate: p = "private"; break; | |
481 case PROTpackage: p = "package"; break; | |
482 case PROTprotected: p = "protected"; break; | |
483 case PROTpublic: p = "public"; break; | |
484 case PROTexport: p = "export"; break; | |
485 default: | |
486 assert(0); | |
487 break; | |
488 } | |
489 buf->writestring(p); | |
490 AttribDeclaration::toCBuffer(buf, hgs); | |
491 } | |
492 | |
493 /********************************* AlignDeclaration ****************************/ | |
494 | |
495 AlignDeclaration::AlignDeclaration(unsigned sa, Array *decl) | |
496 : AttribDeclaration(decl) | |
497 { | |
498 salign = sa; | |
499 } | |
500 | |
501 Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s) | |
502 { | |
503 AlignDeclaration *ad; | |
504 | |
505 assert(!s); | |
506 ad = new AlignDeclaration(salign, Dsymbol::arraySyntaxCopy(decl)); | |
507 return ad; | |
508 } | |
509 | |
510 void AlignDeclaration::semantic(Scope *sc) | |
511 { | |
512 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); | |
513 if (decl) | |
514 { unsigned salign_save = sc->structalign; | |
515 | |
516 sc->structalign = salign; | |
517 for (unsigned i = 0; i < decl->dim; i++) | |
518 { | |
519 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
520 | |
521 s->semantic(sc); | |
522 } | |
523 sc->structalign = salign_save; | |
524 } | |
525 else | |
526 sc->structalign = salign; | |
527 } | |
528 | |
529 | |
530 void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
531 { | |
532 buf->printf("align (%d)", salign); | |
533 AttribDeclaration::toCBuffer(buf, hgs); | |
534 } | |
535 | |
536 /********************************* AnonDeclaration ****************************/ | |
537 | |
538 AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl) | |
539 : AttribDeclaration(decl) | |
540 { | |
541 this->loc = loc; | |
542 this->isunion = isunion; | |
543 this->scope = NULL; | |
544 this->sem = 0; | |
545 } | |
546 | |
547 Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) | |
548 { | |
549 AnonDeclaration *ad; | |
550 | |
551 assert(!s); | |
552 ad = new AnonDeclaration(loc, isunion, Dsymbol::arraySyntaxCopy(decl)); | |
553 return ad; | |
554 } | |
555 | |
556 void AnonDeclaration::semantic(Scope *sc) | |
557 { | |
558 //printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this); | |
559 | |
560 Scope *scx = NULL; | |
561 if (scope) | |
562 { sc = scope; | |
563 scx = scope; | |
564 scope = NULL; | |
565 } | |
566 | |
567 assert(sc->parent); | |
568 | |
569 Dsymbol *parent = sc->parent->pastMixin(); | |
570 AggregateDeclaration *ad = parent->isAggregateDeclaration(); | |
571 | |
572 if (!ad || (!ad->isStructDeclaration() && !ad->isClassDeclaration())) | |
573 { | |
574 error("can only be a part of an aggregate"); | |
575 return; | |
576 } | |
577 | |
578 if (decl) | |
579 { | |
580 AnonymousAggregateDeclaration aad; | |
581 int adisunion; | |
582 | |
583 if (sc->anonAgg) | |
584 { ad = sc->anonAgg; | |
585 adisunion = sc->inunion; | |
586 } | |
587 else | |
588 adisunion = ad->isUnionDeclaration() != NULL; | |
589 | |
590 // printf("\tsc->anonAgg = %p\n", sc->anonAgg); | |
591 // printf("\tad = %p\n", ad); | |
592 // printf("\taad = %p\n", &aad); | |
593 | |
594 sc = sc->push(); | |
595 sc->anonAgg = &aad; | |
596 sc->stc &= ~(STCauto | STCscope | STCstatic); | |
597 sc->inunion = isunion; | |
598 sc->offset = 0; | |
599 sc->flags = 0; | |
600 aad.structalign = sc->structalign; | |
601 aad.parent = ad; | |
602 | |
603 for (unsigned i = 0; i < decl->dim; i++) | |
604 { | |
605 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
606 | |
607 s->semantic(sc); | |
608 if (isunion) | |
609 sc->offset = 0; | |
610 if (aad.sizeok == 2) | |
611 { | |
612 break; | |
613 } | |
614 } | |
615 sc = sc->pop(); | |
616 | |
617 // If failed due to forward references, unwind and try again later | |
618 if (aad.sizeok == 2) | |
619 { | |
620 ad->sizeok = 2; | |
621 //printf("\tsetting ad->sizeok %p to 2\n", ad); | |
622 if (!sc->anonAgg) | |
623 { | |
624 scope = scx ? scx : new Scope(*sc); | |
625 scope->setNoFree(); | |
626 scope->module->addDeferredSemantic(this); | |
627 } | |
628 //printf("\tforward reference %p\n", this); | |
629 return; | |
630 } | |
631 if (sem == 0) | |
632 { Module::dprogress++; | |
633 sem = 1; | |
634 //printf("\tcompleted %p\n", this); | |
635 } | |
636 else | |
637 ;//printf("\talready completed %p\n", this); | |
638 | |
639 // 0 sized structs are set to 1 byte | |
640 if (aad.structsize == 0) | |
641 { | |
642 aad.structsize = 1; | |
643 aad.alignsize = 1; | |
644 } | |
645 | |
646 // Align size of anonymous aggregate | |
647 //printf("aad.structalign = %d, aad.alignsize = %d, sc->offset = %d\n", aad.structalign, aad.alignsize, sc->offset); | |
648 ad->alignmember(aad.structalign, aad.alignsize, &sc->offset); | |
649 //ad->structsize = sc->offset; | |
650 //printf("sc->offset = %d\n", sc->offset); | |
651 | |
652 // Add members of aad to ad | |
653 //printf("\tadding members of aad to '%s'\n", ad->toChars()); | |
654 for (unsigned i = 0; i < aad.fields.dim; i++) | |
655 { | |
656 VarDeclaration *v = (VarDeclaration *)aad.fields.data[i]; | |
657 | |
658 v->offset += sc->offset; | |
659 ad->fields.push(v); | |
660 } | |
661 | |
662 // Add size of aad to ad | |
663 if (adisunion) | |
664 { | |
665 if (aad.structsize > ad->structsize) | |
666 ad->structsize = aad.structsize; | |
667 sc->offset = 0; | |
668 } | |
669 else | |
670 { | |
671 ad->structsize = sc->offset + aad.structsize; | |
672 sc->offset = ad->structsize; | |
673 } | |
674 | |
675 if (ad->alignsize < aad.alignsize) | |
676 ad->alignsize = aad.alignsize; | |
677 } | |
678 } | |
679 | |
680 | |
681 void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
682 { | |
683 buf->printf(isunion ? "union" : "struct"); | |
684 buf->writestring("\n{\n"); | |
685 if (decl) | |
686 { | |
687 for (unsigned i = 0; i < decl->dim; i++) | |
688 { | |
689 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
690 | |
691 //buf->writestring(" "); | |
692 s->toCBuffer(buf, hgs); | |
693 } | |
694 } | |
695 buf->writestring("}\n"); | |
696 } | |
697 | |
336 | 698 const char *AnonDeclaration::kind() |
159 | 699 { |
700 return (char *)(isunion ? "anonymous union" : "anonymous struct"); | |
701 } | |
702 | |
703 /********************************* PragmaDeclaration ****************************/ | |
704 | |
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
|
705 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
|
706 { |
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
|
707 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
|
708 |
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
|
709 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
|
710 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
|
711 { |
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
|
712 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
|
713 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
|
714 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
|
715 } |
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
|
716 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
|
717 } |
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
|
718 |
159 | 719 PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl) |
720 : AttribDeclaration(decl) | |
721 { | |
722 this->loc = loc; | |
723 this->ident = ident; | |
724 this->args = args; | |
725 } | |
726 | |
727 Dsymbol *PragmaDeclaration::syntaxCopy(Dsymbol *s) | |
728 { | |
729 PragmaDeclaration *pd; | |
730 | |
731 assert(!s); | |
732 pd = new PragmaDeclaration(loc, ident, | |
733 Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl)); | |
734 return pd; | |
735 } | |
736 | |
737 void PragmaDeclaration::semantic(Scope *sc) | |
738 { // Should be merged with PragmaStatement | |
739 | |
740 #if IN_LLVM | |
741 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
|
742 std::string arg1str; |
159 | 743 |
744 #endif | |
745 | |
746 //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); | |
747 if (ident == Id::msg) | |
748 { | |
749 if (args) | |
750 { | |
751 for (size_t i = 0; i < args->dim; i++) | |
752 { | |
753 Expression *e = (Expression *)args->data[i]; | |
754 | |
755 e = e->semantic(sc); | |
756 e = e->optimize(WANTvalue | WANTinterpret); | |
757 if (e->op == TOKstring) | |
758 { | |
759 StringExp *se = (StringExp *)e; | |
760 fprintf(stdmsg, "%.*s", (int)se->len, se->string); | |
761 } | |
762 else | |
763 error("string expected for message, not '%s'", e->toChars()); | |
764 } | |
765 fprintf(stdmsg, "\n"); | |
766 } | |
767 goto Lnodecl; | |
768 } | |
769 else if (ident == Id::lib) | |
770 { | |
771 if (!args || args->dim != 1) | |
772 error("string expected for library name"); | |
773 else | |
774 { | |
775 Expression *e = (Expression *)args->data[0]; | |
776 | |
777 e = e->semantic(sc); | |
778 e = e->optimize(WANTvalue | WANTinterpret); | |
779 args->data[0] = (void *)e; | |
780 if (e->op != TOKstring) | |
781 error("string expected for library name, not '%s'", e->toChars()); | |
782 else if (global.params.verbose) | |
783 { | |
784 StringExp *se = (StringExp *)e; | |
785 char *name = (char *)mem.malloc(se->len + 1); | |
786 memcpy(name, se->string, se->len); | |
787 name[se->len] = 0; | |
788 printf("library %s\n", name); | |
789 mem.free(name); | |
790 } | |
791 } | |
792 goto Lnodecl; | |
793 } | |
794 #if IN_GCC | |
795 else if (ident == Id::GNU_asm) | |
796 { | |
797 if (! args || args->dim != 2) | |
798 error("identifier and string expected for asm name"); | |
799 else | |
800 { | |
801 Expression *e; | |
802 Declaration *d = NULL; | |
803 StringExp *s = NULL; | |
804 | |
805 e = (Expression *)args->data[0]; | |
806 e = e->semantic(sc); | |
807 if (e->op == TOKvar) | |
808 { | |
809 d = ((VarExp *)e)->var; | |
810 if (! d->isFuncDeclaration() && ! d->isVarDeclaration()) | |
811 d = NULL; | |
812 } | |
813 if (!d) | |
814 error("first argument of GNU_asm must be a function or variable declaration"); | |
815 | |
816 e = (Expression *)args->data[1]; | |
817 e = e->semantic(sc); | |
818 e = e->optimize(WANTvalue); | |
819 if (e->op == TOKstring && ((StringExp *)e)->sz == 1) | |
820 s = ((StringExp *)e); | |
821 else | |
822 error("second argument of GNU_asm must be a char string"); | |
823 | |
824 if (d && s) | |
825 d->c_ident = Lexer::idPool((char*) s->string); | |
826 } | |
827 goto Lnodecl; | |
828 } | |
829 #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
|
830 |
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
|
831 // LLVMDC |
159 | 832 #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
|
833 |
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
|
834 // 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
|
835 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
|
836 { |
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
|
837 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
|
838 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
|
839 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
|
840 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
841 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
|
842 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
|
843 } |
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
|
844 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
|
845 } |
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
|
846 |
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
|
847 // 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
|
848 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
|
849 { |
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
|
850 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
|
851 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
852 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
|
853 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
|
854 } |
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
|
855 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
|
856 } |
159 | 857 |
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
|
858 // 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
|
859 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
|
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 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
|
862 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
863 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
|
864 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
|
865 } |
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 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
|
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 |
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 // 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
|
870 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
|
871 { |
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 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
|
873 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
874 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
|
875 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
|
876 } |
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 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
|
878 } |
159 | 879 |
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
|
880 // 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
|
881 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
|
882 { |
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 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
|
884 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
885 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
|
886 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
|
887 } |
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 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
|
889 } |
159 | 890 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
891 // 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
|
892 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
|
893 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
894 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
|
895 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
896 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
|
897 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
898 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
899 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
|
900 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
901 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
902 // 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
|
903 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
|
904 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
905 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
|
906 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
907 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
|
908 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
909 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
910 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
|
911 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
912 |
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
|
913 // 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
|
914 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
|
915 { |
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
|
916 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
|
917 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
918 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
|
919 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
|
920 } |
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
|
921 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
|
922 } |
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
|
923 |
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
|
924 // pragma(llvmdc, "string") { templdecl(s) } |
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
|
925 else if (ident == Id::llvmdc) |
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
|
926 { |
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
|
927 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
|
928 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
|
929 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
|
930 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
931 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
|
932 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
|
933 } |
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
|
934 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
|
935 { |
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
|
936 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
|
937 } |
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
|
938 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
|
939 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
940 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
|
941 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
|
942 } |
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
|
943 } |
159 | 944 |
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
|
945 #endif // LLVMDC |
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 |
159 | 947 else if (global.params.ignoreUnsupportedPragmas) |
948 { | |
949 if (global.params.verbose) | |
950 { | |
951 /* Print unrecognized pragmas | |
952 */ | |
953 printf("pragma %s", ident->toChars()); | |
954 if (args) | |
955 { | |
956 for (size_t i = 0; i < args->dim; i++) | |
957 { | |
958 Expression *e = (Expression *)args->data[i]; | |
959 e = e->semantic(sc); | |
960 e = e->optimize(WANTvalue | WANTinterpret); | |
961 if (i == 0) | |
962 printf(" ("); | |
963 else | |
964 printf(","); | |
965 printf("%s", e->toChars()); | |
966 } | |
967 if (args->dim) | |
968 printf(")"); | |
969 } | |
970 printf("\n"); | |
971 } | |
972 goto Lnodecl; | |
973 } | |
974 else | |
975 error("unrecognized pragma(%s)", ident->toChars()); | |
976 | |
977 if (decl) | |
978 { | |
979 for (unsigned i = 0; i < decl->dim; i++) | |
980 { | |
981 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
982 | |
983 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
|
984 |
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
|
985 // LLVMDC |
159 | 986 #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
|
987 |
159 | 988 if (llvm_internal) |
989 { | |
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
|
990 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
|
991 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
992 error("multiple LLVMDC 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
|
993 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
|
994 } |
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
|
995 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
|
996 { |
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
|
997 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
|
998 if (FuncDeclaration* fd = s->isFuncDeclaration()) |
159 | 999 { |
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
|
1000 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
|
1001 fd->intrinsicName = 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
|
1002 } |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1003 else if (TemplateDeclaration* td = s->isTemplateDeclaration()) |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1004 { |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1005 td->llvmInternal = llvm_internal; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1006 td->intrinsicName = arg1str; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1007 } |
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 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
|
1009 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1010 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
|
1011 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
|
1012 } |
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
|
1013 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
|
1014 |
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 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
|
1016 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
|
1017 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
|
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 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
|
1020 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1021 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
|
1022 fatal(); |
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 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
|
1025 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1026 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
|
1027 fatal(); |
159 | 1028 } |
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
|
1029 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
|
1030 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1031 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
|
1032 fatal(); |
159 | 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 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
|
1035 } |
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
|
1036 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
|
1037 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1038 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
|
1039 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1040 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1041 break; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1042 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1043 case LLVMva_copy: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1044 case LLVMva_end: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1045 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
|
1046 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1047 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
|
1048 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1049 else |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1050 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1051 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
|
1052 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
|
1053 } |
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
|
1054 break; |
159 | 1055 |
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
|
1056 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
|
1057 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
|
1058 break; |
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 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
|
1061 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
|
1062 { |
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 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
|
1064 } |
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
|
1065 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
|
1066 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1067 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
|
1068 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
|
1069 } |
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
|
1070 break; |
159 | 1071 |
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
|
1072 default: |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1073 warning("the LLVMDC 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
|
1074 } |
159 | 1075 } |
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
|
1076 |
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
|
1077 #endif // LLVMDC |
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 |
159 | 1079 } |
1080 } | |
1081 return; | |
1082 | |
1083 Lnodecl: | |
1084 if (decl) | |
1085 error("pragma is missing closing ';'"); | |
1086 } | |
1087 | |
1088 int PragmaDeclaration::oneMember(Dsymbol **ps) | |
1089 { | |
1090 *ps = NULL; | |
1091 return TRUE; | |
1092 } | |
1093 | |
336 | 1094 const char *PragmaDeclaration::kind() |
159 | 1095 { |
1096 return "pragma"; | |
1097 } | |
1098 | |
336 | 1099 void PragmaDeclaration::toObjFile(int multiobj) |
159 | 1100 { |
1101 if (ident == Id::lib) | |
1102 { | |
1103 assert(args && args->dim == 1); | |
1104 | |
1105 Expression *e = (Expression *)args->data[0]; | |
1106 | |
1107 assert(e->op == TOKstring); | |
1108 | |
1109 StringExp *se = (StringExp *)e; | |
1110 char *name = (char *)mem.malloc(se->len + 1); | |
1111 memcpy(name, se->string, se->len); | |
1112 name[se->len] = 0; | |
1113 obj_includelib(name); | |
1114 } | |
336 | 1115 AttribDeclaration::toObjFile(multiobj); |
159 | 1116 } |
1117 | |
1118 void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1119 { | |
1120 buf->printf("pragma(%s", ident->toChars()); | |
1121 if (args) | |
1122 { | |
1123 for (size_t i = 0; i < args->dim; i++) | |
1124 { | |
1125 Expression *e = (Expression *)args->data[i]; | |
1126 | |
1127 buf->writestring(", "); | |
1128 e->toCBuffer(buf, hgs); | |
1129 } | |
1130 } | |
1131 buf->writestring(")"); | |
1132 AttribDeclaration::toCBuffer(buf, hgs); | |
1133 } | |
1134 | |
1135 | |
1136 /********************************* ConditionalDeclaration ****************************/ | |
1137 | |
1138 ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl) | |
1139 : AttribDeclaration(decl) | |
1140 { | |
1141 //printf("ConditionalDeclaration::ConditionalDeclaration()\n"); | |
1142 this->condition = condition; | |
1143 this->elsedecl = elsedecl; | |
1144 } | |
1145 | |
1146 Dsymbol *ConditionalDeclaration::syntaxCopy(Dsymbol *s) | |
1147 { | |
1148 ConditionalDeclaration *dd; | |
1149 | |
1150 assert(!s); | |
1151 dd = new ConditionalDeclaration(condition->syntaxCopy(), | |
1152 Dsymbol::arraySyntaxCopy(decl), | |
1153 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1154 return dd; | |
1155 } | |
1156 | |
1157 | |
1158 int ConditionalDeclaration::oneMember(Dsymbol **ps) | |
1159 { | |
1160 //printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc); | |
1161 if (condition->inc) | |
1162 { | |
1163 Array *d = condition->include(NULL, NULL) ? decl : elsedecl; | |
1164 return Dsymbol::oneMembers(d, ps); | |
1165 } | |
1166 *ps = NULL; | |
1167 return TRUE; | |
1168 } | |
1169 | |
1170 void ConditionalDeclaration::emitComment(Scope *sc) | |
1171 { | |
1172 //printf("ConditionalDeclaration::emitComment(sc = %p)\n", sc); | |
1173 if (condition->inc) | |
1174 { | |
1175 AttribDeclaration::emitComment(sc); | |
1176 } | |
1177 } | |
1178 | |
1179 // Decide if 'then' or 'else' code should be included | |
1180 | |
1181 Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd) | |
1182 { | |
1183 //printf("ConditionalDeclaration::include()\n"); | |
1184 assert(condition); | |
1185 return condition->include(sc, sd) ? decl : elsedecl; | |
1186 } | |
1187 | |
1188 | |
1189 void ConditionalDeclaration::addComment(unsigned char *comment) | |
1190 { | |
1191 /* Because addComment is called by the parser, if we called | |
1192 * include() it would define a version before it was used. | |
1193 * But it's no problem to drill down to both decl and elsedecl, | |
1194 * so that's the workaround. | |
1195 */ | |
1196 | |
1197 if (comment) | |
1198 { | |
1199 Array *d = decl; | |
1200 | |
1201 for (int j = 0; j < 2; j++) | |
1202 { | |
1203 if (d) | |
1204 { | |
1205 for (unsigned i = 0; i < d->dim; i++) | |
1206 { Dsymbol *s; | |
1207 | |
1208 s = (Dsymbol *)d->data[i]; | |
1209 //printf("ConditionalDeclaration::addComment %s\n", s->toChars()); | |
1210 s->addComment(comment); | |
1211 } | |
1212 } | |
1213 d = elsedecl; | |
1214 } | |
1215 } | |
1216 } | |
1217 | |
1218 void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1219 { | |
1220 condition->toCBuffer(buf, hgs); | |
1221 if (decl || elsedecl) | |
1222 { | |
1223 buf->writenl(); | |
1224 buf->writeByte('{'); | |
1225 buf->writenl(); | |
1226 if (decl) | |
1227 { | |
1228 for (unsigned i = 0; i < decl->dim; i++) | |
1229 { | |
1230 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1231 | |
1232 buf->writestring(" "); | |
1233 s->toCBuffer(buf, hgs); | |
1234 } | |
1235 } | |
1236 buf->writeByte('}'); | |
1237 if (elsedecl) | |
1238 { | |
1239 buf->writenl(); | |
1240 buf->writestring("else"); | |
1241 buf->writenl(); | |
1242 buf->writeByte('{'); | |
1243 buf->writenl(); | |
1244 for (unsigned i = 0; i < elsedecl->dim; i++) | |
1245 { | |
1246 Dsymbol *s = (Dsymbol *)elsedecl->data[i]; | |
1247 | |
1248 buf->writestring(" "); | |
1249 s->toCBuffer(buf, hgs); | |
1250 } | |
1251 buf->writeByte('}'); | |
1252 } | |
1253 } | |
1254 else | |
1255 buf->writeByte(':'); | |
1256 buf->writenl(); | |
1257 } | |
1258 | |
1259 /***************************** StaticIfDeclaration ****************************/ | |
1260 | |
1261 StaticIfDeclaration::StaticIfDeclaration(Condition *condition, | |
1262 Array *decl, Array *elsedecl) | |
1263 : ConditionalDeclaration(condition, decl, elsedecl) | |
1264 { | |
1265 //printf("StaticIfDeclaration::StaticIfDeclaration()\n"); | |
1266 sd = NULL; | |
1267 addisdone = 0; | |
1268 } | |
1269 | |
1270 | |
1271 Dsymbol *StaticIfDeclaration::syntaxCopy(Dsymbol *s) | |
1272 { | |
1273 StaticIfDeclaration *dd; | |
1274 | |
1275 assert(!s); | |
1276 dd = new StaticIfDeclaration(condition->syntaxCopy(), | |
1277 Dsymbol::arraySyntaxCopy(decl), | |
1278 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1279 return dd; | |
1280 } | |
1281 | |
1282 | |
1283 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1284 { | |
336 | 1285 //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); |
159 | 1286 /* This is deferred until semantic(), so that |
1287 * expressions in the condition can refer to declarations | |
1288 * in the same scope, such as: | |
1289 * | |
1290 * template Foo(int i) | |
1291 * { | |
1292 * const int j = i + 1; | |
1293 * static if (j == 3) | |
1294 * const int k; | |
1295 * } | |
1296 */ | |
1297 this->sd = sd; | |
1298 int m = 0; | |
1299 | |
1300 if (memnum == 0) | |
1301 { m = AttribDeclaration::addMember(sc, sd, memnum); | |
1302 addisdone = 1; | |
1303 } | |
1304 return m; | |
1305 } | |
1306 | |
1307 | |
1308 void StaticIfDeclaration::semantic(Scope *sc) | |
1309 { | |
1310 Array *d = include(sc, sd); | |
1311 | |
336 | 1312 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); |
159 | 1313 if (d) |
1314 { | |
1315 if (!addisdone) | |
1316 { AttribDeclaration::addMember(sc, sd, 1); | |
1317 addisdone = 1; | |
1318 } | |
1319 | |
1320 for (unsigned i = 0; i < d->dim; i++) | |
1321 { | |
1322 Dsymbol *s = (Dsymbol *)d->data[i]; | |
1323 | |
1324 s->semantic(sc); | |
1325 } | |
1326 } | |
1327 } | |
1328 | |
336 | 1329 const char *StaticIfDeclaration::kind() |
159 | 1330 { |
1331 return "static if"; | |
1332 } | |
1333 | |
1334 | |
1335 /***************************** CompileDeclaration *****************************/ | |
1336 | |
1337 CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp) | |
1338 : AttribDeclaration(NULL) | |
1339 { | |
336 | 1340 this->loc = loc; |
159 | 1341 this->exp = exp; |
1342 this->sd = NULL; | |
336 | 1343 this->compiled = 0; |
159 | 1344 } |
1345 | |
1346 Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *s) | |
1347 { | |
1348 //printf("CompileDeclaration::syntaxCopy('%s')\n", toChars()); | |
1349 CompileDeclaration *sc = new CompileDeclaration(loc, exp->syntaxCopy()); | |
1350 return sc; | |
1351 } | |
1352 | |
1353 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1354 { | |
336 | 1355 //printf("CompileDeclaration::addMember(sc = %p)\n", sc); |
159 | 1356 this->sd = sd; |
336 | 1357 if (memnum == 0) |
1358 { /* No members yet, so parse the mixin now | |
1359 */ | |
1360 compileIt(sc); | |
1361 memnum |= AttribDeclaration::addMember(sc, sd, memnum); | |
1362 compiled = 1; | |
1363 } | |
159 | 1364 return memnum; |
1365 } | |
1366 | |
336 | 1367 void CompileDeclaration::compileIt(Scope *sc) |
1368 { | |
1369 //printf("CompileDeclaration::compileIt()\n"); | |
1370 exp = exp->semantic(sc); | |
1371 exp = resolveProperties(sc, exp); | |
1372 exp = exp->optimize(WANTvalue | WANTinterpret); | |
1373 if (exp->op != TOKstring) | |
1374 { exp->error("argument to mixin must be a string, not (%s)", exp->toChars()); | |
1375 } | |
1376 else | |
1377 { | |
1378 StringExp *se = (StringExp *)exp; | |
1379 se = se->toUTF8(sc); | |
1380 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); | |
1381 p.loc = loc; | |
1382 p.nextToken(); | |
1383 decl = p.parseDeclDefs(0); | |
1384 if (p.token.value != TOKeof) | |
1385 exp->error("incomplete mixin declaration (%s)", se->toChars()); | |
1386 } | |
1387 } | |
1388 | |
159 | 1389 void CompileDeclaration::semantic(Scope *sc) |
1390 { | |
1391 //printf("CompileDeclaration::semantic()\n"); | |
336 | 1392 |
1393 if (!compiled) | |
1394 { | |
1395 compileIt(sc); | |
1396 AttribDeclaration::addMember(sc, sd, 0); | |
1397 compiled = 1; | |
159 | 1398 } |
1399 AttribDeclaration::semantic(sc); | |
1400 } | |
1401 | |
1402 void CompileDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1403 { | |
1404 buf->writestring("mixin("); | |
1405 exp->toCBuffer(buf, hgs); | |
1406 buf->writestring(");"); | |
1407 buf->writenl(); | |
1408 } |