annotate dmd/CompoundStatement.d @ 182:b64060ab22df

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