Mercurial > projects > ldc
annotate dmd/attrib.c @ 1602:a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
---
dmd/aggregate.h | 24 ++++-
dmd/attrib.c | 63 ++++++----
dmd/attrib.h | 10 +-
dmd/declaration.h | 5 +-
dmd/func.c | 337 ++++++++++++++++++++++-------------------------------
dmd/mars.c | 2 +-
dmd/mars.h | 7 +
dmd/mtype.h | 13 ++-
dmd/parse.c | 32 ++++-
dmd/parse.h | 14 ++-
dmd/scope.h | 2 +-
11 files changed, 263 insertions(+), 246 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:19 -0300 |
parents | def7a1d494fd |
children | 44b145be2ef5 |
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, |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
81 StorageClass stc, enum LINK linkage, enum PROT protection, int explicitProtection, |
1587 | 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, | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
116 StorageClass stc, enum LINK linkage, enum PROT protection, int explicitProtection, |
1587 | 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 | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
363 StorageClassDeclaration::StorageClassDeclaration(StorageClass stc, Array *decl) |
159 | 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 { | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
382 StorageClass scstc = sc->stc; |
1587 | 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 { |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
405 StorageClass 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 | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
424 void StorageClassDeclaration::stcToCBuffer(OutBuffer *buf, StorageClass stc) |
159 | 425 { |
426 struct SCstring | |
427 { | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
428 StorageClass stc; |
159 | 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 }, | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
444 { STClazy, TOKlazy }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
445 { STCalias, TOKalias }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
446 { STCout, TOKout }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
447 { STCin, TOKin }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
448 #if DMDV2 |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
449 { STCimmutable, TOKimmutable }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
450 { STCshared, TOKshared }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
451 { STCnothrow, TOKnothrow }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
452 { STCpure, TOKpure }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
453 { STCref, TOKref }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
454 { STCtls, TOKtls }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
455 { STCgshared, TOKgshared }, |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
456 #endif |
159 | 457 }; |
458 | |
459 for (int i = 0; i < sizeof(table)/sizeof(table[0]); i++) | |
460 { | |
461 if (stc & table[i].stc) | |
462 { | |
463 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
|
464 buf->writeByte(' '); |
159 | 465 } |
466 } | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
467 } |
159 | 468 |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
469 void StorageClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
470 { |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
471 stcToCBuffer(buf, stc); |
159 | 472 AttribDeclaration::toCBuffer(buf, hgs); |
473 } | |
474 | |
475 /********************************* LinkDeclaration ****************************/ | |
476 | |
477 LinkDeclaration::LinkDeclaration(enum LINK p, Array *decl) | |
478 : AttribDeclaration(decl) | |
479 { | |
480 //printf("LinkDeclaration(linkage = %d, decl = %p)\n", p, decl); | |
481 linkage = p; | |
482 } | |
483 | |
484 Dsymbol *LinkDeclaration::syntaxCopy(Dsymbol *s) | |
485 { | |
486 LinkDeclaration *ld; | |
487 | |
488 assert(!s); | |
489 ld = new LinkDeclaration(linkage, Dsymbol::arraySyntaxCopy(decl)); | |
490 return ld; | |
491 } | |
492 | |
1587 | 493 void LinkDeclaration::setScope(Scope *sc) |
494 { | |
495 //printf("LinkDeclaration::setScope(linkage = %d, decl = %p)\n", linkage, decl); | |
496 if (decl) | |
497 { | |
498 setScopeNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); | |
499 } | |
500 } | |
501 | |
159 | 502 void LinkDeclaration::semantic(Scope *sc) |
503 { | |
504 //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); | |
505 if (decl) | |
506 { | |
1587 | 507 semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); |
159 | 508 } |
509 } | |
510 | |
511 void LinkDeclaration::semantic3(Scope *sc) | |
512 { | |
513 //printf("LinkDeclaration::semantic3(linkage = %d, decl = %p)\n", linkage, decl); | |
514 if (decl) | |
515 { enum LINK linkage_save = sc->linkage; | |
516 | |
517 sc->linkage = linkage; | |
518 for (unsigned i = 0; i < decl->dim; i++) | |
519 { | |
520 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
521 | |
522 s->semantic3(sc); | |
523 } | |
524 sc->linkage = linkage_save; | |
525 } | |
526 else | |
527 { | |
528 sc->linkage = linkage; | |
529 } | |
530 } | |
531 | |
532 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
|
533 { const char *p; |
159 | 534 |
535 switch (linkage) | |
536 { | |
537 case LINKd: p = "D"; break; | |
538 case LINKc: p = "C"; break; | |
539 case LINKcpp: p = "C++"; break; | |
540 case LINKwindows: p = "Windows"; break; | |
541 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
|
542 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
543 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
716
diff
changeset
|
544 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
|
545 |
159 | 546 default: |
547 assert(0); | |
548 break; | |
549 } | |
550 buf->writestring("extern ("); | |
551 buf->writestring(p); | |
552 buf->writestring(") "); | |
553 AttribDeclaration::toCBuffer(buf, hgs); | |
554 } | |
555 | |
556 char *LinkDeclaration::toChars() | |
557 { | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
846
diff
changeset
|
558 return (char *)"extern ()"; |
159 | 559 } |
560 | |
561 /********************************* ProtDeclaration ****************************/ | |
562 | |
563 ProtDeclaration::ProtDeclaration(enum PROT p, Array *decl) | |
564 : AttribDeclaration(decl) | |
565 { | |
566 protection = p; | |
567 //printf("decl = %p\n", decl); | |
568 } | |
569 | |
570 Dsymbol *ProtDeclaration::syntaxCopy(Dsymbol *s) | |
571 { | |
572 ProtDeclaration *pd; | |
573 | |
574 assert(!s); | |
575 pd = new ProtDeclaration(protection, Dsymbol::arraySyntaxCopy(decl)); | |
576 return pd; | |
577 } | |
578 | |
1587 | 579 void ProtDeclaration::setScope(Scope *sc) |
580 { | |
581 if (decl) | |
582 { | |
583 setScopeNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); | |
584 } | |
585 } | |
586 | |
587 void ProtDeclaration::importAll(Scope *sc) | |
588 { | |
589 Scope *newsc = sc; | |
590 if (sc->protection != protection || | |
591 sc->explicitProtection != 1) | |
592 { | |
593 // create new one for changes | |
594 newsc = new Scope(*sc); | |
595 newsc->flags &= ~SCOPEfree; | |
596 newsc->protection = protection; | |
597 newsc->explicitProtection = 1; | |
598 } | |
599 | |
600 for (int i = 0; i < decl->dim; i++) | |
601 { | |
602 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
603 s->importAll(newsc); | |
604 } | |
605 | |
606 if (newsc != sc) | |
607 newsc->pop(); | |
608 } | |
609 | |
159 | 610 void ProtDeclaration::semantic(Scope *sc) |
611 { | |
612 if (decl) | |
1587 | 613 { |
614 semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); | |
159 | 615 } |
616 } | |
617 | |
1587 | 618 void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection) |
619 { | |
620 const char *p; | |
159 | 621 |
622 switch (protection) | |
623 { | |
624 case PROTprivate: p = "private"; break; | |
625 case PROTpackage: p = "package"; break; | |
626 case PROTprotected: p = "protected"; break; | |
627 case PROTpublic: p = "public"; break; | |
628 case PROTexport: p = "export"; break; | |
629 default: | |
630 assert(0); | |
631 break; | |
632 } | |
633 buf->writestring(p); | |
1587 | 634 buf->writeByte(' '); |
635 } | |
636 | |
637 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
638 { | |
639 protectionToCBuffer(buf, protection); | |
159 | 640 AttribDeclaration::toCBuffer(buf, hgs); |
641 } | |
642 | |
643 /********************************* AlignDeclaration ****************************/ | |
644 | |
710
20a5180f2e80
Make align(n), n != 1 an error.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
645 AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl) |
159 | 646 : AttribDeclaration(decl) |
647 { | |
710
20a5180f2e80
Make align(n), n != 1 an error.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
648 this->loc = loc; |
159 | 649 salign = sa; |
650 } | |
651 | |
652 Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s) | |
653 { | |
654 AlignDeclaration *ad; | |
655 | |
656 assert(!s); | |
710
20a5180f2e80
Make align(n), n != 1 an error.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
657 ad = new AlignDeclaration(loc, salign, Dsymbol::arraySyntaxCopy(decl)); |
159 | 658 return ad; |
659 } | |
660 | |
1587 | 661 void AlignDeclaration::setScope(Scope *sc) |
662 { | |
663 //printf("\tAlignDeclaration::setScope '%s'\n",toChars()); | |
664 if (decl) | |
665 { | |
666 setScopeNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); | |
667 } | |
668 } | |
669 | |
159 | 670 void AlignDeclaration::semantic(Scope *sc) |
671 { | |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
723
diff
changeset
|
672 // 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
|
673 // 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
|
674 // other alignments are simply ignored. my tests show this is what llvm-gcc does too ... |
1587 | 675 { |
676 semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); | |
159 | 677 } |
678 } | |
679 | |
680 | |
681 void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
682 { | |
683 buf->printf("align (%d)", salign); | |
684 AttribDeclaration::toCBuffer(buf, hgs); | |
685 } | |
686 | |
687 /********************************* AnonDeclaration ****************************/ | |
688 | |
689 AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl) | |
690 : AttribDeclaration(decl) | |
691 { | |
692 this->loc = loc; | |
693 this->isunion = isunion; | |
694 this->sem = 0; | |
695 } | |
696 | |
697 Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) | |
698 { | |
699 AnonDeclaration *ad; | |
700 | |
701 assert(!s); | |
702 ad = new AnonDeclaration(loc, isunion, Dsymbol::arraySyntaxCopy(decl)); | |
703 return ad; | |
704 } | |
705 | |
706 void AnonDeclaration::semantic(Scope *sc) | |
707 { | |
708 //printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this); | |
709 | |
710 Scope *scx = NULL; | |
711 if (scope) | |
712 { sc = scope; | |
713 scx = scope; | |
714 scope = NULL; | |
715 } | |
716 | |
717 assert(sc->parent); | |
718 | |
719 Dsymbol *parent = sc->parent->pastMixin(); | |
720 AggregateDeclaration *ad = parent->isAggregateDeclaration(); | |
721 | |
722 if (!ad || (!ad->isStructDeclaration() && !ad->isClassDeclaration())) | |
723 { | |
724 error("can only be a part of an aggregate"); | |
725 return; | |
726 } | |
727 | |
728 if (decl) | |
729 { | |
730 AnonymousAggregateDeclaration aad; | |
731 int adisunion; | |
732 | |
733 if (sc->anonAgg) | |
734 { ad = sc->anonAgg; | |
735 adisunion = sc->inunion; | |
736 } | |
737 else | |
738 adisunion = ad->isUnionDeclaration() != NULL; | |
739 | |
740 // printf("\tsc->anonAgg = %p\n", sc->anonAgg); | |
741 // printf("\tad = %p\n", ad); | |
742 // printf("\taad = %p\n", &aad); | |
743 | |
744 sc = sc->push(); | |
745 sc->anonAgg = &aad; | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
746 sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls); |
159 | 747 sc->inunion = isunion; |
748 sc->offset = 0; | |
749 sc->flags = 0; | |
750 aad.structalign = sc->structalign; | |
751 aad.parent = ad; | |
846
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
816
diff
changeset
|
752 |
159 | 753 for (unsigned i = 0; i < decl->dim; i++) |
754 { | |
755 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
756 | |
757 s->semantic(sc); | |
758 if (isunion) | |
759 sc->offset = 0; | |
760 if (aad.sizeok == 2) | |
761 { | |
762 break; | |
763 } | |
764 } | |
765 sc = sc->pop(); | |
766 | |
767 // If failed due to forward references, unwind and try again later | |
768 if (aad.sizeok == 2) | |
769 { | |
770 ad->sizeok = 2; | |
771 //printf("\tsetting ad->sizeok %p to 2\n", ad); | |
772 if (!sc->anonAgg) | |
773 { | |
774 scope = scx ? scx : new Scope(*sc); | |
775 scope->setNoFree(); | |
776 scope->module->addDeferredSemantic(this); | |
777 } | |
778 //printf("\tforward reference %p\n", this); | |
779 return; | |
780 } | |
781 if (sem == 0) | |
782 { Module::dprogress++; | |
783 sem = 1; | |
784 //printf("\tcompleted %p\n", this); | |
785 } | |
786 else | |
787 ;//printf("\talready completed %p\n", this); | |
788 | |
789 // 0 sized structs are set to 1 byte | |
790 if (aad.structsize == 0) | |
791 { | |
792 aad.structsize = 1; | |
793 aad.alignsize = 1; | |
794 } | |
795 | |
796 // Align size of anonymous aggregate | |
797 //printf("aad.structalign = %d, aad.alignsize = %d, sc->offset = %d\n", aad.structalign, aad.alignsize, sc->offset); | |
798 ad->alignmember(aad.structalign, aad.alignsize, &sc->offset); | |
799 //ad->structsize = sc->offset; | |
800 //printf("sc->offset = %d\n", sc->offset); | |
801 | |
802 // 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
|
803 //printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars()); |
159 | 804 for (unsigned i = 0; i < aad.fields.dim; i++) |
805 { | |
806 VarDeclaration *v = (VarDeclaration *)aad.fields.data[i]; | |
807 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
808 // LDC |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
794
diff
changeset
|
809 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
|
810 |
159 | 811 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
|
812 |
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
|
813 // 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
|
814 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
|
815 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
|
816 |
159 | 817 ad->fields.push(v); |
818 } | |
819 | |
820 // Add size of aad to ad | |
821 if (adisunion) | |
822 { | |
823 if (aad.structsize > ad->structsize) | |
824 ad->structsize = aad.structsize; | |
825 sc->offset = 0; | |
826 } | |
827 else | |
828 { | |
829 ad->structsize = sc->offset + aad.structsize; | |
830 sc->offset = ad->structsize; | |
831 } | |
832 | |
833 if (ad->alignsize < aad.alignsize) | |
834 ad->alignsize = aad.alignsize; | |
835 } | |
836 } | |
837 | |
838 | |
839 void AnonDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
840 { | |
841 buf->printf(isunion ? "union" : "struct"); | |
842 buf->writestring("\n{\n"); | |
843 if (decl) | |
844 { | |
845 for (unsigned i = 0; i < decl->dim; i++) | |
846 { | |
847 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
848 | |
849 //buf->writestring(" "); | |
850 s->toCBuffer(buf, hgs); | |
851 } | |
852 } | |
853 buf->writestring("}\n"); | |
854 } | |
855 | |
336 | 856 const char *AnonDeclaration::kind() |
159 | 857 { |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
846
diff
changeset
|
858 return (isunion ? "anonymous union" : "anonymous struct"); |
159 | 859 } |
860 | |
861 /********************************* PragmaDeclaration ****************************/ | |
862 | |
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
|
863 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
|
864 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
865 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
|
866 |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
867 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
|
868 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
|
869 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
870 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
|
871 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
|
872 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
|
873 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
874 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
|
875 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
876 |
159 | 877 PragmaDeclaration::PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl) |
878 : AttribDeclaration(decl) | |
879 { | |
880 this->loc = loc; | |
881 this->ident = ident; | |
882 this->args = args; | |
883 } | |
884 | |
885 Dsymbol *PragmaDeclaration::syntaxCopy(Dsymbol *s) | |
886 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
887 //printf("PragmaDeclaration::syntaxCopy(%s)\n", toChars()); |
159 | 888 PragmaDeclaration *pd; |
889 | |
890 assert(!s); | |
891 pd = new PragmaDeclaration(loc, ident, | |
892 Expression::arraySyntaxCopy(args), Dsymbol::arraySyntaxCopy(decl)); | |
893 return pd; | |
894 } | |
895 | |
1587 | 896 void PragmaDeclaration::setScope(Scope *sc) |
897 { | |
898 #if TARGET_NET | |
899 if (ident == Lexer::idPool("assembly")) | |
900 { | |
901 if (!args || args->dim != 1) | |
902 { | |
903 error("pragma has invalid number of arguments"); | |
904 } | |
905 else | |
906 { | |
907 Expression *e = (Expression *)args->data[0]; | |
908 e = e->semantic(sc); | |
909 e = e->optimize(WANTvalue | WANTinterpret); | |
910 args->data[0] = (void *)e; | |
911 if (e->op != TOKstring) | |
912 { | |
913 error("string expected, not '%s'", e->toChars()); | |
914 } | |
915 PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e)); | |
916 | |
917 assert(sc); | |
918 pragma->setScope(sc); | |
919 | |
920 //add to module members | |
921 assert(sc->module); | |
922 assert(sc->module->members); | |
923 sc->module->members->push(pragma); | |
924 } | |
925 } | |
926 #endif // TARGET_NET | |
927 } | |
928 | |
159 | 929 void PragmaDeclaration::semantic(Scope *sc) |
930 { // Should be merged with PragmaStatement | |
931 | |
932 #if IN_LLVM | |
933 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
|
934 std::string arg1str; |
159 | 935 |
936 #endif | |
937 | |
938 //printf("\tPragmaDeclaration::semantic '%s'\n",toChars()); | |
939 if (ident == Id::msg) | |
940 { | |
941 if (args) | |
942 { | |
943 for (size_t i = 0; i < args->dim; i++) | |
944 { | |
945 Expression *e = (Expression *)args->data[i]; | |
946 | |
947 e = e->semantic(sc); | |
948 e = e->optimize(WANTvalue | WANTinterpret); | |
949 if (e->op == TOKstring) | |
950 { | |
951 StringExp *se = (StringExp *)e; | |
1587 | 952 fprintf(stdmsg, "%.*s", (int)se->len, (char *)se->string); |
159 | 953 } |
954 else | |
1587 | 955 fprintf(stdmsg, e->toChars()); |
159 | 956 } |
957 fprintf(stdmsg, "\n"); | |
958 } | |
959 goto Lnodecl; | |
960 } | |
961 else if (ident == Id::lib) | |
962 { | |
963 if (!args || args->dim != 1) | |
964 error("string expected for library name"); | |
965 else | |
966 { | |
967 Expression *e = (Expression *)args->data[0]; | |
968 | |
969 e = e->semantic(sc); | |
970 e = e->optimize(WANTvalue | WANTinterpret); | |
971 args->data[0] = (void *)e; | |
972 if (e->op != TOKstring) | |
973 error("string expected for library name, not '%s'", e->toChars()); | |
974 else if (global.params.verbose) | |
975 { | |
976 StringExp *se = (StringExp *)e; | |
977 char *name = (char *)mem.malloc(se->len + 1); | |
978 memcpy(name, se->string, se->len); | |
979 name[se->len] = 0; | |
980 printf("library %s\n", name); | |
981 mem.free(name); | |
982 } | |
983 } | |
984 goto Lnodecl; | |
985 } | |
986 #if IN_GCC | |
987 else if (ident == Id::GNU_asm) | |
988 { | |
989 if (! args || args->dim != 2) | |
990 error("identifier and string expected for asm name"); | |
991 else | |
992 { | |
993 Expression *e; | |
994 Declaration *d = NULL; | |
995 StringExp *s = NULL; | |
996 | |
997 e = (Expression *)args->data[0]; | |
998 e = e->semantic(sc); | |
999 if (e->op == TOKvar) | |
1000 { | |
1001 d = ((VarExp *)e)->var; | |
1002 if (! d->isFuncDeclaration() && ! d->isVarDeclaration()) | |
1003 d = NULL; | |
1004 } | |
1005 if (!d) | |
1006 error("first argument of GNU_asm must be a function or variable declaration"); | |
1007 | |
1008 e = (Expression *)args->data[1]; | |
1009 e = e->semantic(sc); | |
1010 e = e->optimize(WANTvalue); | |
1011 if (e->op == TOKstring && ((StringExp *)e)->sz == 1) | |
1012 s = ((StringExp *)e); | |
1013 else | |
1014 error("second argument of GNU_asm must be a char string"); | |
1015 | |
1016 if (d && s) | |
1017 d->c_ident = Lexer::idPool((char*) s->string); | |
1018 } | |
1019 goto Lnodecl; | |
1020 } | |
1021 #endif | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1022 #if DMDV2 |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1023 else if (ident == Id::startaddress) |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1024 { |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1025 if (!args || args->dim != 1) |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1026 error("function name expected for start address"); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1027 else |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1028 { |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1029 Expression *e = (Expression *)args->data[0]; |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1030 e = e->semantic(sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1031 e = e->optimize(WANTvalue | WANTinterpret); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1032 args->data[0] = (void *)e; |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1033 Dsymbol *sa = getDsymbol(e); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1034 if (!sa || !sa->isFuncDeclaration()) |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1035 error("function name expected for start address, not '%s'", e->toChars()); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1036 } |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1037 goto Lnodecl; |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1038 } |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1039 #endif |
1587 | 1040 #if TARGET_NET |
1041 else if (ident == Lexer::idPool("assembly")) | |
1042 { | |
1043 } | |
1044 #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
|
1045 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1046 // LDC |
159 | 1047 #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
|
1048 |
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
|
1049 // 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
|
1050 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
|
1051 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1052 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
|
1053 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
|
1054 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
|
1055 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1056 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
|
1057 fatal(); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1058 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1059 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
|
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 |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 // 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
|
1063 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
|
1064 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1065 if (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
|
1066 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1067 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
|
1068 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
|
1069 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1070 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
|
1071 } |
159 | 1072 |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1073 // 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
|
1074 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
|
1075 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1076 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
|
1077 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1078 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
|
1079 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
|
1080 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1081 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
|
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 |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 // 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
|
1085 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
|
1086 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1088 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1089 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
|
1090 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
|
1091 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1092 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
|
1093 } |
159 | 1094 |
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
|
1095 // 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
|
1096 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
|
1097 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1098 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
|
1099 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1100 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
|
1101 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
|
1102 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1103 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
|
1104 } |
159 | 1105 |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1106 // 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
|
1107 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
|
1108 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1109 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
|
1110 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1111 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
|
1112 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1113 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1114 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
|
1115 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1116 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1117 // 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
|
1118 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
|
1119 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1120 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
|
1121 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1122 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
|
1123 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1124 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1125 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
|
1126 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1127 |
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
|
1128 // 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
|
1129 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
|
1130 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1131 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
|
1132 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1133 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
|
1134 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
|
1135 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1136 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
|
1137 } |
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
|
1138 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1139 // pragma(ldc, "string") { templdecl(s) } |
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1140 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
|
1141 { |
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 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
|
1143 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
|
1144 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
|
1145 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1146 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
|
1147 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
|
1148 } |
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
|
1149 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
|
1150 { |
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
|
1151 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
|
1152 } |
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
|
1153 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
|
1154 { |
1372
229e02867307
Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents:
1195
diff
changeset
|
1155 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
|
1156 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
|
1157 } |
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
|
1158 } |
159 | 1159 |
1152
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1160 // 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
|
1161 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
|
1162 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1163 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
|
1164 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1165 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
|
1166 fatal(); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1167 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1168 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
|
1169 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1170 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1171 #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
|
1172 |
1587 | 1173 |
986
a8cb25d478c4
Use LLVM-style command line (instead of DMD-style)
Frits van Bommel <fvbommel wxs.nl>
parents:
876
diff
changeset
|
1174 else if (ignoreUnsupportedPragmas) |
159 | 1175 { |
1176 if (global.params.verbose) | |
1177 { | |
1178 /* Print unrecognized pragmas | |
1179 */ | |
1180 printf("pragma %s", ident->toChars()); | |
1181 if (args) | |
1182 { | |
1183 for (size_t i = 0; i < args->dim; i++) | |
1184 { | |
1392
336faed34424
Allow ignored pragmas to have a body; don't ignore the body.
Frits van Bommel <fvbommel wxs.nl>
parents:
1372
diff
changeset
|
1185 // 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
|
1186 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
|
1187 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
|
1188 |
159 | 1189 Expression *e = (Expression *)args->data[i]; |
1190 e = e->semantic(sc); | |
1191 e = e->optimize(WANTvalue | WANTinterpret); | |
1192 if (i == 0) | |
1193 printf(" ("); | |
1194 else | |
1195 printf(","); | |
1196 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
|
1197 |
336faed34424
Allow ignored pragmas to have a body; don't ignore the body.
Frits van Bommel <fvbommel wxs.nl>
parents:
1372
diff
changeset
|
1198 // 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
|
1199 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
|
1200 global.errors = errors_save; |
159 | 1201 } |
1202 if (args->dim) | |
1203 printf(")"); | |
1204 } | |
1205 printf("\n"); | |
1206 } | |
1207 } | |
1208 else | |
1209 error("unrecognized pragma(%s)", ident->toChars()); | |
1210 | |
1211 if (decl) | |
1212 { | |
1213 for (unsigned i = 0; i < decl->dim; i++) | |
1214 { | |
1215 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1216 | |
1217 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
|
1218 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1219 // LDC |
159 | 1220 #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
|
1221 |
159 | 1222 if (llvm_internal) |
1223 { | |
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
|
1224 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
|
1225 { |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1226 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
|
1227 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
|
1228 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1230 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1231 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
|
1232 if (FuncDeclaration* fd = s->isFuncDeclaration()) |
159 | 1233 { |
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
|
1234 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
|
1235 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
|
1236 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
|
1237 ((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
|
1238 } |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1239 else if (TemplateDeclaration* td = s->isTemplateDeclaration()) |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1240 { |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1241 td->llvmInternal = llvm_internal; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1242 td->intrinsicName = arg1str; |
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1243 } |
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
|
1244 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
|
1245 { |
527
cecfee2d01a8
Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
1246 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
|
1247 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
|
1248 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1249 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
|
1250 |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1252 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
|
1253 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
|
1254 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 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
|
1256 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1257 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
|
1258 fatal(); |
159 | 1259 } |
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
|
1260 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
|
1261 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1262 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
|
1263 fatal(); |
159 | 1264 } |
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
|
1265 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
|
1266 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1267 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
|
1268 fatal(); |
159 | 1269 } |
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
|
1270 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
|
1271 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1272 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
|
1273 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1274 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
|
1275 fatal(); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1276 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1277 break; |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1278 |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1279 case LLVMva_copy: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1280 case LLVMva_end: |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1281 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
|
1282 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1283 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
|
1284 } |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1285 else |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1286 { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1287 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
|
1288 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
|
1289 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime 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 break; |
159 | 1291 |
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
|
1292 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
|
1293 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
|
1294 break; |
159 | 1295 |
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
|
1296 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
|
1297 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
|
1298 { |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1299 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
|
1300 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1301 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
|
1302 { |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
1303 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
|
1304 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
|
1305 } |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1306 break; |
159 | 1307 |
1152
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1308 case LLVMinline_asm: |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1309 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
|
1310 { |
1153
4454126b4345
Added support for single D type register return from __asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1152
diff
changeset
|
1311 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
|
1312 { |
1153
4454126b4345
Added support for single D type register return from __asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1152
diff
changeset
|
1313 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
|
1314 fatal(); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1315 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1316 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
|
1317 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1318 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
|
1319 fatal(); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1320 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1321 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
|
1322 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1323 else |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1324 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1325 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
|
1326 fatal(); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1327 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1328 break; |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1329 |
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
|
1330 default: |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1331 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
|
1332 } |
159 | 1333 } |
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
|
1334 |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1335 #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
|
1336 |
159 | 1337 } |
1338 } | |
1339 return; | |
1340 | |
1341 Lnodecl: | |
1342 if (decl) | |
1343 error("pragma is missing closing ';'"); | |
1344 } | |
1345 | |
1346 int PragmaDeclaration::oneMember(Dsymbol **ps) | |
1347 { | |
1348 *ps = NULL; | |
1349 return TRUE; | |
1350 } | |
1351 | |
336 | 1352 const char *PragmaDeclaration::kind() |
159 | 1353 { |
1354 return "pragma"; | |
1355 } | |
1356 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
1357 #if IN_DMD |
336 | 1358 void PragmaDeclaration::toObjFile(int multiobj) |
159 | 1359 { |
1360 if (ident == Id::lib) | |
1361 { | |
1362 assert(args && args->dim == 1); | |
1363 | |
1364 Expression *e = (Expression *)args->data[0]; | |
1365 | |
1366 assert(e->op == TOKstring); | |
1367 | |
1368 StringExp *se = (StringExp *)e; | |
1369 char *name = (char *)mem.malloc(se->len + 1); | |
1370 memcpy(name, se->string, se->len); | |
1371 name[se->len] = 0; | |
1372 obj_includelib(name); | |
1373 } | |
1195
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1374 #if DMDV2 |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1375 else if (ident == Id::startaddress) |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1376 { |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1377 assert(args && args->dim == 1); |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1378 Expression *e = (Expression *)args->data[0]; |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1379 Dsymbol *sa = getDsymbol(e); |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1380 FuncDeclaration *f = sa->isFuncDeclaration(); |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1381 assert(f); |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1382 Symbol *s = f->toSymbol(); |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1383 obj_startaddress(s); |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1384 } |
e961851fb8be
Merged DMD 1.042.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1153
diff
changeset
|
1385 #endif |
336 | 1386 AttribDeclaration::toObjFile(multiobj); |
159 | 1387 } |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
1388 #endif |
159 | 1389 |
1390 void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1391 { | |
1392 buf->printf("pragma(%s", ident->toChars()); | |
1393 if (args) | |
1394 { | |
1395 for (size_t i = 0; i < args->dim; i++) | |
1396 { | |
1397 Expression *e = (Expression *)args->data[i]; | |
1398 | |
1399 buf->writestring(", "); | |
1400 e->toCBuffer(buf, hgs); | |
1401 } | |
1402 } | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
1403 buf->writeByte(')'); |
159 | 1404 AttribDeclaration::toCBuffer(buf, hgs); |
1405 } | |
1406 | |
1407 | |
1408 /********************************* ConditionalDeclaration ****************************/ | |
1409 | |
1410 ConditionalDeclaration::ConditionalDeclaration(Condition *condition, Array *decl, Array *elsedecl) | |
1411 : AttribDeclaration(decl) | |
1412 { | |
1413 //printf("ConditionalDeclaration::ConditionalDeclaration()\n"); | |
1414 this->condition = condition; | |
1415 this->elsedecl = elsedecl; | |
1416 } | |
1417 | |
1418 Dsymbol *ConditionalDeclaration::syntaxCopy(Dsymbol *s) | |
1419 { | |
1420 ConditionalDeclaration *dd; | |
1421 | |
1422 assert(!s); | |
1423 dd = new ConditionalDeclaration(condition->syntaxCopy(), | |
1424 Dsymbol::arraySyntaxCopy(decl), | |
1425 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1426 return dd; | |
1427 } | |
1428 | |
1429 | |
1430 int ConditionalDeclaration::oneMember(Dsymbol **ps) | |
1431 { | |
1432 //printf("ConditionalDeclaration::oneMember(), inc = %d\n", condition->inc); | |
1433 if (condition->inc) | |
1434 { | |
1435 Array *d = condition->include(NULL, NULL) ? decl : elsedecl; | |
1436 return Dsymbol::oneMembers(d, ps); | |
1437 } | |
1438 *ps = NULL; | |
1439 return TRUE; | |
1440 } | |
1441 | |
1442 void ConditionalDeclaration::emitComment(Scope *sc) | |
1443 { | |
1444 //printf("ConditionalDeclaration::emitComment(sc = %p)\n", sc); | |
1445 if (condition->inc) | |
1446 { | |
1447 AttribDeclaration::emitComment(sc); | |
1448 } | |
876
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1449 else if (sc->docbuf) |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1450 { |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1451 /* 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
|
1452 * 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
|
1453 */ |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1454 Array *d = decl ? decl : elsedecl; |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1455 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
|
1456 { Dsymbol *s = (Dsymbol *)d->data[i]; |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1457 s->emitComment(sc); |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1458 } |
27a379f288bf
Merged DMD 1.039
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1459 } |
159 | 1460 } |
1461 | |
1462 // Decide if 'then' or 'else' code should be included | |
1463 | |
1464 Array *ConditionalDeclaration::include(Scope *sc, ScopeDsymbol *sd) | |
1465 { | |
1466 //printf("ConditionalDeclaration::include()\n"); | |
1467 assert(condition); | |
1468 return condition->include(sc, sd) ? decl : elsedecl; | |
1469 } | |
1470 | |
1587 | 1471 void ConditionalDeclaration::setScope(Scope *sc) |
1472 { | |
1473 Array *d = include(sc, NULL); | |
1474 | |
1475 //printf("\tConditionalDeclaration::setScope '%s', d = %p\n",toChars(), d); | |
1476 if (d) | |
1477 { | |
1478 for (unsigned i = 0; i < d->dim; i++) | |
1479 { | |
1480 Dsymbol *s = (Dsymbol *)d->data[i]; | |
1481 | |
1482 s->setScope(sc); | |
1483 } | |
1484 } | |
1485 } | |
1486 | |
1487 void ConditionalDeclaration::importAll(Scope *sc) | |
1488 { | |
1489 Array *d = include(sc, NULL); | |
1490 | |
1491 //printf("\tConditionalDeclaration::importAll '%s', d = %p\n",toChars(), d); | |
1492 if (d) | |
1493 { | |
1494 for (unsigned i = 0; i < d->dim; i++) | |
1495 { | |
1496 Dsymbol *s = (Dsymbol *)d->data[i]; | |
1497 | |
1498 s->importAll(sc); | |
1499 } | |
1500 } | |
1501 } | |
159 | 1502 |
1503 void ConditionalDeclaration::addComment(unsigned char *comment) | |
1504 { | |
1505 /* Because addComment is called by the parser, if we called | |
1506 * include() it would define a version before it was used. | |
1507 * But it's no problem to drill down to both decl and elsedecl, | |
1508 * so that's the workaround. | |
1509 */ | |
1510 | |
1511 if (comment) | |
1512 { | |
1513 Array *d = decl; | |
1514 | |
1515 for (int j = 0; j < 2; j++) | |
1516 { | |
1517 if (d) | |
1518 { | |
1519 for (unsigned i = 0; i < d->dim; i++) | |
1520 { Dsymbol *s; | |
1521 | |
1522 s = (Dsymbol *)d->data[i]; | |
1523 //printf("ConditionalDeclaration::addComment %s\n", s->toChars()); | |
1524 s->addComment(comment); | |
1525 } | |
1526 } | |
1527 d = elsedecl; | |
1528 } | |
1529 } | |
1530 } | |
1531 | |
1532 void ConditionalDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1533 { | |
1534 condition->toCBuffer(buf, hgs); | |
1535 if (decl || elsedecl) | |
1536 { | |
1537 buf->writenl(); | |
1538 buf->writeByte('{'); | |
1539 buf->writenl(); | |
1540 if (decl) | |
1541 { | |
1542 for (unsigned i = 0; i < decl->dim; i++) | |
1543 { | |
1544 Dsymbol *s = (Dsymbol *)decl->data[i]; | |
1545 | |
1546 buf->writestring(" "); | |
1547 s->toCBuffer(buf, hgs); | |
1548 } | |
1549 } | |
1550 buf->writeByte('}'); | |
1551 if (elsedecl) | |
1552 { | |
1553 buf->writenl(); | |
1554 buf->writestring("else"); | |
1555 buf->writenl(); | |
1556 buf->writeByte('{'); | |
1557 buf->writenl(); | |
1558 for (unsigned i = 0; i < elsedecl->dim; i++) | |
1559 { | |
1560 Dsymbol *s = (Dsymbol *)elsedecl->data[i]; | |
1561 | |
1562 buf->writestring(" "); | |
1563 s->toCBuffer(buf, hgs); | |
1564 } | |
1565 buf->writeByte('}'); | |
1566 } | |
1567 } | |
1568 else | |
1569 buf->writeByte(':'); | |
1570 buf->writenl(); | |
1571 } | |
1572 | |
1573 /***************************** StaticIfDeclaration ****************************/ | |
1574 | |
1575 StaticIfDeclaration::StaticIfDeclaration(Condition *condition, | |
1576 Array *decl, Array *elsedecl) | |
1577 : ConditionalDeclaration(condition, decl, elsedecl) | |
1578 { | |
1579 //printf("StaticIfDeclaration::StaticIfDeclaration()\n"); | |
1580 sd = NULL; | |
1581 addisdone = 0; | |
1582 } | |
1583 | |
1584 | |
1585 Dsymbol *StaticIfDeclaration::syntaxCopy(Dsymbol *s) | |
1586 { | |
1587 StaticIfDeclaration *dd; | |
1588 | |
1589 assert(!s); | |
1590 dd = new StaticIfDeclaration(condition->syntaxCopy(), | |
1591 Dsymbol::arraySyntaxCopy(decl), | |
1592 Dsymbol::arraySyntaxCopy(elsedecl)); | |
1593 return dd; | |
1594 } | |
1595 | |
1596 | |
1597 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1598 { | |
336 | 1599 //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); |
159 | 1600 /* This is deferred until semantic(), so that |
1601 * expressions in the condition can refer to declarations | |
1602 * in the same scope, such as: | |
1603 * | |
1604 * template Foo(int i) | |
1605 * { | |
1606 * const int j = i + 1; | |
1607 * static if (j == 3) | |
1608 * const int k; | |
1609 * } | |
1610 */ | |
1611 this->sd = sd; | |
1612 int m = 0; | |
1613 | |
1614 if (memnum == 0) | |
1615 { m = AttribDeclaration::addMember(sc, sd, memnum); | |
1616 addisdone = 1; | |
1617 } | |
1618 return m; | |
1619 } | |
1620 | |
1621 | |
1587 | 1622 void StaticIfDeclaration::importAll(Scope *sc) |
1623 { | |
1624 // do not evaluate condition before semantic pass | |
1625 } | |
1626 | |
1627 void StaticIfDeclaration::setScope(Scope *sc) | |
1628 { | |
1629 // do not evaluate condition before semantic pass | |
1630 } | |
1631 | |
159 | 1632 void StaticIfDeclaration::semantic(Scope *sc) |
1633 { | |
1634 Array *d = include(sc, sd); | |
1635 | |
336 | 1636 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); |
159 | 1637 if (d) |
1638 { | |
1639 if (!addisdone) | |
1640 { AttribDeclaration::addMember(sc, sd, 1); | |
1641 addisdone = 1; | |
1642 } | |
1643 | |
1644 for (unsigned i = 0; i < d->dim; i++) | |
1645 { | |
1646 Dsymbol *s = (Dsymbol *)d->data[i]; | |
1647 | |
1648 s->semantic(sc); | |
1649 } | |
1650 } | |
1651 } | |
1652 | |
336 | 1653 const char *StaticIfDeclaration::kind() |
159 | 1654 { |
1655 return "static if"; | |
1656 } | |
1657 | |
1658 | |
1659 /***************************** CompileDeclaration *****************************/ | |
1660 | |
1661 CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp) | |
1662 : AttribDeclaration(NULL) | |
1663 { | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
846
diff
changeset
|
1664 //printf("CompileDeclaration(loc = %d)\n", loc.linnum); |
336 | 1665 this->loc = loc; |
159 | 1666 this->exp = exp; |
1667 this->sd = NULL; | |
336 | 1668 this->compiled = 0; |
159 | 1669 } |
1670 | |
1671 Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *s) | |
1672 { | |
1673 //printf("CompileDeclaration::syntaxCopy('%s')\n", toChars()); | |
1674 CompileDeclaration *sc = new CompileDeclaration(loc, exp->syntaxCopy()); | |
1675 return sc; | |
1676 } | |
1677 | |
1678 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) | |
1679 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
986
diff
changeset
|
1680 //printf("CompileDeclaration::addMember(sc = %p, memnum = %d)\n", sc, memnum); |
159 | 1681 this->sd = sd; |
336 | 1682 if (memnum == 0) |
1683 { /* No members yet, so parse the mixin now | |
1684 */ | |
1685 compileIt(sc); | |
1686 memnum |= AttribDeclaration::addMember(sc, sd, memnum); | |
1687 compiled = 1; | |
1688 } | |
159 | 1689 return memnum; |
1690 } | |
1691 | |
336 | 1692 void CompileDeclaration::compileIt(Scope *sc) |
1693 { | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
846
diff
changeset
|
1694 //printf("CompileDeclaration::compileIt(loc = %d)\n", loc.linnum); |
336 | 1695 exp = exp->semantic(sc); |
1696 exp = resolveProperties(sc, exp); | |
1697 exp = exp->optimize(WANTvalue | WANTinterpret); | |
1698 if (exp->op != TOKstring) | |
1699 { exp->error("argument to mixin must be a string, not (%s)", exp->toChars()); | |
1700 } | |
1701 else | |
1702 { | |
1703 StringExp *se = (StringExp *)exp; | |
1704 se = se->toUTF8(sc); | |
1705 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); | |
1706 p.loc = loc; | |
1707 p.nextToken(); | |
1708 decl = p.parseDeclDefs(0); | |
1709 if (p.token.value != TOKeof) | |
1710 exp->error("incomplete mixin declaration (%s)", se->toChars()); | |
1711 } | |
1712 } | |
1713 | |
159 | 1714 void CompileDeclaration::semantic(Scope *sc) |
1715 { | |
1716 //printf("CompileDeclaration::semantic()\n"); | |
336 | 1717 |
1718 if (!compiled) | |
1719 { | |
1720 compileIt(sc); | |
1721 AttribDeclaration::addMember(sc, sd, 0); | |
1722 compiled = 1; | |
159 | 1723 } |
1724 AttribDeclaration::semantic(sc); | |
1725 } | |
1726 | |
1727 void CompileDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
1728 { | |
1729 buf->writestring("mixin("); | |
1730 exp->toCBuffer(buf, hgs); | |
1731 buf->writestring(");"); | |
1732 buf->writenl(); | |
1733 } |