annotate dmd/StaticDtorDeclaration.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents cd48cb899aee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.StaticDtorDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 110
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.EqualExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.AddAssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
33 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
34
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 class StaticDtorDeclaration : FuncDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
37 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 179
diff changeset
38
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 VarDeclaration vgate; // 'gate' variable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
41 this(Loc loc, Loc endloc, string name = "_staticDtor")
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 122
diff changeset
43 register();
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
44 super(loc, endloc, Identifier.generateId(name), STCstatic, null);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
45 vgate = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
48 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 {
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
50 assert(!s);
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
51 StaticDtorDeclaration sdd = new StaticDtorDeclaration(loc, endloc);
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
52 return super.syntaxCopy(sdd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
55 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
57 ClassDeclaration cd = sc.scopesym.isClassDeclaration();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
58 if (!type)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
59 type = new TypeFunction(null, Type.tvoid, false, LINK.LINKd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 /* If the static ctor appears within a template instantiation,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 * it could get called multiple times by the module constructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 * for different modules. Thus, protect it with a gate.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 */
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
65 if (inTemplateInstance() && semanticRun < PASSsemantic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 /* Add this prefix to the function:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 * static int gate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 * if (--gate != 0) return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 * Increment gate during constructor execution.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 * Note that this is not thread safe; should not have threads
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 * during static destruction.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 Identifier id = Lexer.idPool("__gate");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 VarDeclaration v = new VarDeclaration(Loc(0), Type.tint32, id, null);
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
76 v.storage_class = isSharedStaticDtorDeclaration() ? STCstatic : STCtls;
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
77 auto sa = new Statements();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 Statement s = new DeclarationStatement(Loc(0), v);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
79 sa.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 Expression e = new IdentifierExp(Loc(0), id);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 e = new AddAssignExp(Loc(0), e, new IntegerExp(-1));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 e = new EqualExp(TOKnotequal, Loc(0), e, new IntegerExp(0));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 s = new IfStatement(Loc(0), null, e, new ReturnStatement(Loc(0), null), null);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
84 sa.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 if (fbody)
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
86 sa.push(fbody);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 fbody = new CompoundStatement(Loc(0), sa);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 vgate = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 FuncDeclaration.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 // We're going to need ModuleInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 Module m = getModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (!m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 m = sc.module_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 m.needmoduleinfo = 1;
98
5c859d5fbe27 and more
Trass3r
parents: 79
diff changeset
100 // writef("module2 %s needs moduleinfo\n", m.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 version (IN_GCC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 m.strictlyneedmoduleinfo = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
107 override AggregateDeclaration isThis()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
112 override bool isVirtual()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
117 override bool addPreInvariant()
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
118 {
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
119 return false;
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
120 }
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
121
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
122 override bool addPostInvariant()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
127 override void emitComment(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
131 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 {
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
133 if (hgs.hdrgen)
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
134 return;
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
135 buf.writestring("static ~this()");
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
136 bodyToCBuffer(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
139 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
140 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
141 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
142
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
143 override StaticDtorDeclaration isStaticDtorDeclaration() { return this; }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
144 }