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