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