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