Mercurial > projects > ldc
annotate dmd/struct.c @ 1625:79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
bugzilla 400 forward reference error; no propety X for type Y (struct
within struct).
---
dmd/class.c | 19 +++++++++++++++++--
dmd/struct.c | 16 ++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:22 -0300 |
parents | ae8a94d87ca9 |
children | 6c36e3f49b28 |
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) | |
256 { if (!scope) | |
257 return; // semantic() already completed | |
258 } | |
259 else | |
260 symtab = new DsymbolTable(); | |
261 | |
262 Scope *scx = NULL; | |
263 if (scope) | |
264 { sc = scope; | |
265 scx = scope; // save so we don't make redundant copies | |
266 scope = NULL; | |
267 } | |
268 | |
269 parent = sc->parent; | |
270 type = type->semantic(loc, sc); | |
271 #if STRUCTTHISREF | |
272 handle = type; | |
273 #else | |
274 handle = type->pointerTo(); | |
275 #endif | |
276 structalign = sc->structalign; | |
277 protection = sc->protection; | |
278 if (sc->stc & STCdeprecated) | |
279 isdeprecated = 1; | |
280 assert(!isAnonymous()); | |
281 if (sc->stc & STCabstract) | |
282 error("structs, unions cannot be abstract"); | |
283 #if DMDV2 | |
1619
c61782a76dff
Merge DMD r304: refactor invariant => immutable
Leandro Lucarella <llucax@gmail.com>
parents:
1607
diff
changeset
|
284 if (storage_class & STCimmutable) |
1587 | 285 type = type->invariantOf(); |
286 else if (storage_class & STCconst) | |
287 type = type->constOf(); | |
288 #endif | |
289 | |
290 if (sizeok == 0) // if not already done the addMember step | |
291 { | |
292 for (i = 0; i < members->dim; i++) | |
293 { | |
294 Dsymbol *s = (Dsymbol *)members->data[i]; | |
295 //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars()); | |
296 s->addMember(sc, this, 1); | |
297 } | |
298 } | |
299 | |
300 sizeok = 0; | |
301 sc2 = sc->push(this); | |
302 sc2->stc = 0; | |
303 sc2->parent = this; | |
304 if (isUnionDeclaration()) | |
305 sc2->inunion = 1; | |
306 sc2->protection = PROTpublic; | |
307 sc2->explicitProtection = 0; | |
308 | |
309 int members_dim = members->dim; | |
1625
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
310 |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
311 /* 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
|
312 * resolve individual members like enums. |
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 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
|
315 { Dsymbol *s = (Dsymbol *)members->data[i]; |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
316 /* 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
|
317 * 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
|
318 */ |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
319 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
|
320 { |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
321 //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
|
322 s->setScope(sc2); |
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 } |
79f64d5fee9e
Merge DMD r319: bugzilla 400 forward reference error...
Leandro Lucarella <llucax@gmail.com>
parents:
1624
diff
changeset
|
325 |
1587 | 326 for (i = 0; i < members_dim; i++) |
327 { | |
328 Dsymbol *s = (Dsymbol *)members->data[i]; | |
329 s->semantic(sc2); | |
330 if (isUnionDeclaration()) | |
331 sc2->offset = 0; | |
332 #if 0 | |
333 if (sizeok == 2) | |
334 { //printf("forward reference\n"); | |
335 break; | |
336 } | |
337 #endif | |
338 } | |
339 | |
340 /* The TypeInfo_Struct is expecting an opEquals and opCmp with | |
341 * a parameter that is a pointer to the struct. But if there | |
342 * isn't one, but is an opEquals or opCmp with a value, write | |
343 * another that is a shell around the value: | |
344 * int opCmp(struct *p) { return opCmp(*p); } | |
345 */ | |
346 | |
347 TypeFunction *tfeqptr; | |
348 { | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
349 Parameters *arguments = new Parameters; |
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
350 Parameter *arg = new Parameter(STCin, handle, Id::p, NULL); |
1587 | 351 |
352 arguments->push(arg); | |
353 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
354 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, sc); | |
355 } | |
356 | |
357 TypeFunction *tfeq; | |
358 { | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
359 Parameters *arguments = new Parameters; |
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
360 Parameter *arg = new Parameter(STCin, type, NULL, NULL); |
1587 | 361 |
362 arguments->push(arg); | |
363 tfeq = new TypeFunction(arguments, Type::tint32, 0, LINKd); | |
364 tfeq = (TypeFunction *)tfeq->semantic(0, sc); | |
365 } | |
366 | |
367 Identifier *id = Id::eq; | |
368 for (int i = 0; i < 2; i++) | |
369 { | |
370 Dsymbol *s = search_function(this, id); | |
371 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; | |
372 if (fdx) | |
373 { FuncDeclaration *fd = fdx->overloadExactMatch(tfeqptr, getModule()); | |
374 if (!fd) | |
375 { fd = fdx->overloadExactMatch(tfeq, getModule()); | |
376 if (fd) | |
377 { // Create the thunk, fdptr | |
378 FuncDeclaration *fdptr = new FuncDeclaration(loc, loc, fdx->ident, STCundefined, tfeqptr); | |
379 Expression *e = new IdentifierExp(loc, Id::p); | |
380 e = new PtrExp(loc, e); | |
381 Expressions *args = new Expressions(); | |
382 args->push(e); | |
383 e = new IdentifierExp(loc, id); | |
384 e = new CallExp(loc, e, args); | |
385 fdptr->fbody = new ReturnStatement(loc, e); | |
386 ScopeDsymbol *s = fdx->parent->isScopeDsymbol(); | |
387 assert(s); | |
388 s->members->push(fdptr); | |
389 fdptr->addMember(sc, s, 1); | |
390 fdptr->semantic(sc2); | |
391 } | |
392 } | |
393 } | |
394 | |
395 id = Id::cmp; | |
396 } | |
397 #if DMDV2 | |
398 dtor = buildDtor(sc2); | |
399 postblit = buildPostBlit(sc2); | |
400 cpctor = buildCpCtor(sc2); | |
401 buildOpAssign(sc2); | |
402 #endif | |
403 | |
404 sc2->pop(); | |
405 | |
406 if (sizeok == 2) | |
407 { // semantic() failed because of forward references. | |
408 // Unwind what we did, and defer it for later | |
409 fields.setDim(0); | |
410 structsize = 0; | |
411 alignsize = 0; | |
412 structalign = 0; | |
413 | |
414 scope = scx ? scx : new Scope(*sc); | |
415 scope->setNoFree(); | |
416 scope->module->addDeferredSemantic(this); | |
417 //printf("\tdeferring %s\n", toChars()); | |
418 return; | |
419 } | |
420 | |
421 // 0 sized struct's are set to 1 byte | |
422 if (structsize == 0) | |
423 { | |
424 structsize = 1; | |
425 alignsize = 1; | |
426 } | |
427 | |
428 // Round struct size up to next alignsize boundary. | |
429 // This will ensure that arrays of structs will get their internals | |
430 // aligned properly. | |
431 structsize = (structsize + alignsize - 1) & ~(alignsize - 1); | |
432 | |
433 sizeok = 1; | |
434 Module::dprogress++; | |
435 | |
436 //printf("-StructDeclaration::semantic(this=%p, '%s')\n", this, toChars()); | |
437 | |
438 // Determine if struct is all zeros or not | |
439 zeroInit = 1; | |
440 for (i = 0; i < fields.dim; i++) | |
441 { | |
442 Dsymbol *s = (Dsymbol *)fields.data[i]; | |
443 VarDeclaration *vd = s->isVarDeclaration(); | |
444 if (vd && !vd->isDataseg()) | |
445 { | |
446 if (vd->init) | |
447 { | |
448 // Should examine init to see if it is really all 0's | |
449 zeroInit = 0; | |
450 break; | |
451 } | |
452 else | |
453 { | |
454 if (!vd->type->isZeroInit(loc)) | |
455 { | |
456 zeroInit = 0; | |
457 break; | |
458 } | |
459 } | |
460 } | |
461 } | |
462 | |
463 /* Look for special member functions. | |
464 */ | |
465 #if DMDV2 | |
466 ctor = (CtorDeclaration *)search(0, Id::ctor, 0); | |
467 #endif | |
468 inv = (InvariantDeclaration *)search(0, Id::classInvariant, 0); | |
469 aggNew = (NewDeclaration *)search(0, Id::classNew, 0); | |
470 aggDelete = (DeleteDeclaration *)search(0, Id::classDelete, 0); | |
471 | |
472 if (sc->func) | |
473 { | |
474 semantic2(sc); | |
475 semantic3(sc); | |
476 } | |
477 } | |
478 | |
1624
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
479 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
|
480 { |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
481 //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
|
482 |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
483 if (scope) |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
484 semantic(scope); |
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 (!members || !symtab) |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
487 { |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
488 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
|
489 return NULL; |
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 |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
492 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
|
493 } |
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
494 |
1587 | 495 void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) |
496 { int i; | |
497 | |
498 buf->printf("%s ", kind()); | |
499 if (!isAnonymous()) | |
500 buf->writestring(toChars()); | |
501 if (!members) | |
502 { | |
503 buf->writeByte(';'); | |
504 buf->writenl(); | |
505 return; | |
506 } | |
507 buf->writenl(); | |
508 buf->writeByte('{'); | |
509 buf->writenl(); | |
510 for (i = 0; i < members->dim; i++) | |
511 { | |
512 Dsymbol *s = (Dsymbol *)members->data[i]; | |
513 | |
514 buf->writestring(" "); | |
515 s->toCBuffer(buf, hgs); | |
516 } | |
517 buf->writeByte('}'); | |
518 buf->writenl(); | |
519 } | |
520 | |
521 | |
522 const char *StructDeclaration::kind() | |
523 { | |
524 return "struct"; | |
525 } | |
526 | |
527 /********************************* UnionDeclaration ****************************/ | |
528 | |
529 UnionDeclaration::UnionDeclaration(Loc loc, Identifier *id) | |
530 : StructDeclaration(loc, id) | |
531 { | |
532 } | |
533 | |
534 Dsymbol *UnionDeclaration::syntaxCopy(Dsymbol *s) | |
535 { | |
536 UnionDeclaration *ud; | |
537 | |
538 if (s) | |
539 ud = (UnionDeclaration *)s; | |
540 else | |
541 ud = new UnionDeclaration(loc, ident); | |
542 StructDeclaration::syntaxCopy(ud); | |
543 return ud; | |
544 } | |
545 | |
546 | |
547 const char *UnionDeclaration::kind() | |
548 { | |
549 return "union"; | |
550 } | |
551 | |
552 |