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