Mercurial > projects > ldc
annotate dmd/struct.c @ 1628:6c36e3f49b28
Merge DMD r324: bugzilla 3663 and 3664 - fwd ref regressions
---
dmd/class.c | 2 +-
dmd/enum.c | 4 +++-
dmd/enum.h | 2 ++
dmd/mars.c | 2 +-
dmd/struct.c | 5 ++++-
5 files changed, 11 insertions(+), 4 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:23 -0300 |
parents | 79f64d5fee9e |
children | 44b145be2ef5 |
rev | line source |
---|---|
1587 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2009 by Digital Mars | |
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 <assert.h> | |
13 | |
14 #include "root.h" | |
15 #include "aggregate.h" | |
16 #include "scope.h" | |
17 #include "mtype.h" | |
18 #include "declaration.h" | |
19 #include "module.h" | |
20 #include "id.h" | |
21 #include "statement.h" | |
22 | |
23 /********************************* AggregateDeclaration ****************************/ | |
24 | |
25 AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id) | |
26 : ScopeDsymbol(id) | |
27 { | |
28 this->loc = loc; | |
29 | |
30 storage_class = 0; | |
31 protection = PROTpublic; | |
32 type = NULL; | |
33 handle = NULL; | |
34 structsize = 0; // size of struct | |
35 alignsize = 0; // size of struct for alignment purposes | |
36 structalign = 0; // struct member alignment in effect | |
37 hasUnions = 0; | |
38 sizeok = 0; // size not determined yet | |
39 isdeprecated = 0; | |
40 inv = NULL; | |
41 aggNew = NULL; | |
42 aggDelete = NULL; | |
43 | |
44 #if IN_DMD | |
45 stag = NULL; | |
46 sinit = NULL; | |
47 #endif | |
48 #if DMDV2 | |
49 dtor = NULL; | |
50 | |
51 ctor = NULL; | |
52 defaultCtor = NULL; | |
53 #endif | |
54 | |
55 #if IN_LLVM | |
56 availableExternally = true; // assume this unless proven otherwise | |
57 #endif | |
58 } | |
59 | |
60 enum PROT AggregateDeclaration::prot() | |
61 { | |
62 return protection; | |
63 } | |
64 | |
65 void AggregateDeclaration::semantic2(Scope *sc) | |
66 { | |
67 //printf("AggregateDeclaration::semantic2(%s)\n", toChars()); | |
68 if (scope && members) | |
69 { error("has forward references"); | |
70 return; | |
71 } | |
72 if (members) | |
73 { | |
74 sc = sc->push(this); | |
75 for (size_t i = 0; i < members->dim; i++) | |
76 { | |
77 Dsymbol *s = (Dsymbol *)members->data[i]; | |
78 s->semantic2(sc); | |
79 } | |
80 sc->pop(); | |
81 } | |
82 } | |
83 | |
84 void AggregateDeclaration::semantic3(Scope *sc) | |
85 { int i; | |
86 | |
87 // LDC | |
88 if (!global.params.useAvailableExternally) | |
89 availableExternally = false; | |
90 | |
91 //printf("AggregateDeclaration::semantic3(%s)\n", toChars()); | |
92 if (members) | |
93 { | |
94 sc = sc->push(this); | |
95 for (i = 0; i < members->dim; i++) | |
96 { | |
97 Dsymbol *s = (Dsymbol *)members->data[i]; | |
98 s->semantic3(sc); | |
99 } | |
100 sc->pop(); | |
101 } | |
102 } | |
103 | |
104 void AggregateDeclaration::inlineScan() | |
105 { int i; | |
106 | |
107 //printf("AggregateDeclaration::inlineScan(%s)\n", toChars()); | |
108 if (members) | |
109 { | |
110 for (i = 0; i < members->dim; i++) | |
111 { | |
112 Dsymbol *s = (Dsymbol *)members->data[i]; | |
113 //printf("inline scan aggregate symbol '%s'\n", s->toChars()); | |
114 s->inlineScan(); | |
115 } | |
116 } | |
117 } | |
118 | |
119 unsigned AggregateDeclaration::size(Loc loc) | |
120 { | |
121 //printf("AggregateDeclaration::size() = %d\n", structsize); | |
122 if (!members) | |
123 error(loc, "unknown size"); | |
124 if (sizeok != 1) | |
125 { error(loc, "no size yet for forward reference"); | |
126 //*(char*)0=0; | |
127 } | |
128 return structsize; | |
129 } | |
130 | |
131 Type *AggregateDeclaration::getType() | |
132 { | |
133 return type; | |
134 } | |
135 | |
136 int AggregateDeclaration::isDeprecated() | |
137 { | |
138 return isdeprecated; | |
139 } | |
140 | |
141 /**************************** | |
142 * Do byte or word alignment as necessary. | |
143 * Align sizes of 0, as we may not know array sizes yet. | |
144 */ | |
145 | |
146 void AggregateDeclaration::alignmember( | |
147 unsigned salign, // struct alignment that is in effect | |
148 unsigned size, // alignment requirement of field | |
149 unsigned *poffset) | |
150 { | |
151 //printf("salign = %d, size = %d, offset = %d\n",salign,size,offset); | |
152 if (salign > 1) | |
153 { | |
154 assert(size != 3); | |
155 int sa = size; | |
156 if (sa == 0 || salign < sa) | |
157 sa = salign; | |
158 *poffset = (*poffset + sa - 1) & ~(sa - 1); | |
159 } | |
160 //printf("result = %d\n",offset); | |
161 } | |
162 | |
163 | |
164 void AggregateDeclaration::addField(Scope *sc, VarDeclaration *v) | |
165 { | |
166 unsigned memsize; // size of member | |
167 unsigned memalignsize; // size of member for alignment purposes | |
168 unsigned xalign; // alignment boundaries | |
169 | |
170 //printf("AggregateDeclaration::addField('%s') %s\n", v->toChars(), toChars()); | |
171 | |
172 // Check for forward referenced types which will fail the size() call | |
173 Type *t = v->type->toBasetype(); | |
174 if (t->ty == Tstruct /*&& isStructDeclaration()*/) | |
175 { TypeStruct *ts = (TypeStruct *)t; | |
176 #if DMDV2 | |
177 if (ts->sym == this) | |
178 { | |
179 error("cannot have field %s with same struct type", v->toChars()); | |
180 } | |
181 #endif | |
182 | |
183 if (ts->sym->sizeok != 1) | |
184 { | |
185 sizeok = 2; // cannot finish; flag as forward referenced | |
186 return; | |
187 } | |
188 } | |
189 if (t->ty == Tident) | |
190 { | |
191 sizeok = 2; // cannot finish; flag as forward referenced | |
192 return; | |
193 } | |
194 | |
195 memsize = v->type->size(loc); | |
196 memalignsize = v->type->alignsize(); | |
197 xalign = v->type->memalign(sc->structalign); | |
198 alignmember(xalign, memalignsize, &sc->offset); | |
199 v->offset = sc->offset; | |
200 sc->offset += memsize; | |
201 if (sc->offset > structsize) | |
202 structsize = sc->offset; | |
203 if (sc->structalign < memalignsize) | |
204 memalignsize = sc->structalign; | |
205 if (alignsize < memalignsize) | |
206 alignsize = memalignsize; | |
207 //printf("\talignsize = %d\n", alignsize); | |
208 | |
209 v->storage_class |= STCfield; | |
210 //printf(" addField '%s' to '%s' at offset %d, size = %d\n", v->toChars(), toChars(), v->offset, memsize); | |
211 fields.push(v); | |
212 } | |
213 | |
214 | |
215 /********************************* StructDeclaration ****************************/ | |
216 | |
217 StructDeclaration::StructDeclaration(Loc loc, Identifier *id) | |
218 : AggregateDeclaration(loc, id) | |
219 { | |
220 zeroInit = 0; // assume false until we do semantic processing | |
221 #if DMDV2 | |
222 hasIdentityAssign = 0; | |
223 cpctor = NULL; | |
224 postblit = NULL; | |
225 #endif | |
226 | |
227 // For forward references | |
228 type = new TypeStruct(this); | |
229 } | |
230 | |
231 Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s) | |
232 { | |
233 StructDeclaration *sd; | |
234 | |
235 if (s) | |
236 sd = (StructDeclaration *)s; | |
237 else | |
238 sd = new StructDeclaration(loc, ident); | |
239 ScopeDsymbol::syntaxCopy(sd); | |
240 return sd; | |
241 } | |
242 | |
243 void StructDeclaration::semantic(Scope *sc) | |
244 { int i; | |
245 Scope *sc2; | |
246 | |
247 //printf("+StructDeclaration::semantic(this=%p, '%s')\n", this, toChars()); | |
248 | |
249 //static int count; if (++count == 20) *(char*)0=0; | |
250 | |
251 assert(type); | |
252 if (!members) // if forward reference | |
253 return; | |
254 | |
255 if (symtab) | |
1628
6c36e3f49b28
Merge DMD r324: bugzilla 3663 and 3664 - fwd ref regressions
Leandro Lucarella <llucax@gmail.com>
parents:
1625
diff
changeset
|
256 { if (sizeok == 1 || !scope) |
6c36e3f49b28
Merge DMD r324: bugzilla 3663 and 3664 - fwd ref regressions
Leandro Lucarella <llucax@gmail.com>
parents:
1625
diff
changeset
|
257 { //printf("already completed\n"); |
6c36e3f49b28
Merge DMD r324: bugzilla 3663 and 3664 - fwd ref regressions
Leandro Lucarella <llucax@gmail.com>
parents:
1625
diff
changeset
|
258 scope = NULL; |
1587 | 259 return; // semantic() already completed |
1628
6c36e3f49b28
Merge DMD r324: bugzilla 3663 and 3664 - fwd ref regressions
Leandro Lucarella <llucax@gmail.com>
parents:
1625
diff
changeset
|
260 } |
1587 | 261 } |
262 else | |
263 symtab = new DsymbolTable(); | |
264 | |
265 Scope *scx = NULL; | |
266 if (scope) | |
267 { sc = scope; | |
268 scx = scope; // save so we don't make redundant copies | |
269 scope = NULL; | |
270 } | |
271 | |
272 parent = sc->parent; | |
273 type = type->semantic(loc, sc); | |
274 #if STRUCTTHISREF | |
275 handle = type; | |
276 #else | |
277 handle = type->pointerTo(); | |
278 #endif | |
279 structalign = sc->structalign; | |
280 protection = sc->protection; | |
281 if (sc->stc & STCdeprecated) | |
282 isdeprecated = 1; | |
283 assert(!isAnonymous()); | |
284 if (sc->stc & STCabstract) | |
285 error("structs, unions cannot be abstract"); | |
286 #if DMDV2 | |
1619
c61782a76dff
Merge DMD r304: refactor invariant => immutable
Leandro Lucarella <llucax@gmail.com>
parents:
1607
diff
changeset
|
287 if (storage_class & STCimmutable) |
1587 | 288 type = type->invariantOf(); |
289 else if (storage_class & STCconst) | |
290 type = type->constOf(); | |
291 #endif | |
292 | |
293 if (sizeok == 0) // if not already done the addMember step | |
294 { | |
295 for (i = 0; i < members->dim; i++) | |
296 { | |
297 Dsymbol *s = (Dsymbol *)members->data[i]; | |
298 //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars()); | |
299 s->addMember(sc, this, 1); | |
300 } | |
301 } | |
302 | |
303 sizeok = 0; | |
304 sc2 = sc->push(this); | |
305 sc2->stc = 0; | |
306 sc2->parent = this; | |
307 if (isUnionDeclaration()) | |
308 sc2->inunion = 1; | |
309 sc2->protection = PROTpublic; | |
310 sc2->explicitProtection = 0; | |
311 | |
312 int members_dim = members->dim; | |
1625
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
313 |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
314 /* Set scope so if there are forward references, we still might be able to |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
315 * resolve individual members like enums. |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
316 */ |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
317 for (int i = 0; i < members_dim; i++) |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
318 { Dsymbol *s = (Dsymbol *)members->data[i]; |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
319 /* There are problems doing this in the general case because |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
320 * Scope keeps track of things like 'offset' |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
321 */ |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
322 if (s->isEnumDeclaration() || (s->isAggregateDeclaration() && s->ident)) |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
323 { |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
324 //printf("setScope %s %s\n", s->kind(), s->toChars()); |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
325 s->setScope(sc2); |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
326 } |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
327 } |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
328 |
1587 | 329 for (i = 0; i < members_dim; i++) |
330 { | |
331 Dsymbol *s = (Dsymbol *)members->data[i]; | |
332 s->semantic(sc2); | |
333 if (isUnionDeclaration()) | |
334 sc2->offset = 0; | |
335 #if 0 | |
336 if (sizeok == 2) | |
337 { //printf("forward reference\n"); | |
338 break; | |
339 } | |
340 #endif | |
341 } | |
342 | |
343 /* The TypeInfo_Struct is expecting an opEquals and opCmp with | |
344 * a parameter that is a pointer to the struct. But if there | |
345 * isn't one, but is an opEquals or opCmp with a value, write | |
346 * another that is a shell around the value: | |
347 * int opCmp(struct *p) { return opCmp(*p); } | |
348 */ | |
349 | |
350 TypeFunction *tfeqptr; | |
351 { | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
352 Parameters *arguments = new Parameters; |
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
353 Parameter *arg = new Parameter(STCin, handle, Id::p, NULL); |
1587 | 354 |
355 arguments->push(arg); | |
356 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
357 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, sc); | |
358 } | |
359 | |
360 TypeFunction *tfeq; | |
361 { | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
362 Parameters *arguments = new Parameters; |
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
363 Parameter *arg = new Parameter(STCin, type, NULL, NULL); |
1587 | 364 |
365 arguments->push(arg); | |
366 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
367 tfeq = (TypeFunction *)tfeq->semantic(0, sc); | |
368 } | |
369 | |
370 Identifier *id = Id::eq; | |
371 for (int i = 0; i < 2; i++) | |
372 { | |
373 Dsymbol *s = search_function(this, id); | |
374 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; | |
375 if (fdx) | |
376 { FuncDeclaration *fd = fdx->overloadExactMatch(tfeqptr, getModule()); | |
377 if (!fd) | |
378 { fd = fdx->overloadExactMatch(tfeq, getModule()); | |
379 if (fd) | |
380 { // Create the thunk, fdptr | |
381 FuncDeclaration *fdptr = new FuncDeclaration(loc, loc, fdx->ident, STCundefined, tfeqptr); | |
382 Expression *e = new IdentifierExp(loc, Id::p); | |
383 e = new PtrExp(loc, e); | |
384 Expressions *args = new Expressions(); | |
385 args->push(e); | |
386 e = new IdentifierExp(loc, id); | |
387 e = new CallExp(loc, e, args); | |
388 fdptr->fbody = new ReturnStatement(loc, e); | |
389 ScopeDsymbol *s = fdx->parent->isScopeDsymbol(); | |
390 assert(s); | |
391 s->members->push(fdptr); | |
392 fdptr->addMember(sc, s, 1); | |
393 fdptr->semantic(sc2); | |
394 } | |
395 } | |
396 } | |
397 | |
398 id = Id::cmp; | |
399 } | |
400 #if DMDV2 | |
401 dtor = buildDtor(sc2); | |
402 postblit = buildPostBlit(sc2); | |
403 cpctor = buildCpCtor(sc2); | |
404 buildOpAssign(sc2); | |
405 #endif | |
406 | |
407 sc2->pop(); | |
408 | |
409 if (sizeok == 2) | |
410 { // semantic() failed because of forward references. | |
411 // Unwind what we did, and defer it for later | |
412 fields.setDim(0); | |
413 structsize = 0; | |
414 alignsize = 0; | |
415 structalign = 0; | |
416 | |
417 scope = scx ? scx : new Scope(*sc); | |
418 scope->setNoFree(); | |
419 scope->module->addDeferredSemantic(this); | |
420 //printf("\tdeferring %s\n", toChars()); | |
421 return; | |
422 } | |
423 | |
424 // 0 sized struct's are set to 1 byte | |
425 if (structsize == 0) | |
426 { | |
427 structsize = 1; | |
428 alignsize = 1; | |
429 } | |
430 | |
431 // Round struct size up to next alignsize boundary. | |
432 // This will ensure that arrays of structs will get their internals | |
433 // aligned properly. | |
434 structsize = (structsize + alignsize - 1) & ~(alignsize - 1); | |
435 | |
436 sizeok = 1; | |
437 Module::dprogress++; | |
438 | |
439 //printf("-StructDeclaration::semantic(this=%p, '%s')\n", this, toChars()); | |
440 | |
441 // Determine if struct is all zeros or not | |
442 zeroInit = 1; | |
443 for (i = 0; i < fields.dim; i++) | |
444 { | |
445 Dsymbol *s = (Dsymbol *)fields.data[i]; | |
446 VarDeclaration *vd = s->isVarDeclaration(); | |
447 if (vd && !vd->isDataseg()) | |
448 { | |
449 if (vd->init) | |
450 { | |
451 // Should examine init to see if it is really all 0's | |
452 zeroInit = 0; | |
453 break; | |
454 } | |
455 else | |
456 { | |
457 if (!vd->type->isZeroInit(loc)) | |
458 { | |
459 zeroInit = 0; | |
460 break; | |
461 } | |
462 } | |
463 } | |
464 } | |
465 | |
466 /* Look for special member functions. | |
467 */ | |
468 #if DMDV2 | |
469 ctor = (CtorDeclaration *)search(0, Id::ctor, 0); | |
470 #endif | |
471 inv = (InvariantDeclaration *)search(0, Id::classInvariant, 0); | |
472 aggNew = (NewDeclaration *)search(0, Id::classNew, 0); | |
473 aggDelete = (DeleteDeclaration *)search(0, Id::classDelete, 0); | |
474 | |
475 if (sc->func) | |
476 { | |
477 semantic2(sc); | |
478 semantic3(sc); | |
479 } | |
480 } | |
481 | |
1624
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
482 Dsymbol *StructDeclaration::search(Loc loc, Identifier *ident, int flags) |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
483 { |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
484 //printf("%s.StructDeclaration::search('%s')\n", toChars(), ident->toChars()); |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
485 |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
486 if (scope) |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
487 semantic(scope); |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
488 |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
489 if (!members || !symtab) |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
490 { |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
491 error("is forward referenced when looking for '%s'", ident->toChars()); |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
492 return NULL; |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
493 } |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
494 |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
495 return ScopeDsymbol::search(loc, ident, flags); |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
496 } |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
497 |
1587 | 498 void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
499 { int i; | |
500 | |
501 buf->printf("%s ", kind()); | |
502 if (!isAnonymous()) | |
503 buf->writestring(toChars()); | |
504 if (!members) | |
505 { | |
506 buf->writeByte(';'); | |
507 buf->writenl(); | |
508 return; | |
509 } | |
510 buf->writenl(); | |
511 buf->writeByte('{'); | |
512 buf->writenl(); | |
513 for (i = 0; i < members->dim; i++) | |
514 { | |
515 Dsymbol *s = (Dsymbol *)members->data[i]; | |
516 | |
517 buf->writestring(" "); | |
518 s->toCBuffer(buf, hgs); | |
519 } | |
520 buf->writeByte('}'); | |
521 buf->writenl(); | |
522 } | |
523 | |
524 | |
525 const char *StructDeclaration::kind() | |
526 { | |
527 return "struct"; | |
528 } | |
529 | |
530 /********************************* UnionDeclaration ****************************/ | |
531 | |
532 UnionDeclaration::UnionDeclaration(Loc loc, Identifier *id) | |
533 : StructDeclaration(loc, id) | |
534 { | |
535 } | |
536 | |
537 Dsymbol *UnionDeclaration::syntaxCopy(Dsymbol *s) | |
538 { | |
539 UnionDeclaration *ud; | |
540 | |
541 if (s) | |
542 ud = (UnionDeclaration *)s; | |
543 else | |
544 ud = new UnionDeclaration(loc, ident); | |
545 StructDeclaration::syntaxCopy(ud); | |
546 return ud; | |
547 } | |
548 | |
549 | |
550 const char *UnionDeclaration::kind() | |
551 { | |
552 return "union"; | |
553 } | |
554 | |
555 |