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