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