Mercurial > projects > ddmd
annotate dmd/ClassDeclaration.d @ 126:1765f3ef917d
ClassDeclarations, Arguments -> Vector
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Fri, 03 Sep 2010 23:25:55 +0100 |
parents | 767a01c2a272 |
children | 60bb0fe4563e |
rev | line source |
---|---|
73 | 1 module dmd.ClassDeclaration; |
2 | |
114 | 3 import dmd.common; |
73 | 4 import dmd.AggregateDeclaration; |
5 import dmd.InterfaceDeclaration; | |
6 import dmd.ThisDeclaration; | |
7 import dmd.CompoundStatement; | |
8 import dmd.DeleteDeclaration; | |
9 import dmd.NewDeclaration; | |
10 import dmd.CtorDeclaration; | |
11 import dmd.TypeIdentifier; | |
12 import dmd.STC; | |
13 import dmd.Argument; | |
14 import dmd.TypeTuple; | |
15 import dmd.TY; | |
16 import dmd.LINK; | |
17 import dmd.DsymbolTable; | |
18 import dmd.FuncDeclaration; | |
19 import dmd.Array; | |
20 import dmd.TypeClass; | |
21 import dmd.Module; | |
22 import dmd.Id; | |
23 import dmd.Type; | |
24 import dmd.OverloadSet; | |
25 import dmd.ArrayTypes; | |
26 import dmd.BaseClass; | |
27 import dmd.ClassInfoDeclaration; | |
28 import dmd.Loc; | |
29 import dmd.Identifier; | |
30 import dmd.Dsymbol; | |
31 import dmd.Scope; | |
32 import dmd.TypeFunction; | |
33 import dmd.OutBuffer; | |
34 import dmd.HdrGenState; | |
35 import dmd.VarDeclaration; | |
36 import dmd.Initializer; | |
37 import dmd.ExpInitializer; | |
38 import dmd.TypeSArray; | |
39 import dmd.ScopeDsymbol; | |
40 import dmd.PROT; | |
41 import dmd.Util; | |
42 import dmd.Global; | |
43 | |
44 import dmd.expression.Util; | |
45 | |
46 import dmd.backend.Symbol; | |
47 import dmd.backend.dt_t; | |
48 import dmd.backend.TYPE; | |
49 import dmd.backend.FL; | |
50 import dmd.backend.SFL; | |
51 import dmd.backend.mTY; | |
52 import dmd.backend.SC; | |
53 import dmd.backend.mTYman; | |
54 import dmd.backend.Util; | |
55 import dmd.backend.TYM; | |
56 import dmd.backend.Classsym; | |
57 import dmd.backend.glue; | |
58 import dmd.backend.RTLSYM; | |
59 import dmd.backend.LIST; | |
60 | |
61 import dmd.codegen.Util; | |
62 | |
63 import std.string; | |
64 | |
65 version (DMDV2) { | |
66 enum CLASSINFO_SIZE = (0x3C+16+4); // value of ClassInfo.size | |
67 } else { | |
68 enum CLASSINFO_SIZE = (0x3C+12+4); // value of ClassInfo.size | |
69 } | |
70 | |
71 enum OFFSET_RUNTIME = 0x76543210; | |
72 | |
73 struct Param | |
74 { | |
75 int isf(void*, FuncDeclaration fd2) | |
76 { | |
77 //printf("param = %p, fd = %p %s\n", param, fd, fd.toChars()); | |
78 return fd is fd2; | |
79 } | |
80 | |
81 FuncDeclaration fd; | |
82 } | |
83 | |
84 class ClassDeclaration : AggregateDeclaration | |
85 { | |
86 static __gshared ClassDeclaration object; | |
87 static __gshared ClassDeclaration classinfo; | |
88 | |
89 ClassDeclaration baseClass; // null only if this is Object | |
90 FuncDeclaration staticCtor; | |
91 FuncDeclaration staticDtor; | |
92 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
93 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
94 | |
95 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
96 // rest are Interface's | |
97 | |
98 int interfaces_dim; | |
99 BaseClass* interfaces; // interfaces[interfaces_dim] for this class | |
100 // (does not include baseClass) | |
101 | |
102 BaseClasses vtblInterfaces; // array of base interfaces that have | |
103 // their own vtbl[] | |
104 | |
105 ClassInfoDeclaration vclassinfo; // the ClassInfo object for this ClassDeclaration | |
106 bool com; // true if this is a COM class (meaning | |
107 // it derives from IUnknown) | |
108 bool isauto; // true if this is an auto class | |
109 bool isabstract; // true if abstract class | |
110 | |
111 int inuse; // to prevent recursive attempts | |
112 | |
113 this(Loc loc, Identifier id, BaseClasses baseclasses) | |
114 { | |
115 super(loc, id); | |
116 | |
117 vtbl = new Array(); | |
118 vtblFinal = new Array(); | |
119 | |
120 enum msg = "only object.d can define this reserved class name"; | |
121 | |
122 if (baseclasses) { | |
123 this.baseclasses = baseclasses; | |
124 } else { | |
125 this.baseclasses = new BaseClasses(); | |
126 } | |
127 | |
128 //printf("ClassDeclaration(%s), dim = %d\n", id.toChars(), this.baseclasses.dim); | |
129 | |
130 // For forward references | |
131 type = new TypeClass(this); | |
132 | |
133 if (id) | |
134 { | |
135 // Look for special class names | |
136 | |
137 if (id is Id.__sizeof || id is Id.alignof_ || id is Id.mangleof_) | |
138 error("illegal class name"); | |
139 | |
140 // BUG: What if this is the wrong TypeInfo, i.e. it is nested? | |
141 if (id.toChars()[0] == 'T') | |
142 { | |
143 if (id is Id.TypeInfo) | |
144 { | |
145 if (Type.typeinfo) | |
146 Type.typeinfo.error("%s", msg); | |
147 Type.typeinfo = this; | |
148 } | |
149 | |
150 if (id is Id.TypeInfo_Class) | |
151 { | |
152 if (Type.typeinfoclass) | |
153 Type.typeinfoclass.error("%s", msg); | |
154 Type.typeinfoclass = this; | |
155 } | |
156 | |
157 if (id is Id.TypeInfo_Interface) | |
158 { | |
159 if (Type.typeinfointerface) | |
160 Type.typeinfointerface.error("%s", msg); | |
161 Type.typeinfointerface = this; | |
162 } | |
163 | |
164 if (id is Id.TypeInfo_Struct) | |
165 { | |
166 if (Type.typeinfostruct) | |
167 Type.typeinfostruct.error("%s", msg); | |
168 Type.typeinfostruct = this; | |
169 } | |
170 | |
171 if (id is Id.TypeInfo_Typedef) | |
172 { | |
173 if (Type.typeinfotypedef) | |
174 Type.typeinfotypedef.error("%s", msg); | |
175 Type.typeinfotypedef = this; | |
176 } | |
177 | |
178 if (id is Id.TypeInfo_Pointer) | |
179 { | |
180 if (Type.typeinfopointer) | |
181 Type.typeinfopointer.error("%s", msg); | |
182 Type.typeinfopointer = this; | |
183 } | |
184 | |
185 if (id is Id.TypeInfo_Array) | |
186 { | |
187 if (Type.typeinfoarray) | |
188 Type.typeinfoarray.error("%s", msg); | |
189 Type.typeinfoarray = this; | |
190 } | |
191 | |
192 if (id is Id.TypeInfo_StaticArray) | |
193 { //if (Type.typeinfostaticarray) | |
194 //Type.typeinfostaticarray.error("%s", msg); | |
195 Type.typeinfostaticarray = this; | |
196 } | |
197 | |
198 if (id is Id.TypeInfo_AssociativeArray) | |
199 { | |
200 if (Type.typeinfoassociativearray) | |
201 Type.typeinfoassociativearray.error("%s", msg); | |
202 Type.typeinfoassociativearray = this; | |
203 } | |
204 | |
205 if (id is Id.TypeInfo_Enum) | |
206 { | |
207 if (Type.typeinfoenum) | |
208 Type.typeinfoenum.error("%s", msg); | |
209 Type.typeinfoenum = this; | |
210 } | |
211 | |
212 if (id is Id.TypeInfo_Function) | |
213 { | |
214 if (Type.typeinfofunction) | |
215 Type.typeinfofunction.error("%s", msg); | |
216 Type.typeinfofunction = this; | |
217 } | |
218 | |
219 if (id is Id.TypeInfo_Delegate) | |
220 { | |
221 if (Type.typeinfodelegate) | |
222 Type.typeinfodelegate.error("%s", msg); | |
223 Type.typeinfodelegate = this; | |
224 } | |
225 | |
226 if (id is Id.TypeInfo_Tuple) | |
227 { | |
228 if (Type.typeinfotypelist) | |
229 Type.typeinfotypelist.error("%s", msg); | |
230 Type.typeinfotypelist = this; | |
231 } | |
232 | |
233 version (DMDV2) { | |
234 if (id is Id.TypeInfo_Const) | |
235 { | |
236 if (Type.typeinfoconst) | |
237 Type.typeinfoconst.error("%s", msg); | |
238 Type.typeinfoconst = this; | |
239 } | |
240 | |
241 if (id is Id.TypeInfo_Invariant) | |
242 { | |
243 if (Type.typeinfoinvariant) | |
244 Type.typeinfoinvariant.error("%s", msg); | |
245 Type.typeinfoinvariant = this; | |
246 } | |
247 | |
248 if (id is Id.TypeInfo_Shared) | |
249 { | |
250 if (Type.typeinfoshared) | |
251 Type.typeinfoshared.error("%s", msg); | |
252 Type.typeinfoshared = this; | |
253 } | |
254 } | |
255 } | |
256 | |
257 if (id is Id.Object_) | |
258 { | |
259 if (object) | |
260 object.error("%s", msg); | |
261 object = this; | |
262 } | |
263 | |
264 if (id is Id.ClassInfo) | |
265 { | |
266 if (classinfo) | |
267 classinfo.error("%s", msg); | |
268 classinfo = this; | |
269 } | |
270 | |
271 if (id is Id.ModuleInfo) | |
272 { | |
273 if (Module.moduleinfo) | |
274 Module.moduleinfo.error("%s", msg); | |
275 Module.moduleinfo = this; | |
276 } | |
277 } | |
278 | |
279 com = 0; | |
280 isauto = false; | |
281 isabstract = false; | |
282 inuse = 0; | |
283 } | |
284 | |
285 override Dsymbol syntaxCopy(Dsymbol s) | |
286 { | |
287 ClassDeclaration cd; | |
288 | |
289 //printf("ClassDeclaration.syntaxCopy('%s')\n", toChars()); | |
290 if (s) | |
291 cd = cast(ClassDeclaration)s; | |
292 else | |
293 cd = new ClassDeclaration(loc, ident, null); | |
294 | |
295 cd.storage_class |= storage_class; | |
296 | |
297 cd.baseclasses.setDim(this.baseclasses.dim); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
298 for (size_t i = 0; i < cd.baseclasses.dim; i++) |
73 | 299 { |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
300 auto b = this.baseclasses[i]; |
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
301 auto b2 = new BaseClass(b.type.syntaxCopy(), b.protection); |
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
302 cd.baseclasses[i] = b2; |
73 | 303 } |
304 | |
305 ScopeDsymbol.syntaxCopy(cd); | |
306 return cd; | |
307 } | |
308 | |
309 override void semantic(Scope sc) | |
310 { | |
311 uint offset; | |
312 | |
313 //printf("ClassDeclaration.semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this); | |
314 //printf("\tparent = %p, '%s'\n", sc.parent, sc.parent ? sc.parent.toChars() : ""); | |
315 //printf("sc.stc = %x\n", sc.stc); | |
316 | |
317 //{ static int n; if (++n == 20) *(char*)0=0; } | |
318 | |
319 if (!ident) // if anonymous class | |
320 { | |
321 string id = "__anonclass"; | |
322 ident = Identifier.generateId(id); | |
323 } | |
324 | |
325 if (!sc) | |
326 sc = scope_; | |
327 | |
328 if (!parent && sc.parent && !sc.parent.isModule()) | |
329 parent = sc.parent; | |
330 | |
331 type = type.semantic(loc, sc); | |
332 handle = type; | |
333 | |
334 if (!members) // if forward reference | |
335 { | |
336 //printf("\tclass '%s' is forward referenced\n", toChars()); | |
337 return; | |
338 } | |
339 if (symtab) | |
340 { if (!scope_) | |
341 { //printf("\tsemantic for '%s' is already completed\n", toChars()); | |
342 return; // semantic() already completed | |
343 } | |
344 } | |
345 else | |
346 symtab = new DsymbolTable(); | |
347 | |
348 Scope scx = null; | |
349 if (scope_) | |
350 { sc = scope_; | |
351 scx = scope_; // save so we don't make redundant copies | |
352 scope_ = null; | |
353 } | |
354 version (IN_GCC) { | |
355 methods.setDim(0); | |
356 } | |
357 | |
358 if (sc.stc & STC.STCdeprecated) | |
359 { | |
360 isdeprecated = 1; | |
361 } | |
362 | |
363 if (sc.linkage == LINK.LINKcpp) | |
364 error("cannot create C++ classes"); | |
365 | |
366 // Expand any tuples in baseclasses[] | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
367 for (size_t i = 0; i < baseclasses.dim; ) |
73 | 368 { |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
369 auto b = baseclasses[i]; |
73 | 370 //printf("test1 %s %s\n", toChars(), b.type.toChars()); |
371 b.type = b.type.semantic(loc, sc); | |
372 //printf("test2\n"); | |
373 Type tb = b.type.toBasetype(); | |
374 | |
375 if (tb.ty == TY.Ttuple) | |
376 { | |
377 TypeTuple tup = cast(TypeTuple)tb; | |
378 enum PROT protection = b.protection; | |
379 baseclasses.remove(i); | |
380 size_t dim = Argument.dim(tup.arguments); | |
381 for (size_t j = 0; j < dim; j++) | |
382 { | |
383 Argument arg = Argument.getNth(tup.arguments, j); | |
384 b = new BaseClass(arg.type, protection); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
385 baseclasses.insert(i + j, b); |
73 | 386 } |
387 } | |
388 else | |
389 i++; | |
390 } | |
391 | |
392 // See if there's a base class as first in baseclasses[] | |
393 if (baseclasses.dim) | |
394 { | |
395 TypeClass tc; | |
396 BaseClass b; | |
397 Type tb; | |
398 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
399 b = baseclasses[0]; |
73 | 400 //b.type = b.type.semantic(loc, sc); |
401 tb = b.type.toBasetype(); | |
402 if (tb.ty != TY.Tclass) | |
403 { error("base type must be class or interface, not %s", b.type.toChars()); | |
404 baseclasses.remove(0); | |
405 } | |
406 else | |
407 { | |
408 tc = cast(TypeClass)(tb); | |
409 | |
410 if (tc.sym.isDeprecated()) | |
411 { | |
412 if (!isDeprecated()) | |
413 { | |
414 // Deriving from deprecated class makes this one deprecated too | |
415 isdeprecated = 1; | |
416 | |
417 tc.checkDeprecated(loc, sc); | |
418 } | |
419 } | |
420 | |
421 if (tc.sym.isInterfaceDeclaration()) { | |
422 ; | |
423 } else { | |
424 for (ClassDeclaration cdb = tc.sym; cdb; cdb = cdb.baseClass) | |
425 { | |
426 if (cdb == this) | |
427 { | |
428 error("circular inheritance"); | |
429 baseclasses.remove(0); | |
430 goto L7; | |
431 } | |
432 } | |
433 if (!tc.sym.symtab || tc.sym.sizeok == 0) | |
434 { // Try to resolve forward reference | |
435 if (sc.mustsemantic && tc.sym.scope_) | |
436 tc.sym.semantic(null); | |
437 } | |
438 if (!tc.sym.symtab || tc.sym.scope_ || tc.sym.sizeok == 0) | |
439 { | |
440 //printf("%s: forward reference of base class %s\n", toChars(), tc.sym.toChars()); | |
441 //error("forward reference of base class %s", baseClass.toChars()); | |
442 // Forward reference of base class, try again later | |
443 //printf("\ttry later, forward reference of base class %s\n", tc.sym.toChars()); | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
444 scope_ = scx ? scx : sc.clone(); |
73 | 445 scope_.setNoFree(); |
446 if (tc.sym.scope_) | |
447 tc.sym.scope_.module_.addDeferredSemantic(tc.sym); | |
448 scope_.module_.addDeferredSemantic(this); | |
449 return; | |
450 } | |
451 else | |
452 { baseClass = tc.sym; | |
453 b.base = baseClass; | |
454 } | |
455 L7: ; | |
456 } | |
457 } | |
458 } | |
459 | |
460 // Treat the remaining entries in baseclasses as interfaces | |
461 // Check for errors, handle forward references | |
89 | 462 for (int i = (baseClass ? 1 : 0); i < baseclasses.dim; ) |
73 | 463 { TypeClass tc; |
464 BaseClass b; | |
465 Type tb; | |
466 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
467 b = baseclasses[i]; |
73 | 468 b.type = b.type.semantic(loc, sc); |
469 tb = b.type.toBasetype(); | |
470 if (tb.ty == TY.Tclass) | |
471 tc = cast(TypeClass)tb; | |
472 else | |
473 tc = null; | |
474 if (!tc || !tc.sym.isInterfaceDeclaration()) | |
475 { | |
476 error("base type must be interface, not %s", b.type.toChars()); | |
477 baseclasses.remove(i); | |
478 continue; | |
479 } | |
480 else | |
481 { | |
482 if (tc.sym.isDeprecated()) | |
483 { | |
484 if (!isDeprecated()) | |
485 { | |
486 // Deriving from deprecated class makes this one deprecated too | |
487 isdeprecated = 1; | |
488 | |
489 tc.checkDeprecated(loc, sc); | |
490 } | |
491 } | |
492 | |
493 // Check for duplicate interfaces | |
494 for (size_t j = (baseClass ? 1 : 0); j < i; j++) | |
495 { | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
496 auto b2 = baseclasses[j]; |
73 | 497 if (b2.base == tc.sym) |
498 error("inherits from duplicate interface %s", b2.base.toChars()); | |
499 } | |
500 | |
501 if (!tc.sym.symtab) | |
502 { // Try to resolve forward reference | |
503 if (sc.mustsemantic && tc.sym.scope_) | |
504 tc.sym.semantic(null); | |
505 } | |
506 | |
507 b.base = tc.sym; | |
508 if (!b.base.symtab || b.base.scope_) | |
509 { | |
510 //error("forward reference of base class %s", baseClass.toChars()); | |
511 // Forward reference of base, try again later | |
512 //printf("\ttry later, forward reference of base %s\n", baseClass.toChars()); | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
513 scope_ = scx ? scx : sc.clone(); |
73 | 514 scope_.setNoFree(); |
515 if (tc.sym.scope_) | |
516 tc.sym.scope_.module_.addDeferredSemantic(tc.sym); | |
517 scope_.module_.addDeferredSemantic(this); | |
518 return; | |
519 } | |
520 } | |
521 i++; | |
522 } | |
523 | |
524 | |
525 // If no base class, and this is not an Object, use Object as base class | |
526 if (!baseClass && ident !is Id.Object_) | |
527 { | |
528 // BUG: what if Object is redefined in an inner scope? | |
529 Type tbase = new TypeIdentifier(Loc(0), Id.Object_); | |
530 BaseClass b; | |
531 TypeClass tc; | |
532 Type bt; | |
533 | |
534 if (!object) | |
535 { | |
536 error("missing or corrupt object.d"); | |
537 fatal(); | |
538 } | |
539 bt = tbase.semantic(loc, sc).toBasetype(); | |
540 b = new BaseClass(bt, PROT.PROTpublic); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
541 baseclasses.shift(b); |
73 | 542 assert(b.type.ty == TY.Tclass); |
543 tc = cast(TypeClass)(b.type); | |
544 baseClass = tc.sym; | |
545 assert(!baseClass.isInterfaceDeclaration()); | |
546 b.base = baseClass; | |
547 } | |
548 | |
549 interfaces_dim = baseclasses.dim; | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
550 interfaces = baseclasses.ptr; |
73 | 551 |
552 if (baseClass) | |
553 { | |
554 if (baseClass.storage_class & STC.STCfinal) | |
555 error("cannot inherit from final class %s", baseClass.toChars()); | |
556 | |
557 interfaces_dim--; | |
558 interfaces++; | |
559 | |
560 // Copy vtbl[] from base class | |
561 vtbl.setDim(baseClass.vtbl.dim); | |
562 memcpy(vtbl.data, baseClass.vtbl.data, (void*).sizeof * vtbl.dim); | |
563 | |
564 // Inherit properties from base class | |
565 com = baseClass.isCOMclass(); | |
566 isauto = baseClass.isauto; | |
567 vthis = baseClass.vthis; | |
568 storage_class |= baseClass.storage_class & STC.STC_TYPECTOR; | |
569 } | |
570 else | |
571 { | |
572 // No base class, so this is the root of the class hierarchy | |
573 vtbl.setDim(0); | |
574 vtbl.push(cast(void*)this); // leave room for classinfo as first member | |
575 } | |
576 | |
577 protection = sc.protection; | |
578 storage_class |= sc.stc; | |
579 | |
580 if (sizeok == 0) | |
581 { | |
582 interfaceSemantic(sc); | |
583 | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
584 foreach (s; members) |
73 | 585 s.addMember(sc, this, true); |
586 | |
587 /* If this is a nested class, add the hidden 'this' | |
588 * member which is a pointer to the enclosing scope. | |
589 */ | |
590 if (vthis) // if inheriting from nested class | |
591 { // Use the base class's 'this' member | |
592 isnested = true; | |
593 if (storage_class & STC.STCstatic) | |
594 error("static class cannot inherit from nested class %s", baseClass.toChars()); | |
595 if (toParent2() != baseClass.toParent2()) | |
596 { | |
597 if (toParent2()) | |
598 { | |
599 error("is nested within %s, but super class %s is nested within %s", | |
600 toParent2().toChars(), | |
601 baseClass.toChars(), | |
602 baseClass.toParent2().toChars()); | |
603 } | |
604 else | |
605 { | |
606 error("is not nested, but super class %s is nested within %s", | |
607 baseClass.toChars(), | |
608 baseClass.toParent2().toChars()); | |
609 } | |
610 isnested = false; | |
611 } | |
612 } | |
613 else if (!(storage_class & STC.STCstatic)) | |
614 { | |
615 Dsymbol s = toParent2(); | |
616 if (s) | |
617 { | |
618 AggregateDeclaration ad = s.isClassDeclaration(); | |
619 FuncDeclaration fd = s.isFuncDeclaration(); | |
620 | |
621 if (ad || fd) | |
622 { isnested = true; | |
623 Type t; | |
624 if (ad) | |
625 t = ad.handle; | |
626 else if (fd) | |
627 { | |
628 AggregateDeclaration ad2 = fd.isMember2(); | |
629 if (ad2) | |
630 t = ad2.handle; | |
631 else | |
632 { | |
633 t = Type.tvoidptr; | |
634 } | |
635 } | |
636 else | |
637 assert(0); | |
638 if (t.ty == TY.Tstruct) // ref to struct | |
639 t = Type.tvoidptr; | |
640 assert(!vthis); | |
641 vthis = new ThisDeclaration(loc, t); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
642 members.push(vthis); |
73 | 643 } |
644 } | |
645 } | |
646 } | |
647 | |
648 if (storage_class & (STC.STCauto | STC.STCscope)) | |
649 isauto = true; | |
650 if (storage_class & STC.STCabstract) | |
651 isabstract = true; | |
652 if (storage_class & STC.STCimmutable) | |
653 type = type.invariantOf(); | |
654 else if (storage_class & STC.STCconst) | |
655 type = type.constOf(); | |
656 else if (storage_class & STC.STCshared) | |
657 type = type.sharedOf(); | |
658 | |
659 sc = sc.push(this); | |
660 sc.stc &= ~(STC.STCfinal | STC.STCauto | STC.STCscope | STC.STCstatic | | |
661 STC.STCabstract | STC.STCdeprecated | STC.STC_TYPECTOR | STC.STCtls | STC.STCgshared); | |
662 sc.stc |= storage_class & STC.STC_TYPECTOR; | |
663 sc.parent = this; | |
664 sc.inunion = 0; | |
665 | |
666 if (isCOMclass()) | |
667 { | |
114 | 668 version (Windows) { |
73 | 669 sc.linkage = LINK.LINKwindows; |
670 } else { | |
671 /* This enables us to use COM objects under Linux and | |
672 * work with things like XPCOM | |
673 */ | |
674 sc.linkage = LINK.LINKc; | |
675 } | |
676 } | |
677 sc.protection = PROT.PROTpublic; | |
678 sc.explicitProtection = 0; | |
679 sc.structalign = 8; | |
680 structalign = sc.structalign; | |
681 if (baseClass) | |
682 { sc.offset = baseClass.structsize; | |
683 alignsize = baseClass.alignsize; | |
684 // if (isnested) | |
685 // sc.offset += PTRSIZE; // room for uplevel context pointer | |
686 } | |
687 else | |
688 { sc.offset = PTRSIZE * 2; // allow room for __vptr and __monitor | |
689 alignsize = PTRSIZE; | |
690 } | |
691 structsize = sc.offset; | |
92 | 692 Scope scsave = sc.clone(); |
73 | 693 sizeok = 0; |
89 | 694 foreach (Dsymbol s; members) { |
73 | 695 s.semantic(sc); |
89 | 696 } |
73 | 697 |
698 if (sizeok == 2) | |
699 { // semantic() failed because of forward references. | |
700 // Unwind what we did, and defer it for later | |
701 fields.setDim(0); | |
702 structsize = 0; | |
703 alignsize = 0; | |
704 structalign = 0; | |
705 | |
706 sc = sc.pop(); | |
707 | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
708 scope_ = scx ? scx : sc.clone(); |
73 | 709 scope_.setNoFree(); |
710 scope_.module_.addDeferredSemantic(this); | |
711 | |
712 //printf("\tsemantic('%s') failed due to forward references\n", toChars()); | |
713 return; | |
714 } | |
715 | |
716 //printf("\tsemantic('%s') successful\n", toChars()); | |
717 | |
718 structsize = sc.offset; | |
719 //members.print(); | |
720 | |
721 /* Look for special member functions. | |
722 * They must be in this class, not in a base class. | |
723 */ | |
724 ctor = cast(CtorDeclaration)search(Loc(0), Id.ctor, 0); | |
725 if (ctor && (ctor.toParent() != this || !ctor.isCtorDeclaration())) | |
726 ctor = null; | |
727 | |
728 // dtor = (DtorDeclaration *)search(Id.dtor, 0); | |
729 // if (dtor && dtor.toParent() != this) | |
730 // dtor = null; | |
731 | |
732 // inv = (InvariantDeclaration *)search(Id.classInvariant, 0); | |
733 // if (inv && inv.toParent() != this) | |
734 // inv = null; | |
735 | |
736 // Can be in base class | |
737 aggNew = cast(NewDeclaration)search(Loc(0), Id.classNew, 0); | |
738 aggDelete = cast(DeleteDeclaration)search(Loc(0), Id.classDelete, 0); | |
739 | |
740 // If this class has no constructor, but base class does, create | |
741 // a constructor: | |
742 // this() { } | |
743 if (!ctor && baseClass && baseClass.ctor) | |
744 { | |
745 //printf("Creating default this(){} for class %s\n", toChars()); | |
746 CtorDeclaration ctor = new CtorDeclaration(loc, Loc(0), null, 0); | |
747 ctor.fbody = new CompoundStatement(Loc(0), new Statements()); | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
748 members.push(ctor); |
73 | 749 ctor.addMember(sc, this, true); |
750 sc = scsave; // why? What about sc.nofree? /// | |
751 sc.offset = structsize; | |
752 ctor.semantic(sc); | |
753 this.ctor = ctor; | |
754 defaultCtor = ctor; | |
755 } | |
756 | |
757 static if (false) { | |
758 if (baseClass) | |
759 { if (!aggDelete) | |
760 aggDelete = baseClass.aggDelete; | |
761 if (!aggNew) | |
762 aggNew = baseClass.aggNew; | |
763 } | |
764 } | |
765 | |
766 // Allocate instance of each new interface | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
767 foreach (b; vtblInterfaces) |
73 | 768 { |
769 uint thissize = PTRSIZE; | |
770 | |
771 alignmember(structalign, thissize, &sc.offset); | |
772 assert(b.offset == 0); | |
773 b.offset = sc.offset; | |
774 | |
775 // Take care of single inheritance offsets | |
776 while (b.baseInterfaces.length) | |
777 { | |
778 b = b.baseInterfaces[0]; | |
779 b.offset = sc.offset; | |
780 } | |
781 | |
782 sc.offset += thissize; | |
783 if (alignsize < thissize) | |
784 alignsize = thissize; | |
785 } | |
786 structsize = sc.offset; | |
787 sizeok = 1; | |
788 Module.dprogress++; | |
789 | |
790 dtor = buildDtor(sc); | |
791 | |
792 sc.pop(); | |
793 | |
794 static if (false) { // Do not call until toObjfile() because of forward references | |
795 // Fill in base class vtbl[]s | |
89 | 796 for (int i = 0; i < vtblInterfaces.dim; i++) |
73 | 797 { |
798 BaseClass b = cast(BaseClass)vtblInterfaces.data[i]; | |
799 | |
800 //b.fillVtbl(this, &b.vtbl, 1); | |
801 } | |
802 } | |
803 //printf("-ClassDeclaration.semantic(%s), type = %p\n", toChars(), type); | |
804 } | |
805 | |
806 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
807 { | |
808 if (!isAnonymous()) | |
809 { | |
810 buf.printf("%s ", kind()); | |
811 buf.writestring(toChars()); | |
812 if (baseclasses.dim) | |
813 buf.writestring(" : "); | |
814 } | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
815 foreach (size_t i, BaseClass b; baseclasses) |
73 | 816 { |
817 if (i) | |
818 buf.writeByte(','); | |
819 //buf.writestring(b.base.ident.toChars()); | |
820 b.type.toCBuffer(buf, null, hgs); | |
821 } | |
822 if (members) | |
823 { | |
824 buf.writenl(); | |
825 buf.writeByte('{'); | |
826 buf.writenl(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
827 foreach (s; members) |
73 | 828 { |
829 buf.writestring(" "); | |
830 s.toCBuffer(buf, hgs); | |
831 } | |
832 buf.writestring("}"); | |
833 } | |
834 else | |
835 buf.writeByte(';'); | |
836 buf.writenl(); | |
837 } | |
838 | |
839 /********************************************* | |
840 * Determine if 'this' is a base class of cd. | |
841 * This is used to detect circular inheritance only. | |
842 */ | |
843 int isBaseOf2(ClassDeclaration cd) | |
844 { | |
845 if (!cd) | |
846 return 0; | |
847 //printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd.toChars()); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
848 foreach (b; cd.baseclasses) |
73 | 849 { |
850 if (b.base is this || isBaseOf2(b.base)) | |
851 return 1; | |
852 } | |
853 return 0; | |
854 } | |
855 | |
856 /******************************************* | |
857 * Determine if 'this' is a base class of cd. | |
858 */ | |
859 /// #define OFFSET_RUNTIME 0x76543210 | |
860 bool isBaseOf(ClassDeclaration cd, int* poffset) | |
861 { | |
862 if (!cd) | |
863 return 0; | |
864 //printf("ClassDeclaration::isBaseOf2(this = '%s', cd = '%s')\n", toChars(), cd.toChars()); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
865 foreach (b; cd.baseclasses) |
73 | 866 { |
867 if (b.base == this || isBaseOf2(b.base)) | |
868 return 1; | |
869 } | |
870 | |
871 return 0; | |
872 } | |
873 | |
874 override Dsymbol search(Loc, Identifier ident, int flags) | |
875 { | |
876 Dsymbol s; | |
877 //printf("%s.ClassDeclaration.search('%s')\n", toChars(), ident.toChars()); | |
878 | |
879 if (scope_) | |
880 { | |
881 Scope sc = scope_; | |
882 sc.mustsemantic++; | |
883 semantic(sc); | |
884 sc.mustsemantic--; | |
885 } | |
886 | |
887 if (!members || !symtab || scope_) | |
888 { | |
889 error("is forward referenced when looking for '%s'", ident.toChars()); | |
890 //*(char*)0=0; | |
891 return null; | |
892 } | |
893 | |
894 s = ScopeDsymbol.search(loc, ident, flags); | |
895 if (!s) | |
896 { | |
897 // Search bases classes in depth-first, left to right order | |
898 | |
899 int i; | |
900 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
901 foreach (b; baseclasses) |
73 | 902 { |
903 if (b.base) | |
904 { | |
905 if (!b.base.symtab) | |
906 error("base %s is forward referenced", b.base.ident.toChars()); | |
907 else | |
908 { | |
909 s = b.base.search(loc, ident, flags); | |
910 if (s is this) // happens if s is nested in this and derives from this | |
911 s = null; | |
912 else if (s) | |
913 break; | |
914 } | |
915 } | |
916 } | |
917 } | |
918 return s; | |
919 } | |
920 | |
921 version (DMDV2) { | |
922 bool isFuncHidden(FuncDeclaration fd) | |
923 { | |
924 //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd.toChars()); | |
925 Dsymbol s = search(Loc(0), fd.ident, 4|2); | |
926 if (!s) | |
927 { | |
928 //printf("not found\n"); | |
929 /* Because, due to a hack, if there are multiple definitions | |
930 * of fd.ident, null is returned. | |
931 */ | |
932 return false; | |
933 } | |
934 | |
935 Param p; p.fd = fd; | |
936 | |
937 s = s.toAlias(); | |
938 OverloadSet os = s.isOverloadSet(); | |
939 if (os) | |
940 { | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
941 foreach (s2; os.a) |
73 | 942 { |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
943 auto f2 = s2.isFuncDeclaration(); |
73 | 944 if (f2 && overloadApply(f2, &p.isf, &p)) |
945 return false; | |
946 } | |
947 return true; | |
948 } | |
949 else | |
950 { | |
951 FuncDeclaration fdstart = s.isFuncDeclaration(); | |
952 //printf("%s fdstart = %p\n", s.kind(), fdstart); | |
953 return !overloadApply(fdstart, &p.isf, &p); | |
954 } | |
955 } | |
956 } | |
957 FuncDeclaration findFunc(Identifier ident, TypeFunction tf) | |
958 { | |
959 //printf("ClassDeclaration.findFunc(%s, %s) %s\n", ident.toChars(), tf.toChars(), toChars()); | |
960 | |
961 ClassDeclaration cd = this; | |
962 Array vtbl = cd.vtbl; | |
963 while (true) | |
964 { | |
965 for (size_t i = 0; i < vtbl.dim; i++) | |
966 { | |
967 FuncDeclaration fd = (cast(Dsymbol)vtbl.data[i]).isFuncDeclaration(); | |
968 if (!fd) | |
969 continue; // the first entry might be a ClassInfo | |
970 | |
971 //printf("\t[%d] = %s\n", i, fd.toChars()); | |
972 if (ident == fd.ident && | |
973 //tf.equals(fd.type) | |
974 fd.type.covariant(tf) == 1 | |
975 ) | |
976 { //printf("\t\tfound\n"); | |
977 return fd; | |
978 } | |
979 //else printf("\t\t%d\n", fd.type.covariant(tf)); | |
980 } | |
981 if (!cd) | |
982 break; | |
983 | |
984 vtbl = cd.vtblFinal; | |
985 cd = cd.baseClass; | |
986 } | |
987 | |
988 return null; | |
989 } | |
990 | |
991 void interfaceSemantic(Scope sc) | |
992 { | |
993 InterfaceDeclaration id = isInterfaceDeclaration(); | |
994 | |
995 vtblInterfaces = new BaseClasses(); | |
996 vtblInterfaces.reserve(interfaces_dim); | |
997 | |
998 for (size_t i = 0; i < interfaces_dim; i++) | |
999 { | |
1000 BaseClass b = interfaces[i]; | |
1001 | |
1002 // If this is an interface, and it derives from a COM interface, | |
1003 // then this is a COM interface too. | |
1004 if (b.base.isCOMinterface()) | |
1005 com = 1; | |
1006 | |
1007 if (b.base.isCPPinterface() && id) | |
1008 id.cpp = 1; | |
1009 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1010 vtblInterfaces.push(b); |
73 | 1011 b.copyBaseInterfaces(vtblInterfaces); |
1012 } | |
1013 } | |
1014 | |
1015 bool isCOMclass() | |
1016 { | |
1017 return com; | |
1018 } | |
1019 | |
1020 bool isCOMinterface() | |
1021 { | |
1022 return false; | |
1023 } | |
1024 | |
1025 version (DMDV2) { | |
1026 bool isCPPinterface() | |
1027 { | |
1028 return false; | |
1029 } | |
1030 } | |
1031 bool isAbstract() | |
1032 { | |
1033 if (isabstract) | |
1034 return true; | |
1035 | |
1036 for (int i = 1; i < vtbl.dim; i++) | |
1037 { | |
1038 FuncDeclaration fd = (cast(Dsymbol)vtbl.data[i]).isFuncDeclaration(); | |
1039 | |
1040 //printf("\tvtbl[%d] = %p\n", i, fd); | |
1041 if (!fd || fd.isAbstract()) | |
1042 { | |
1043 isabstract = true; | |
1044 return true; | |
1045 } | |
1046 } | |
1047 | |
1048 return false; | |
1049 } | |
1050 | |
1051 int vtblOffset() | |
1052 { | |
1053 assert(false); | |
1054 } | |
1055 | |
1056 override string kind() | |
1057 { | |
1058 return "class"; | |
1059 } | |
1060 | |
1061 override string mangle() | |
1062 { | |
1063 Dsymbol parentsave = parent; | |
1064 | |
1065 //printf("ClassDeclaration.mangle() %s.%s\n", parent.toChars(), toChars()); | |
1066 | |
1067 /* These are reserved to the compiler, so keep simple | |
1068 * names for them. | |
1069 */ | |
1070 if (ident is Id.Exception) | |
1071 { | |
1072 if (parent.ident is Id.object) | |
1073 parent = null; | |
1074 } | |
1075 else if (ident is Id.TypeInfo || | |
1076 // ident is Id.Exception || | |
1077 ident is Id.TypeInfo_Struct || | |
1078 ident is Id.TypeInfo_Class || | |
1079 ident is Id.TypeInfo_Typedef || | |
1080 ident is Id.TypeInfo_Tuple || | |
1081 this is object || | |
1082 this is classinfo || | |
1083 this is Module.moduleinfo || | |
1084 ident.toChars().startsWith("TypeInfo_") | |
1085 ) | |
1086 { | |
1087 parent = null; | |
1088 } | |
1089 | |
1090 string id = Dsymbol.mangle(); | |
1091 parent = parentsave; | |
1092 return id; | |
1093 } | |
1094 | |
1095 override void toDocBuffer(OutBuffer buf) | |
1096 { | |
1097 assert(false); | |
1098 } | |
1099 | |
1100 override PROT getAccess(Dsymbol smember) // determine access to smember | |
1101 { | |
1102 PROT access_ret = PROT.PROTnone; | |
1103 | |
1104 version (LOG) { | |
1105 printf("+ClassDeclaration::getAccess(this = '%s', smember = '%s')\n", | |
1106 toChars(), smember.toChars()); | |
1107 } | |
1108 if (smember.toParent() is this) | |
1109 { | |
1110 access_ret = smember.prot(); | |
1111 } | |
1112 else | |
1113 { | |
1114 PROT access; | |
1115 | |
1116 if (smember.isDeclaration().isStatic()) | |
1117 { | |
1118 access_ret = smember.prot(); | |
1119 } | |
1120 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1121 foreach (b; baseclasses) |
73 | 1122 { |
1123 access = b.base.getAccess(smember); | |
1124 switch (access) | |
1125 { | |
1126 case PROT.PROTnone: | |
1127 break; | |
1128 | |
1129 case PROT.PROTprivate: | |
1130 access = PROT.PROTnone; // private members of base class not accessible | |
1131 break; | |
1132 | |
1133 case PROT.PROTpackage: | |
1134 case PROT.PROTprotected: | |
1135 case PROT.PROTpublic: | |
1136 case PROT.PROTexport: | |
1137 // If access is to be tightened | |
1138 if (b.protection < access) | |
1139 access = b.protection; | |
1140 | |
1141 // Pick path with loosest access | |
1142 if (access > access_ret) | |
1143 access_ret = access; | |
1144 break; | |
1145 | |
1146 default: | |
1147 assert(0); | |
1148 } | |
1149 } | |
1150 } | |
1151 | |
1152 version (LOG) { | |
1153 printf("-ClassDeclaration::getAccess(this = '%s', smember = '%s') = %d\n", | |
1154 toChars(), smember.toChars(), access_ret); | |
1155 } | |
1156 | |
1157 return access_ret; | |
1158 } | |
1159 | |
1160 override void addLocalClass(ClassDeclarations aclasses) | |
1161 { | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
125
diff
changeset
|
1162 aclasses.push(this); |
73 | 1163 } |
1164 | |
1165 // Back end | |
1166 override void toObjFile(int multiobj) // compile to .obj file | |
1167 { | |
1168 uint offset; | |
1169 Symbol* sinit; | |
1170 enum_SC scclass; | |
1171 | |
1172 //printf("ClassDeclaration.toObjFile('%s')\n", toChars()); | |
1173 | |
1174 if (!members) | |
1175 return; | |
1176 | |
1177 if (multiobj) | |
1178 { | |
1179 obj_append(this); | |
1180 return; | |
1181 } | |
1182 | |
1183 if (global.params.symdebug) | |
1184 toDebug(); | |
1185 | |
1186 assert(!scope_); // semantic() should have been run to completion | |
1187 | |
1188 scclass = SCglobal; | |
1189 if (inTemplateInstance()) | |
1190 scclass = SCcomdat; | |
1191 | |
1192 // Put out the members | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1193 foreach (member; members) |
73 | 1194 member.toObjFile(0); |
1195 | |
1196 static if (false) { | |
1197 // Build destructor by aggregating dtors[] | |
1198 Symbol* sdtor; | |
1199 switch (dtors.dim) | |
1200 { | |
1201 case 0: | |
1202 // No destructors for this class | |
1203 sdtor = null; | |
1204 break; | |
1205 | |
1206 case 1: | |
1207 // One destructor, just use it directly | |
1208 sdtor = (cast(DtorDeclaration)dtors.data[0]).toSymbol(); | |
1209 break; | |
1210 | |
1211 default: | |
1212 { | |
1213 /* Build a destructor that calls all the | |
1214 * other destructors in dtors[]. | |
1215 */ | |
1216 | |
1217 elem* edtor = null; | |
1218 | |
1219 // Declare 'this' pointer for our new destructor | |
1220 Symbol* sthis = symbol_calloc("this"); | |
1221 sthis.Stype = type_fake(TYnptr); | |
1222 sthis.Stype.Tcount++; | |
1223 sthis.Sclass = SCfastpar; | |
1224 sthis.Spreg = AX; | |
1225 sthis.Sfl = FLauto; | |
1226 | |
1227 // Call each of the destructors in dtors[] | |
1228 // in reverse order | |
89 | 1229 for (size_t i = 0; i < dtors.dim; i++) |
73 | 1230 { |
1231 DtorDeclaration d = cast(DtorDeclaration)dtors.data[i]; | |
1232 Symbol* s = d.toSymbol(); | |
1233 elem* e = el_bin(OPcall, TYvoid, el_var(s), el_var(sthis)); | |
1234 edtor = el_combine(e, edtor); | |
1235 } | |
1236 | |
1237 // Create type for the function | |
1238 .type* t = type_alloc(TYjfunc); | |
1239 t.Tflags |= TFprototype | TFfixed; | |
1240 t.Tmangle = mTYman_d; | |
1241 t.Tnext = tsvoid; | |
1242 tsvoid.Tcount++; | |
1243 | |
1244 // Create the function, sdtor, and write it out | |
1245 localgot = null; | |
1246 sdtor = toSymbolX("__dtor", SCglobal, t, "FZv"); | |
1247 block* b = block_calloc(); | |
1248 b.BC = BCret; | |
1249 b.Belem = edtor; | |
1250 sdtor.Sfunc.Fstartblock = b; | |
1251 cstate.CSpsymtab = &sdtor.Sfunc.Flocsym; | |
1252 symbol_add(sthis); | |
1253 writefunc(sdtor); | |
1254 } | |
1255 } | |
1256 } | |
1257 | |
1258 // Generate C symbols | |
1259 toSymbol(); | |
1260 toVtblSymbol(); | |
1261 sinit = toInitializer(); | |
1262 | |
1263 ////////////////////////////////////////////// | |
1264 | |
1265 // Generate static initializer | |
1266 sinit.Sclass = scclass; | |
1267 sinit.Sfl = FLdata; | |
1268 version (ELFOBJ) { // Burton | |
1269 sinit.Sseg = Segment.CDATA; | |
1270 } | |
1271 version (MACHOBJ) { | |
1272 sinit.Sseg = Segment.DATA; | |
1273 } | |
1274 toDt(&sinit.Sdt); | |
1275 outdata(sinit); | |
1276 | |
1277 ////////////////////////////////////////////// | |
1278 | |
1279 // Put out the TypeInfo | |
1280 type.getTypeInfo(null); | |
1281 type.vtinfo.toObjFile(multiobj); | |
1282 | |
1283 ////////////////////////////////////////////// | |
1284 | |
1285 // Put out the ClassInfo | |
1286 csym.Sclass = scclass; | |
1287 csym.Sfl = FLdata; | |
1288 | |
1289 /* The layout is: | |
1290 { | |
1291 void **vptr; | |
1292 monitor_t monitor; | |
1293 byte[] initializer; // static initialization data | |
1294 char[] name; // class name | |
1295 void *[] vtbl; | |
1296 Interface[] interfaces; | |
1297 ClassInfo *base; // base class | |
1298 void *destructor; | |
1299 void *invariant; // class invariant | |
1300 uint flags; | |
1301 void *deallocator; | |
1302 OffsetTypeInfo[] offTi; | |
1303 void *defaultConstructor; | |
1304 const(MemberInfo[]) function(string) xgetMembers; // module getMembers() function | |
1305 TypeInfo typeinfo; | |
1306 } | |
1307 */ | |
1308 dt_t* dt = null; | |
1309 offset = CLASSINFO_SIZE; // must be ClassInfo.size | |
1310 if (classinfo) | |
1311 { | |
1312 if (classinfo.structsize != CLASSINFO_SIZE) | |
1313 error("D compiler and phobos' object.d are mismatched"); | |
1314 } | |
1315 | |
1316 if (classinfo) | |
1317 dtxoff(&dt, classinfo.toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo | |
1318 else | |
1319 dtdword(&dt, 0); // BUG: should be an assert() | |
1320 | |
1321 dtdword(&dt, 0); // monitor | |
1322 | |
1323 // initializer[] | |
1324 assert(structsize >= 8); | |
1325 dtdword(&dt, structsize); // size | |
1326 dtxoff(&dt, sinit, 0, TYnptr); // initializer | |
1327 | |
1328 // name[] | |
1329 string name = ident.toChars(); | |
1330 size_t namelen = name.length; | |
1331 if (!(namelen > 9 && name[0..9] == "TypeInfo_")) | |
1332 { | |
1333 name = toPrettyChars(); | |
1334 namelen = name.length; | |
1335 } | |
1336 dtdword(&dt, namelen); | |
1337 dtabytes(&dt, TYnptr, 0, namelen + 1, toStringz(name)); | |
1338 | |
1339 // vtbl[] | |
1340 dtdword(&dt, vtbl.dim); | |
1341 dtxoff(&dt, vtblsym, 0, TYnptr); | |
1342 | |
1343 // interfaces[] | |
1344 dtdword(&dt, vtblInterfaces.dim); | |
1345 if (vtblInterfaces.dim) | |
1346 dtxoff(&dt, csym, offset, TYnptr); // (*) | |
1347 else | |
1348 dtdword(&dt, 0); | |
1349 | |
1350 // base | |
1351 if (baseClass) | |
1352 dtxoff(&dt, baseClass.toSymbol(), 0, TYnptr); | |
1353 else | |
1354 dtdword(&dt, 0); | |
1355 | |
1356 // destructor | |
1357 if (dtor) | |
1358 dtxoff(&dt, dtor.toSymbol(), 0, TYnptr); | |
1359 else | |
1360 dtdword(&dt, 0); | |
1361 | |
1362 // invariant | |
1363 if (inv) | |
1364 dtxoff(&dt, inv.toSymbol(), 0, TYnptr); | |
1365 else | |
1366 dtdword(&dt, 0); | |
1367 | |
1368 // flags | |
1369 int flags = 4 | isCOMclass(); | |
1370 version (DMDV2) { | |
1371 flags |= 16; | |
1372 } | |
1373 flags |= 32; | |
1374 | |
1375 if (ctor) | |
1376 flags |= 8; | |
1377 for (ClassDeclaration cd = this; cd; cd = cd.baseClass) | |
1378 { | |
1379 if (cd.members) | |
1380 { | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1381 foreach (sm; cd.members) |
73 | 1382 { |
1383 //printf("sm = %s %s\n", sm.kind(), sm.toChars()); | |
1384 if (sm.hasPointers()) | |
1385 goto L2; | |
1386 } | |
1387 } | |
1388 } | |
1389 flags |= 2; // no pointers | |
1390 L2: | |
1391 dtdword(&dt, flags); | |
1392 | |
1393 | |
1394 // deallocator | |
1395 if (aggDelete) | |
1396 dtxoff(&dt, aggDelete.toSymbol(), 0, TYnptr); | |
1397 else | |
1398 dtdword(&dt, 0); | |
1399 | |
1400 // offTi[] | |
1401 dtdword(&dt, 0); | |
1402 dtdword(&dt, 0); // null for now, fix later | |
1403 | |
1404 // defaultConstructor | |
1405 if (defaultCtor) | |
1406 dtxoff(&dt, defaultCtor.toSymbol(), 0, TYnptr); | |
1407 else | |
1408 dtdword(&dt, 0); | |
1409 | |
1410 version (DMDV2) { | |
1411 FuncDeclaration sgetmembers = findGetMembers(); | |
1412 if (sgetmembers) | |
1413 dtxoff(&dt, sgetmembers.toSymbol(), 0, TYnptr); | |
1414 else | |
1415 dtdword(&dt, 0); // module getMembers() function | |
1416 } | |
1417 | |
1418 dtxoff(&dt, type.vtinfo.toSymbol(), 0, TYnptr); // typeinfo | |
1419 //dtdword(&dt, 0); | |
1420 | |
1421 ////////////////////////////////////////////// | |
1422 | |
1423 // Put out vtblInterfaces.data[]. Must immediately follow csym, because | |
1424 // of the fixup (*) | |
1425 | |
1426 offset += vtblInterfaces.dim * (4 * PTRSIZE); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1427 foreach (b; vtblInterfaces) |
73 | 1428 { |
1429 ClassDeclaration id = b.base; | |
1430 | |
1431 /* The layout is: | |
1432 * { | |
1433 * ClassInfo *interface; | |
1434 * void *[] vtbl; | |
1435 * unsigned offset; | |
1436 * } | |
1437 */ | |
1438 | |
1439 // Fill in vtbl[] | |
1440 b.fillVtbl(this, b.vtbl, 1); | |
1441 | |
1442 dtxoff(&dt, id.toSymbol(), 0, TYnptr); // ClassInfo | |
1443 | |
1444 // vtbl[] | |
1445 dtdword(&dt, id.vtbl.dim); | |
1446 dtxoff(&dt, csym, offset, TYnptr); | |
1447 | |
1448 dtdword(&dt, b.offset); // this offset | |
1449 | |
1450 offset += id.vtbl.dim * PTRSIZE; | |
1451 } | |
1452 | |
1453 // Put out the vtblInterfaces.data[].vtbl[] | |
1454 // This must be mirrored with ClassDeclaration.baseVtblOffset() | |
1455 //printf("putting out %d interface vtbl[]s for '%s'\n", vtblInterfaces.dim, toChars()); | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1456 foreach (size_t i, BaseClass b; vtblInterfaces) |
73 | 1457 { |
1458 ClassDeclaration id = b.base; | |
1459 int j; | |
1460 | |
1461 //printf(" interface[%d] is '%s'\n", i, id.toChars()); | |
1462 j = 0; | |
1463 if (id.vtblOffset()) | |
1464 { | |
1465 // First entry is ClassInfo reference | |
1466 //dtxoff(&dt, id.toSymbol(), 0, TYnptr); | |
1467 | |
1468 // First entry is struct Interface reference | |
1469 dtxoff(&dt, csym, CLASSINFO_SIZE + i * (4 * PTRSIZE), TYnptr); | |
1470 j = 1; | |
1471 } | |
1472 | |
1473 assert(id.vtbl.dim == b.vtbl.dim); | |
1474 for (; j < id.vtbl.dim; j++) | |
1475 { | |
1476 FuncDeclaration fd; | |
1477 | |
1478 assert(j < b.vtbl.dim); | |
1479 static if (false) { | |
1480 Object o = cast(Object)b.vtbl.data[j]; | |
1481 if (o) | |
1482 { | |
1483 printf("o = %p\n", o); | |
1484 assert(o.dyncast() == DYNCAST_DSYMBOL); | |
1485 Dsymbol s = cast(Dsymbol)o; | |
1486 printf("s.kind() = '%s'\n", s.kind()); | |
1487 } | |
1488 } | |
1489 fd = cast(FuncDeclaration)b.vtbl.data[j]; | |
1490 if (fd) | |
1491 dtxoff(&dt, fd.toThunkSymbol(b.offset), 0, TYnptr); | |
1492 else | |
1493 dtdword(&dt, 0); | |
1494 } | |
1495 } | |
1496 | |
1497 static if (true) { | |
1498 // Put out the overriding interface vtbl[]s. | |
1499 // This must be mirrored with ClassDeclaration.baseVtblOffset() | |
1500 //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset); | |
1501 ClassDeclaration cd; | |
1502 scope Array bvtbl = new Array(); | |
1503 | |
1504 for (cd = this.baseClass; cd; cd = cd.baseClass) | |
1505 { | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1506 foreach (size_t k, BaseClass bs; cd.vtblInterfaces) |
73 | 1507 { |
1508 if (bs.fillVtbl(this, bvtbl, 0)) | |
1509 { | |
1510 //printf("\toverriding vtbl[] for %s\n", bs.base.toChars()); | |
1511 ClassDeclaration id = bs.base; | |
1512 int j; | |
1513 | |
1514 j = 0; | |
1515 if (id.vtblOffset()) | |
1516 { | |
1517 // First entry is ClassInfo reference | |
1518 //dtxoff(&dt, id.toSymbol(), 0, TYnptr); | |
1519 | |
1520 // First entry is struct Interface reference | |
1521 dtxoff(&dt, cd.toSymbol(), CLASSINFO_SIZE + k * (4 * PTRSIZE), TYnptr); | |
1522 j = 1; | |
1523 } | |
1524 | |
1525 for (; j < id.vtbl.dim; j++) | |
1526 { | |
1527 assert(j < bvtbl.dim); | |
1528 FuncDeclaration fd = cast(FuncDeclaration)bvtbl.data[j]; | |
1529 if (fd) | |
1530 dtxoff(&dt, fd.toThunkSymbol(bs.offset), 0, TYnptr); | |
1531 else | |
1532 dtdword(&dt, 0); | |
1533 } | |
1534 } | |
1535 } | |
1536 } | |
1537 } | |
1538 | |
1539 version (INTERFACE_VIRTUAL) { | |
1540 // Put out the overriding interface vtbl[]s. | |
1541 // This must be mirrored with ClassDeclaration.baseVtblOffset() | |
1542 //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset); | |
89 | 1543 for (size_t i = 0; i < vtblInterfaces.dim; i++) |
73 | 1544 { |
1545 BaseClass b = cast(BaseClass)vtblInterfaces.data[i]; | |
1546 ClassDeclaration cd; | |
1547 | |
1548 for (cd = this.baseClass; cd; cd = cd.baseClass) | |
1549 { | |
1550 for (int k = 0; k < cd.vtblInterfaces.dim; k++) | |
1551 { | |
1552 BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k]; | |
1553 | |
1554 if (b.base == bs.base) | |
1555 { | |
1556 //printf("\toverriding vtbl[] for %s\n", b.base.toChars()); | |
1557 ClassDeclaration id = b.base; | |
1558 int j; | |
1559 | |
1560 j = 0; | |
1561 if (id.vtblOffset()) | |
1562 { | |
1563 // First entry is ClassInfo reference | |
1564 //dtxoff(&dt, id.toSymbol(), 0, TYnptr); | |
1565 | |
1566 // First entry is struct Interface reference | |
1567 dtxoff(&dt, cd.toSymbol(), CLASSINFO_SIZE + k * (4 * PTRSIZE), TYnptr); | |
1568 j = 1; | |
1569 } | |
1570 | |
1571 for (; j < id.vtbl.dim; j++) | |
1572 { | |
1573 assert(j < b.vtbl.dim); | |
1574 FuncDeclaration fd = cast(FuncDeclaration)b.vtbl.data[j]; | |
1575 if (fd) | |
1576 dtxoff(&dt, fd.toThunkSymbol(bs.offset), 0, TYnptr); | |
1577 else | |
1578 dtdword(&dt, 0); | |
1579 } | |
1580 } | |
1581 } | |
1582 } | |
1583 } | |
1584 } | |
1585 | |
1586 | |
1587 csym.Sdt = dt; | |
1588 version (ELFOBJ_OR_MACHOBJ) { // Burton | |
1589 // ClassInfo cannot be const data, because we use the monitor on it | |
1590 csym.Sseg = Segment.DATA; | |
1591 } | |
1592 outdata(csym); | |
1593 if (isExport()) | |
1594 obj_export(csym,0); | |
1595 | |
1596 ////////////////////////////////////////////// | |
1597 | |
1598 // Put out the vtbl[] | |
1599 //printf("putting out %s.vtbl[]\n", toChars()); | |
1600 dt = null; | |
89 | 1601 size_t i; |
73 | 1602 if (0) |
1603 i = 0; | |
1604 else | |
1605 { | |
1606 dtxoff(&dt, csym, 0, TYnptr); // first entry is ClassInfo reference | |
1607 i = 1; | |
1608 } | |
1609 for (; i < vtbl.dim; i++) | |
1610 { | |
1611 FuncDeclaration fd = (cast(Dsymbol)vtbl.data[i]).isFuncDeclaration(); | |
1612 | |
1613 //printf("\tvtbl[%d] = %p\n", i, fd); | |
1614 if (fd && (fd.fbody || !isAbstract())) | |
1615 { | |
1616 Symbol* s = fd.toSymbol(); | |
1617 | |
1618 version (DMDV2) { | |
1619 if (isFuncHidden(fd)) | |
1620 { | |
1621 /* fd is hidden from the view of this class. | |
1622 * If fd overlaps with any function in the vtbl[], then | |
1623 * issue 'hidden' error. | |
1624 */ | |
1625 for (int j = 1; j < vtbl.dim; j++) | |
1626 { | |
1627 if (j == i) | |
1628 continue; | |
1629 FuncDeclaration fd2 = (cast(Dsymbol)vtbl.data[j]).isFuncDeclaration(); | |
1630 if (!fd2.ident.equals(fd.ident)) | |
1631 continue; | |
1632 if (fd.leastAsSpecialized(fd2) || fd2.leastAsSpecialized(fd)) | |
1633 { | |
1634 if (global.params.warnings) | |
1635 { | |
1636 TypeFunction tf = cast(TypeFunction)fd.type; | |
1637 if (tf.ty == Tfunction) | |
1638 warning("%s%s is hidden by %s\n", fd.toPrettyChars(), Argument.argsTypesToChars(tf.parameters, tf.varargs), toChars()); | |
1639 else | |
1640 warning("%s is hidden by %s\n", fd.toPrettyChars(), toChars()); | |
1641 } | |
1642 s = rtlsym[RTLSYM_DHIDDENFUNC]; | |
1643 break; | |
1644 } | |
1645 } | |
1646 } | |
1647 } | |
1648 dtxoff(&dt, s, 0, TYnptr); | |
1649 } | |
1650 else | |
1651 dtdword(&dt, 0); | |
1652 } | |
1653 | |
1654 vtblsym.Sdt = dt; | |
1655 vtblsym.Sclass = scclass; | |
1656 vtblsym.Sfl = FLdata; | |
1657 version (ELFOBJ) { | |
1658 vtblsym.Sseg = Segment.CDATA; | |
1659 } | |
1660 version (MACHOBJ) { | |
1661 vtblsym.Sseg = Segment.DATA; | |
1662 } | |
1663 outdata(vtblsym); | |
1664 if (isExport()) | |
1665 obj_export(vtblsym,0); | |
1666 } | |
1667 | |
1668 void toDebug() | |
1669 { | |
1670 assert(false); | |
1671 } | |
1672 | |
1673 /****************************************** | |
1674 * Get offset of base class's vtbl[] initializer from start of csym. | |
1675 * Returns ~0 if not this csym. | |
1676 */ | |
1677 uint baseVtblOffset(BaseClass bc) | |
1678 { | |
1679 uint csymoffset; | |
1680 | |
1681 //printf("ClassDeclaration.baseVtblOffset('%s', bc = %p)\n", toChars(), bc); | |
1682 csymoffset = CLASSINFO_SIZE; | |
1683 csymoffset += vtblInterfaces.dim * (4 * PTRSIZE); | |
1684 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1685 foreach (b; vtblInterfaces) |
73 | 1686 { |
1687 if (b == bc) | |
1688 return csymoffset; | |
1689 csymoffset += b.base.vtbl.dim * PTRSIZE; | |
1690 } | |
1691 | |
1692 static if (true) { | |
1693 // Put out the overriding interface vtbl[]s. | |
1694 // This must be mirrored with ClassDeclaration.baseVtblOffset() | |
1695 //printf("putting out overriding interface vtbl[]s for '%s' at offset x%x\n", toChars(), offset); | |
1696 ClassDeclaration cd; | |
1697 Array bvtbl; | |
1698 | |
1699 for (cd = this.baseClass; cd; cd = cd.baseClass) | |
1700 { | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1701 foreach(bs; cd.vtblInterfaces) |
73 | 1702 { |
1703 if (bs.fillVtbl(this, null, 0)) | |
1704 { | |
1705 if (bc == bs) | |
1706 { | |
1707 //printf("\tcsymoffset = x%x\n", csymoffset); | |
1708 return csymoffset; | |
1709 } | |
1710 csymoffset += bs.base.vtbl.dim * PTRSIZE; | |
1711 } | |
1712 } | |
1713 } | |
1714 } | |
1715 version (INTERFACE_VIRTUAL) { | |
89 | 1716 for (size_t i = 0; i < vtblInterfaces.dim; i++) |
73 | 1717 { |
1718 BaseClass b = cast(BaseClass)vtblInterfaces.data[i]; | |
1719 ClassDeclaration cd; | |
1720 | |
1721 for (cd = this.baseClass; cd; cd = cd.baseClass) | |
1722 { | |
1723 //printf("\tbase class %s\n", cd.toChars()); | |
1724 for (int k = 0; k < cd.vtblInterfaces.dim; k++) | |
1725 { | |
1726 BaseClass bs = cast(BaseClass)cd.vtblInterfaces.data[k]; | |
1727 | |
1728 if (bc == bs) | |
1729 { | |
1730 //printf("\tcsymoffset = x%x\n", csymoffset); | |
1731 return csymoffset; | |
1732 } | |
1733 if (b.base == bs.base) | |
1734 csymoffset += bs.base.vtbl.dim * PTRSIZE; | |
1735 } | |
1736 } | |
1737 } | |
1738 } | |
1739 | |
1740 return ~0; | |
1741 } | |
1742 | |
1743 static private __gshared Classsym* scc; | |
1744 | |
1745 /************************************* | |
1746 * Create the "ClassInfo" symbol | |
1747 */ | |
1748 override Symbol* toSymbol() | |
1749 { | |
1750 if (!csym) | |
1751 { | |
1752 Symbol* s; | |
1753 | |
1754 if (!scc) | |
1755 scc = fake_classsym(Id.ClassInfo); | |
1756 | |
1757 s = toSymbolX("__Class", SC.SCextern, scc.Stype, "Z"); | |
1758 s.Sfl = FL.FLextern; | |
1759 s.Sflags |= SFL.SFLnodebug; | |
1760 csym = s; | |
1761 slist_add(s); | |
1762 } | |
1763 | |
1764 return csym; | |
1765 } | |
1766 | |
1767 /************************************* | |
1768 * This is accessible via the ClassData, but since it is frequently | |
1769 * needed directly (like for rtti comparisons), make it directly accessible. | |
1770 */ | |
1771 Symbol* toVtblSymbol() | |
1772 { | |
1773 if (!vtblsym) | |
1774 { | |
1775 if (!csym) | |
1776 toSymbol(); | |
1777 | |
1778 TYPE* t = type_alloc(TYM.TYnptr | mTY.mTYconst); | |
1779 t.Tnext = tsvoid; | |
1780 t.Tnext.Tcount++; | |
1781 t.Tmangle = mTYman.mTYman_d; | |
1782 | |
1783 Symbol* s = toSymbolX("__vtbl", SC.SCextern, t, "Z"); | |
1784 s.Sflags |= SFL.SFLnodebug; | |
1785 s.Sfl = FL.FLextern; | |
1786 vtblsym = s; | |
1787 slist_add(s); | |
1788 } | |
1789 return vtblsym; | |
1790 } | |
1791 | |
1792 // Generate the data for the static initializer. | |
1793 void toDt(dt_t **pdt) | |
1794 { | |
1795 //printf("ClassDeclaration.toDt(this = '%s')\n", toChars()); | |
1796 | |
1797 // Put in first two members, the vtbl[] and the monitor | |
1798 dtxoff(pdt, toVtblSymbol(), 0, TYnptr); | |
1799 dtdword(pdt, 0); // monitor | |
1800 | |
1801 // Put in the rest | |
1802 toDt2(pdt, this); | |
1803 | |
1804 //printf("-ClassDeclaration.toDt(this = '%s')\n", toChars()); | |
1805 } | |
1806 | |
1807 void toDt2(dt_t** pdt, ClassDeclaration cd) | |
1808 { | |
1809 uint offset; | |
89 | 1810 |
73 | 1811 dt_t* dt; |
1812 uint csymoffset; | |
1813 | |
1814 version (LOG) { | |
1815 printf("ClassDeclaration.toDt2(this = '%s', cd = '%s')\n", toChars(), cd.toChars()); | |
1816 } | |
1817 if (baseClass) | |
1818 { | |
1819 baseClass.toDt2(pdt, cd); | |
1820 offset = baseClass.structsize; | |
1821 } | |
1822 else | |
1823 { | |
1824 offset = 8; | |
1825 } | |
1826 | |
1827 // Note equivalence of this loop to struct's | |
89 | 1828 for (size_t i = 0; i < fields.dim; i++) |
73 | 1829 { |
79 | 1830 VarDeclaration v = cast(VarDeclaration)fields[i]; |
73 | 1831 Initializer init; |
1832 | |
1833 //printf("\t\tv = '%s' v.offset = %2d, offset = %2d\n", v.toChars(), v.offset, offset); | |
1834 dt = null; | |
1835 init = v.init; | |
1836 if (init) | |
1837 { | |
1838 //printf("\t\t%s has initializer %s\n", v.toChars(), init.toChars()); | |
1839 ExpInitializer ei = init.isExpInitializer(); | |
1840 Type tb = v.type.toBasetype(); | |
1841 if (ei && tb.ty == Tsarray) | |
1842 (cast(TypeSArray)tb).toDtElem(&dt, ei.exp); | |
1843 else | |
1844 dt = init.toDt(); | |
1845 } | |
1846 else if (v.offset >= offset) | |
1847 { //printf("\t\tdefault initializer\n"); | |
1848 v.type.toDt(&dt); | |
1849 } | |
1850 if (dt) | |
1851 { | |
1852 if (v.offset < offset) | |
1853 error("duplicated union initialization for %s", v.toChars()); | |
1854 else | |
1855 { | |
1856 if (offset < v.offset) | |
1857 dtnzeros(pdt, v.offset - offset); | |
1858 dtcat(pdt, dt); | |
1859 offset = v.offset + cast(uint)v.type.size(); | |
1860 } | |
1861 } | |
1862 } | |
1863 | |
1864 // Interface vptr initializations | |
1865 toSymbol(); // define csym | |
1866 | |
125
767a01c2a272
BaseClasses -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
1867 foreach (b; vtblInterfaces) |
73 | 1868 { |
1869 /// version (1 || INTERFACE_VIRTUAL) { | |
1870 for (ClassDeclaration cd2 = cd; 1; cd2 = cd2.baseClass) | |
1871 { | |
1872 assert(cd2); | |
1873 csymoffset = cd2.baseVtblOffset(b); | |
1874 if (csymoffset != ~0) | |
1875 { | |
1876 if (offset < b.offset) | |
1877 dtnzeros(pdt, b.offset - offset); | |
1878 dtxoff(pdt, cd2.toSymbol(), csymoffset, TYnptr); | |
1879 break; | |
1880 } | |
1881 } | |
1882 /// } else { | |
1883 /// csymoffset = baseVtblOffset(b); | |
1884 /// assert(csymoffset != ~0); | |
1885 /// dtxoff(pdt, csym, csymoffset, TYnptr); | |
1886 /// } | |
1887 offset = b.offset + 4; | |
1888 } | |
1889 | |
1890 if (offset < structsize) | |
1891 dtnzeros(pdt, structsize - offset); | |
1892 } | |
1893 | |
1894 Symbol* vtblsym; | |
1895 | |
1896 ///ClassDeclaration isClassDeclaration() { return cast(ClassDeclaration)this; } /// huh? | |
1897 override ClassDeclaration isClassDeclaration() { return this; } | |
1898 } |