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