Mercurial > projects > ldc
annotate dmd/attrib.c @ 829:0a31c60a6bc1
.. and fixed the install target (hopefully)
author | elrood |
---|---|
date | Fri, 05 Dec 2008 22:01:50 +0100 |
parents | 7d16ce7ad19d |
children | bc982f1ad106 |
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; | |
618 for (unsigned i = 0; i < decl->dim; i++) | |
619 { | |
620 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
621 | |
622 s->semantic(sc); | |
623 if (isunion) | |
624 sc->offset = 0; | |
625 if (aad.sizeok == 2) | |
626 { | |
627 break; | |
628 } | |
629 } | |
630 sc = sc->pop(); | |
631 | |
632 // If failed due to forward references, unwind and try again later | |
633 if (aad.sizeok == 2) | |
634 { | |
635 ad->sizeok = 2; | |
636 //printf("\tsetting ad->sizeok %p to 2\n", ad); | |
637 if (!sc->anonAgg) | |
638 { | |
639 scope = scx ? scx : new Scope(*sc); | |
640 scope->setNoFree(); | |
641 scope->module->addDeferredSemantic(this); | |
642 } | |
643 //printf("\tforward reference %p\n", this); | |
644 return; | |
645 } | |
646 if (sem == 0) | |
647 { Module::dprogress++; | |
648 sem = 1; | |
649 //printf("\tcompleted %p\n", this); | |
650 } | |
651 else | |
652 ;//printf("\talready completed %p\n", this); | |
653 | |
654 // 0 sized structs are set to 1 byte | |
655 if (aad.structsize == 0) | |
656 { | |
657 aad.structsize = 1; | |
658 aad.alignsize = 1; | |
659 } | |
660 | |
661 // Align size of anonymous aggregate | |
662 //printf("aad.structalign = %d, aad.alignsize = %d, sc->offset = %d\n", aad.structalign, aad.alignsize, sc->offset); | |
663 ad->alignmember(aad.structalign, aad.alignsize, &sc->offset); | |
664 //ad->structsize = sc->offset; | |
665 //printf("sc->offset = %d\n", sc->offset); | |
666 | |
667 // 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
|
668 //printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars()); |
159 | 669 for (unsigned i = 0; i < aad.fields.dim; i++) |
670 { | |
671 VarDeclaration *v = (VarDeclaration *)aad.fields.data[i]; | |
672 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
673 // LDC |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
674 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
|
675 |
159 | 676 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
|
677 |
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 // 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
|
679 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
|
680 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
|
681 |
159 | 682 ad->fields.push(v); |
683 } | |
684 | |
685 // Add size of aad to ad | |
686 if (adisunion) | |
687 { | |
688 if (aad.structsize > ad->structsize) | |
689 ad->structsize = aad.structsize; | |
690 sc->offset = 0; | |
691 } | |
692 else | |
693 { | |
694 ad->structsize = sc->offset + aad.structsize; | |
695 sc->offset = ad->structsize; | |
696 } | |
697 | |
698 if (ad->alignsize < aad.alignsize) | |
699 ad->alignsize = aad.alignsize; | |
700 } | |
701 } | |
702 | |
703 | |
704 void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
705 { | |
706 buf->printf(isunion ? "union" : "struct"); | |
707 buf->writestring("\n{\n"); | |
708 if (decl) | |
709 { | |
710 for (unsigned i = 0; i < decl->dim; i++) | |
711 { | |
712 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
713 | |
714 //buf->writestring(" "); | |
715 s->toCBuffer(buf, hgs); | |
716 } | |
717 } | |
718 buf->writestring("}\n"); | |
719 } | |
720 | |
336 | 721 const char *AnonDeclaration::kind() |
159 | 722 { |
723 return (char *)(isunion ? "anonymous union" : "anonymous struct"); | |
724 } | |
725 | |
726 /********************************* PragmaDeclaration ****************************/ | |
727 | |
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
|
728 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
|
729 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
731 |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
733 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
|
734 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
736 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
|
737 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
|
738 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
740 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 |
159 | 742 PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl) |
743 : AttribDeclaration(decl) | |
744 { | |
745 this->loc = loc; | |
746 this->ident = ident; | |
747 this->args = args; | |
748 } | |
749 | |
750 Dsymbol *PragmaDeclaration::syntaxCopy(Dsymbol *s) | |
751 { | |
752 PragmaDeclaration *pd; | |
753 | |
754 assert(!s); | |
755 pd = new PragmaDeclaration(loc, ident, | |
756 Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl)); | |
757 return pd; | |
758 } | |
759 | |
760 void PragmaDeclaration::semantic(Scope *sc) | |
761 { // Should be merged with PragmaStatement | |
762 | |
763 #if IN_LLVM | |
764 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
|
765 std::string arg1str; |
159 | 766 |
767 #endif | |
768 | |
769 //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); | |
770 if (ident == Id::msg) | |
771 { | |
772 if (args) | |
773 { | |
774 for (size_t i = 0; i < args->dim; i++) | |
775 { | |
776 Expression *e = (Expression *)args->data[i]; | |
777 | |
778 e = e->semantic(sc); | |
779 e = e->optimize(WANTvalue | WANTinterpret); | |
780 if (e->op == TOKstring) | |
781 { | |
782 StringExp *se = (StringExp *)e; | |
794
661384d6a936
Fix warnings on x86-64. By fvbommel.
Christian Kamm <kamm incasoftware de>
parents:
737
diff
changeset
|
783 fprintf(stdmsg, "%.*s", (int)se->len, (char*)se->string); |
159 | 784 } |
785 else | |
786 error("string expected for message, not '%s'", e->toChars()); | |
787 } | |
788 fprintf(stdmsg, "\n"); | |
789 } | |
790 goto Lnodecl; | |
791 } | |
792 else if (ident == Id::lib) | |
793 { | |
794 if (!args || args->dim != 1) | |
795 error("string expected for library name"); | |
796 else | |
797 { | |
798 Expression *e = (Expression *)args->data[0]; | |
799 | |
800 e = e->semantic(sc); | |
801 e = e->optimize(WANTvalue | WANTinterpret); | |
802 args->data[0] = (void *)e; | |
803 if (e->op != TOKstring) | |
804 error("string expected for library name, not '%s'", e->toChars()); | |
805 else if (global.params.verbose) | |
806 { | |
807 StringExp *se = (StringExp *)e; | |
808 char *name = (char *)mem.malloc(se->len + 1); | |
809 memcpy(name, se->string, se->len); | |
810 name[se->len] = 0; | |
811 printf("library %s\n", name); | |
812 mem.free(name); | |
813 } | |
814 } | |
815 goto Lnodecl; | |
816 } | |
817 #if IN_GCC | |
818 else if (ident == Id::GNU_asm) | |
819 { | |
820 if (! args || args->dim != 2) | |
821 error("identifier and string expected for asm name"); | |
822 else | |
823 { | |
824 Expression *e; | |
825 Declaration *d = NULL; | |
826 StringExp *s = NULL; | |
827 | |
828 e = (Expression *)args->data[0]; | |
829 e = e->semantic(sc); | |
830 if (e->op == TOKvar) | |
831 { | |
832 d = ((VarExp *)e)->var; | |
833 if (! d->isFuncDeclaration() && ! d->isVarDeclaration()) | |
834 d = NULL; | |
835 } | |
836 if (!d) | |
837 error("first argument of GNU_asm must be a function or variable declaration"); | |
838 | |
839 e = (Expression *)args->data[1]; | |
840 e = e->semantic(sc); | |
841 e = e->optimize(WANTvalue); | |
842 if (e->op == TOKstring && ((StringExp *)e)->sz == 1) | |
843 s = ((StringExp *)e); | |
844 else | |
845 error("second argument of GNU_asm must be a char string"); | |
846 | |
847 if (d && s) | |
848 d->c_ident = Lexer::idPool((char*) s->string); | |
849 } | |
850 goto Lnodecl; | |
851 } | |
852 #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
|
853 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
854 // LDC |
159 | 855 #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
|
856 |
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
|
857 // 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
|
858 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
|
859 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
861 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
|
862 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
|
863 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
864 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
|
865 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
|
866 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
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 |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 // 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
|
871 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
|
872 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
873 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
|
874 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
875 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
|
876 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
|
877 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
879 } |
159 | 880 |
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
|
881 // 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
|
882 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
|
883 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
885 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
886 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
|
887 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
|
888 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
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 |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 // 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
|
893 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
|
894 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
896 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
897 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
|
898 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
|
899 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
901 } |
159 | 902 |
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
|
903 // 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
|
904 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
|
905 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
907 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
908 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
|
909 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
|
910 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
912 } |
159 | 913 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
914 // 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
|
915 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
|
916 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
917 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
|
918 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
919 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
|
920 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
921 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
922 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
|
923 } |
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 // 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
|
926 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
|
927 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
928 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
|
929 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
930 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
|
931 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
932 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
933 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
|
934 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
935 |
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
|
936 // 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
|
937 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
|
938 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
940 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
941 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
|
942 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
|
943 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
945 } |
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
|
946 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
947 // pragma(ldc, "string") { templdecl(s) } |
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
948 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
|
949 { |
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 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
|
951 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
|
952 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
|
953 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
954 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
|
955 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
|
956 } |
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 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
|
958 { |
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 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
|
960 } |
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 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
|
962 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
963 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
|
964 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
|
965 } |
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 } |
159 | 967 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
968 #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
|
969 |
159 | 970 else if (global.params.ignoreUnsupportedPragmas) |
971 { | |
972 if (global.params.verbose) | |
973 { | |
974 /* Print unrecognized pragmas | |
975 */ | |
976 printf("pragma %s", ident->toChars()); | |
977 if (args) | |
978 { | |
979 for (size_t i = 0; i < args->dim; i++) | |
980 { | |
981 Expression *e = (Expression *)args->data[i]; | |
982 e = e->semantic(sc); | |
983 e = e->optimize(WANTvalue | WANTinterpret); | |
984 if (i == 0) | |
985 printf(" ("); | |
986 else | |
987 printf(","); | |
988 printf("%s", e->toChars()); | |
989 } | |
990 if (args->dim) | |
991 printf(")"); | |
992 } | |
993 printf("\n"); | |
994 } | |
995 goto Lnodecl; | |
996 } | |
997 else | |
998 error("unrecognized pragma(%s)", ident->toChars()); | |
999 | |
1000 if (decl) | |
1001 { | |
1002 for (unsigned i = 0; i < decl->dim; i++) | |
1003 { | |
1004 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1005 | |
1006 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
|
1007 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1008 // LDC |
159 | 1009 #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
|
1010 |
159 | 1011 if (llvm_internal) |
1012 { | |
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
|
1013 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
|
1014 { |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1015 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
|
1016 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
|
1017 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1019 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1020 case 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
|
1021 if (FuncDeclaration* fd = s->isFuncDeclaration()) |
159 | 1022 { |
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
|
1023 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
|
1024 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
|
1025 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
|
1026 ((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
|
1027 } |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1028 else if (TemplateDeclaration* td = s->isTemplateDeclaration()) |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1029 { |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1030 td->llvmInternal = llvm_internal; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1031 td->intrinsicName = arg1str; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1032 } |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1033 else |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1035 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
|
1036 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
|
1037 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1039 |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1040 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
|
1041 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
|
1042 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
|
1043 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1045 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1046 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
|
1047 fatal(); |
159 | 1048 } |
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
|
1049 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
|
1050 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1051 error("the '%s' pragma 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
|
1052 fatal(); |
159 | 1053 } |
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
|
1054 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
|
1055 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1056 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
|
1057 fatal(); |
159 | 1058 } |
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
|
1059 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
|
1060 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1062 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1063 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
|
1064 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1065 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1066 break; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1067 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1068 case LLVMva_copy: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1069 case LLVMva_end: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1070 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
|
1071 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1072 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
|
1073 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1074 else |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1075 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1076 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
|
1077 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
|
1078 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 break; |
159 | 1080 |
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
|
1081 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
|
1082 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
|
1083 break; |
159 | 1084 |
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
|
1085 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
|
1086 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
|
1087 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1089 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1091 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1092 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
|
1093 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
|
1094 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 break; |
159 | 1096 |
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
|
1097 default: |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1098 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
|
1099 } |
159 | 1100 } |
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
|
1101 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1102 #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
|
1103 |
159 | 1104 } |
1105 } | |
1106 return; | |
1107 | |
1108 Lnodecl: | |
1109 if (decl) | |
1110 error("pragma is missing closing ';'"); | |
1111 } | |
1112 | |
1113 int PragmaDeclaration::oneMember(Dsymbol **ps) | |
1114 { | |
1115 *ps = NULL; | |
1116 return TRUE; | |
1117 } | |
1118 | |
336 | 1119 const char *PragmaDeclaration::kind() |
159 | 1120 { |
1121 return "pragma"; | |
1122 } | |
1123 | |
336 | 1124 void PragmaDeclaration::toObjFile(int multiobj) |
159 | 1125 { |
1126 if (ident == Id::lib) | |
1127 { | |
1128 assert(args && args->dim == 1); | |
1129 | |
1130 Expression *e = (Expression *)args->data[0]; | |
1131 | |
1132 assert(e->op == TOKstring); | |
1133 | |
1134 StringExp *se = (StringExp *)e; | |
1135 char *name = (char *)mem.malloc(se->len + 1); | |
1136 memcpy(name, se->string, se->len); | |
1137 name[se->len] = 0; | |
1138 obj_includelib(name); | |
1139 } | |
336 | 1140 AttribDeclaration::toObjFile(multiobj); |
159 | 1141 } |
1142 | |
1143 void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1144 { | |
1145 buf->printf("pragma(%s", ident->toChars()); | |
1146 if (args) | |
1147 { | |
1148 for (size_t i = 0; i < args->dim; i++) | |
1149 { | |
1150 Expression *e = (Expression *)args->data[i]; | |
1151 | |
1152 buf->writestring(", "); | |
1153 e->toCBuffer(buf, hgs); | |
1154 } | |
1155 } | |
1156 buf->writestring(")"); | |
1157 AttribDeclaration::toCBuffer(buf, hgs); | |
1158 } | |
1159 | |
1160 | |
1161 /********************************* ConditionalDeclaration ****************************/ | |
1162 | |
1163 ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl) | |
1164 : AttribDeclaration(decl) | |
1165 { | |
1166 //printf("ConditionalDeclaration::ConditionalDeclaration()\n"); | |
1167 this->condition = condition; | |
1168 this->elsedecl = elsedecl; | |
1169 } | |
1170 | |
1171 Dsymbol *ConditionalDeclaration::syntaxCopy(Dsymbol *s) | |
1172 { | |
1173 ConditionalDeclaration *dd; | |
1174 | |
1175 assert(!s); | |
1176 dd = new ConditionalDeclaration(condition->syntaxCopy(), | |
1177 Dsymbol::arraySyntaxCopy(decl), | |
1178 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1179 return dd; | |
1180 } | |
1181 | |
1182 | |
1183 int ConditionalDeclaration::oneMember(Dsymbol **ps) | |
1184 { | |
1185 //printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc); | |
1186 if (condition->inc) | |
1187 { | |
1188 Array *d = condition->include(NULL, NULL) ? decl : elsedecl; | |
1189 return Dsymbol::oneMembers(d, ps); | |
1190 } | |
1191 *ps = NULL; | |
1192 return TRUE; | |
1193 } | |
1194 | |
1195 void ConditionalDeclaration::emitComment(Scope *sc) | |
1196 { | |
1197 //printf("ConditionalDeclaration::emitComment(sc = %p)\n", sc); | |
1198 if (condition->inc) | |
1199 { | |
1200 AttribDeclaration::emitComment(sc); | |
1201 } | |
1202 } | |
1203 | |
1204 // Decide if 'then' or 'else' code should be included | |
1205 | |
1206 Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd) | |
1207 { | |
1208 //printf("ConditionalDeclaration::include()\n"); | |
1209 assert(condition); | |
1210 return condition->include(sc, sd) ? decl : elsedecl; | |
1211 } | |
1212 | |
1213 | |
1214 void ConditionalDeclaration::addComment(unsigned char *comment) | |
1215 { | |
1216 /* Because addComment is called by the parser, if we called | |
1217 * include() it would define a version before it was used. | |
1218 * But it's no problem to drill down to both decl and elsedecl, | |
1219 * so that's the workaround. | |
1220 */ | |
1221 | |
1222 if (comment) | |
1223 { | |
1224 Array *d = decl; | |
1225 | |
1226 for (int j = 0; j < 2; j++) | |
1227 { | |
1228 if (d) | |
1229 { | |
1230 for (unsigned i = 0; i < d->dim; i++) | |
1231 { Dsymbol *s; | |
1232 | |
1233 s = (Dsymbol *)d->data[i]; | |
1234 //printf("ConditionalDeclaration::addComment %s\n", s->toChars()); | |
1235 s->addComment(comment); | |
1236 } | |
1237 } | |
1238 d = elsedecl; | |
1239 } | |
1240 } | |
1241 } | |
1242 | |
1243 void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1244 { | |
1245 condition->toCBuffer(buf, hgs); | |
1246 if (decl || elsedecl) | |
1247 { | |
1248 buf->writenl(); | |
1249 buf->writeByte('{'); | |
1250 buf->writenl(); | |
1251 if (decl) | |
1252 { | |
1253 for (unsigned i = 0; i < decl->dim; i++) | |
1254 { | |
1255 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1256 | |
1257 buf->writestring(" "); | |
1258 s->toCBuffer(buf, hgs); | |
1259 } | |
1260 } | |
1261 buf->writeByte('}'); | |
1262 if (elsedecl) | |
1263 { | |
1264 buf->writenl(); | |
1265 buf->writestring("else"); | |
1266 buf->writenl(); | |
1267 buf->writeByte('{'); | |
1268 buf->writenl(); | |
1269 for (unsigned i = 0; i < elsedecl->dim; i++) | |
1270 { | |
1271 Dsymbol *s = (Dsymbol *)elsedecl->data[i]; | |
1272 | |
1273 buf->writestring(" "); | |
1274 s->toCBuffer(buf, hgs); | |
1275 } | |
1276 buf->writeByte('}'); | |
1277 } | |
1278 } | |
1279 else | |
1280 buf->writeByte(':'); | |
1281 buf->writenl(); | |
1282 } | |
1283 | |
1284 /***************************** StaticIfDeclaration ****************************/ | |
1285 | |
1286 StaticIfDeclaration::StaticIfDeclaration(Condition *condition, | |
1287 Array *decl, Array *elsedecl) | |
1288 : ConditionalDeclaration(condition, decl, elsedecl) | |
1289 { | |
1290 //printf("StaticIfDeclaration::StaticIfDeclaration()\n"); | |
1291 sd = NULL; | |
1292 addisdone = 0; | |
1293 } | |
1294 | |
1295 | |
1296 Dsymbol *StaticIfDeclaration::syntaxCopy(Dsymbol *s) | |
1297 { | |
1298 StaticIfDeclaration *dd; | |
1299 | |
1300 assert(!s); | |
1301 dd = new StaticIfDeclaration(condition->syntaxCopy(), | |
1302 Dsymbol::arraySyntaxCopy(decl), | |
1303 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1304 return dd; | |
1305 } | |
1306 | |
1307 | |
1308 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1309 { | |
336 | 1310 //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); |
159 | 1311 /* This is deferred until semantic(), so that |
1312 * expressions in the condition can refer to declarations | |
1313 * in the same scope, such as: | |
1314 * | |
1315 * template Foo(int i) | |
1316 * { | |
1317 * const int j = i + 1; | |
1318 * static if (j == 3) | |
1319 * const int k; | |
1320 * } | |
1321 */ | |
1322 this->sd = sd; | |
1323 int m = 0; | |
1324 | |
1325 if (memnum == 0) | |
1326 { m = AttribDeclaration::addMember(sc, sd, memnum); | |
1327 addisdone = 1; | |
1328 } | |
1329 return m; | |
1330 } | |
1331 | |
1332 | |
1333 void StaticIfDeclaration::semantic(Scope *sc) | |
1334 { | |
1335 Array *d = include(sc, sd); | |
1336 | |
336 | 1337 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); |
159 | 1338 if (d) |
1339 { | |
1340 if (!addisdone) | |
1341 { AttribDeclaration::addMember(sc, sd, 1); | |
1342 addisdone = 1; | |
1343 } | |
1344 | |
1345 for (unsigned i = 0; i < d->dim; i++) | |
1346 { | |
1347 Dsymbol *s = (Dsymbol *)d->data[i]; | |
1348 | |
1349 s->semantic(sc); | |
1350 } | |
1351 } | |
1352 } | |
1353 | |
336 | 1354 const char *StaticIfDeclaration::kind() |
159 | 1355 { |
1356 return "static if"; | |
1357 } | |
1358 | |
1359 | |
1360 /***************************** CompileDeclaration *****************************/ | |
1361 | |
1362 CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp) | |
1363 : AttribDeclaration(NULL) | |
1364 { | |
336 | 1365 this->loc = loc; |
159 | 1366 this->exp = exp; |
1367 this->sd = NULL; | |
336 | 1368 this->compiled = 0; |
159 | 1369 } |
1370 | |
1371 Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *s) | |
1372 { | |
1373 //printf("CompileDeclaration::syntaxCopy('%s')\n", toChars()); | |
1374 CompileDeclaration *sc = new CompileDeclaration(loc, exp->syntaxCopy()); | |
1375 return sc; | |
1376 } | |
1377 | |
1378 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1379 { | |
336 | 1380 //printf("CompileDeclaration::addMember(sc = %p)\n", sc); |
159 | 1381 this->sd = sd; |
336 | 1382 if (memnum == 0) |
1383 { /* No members yet, so parse the mixin now | |
1384 */ | |
1385 compileIt(sc); | |
1386 memnum |= AttribDeclaration::addMember(sc, sd, memnum); | |
1387 compiled = 1; | |
1388 } | |
159 | 1389 return memnum; |
1390 } | |
1391 | |
336 | 1392 void CompileDeclaration::compileIt(Scope *sc) |
1393 { | |
1394 //printf("CompileDeclaration::compileIt()\n"); | |
1395 exp = exp->semantic(sc); | |
1396 exp = resolveProperties(sc, exp); | |
1397 exp = exp->optimize(WANTvalue | WANTinterpret); | |
1398 if (exp->op != TOKstring) | |
1399 { exp->error("argument to mixin must be a string, not (%s)", exp->toChars()); | |
1400 } | |
1401 else | |
1402 { | |
1403 StringExp *se = (StringExp *)exp; | |
1404 se = se->toUTF8(sc); | |
1405 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); | |
1406 p.loc = loc; | |
1407 p.nextToken(); | |
1408 decl = p.parseDeclDefs(0); | |
1409 if (p.token.value != TOKeof) | |
1410 exp->error("incomplete mixin declaration (%s)", se->toChars()); | |
1411 } | |
1412 } | |
1413 | |
159 | 1414 void CompileDeclaration::semantic(Scope *sc) |
1415 { | |
1416 //printf("CompileDeclaration::semantic()\n"); | |
336 | 1417 |
1418 if (!compiled) | |
1419 { | |
1420 compileIt(sc); | |
1421 AttribDeclaration::addMember(sc, sd, 0); | |
1422 compiled = 1; | |
159 | 1423 } |
1424 AttribDeclaration::semantic(sc); | |
1425 } | |
1426 | |
1427 void CompileDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1428 { | |
1429 buf->writestring("mixin("); | |
1430 exp->toCBuffer(buf, hgs); | |
1431 buf->writestring(");"); | |
1432 buf->writenl(); | |
1433 } |