annotate dmd/CompoundStatement.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.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 93
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.TryCatchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Catch;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.ThrowStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.IdentifierExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
30 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
31
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 class CompoundStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
34 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
35
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Statements statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this(Loc loc, Statements s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
40 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 statements = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 this(Loc loc, Statement s1, Statement s2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 177
diff changeset
47 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 statements = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 statements.reserve(2);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
52 statements.push(s1);
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
53 statements.push(s2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
56 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 Statements a = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 a.setDim(statements.dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
61 foreach (size_t i, Statement s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 s = s.syntaxCopy();
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
65 a[i] = s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return new CompoundStatement(loc, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
71 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
73 foreach (s; statements)
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
74 {
177
1475fd394c9e bug fixes
korDen
parents: 174
diff changeset
75 if (s)
93
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
76 s.toCBuffer(buf, hgs);
df6d0f967680 implemented a whole bunch of methods to make phobos 2.035 compile
Trass3r
parents: 79
diff changeset
77 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79
167
50a6d232176c rewrite GlobalExpressions, moved DsymbolTable to Global, some cleanup
korDen
parents: 123
diff changeset
80 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 //printf("CompoundStatement.semantic(this = %p, sc = %p)\n", this, sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 for (size_t i = 0; i < statements.dim; )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
88 s = statements[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 Statements a = s.flatten(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 if (a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 statements.remove(i);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 statements.insert(i, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
27
0613413fa94c Accidentally removed line restored.
korDen
parents: 25
diff changeset
99
0613413fa94c Accidentally removed line restored.
korDen
parents: 25
diff changeset
100 s = s.semantic(sc);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
102 statements[i] = s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 Statement sentry;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Statement sexception;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 Statement sfinally;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 s.scopeCode(sc, &sentry, &sexception, &sfinally);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 if (sentry)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 sentry = sentry.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (s.isDeclarationStatement())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
115 statements.insert(i, sentry);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 i++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 else
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
119 statements[i] = sentry;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 if (sexception)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 if (i + 1 == statements.dim && !sfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 sexception = sexception.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 statements.push(sexception);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 if (sfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 // Assume sexception does not throw
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 statements.push(sfinally);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 /* Rewrite:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 * s; s1; s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 * As:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 * s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 * try { s1; s2; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 * catch (Object __o)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 * { sexception; throw __o; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 Statements aa = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 for (int j = i + 1; j < statements.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
149 aa.push(statements[j]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 body_ = new CompoundStatement(Loc(0), aa);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 body_ = new ScopeStatement(Loc(0), body_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 Identifier id = Lexer.uniqueId("__o");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 Statement handler = new ThrowStatement(Loc(0), new IdentifierExp(Loc(0), id));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 handler = new CompoundStatement(Loc(0), sexception, handler);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 Array catches = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 Catch ctch = new Catch(Loc(0), null, id, handler);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 catches.push(cast(void*)ctch);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 s = new TryCatchStatement(Loc(0), body_, catches);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 if (sfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 s = new TryFinallyStatement(Loc(0), s, sfinally);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 s = s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 statements.setDim(i + 1);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
168 statements.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 else if (sfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 if (0 && i + 1 == statements.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
176 statements.push(sfinally);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 /* Rewrite:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 * s; s1; s2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 * As:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 * s; try { s1; s2; } finally { sfinally; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 Statements aa = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 for (int j = i + 1; j < statements.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
190 aa.push(statements[j]);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 body_ = new CompoundStatement(Loc(0), aa);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 s = new TryFinallyStatement(Loc(0), body_, sfinally);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 s = s.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 statements.setDim(i + 1);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
196 statements.push(s);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 i++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (statements.dim == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
206 return statements[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
211 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
213 foreach (Statement s; statements)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
214 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
215 if (s && s.usesEH())
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
216 return true;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
217 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
218
9e39c7de8438 Make dmd test suite compile
korDen
parents: 122
diff changeset
219 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
222 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 //printf("CompoundStatement::blockExit(%p) %d\n", this, statements->dim);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 BE result = BE.BEfallthru;
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
226 foreach (s; statements)
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
227 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 //printf("result = x%x\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 //printf("%s\n", s->toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 if (!(result & BE.BEfallthru) && !s.comeFrom())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
234 if (s.blockExit() != BE.BEhalt && !s.isEmpty())
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 s.warning("statement is not reachable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
237 else
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
238 {
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
239 result &= ~BE.BEfallthru;
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
240 result |= s.blockExit();
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
241 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
248 override bool comeFrom()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
253 override bool isEmpty()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
255 foreach (s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 if (s && !s.isEmpty())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
263 override Statements flatten(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 return statements;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
268 override ReturnStatement isReturnStatement()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 ReturnStatement rs = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
272 foreach(s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 rs = s.isReturnStatement();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 if (rs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 return rs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
284 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 {
63
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
286 Expression e = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
287
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
288 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
289 printf("CompoundStatement.interpret()\n");
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
290 }
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
291 if (istate.start == this)
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
292 istate.start = null;
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
293 if (statements)
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
294 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
295 foreach(s; statements)
63
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
296 {
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
297 if (s)
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
298 {
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
299 e = s.interpret(istate);
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
300 if (e)
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
301 break;
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
302 }
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
303 }
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
304 }
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
305 version (LOG) {
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
306 printf("-CompoundStatement.interpret() %p\n", e);
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
307 }
cab4c37afb89 A bunch of implementations
korDen
parents: 27
diff changeset
308 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
311 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 int cost = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
315 foreach(s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 cost += s.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 if (cost >= COST_MAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 return cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
328 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 Expression e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 //printf("CompoundStatement.doInline() %d\n", statements.dim);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
333 foreach(s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 if (s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 Expression e2 = s.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 e = Expression.combine(e, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 if (s.isReturnStatement())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 /* Check for:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 * if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 * return exp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 * else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 * return exp2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 IfStatement ifs = s.isIfStatement();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 if (ifs && ifs.elsebody && ifs.ifbody &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 ifs.ifbody.isReturnStatement() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 ifs.elsebody.isReturnStatement()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
359 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
361 foreach(ref Statement s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 if (s)
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
364 s = s.inlineScan(iss);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
370 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 if (statements)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
374 foreach(s; statements)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 if (s !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 167
diff changeset
378 //writeln(s.classinfo.name);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 s.toIR(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
385 override CompoundStatement isCompoundStatement() { return this; }
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
386 }