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