Mercurial > projects > ddmd
annotate dmd/DtorDeclaration.d @ 98:5c859d5fbe27
and more
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 03:53:49 +0200 |
parents | 43073c7c7769 |
children | e28b18c23469 |
rev | line source |
---|---|
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 { | |
98 | 20 this(Loc loc, Loc endloc) |
0 | 21 { |
22 super(loc, endloc, Id.dtor, STCundefined, null); | |
23 } | |
24 | |
98 | 25 this(Loc loc, Loc endloc, Identifier id) |
0 | 26 { |
98 | 27 super(loc, endloc, id, STCundefined, null); |
0 | 28 } |
29 | |
98 | 30 override Dsymbol syntaxCopy(Dsymbol s) |
0 | 31 { |
98 | 32 assert(!s); |
33 DtorDeclaration dd = new DtorDeclaration(loc, endloc, ident); | |
34 return super.syntaxCopy(dd); | |
0 | 35 } |
36 | |
98 | 37 override void semantic(Scope sc) |
0 | 38 { |
39 //printf("DtorDeclaration::semantic() %s\n", toChars()); | |
40 //printf("ident: %s, %s, %p, %p\n", ident.toChars(), Id::dtor.toChars(), ident, Id::dtor); | |
41 parent = sc.parent; | |
42 Dsymbol parent = toParent(); | |
43 AggregateDeclaration ad = parent.isAggregateDeclaration(); | |
44 if (!ad) | |
45 { | |
46 error("destructors are only for class/struct/union definitions, not %s %s", parent.kind(), parent.toChars()); | |
47 } | |
48 else if (ident == Id.dtor) | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
49 ad.dtors.push(this); |
0 | 50 |
51 type = new TypeFunction(null, Type.tvoid, false, LINK.LINKd); | |
52 | |
53 sc = sc.push(); | |
54 sc.stc &= ~STCstatic; // not a static destructor | |
55 sc.linkage = LINK.LINKd; | |
56 | |
98 | 57 super.semantic(sc); |
0 | 58 |
59 sc.pop(); | |
60 } | |
61 | |
98 | 62 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 63 { |
98 | 64 buf.writestring("~this()"); |
65 bodyToCBuffer(buf, hgs); | |
0 | 66 } |
98 | 67 |
79 | 68 override void toJsonBuffer(OutBuffer buf) |
69 { | |
98 | 70 // intentionally empty |
79 | 71 } |
0 | 72 |
98 | 73 override string kind() |
0 | 74 { |
98 | 75 return "destructor"; |
0 | 76 } |
77 | |
98 | 78 override string toChars() |
0 | 79 { |
80 return "~this"; | |
81 } | |
82 | |
98 | 83 override bool isVirtual() |
0 | 84 { |
85 /* This should be FALSE so that dtor's don't get put into the vtbl[], | |
86 * but doing so will require recompiling everything. | |
87 */ | |
88 version (BREAKABI) { | |
89 return false; | |
90 } else { | |
98 | 91 return super.isVirtual(); |
0 | 92 } |
93 } | |
94 | |
98 | 95 override bool addPreInvariant() |
0 | 96 { |
97 return (isThis() && vthis && global.params.useInvariants); | |
98 } | |
99 | |
98 | 100 override bool addPostInvariant() |
0 | 101 { |
102 return false; | |
103 } | |
104 | |
98 | 105 override bool overloadInsert(Dsymbol s) |
0 | 106 { |
98 | 107 return false; // cannot overload destructors |
0 | 108 } |
109 | |
98 | 110 override void emitComment(Scope sc) |
0 | 111 { |
98 | 112 // intentionally empty |
0 | 113 } |
114 | |
98 | 115 override DtorDeclaration isDtorDeclaration() { return this; } |
72 | 116 } |