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