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