annotate dmd/SynchronizedStatement.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 e3afd1303184
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.SynchronizedStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.TypeIdentifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.CastExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.DeclarationExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.DotIdExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
40 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
41
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 class SynchronizedStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
44 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
45
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 Expression exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 this(Loc loc, Expression exp, Statement body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 122
diff changeset
51 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 this.exp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 this.body_ = body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 this.esync = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
59 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
64 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 if (exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 exp = resolveProperties(sc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 ClassDeclaration cd = exp.type.isClassHandle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 if (!cd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 error("can only synchronize on class objects, not '%s'", exp.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 else if (cd.isInterfaceDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 /* Cast the interface to an object, as the object has the monitor,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 * not the interface.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 Type t = new TypeIdentifier(Loc(0), Id.Object_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 t = t.semantic(Loc(0), sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 exp = new CastExp(loc, exp, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 exp = exp.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 /* Rewrite as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 * auto tmp = exp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 * _d_monitorenter(tmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 * try { body } finally { _d_monitorexit(tmp); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 Identifier id = Lexer.uniqueId("__sync");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 ExpInitializer ie = new ExpInitializer(loc, exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 VarDeclaration tmp = new VarDeclaration(loc, exp.type, id, ie);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 Statements cs = new Statements();
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
96 cs.push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 FuncDeclaration fdenter = FuncDeclaration.genCfunc(Type.tvoid, Id.monitorenter);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 Expression e = new CallExp(loc, new VarExp(loc, fdenter), new VarExp(loc, tmp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 e.type = Type.tvoid; // do not run semantic on e
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
101 cs.push(new ExpStatement(loc, e));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 FuncDeclaration fdexit = FuncDeclaration.genCfunc(Type.tvoid, Id.monitorexit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 e.type = Type.tvoid; // do not run semantic on e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Statement s = new ExpStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 s = new TryFinallyStatement(loc, body_, s);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
108 cs.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 s = new CompoundStatement(loc, cs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 /// static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 /* Generate our own critical section, then rewrite as:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 * __gshared byte[CriticalSection.sizeof] critsec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 * _d_criticalenter(critsec.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 * try { body } finally { _d_criticalexit(critsec.ptr); }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 Identifier id = Lexer.uniqueId("__critsec");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 Type t = new TypeSArray(Type.tint8, new IntegerExp(PTRSIZE + os_critsecsize()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 VarDeclaration tmp = new VarDeclaration(loc, t, id, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 tmp.storage_class |= STCgshared | STCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 Statements cs = new Statements();
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
128 cs.push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 FuncDeclaration fdenter = FuncDeclaration.genCfunc(Type.tvoid, Id.criticalenter);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 Expression e = new DotIdExp(loc, new VarExp(loc, tmp), Id.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 e = new CallExp(loc, new VarExp(loc, fdenter), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 e.type = Type.tvoid; // do not run semantic on e
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
135 cs.push(new ExpStatement(loc, e));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 FuncDeclaration fdexit = FuncDeclaration.genCfunc(Type.tvoid, Id.criticalexit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 e = new DotIdExp(loc, new VarExp(loc, tmp), Id.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 e = e.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 e = new CallExp(loc, new VarExp(loc, fdexit), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 e.type = Type.tvoid; // do not run semantic on e
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 Statement s = new ExpStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 s = new TryFinallyStatement(loc, body_, s);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
144 cs.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 s = new CompoundStatement(loc, cs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 return s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 body_ = body_.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
156 override bool hasBreak()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
161 override bool hasContinue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
166 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
171 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
176 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
181 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 elem* esync;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 this(Loc loc, elem *esync, Statement body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 122
diff changeset
191 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
196 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
200 }