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