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