annotate dmd/StaticDtorDeclaration.d @ 179:cd48cb899aee

Updated to dmd2.040
author korDen
date Sun, 17 Oct 2010 20:56:07 +0400
parents e3afd1303184
children b0d41ff5e0df
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 class StaticDtorDeclaration : FuncDeclaration
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 VarDeclaration vgate; // 'gate' variable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
37 this(Loc loc, Loc endloc, string name = "_staticDtor")
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 122
diff changeset
39 register();
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
40 super(loc, endloc, Identifier.generateId(name), STCstatic, null);
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
41 vgate = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
44 override Dsymbol syntaxCopy(Dsymbol s)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 {
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
46 assert(!s);
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
47 StaticDtorDeclaration sdd = new StaticDtorDeclaration(loc, endloc);
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
48 return super.syntaxCopy(sdd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
51 override void semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
53 ClassDeclaration cd = sc.scopesym.isClassDeclaration();
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
54 if (!type)
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
55 type = new TypeFunction(null, Type.tvoid, false, LINK.LINKd);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 /* If the static ctor appears within a template instantiation,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 * it could get called multiple times by the module constructors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 * for different modules. Thus, protect it with a gate.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 */
179
cd48cb899aee Updated to dmd2.040
korDen
parents: 178
diff changeset
61 if (inTemplateInstance() && semanticRun < PASSsemantic)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 /* Add this prefix to the function:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 * static int gate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 * if (--gate != 0) return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 * Increment gate during constructor execution.
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 destruction.
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 = isSharedStaticDtorDeclaration() ? STCstatic : STCtls;
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
73 auto sa = new Statements();
0
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(0));
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 vgate = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 FuncDeclaration.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 // We're going to need ModuleInfo
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 Module m = getModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (!m)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 m = sc.module_;
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("module2 %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
100
8e1e220cebb3 implemented missing methods
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
100
8e1e220cebb3 implemented missing methods
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
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
113 override bool addPreInvariant()
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
114 {
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
115 return false;
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
116 }
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
117
8e1e220cebb3 implemented missing methods
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
100
8e1e220cebb3 implemented missing methods
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
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
127 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 {
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
129 if (hgs.hdrgen)
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
130 return;
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
131 buf.writestring("static ~this()");
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
132 bodyToCBuffer(buf, hgs);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
135 override void toJsonBuffer(OutBuffer buf)
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
136 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
137 }
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
138
100
8e1e220cebb3 implemented missing methods
Trass3r
parents: 79
diff changeset
139 override StaticDtorDeclaration isStaticDtorDeclaration() { return this; }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
140 }