annotate dmd/CompoundStatement.d @ 177:1475fd394c9e

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