0
|
1 module dmd.DtorDeclaration;
|
|
2
|
|
3 import dmd.FuncDeclaration;
|
|
4 import dmd.Loc;
|
|
5 import dmd.Global;
|
|
6 import dmd.Identifier;
|
|
7 import dmd.Dsymbol;
|
|
8 import dmd.Scope;
|
|
9 import dmd.LINK;
|
|
10 import dmd.AggregateDeclaration;
|
|
11 import dmd.TypeFunction;
|
|
12 import dmd.Type;
|
|
13 import dmd.OutBuffer;
|
|
14 import dmd.HdrGenState;
|
|
15 import dmd.STC;
|
|
16 import dmd.Id;
|
|
17
|
|
18 class DtorDeclaration : FuncDeclaration
|
|
19 {
|
|
20 this(Loc loc, Loc endloc)
|
|
21 {
|
|
22 super(loc, endloc, Id.dtor, STCundefined, null);
|
|
23 }
|
|
24
|
|
25 this(Loc loc, Loc endloc, Identifier id)
|
|
26 {
|
|
27 assert(false);
|
|
28 super(loc, endloc, null, STC.init, null);
|
|
29 }
|
|
30
|
|
31 Dsymbol syntaxCopy(Dsymbol)
|
|
32 {
|
|
33 assert(false);
|
|
34 }
|
|
35
|
|
36 void semantic(Scope sc)
|
|
37 {
|
|
38 //printf("DtorDeclaration::semantic() %s\n", toChars());
|
|
39 //printf("ident: %s, %s, %p, %p\n", ident.toChars(), Id::dtor.toChars(), ident, Id::dtor);
|
|
40 parent = sc.parent;
|
|
41 Dsymbol parent = toParent();
|
|
42 AggregateDeclaration ad = parent.isAggregateDeclaration();
|
|
43 if (!ad)
|
|
44 {
|
|
45 error("destructors are only for class/struct/union definitions, not %s %s", parent.kind(), parent.toChars());
|
|
46 }
|
|
47 else if (ident == Id.dtor)
|
|
48 ad.dtors.push(cast(void*)this);
|
|
49
|
|
50 type = new TypeFunction(null, Type.tvoid, false, LINK.LINKd);
|
|
51
|
|
52 sc = sc.push();
|
|
53 sc.stc &= ~STCstatic; // not a static destructor
|
|
54 sc.linkage = LINK.LINKd;
|
|
55
|
|
56 FuncDeclaration.semantic(sc);
|
|
57
|
|
58 sc.pop();
|
|
59 }
|
|
60
|
|
61 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
62 {
|
|
63 assert(false);
|
|
64 }
|
|
65
|
|
66 string kind()
|
|
67 {
|
|
68 assert(false);
|
|
69 }
|
|
70
|
|
71 string toChars()
|
|
72 {
|
|
73 return "~this";
|
|
74 }
|
|
75
|
|
76 bool isVirtual()
|
|
77 {
|
|
78 /* This should be FALSE so that dtor's don't get put into the vtbl[],
|
|
79 * but doing so will require recompiling everything.
|
|
80 */
|
|
81 version (BREAKABI) {
|
|
82 return false;
|
|
83 } else {
|
|
84 return FuncDeclaration.isVirtual();
|
|
85 }
|
|
86 }
|
|
87
|
|
88 bool addPreInvariant()
|
|
89 {
|
|
90 return (isThis() && vthis && global.params.useInvariants);
|
|
91 }
|
|
92
|
|
93 bool addPostInvariant()
|
|
94 {
|
|
95 return false;
|
|
96 }
|
|
97
|
|
98 bool overloadInsert(Dsymbol s)
|
|
99 {
|
|
100 assert(false);
|
|
101 }
|
|
102
|
|
103 void emitComment(Scope sc)
|
|
104 {
|
|
105 assert(false);
|
|
106 }
|
|
107
|
|
108 DtorDeclaration isDtorDeclaration() { return this; }
|
|
109 } |