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