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