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