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