annotate dmd/ForStatement.d @ 161:584dc990e12f

type fixed
author korDen
date Mon, 20 Sep 2010 01:19:36 +0400
parents 9e39c7de8438
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.ForStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Expression;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
6 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 class ForStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 Statement init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 Expression condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 Expression increment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this(Loc loc, Statement init, Expression condition, Expression increment, Statement body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 this.init = init;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 this.condition = condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 this.increment = increment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 this.body_ = body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
40 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 Statement i = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 i = init.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 Expression c = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 c = condition.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 Expression inc = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 if (increment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 inc = increment.syntaxCopy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 ForStatement s = new ForStatement(loc, i, c, inc, body_.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
55 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 ScopeDsymbol sym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 sym.parent = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 sc = sc.push(sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 init = init.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 sc.noctor++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 condition = condition.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 condition = resolveProperties(sc, condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 condition = condition.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 condition = condition.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 if (increment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 increment = increment.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 increment = resolveProperties(sc, increment);
79
43073c7c7769 updated to 2.035
Trass3r
parents: 72
diff changeset
74 increment = increment.optimize(0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 sc.sbreak = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 sc.scontinue = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 body_ = body_.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 sc.noctor--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
87 override void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 //printf("ForStatement::scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 init.scopeCode(sc, sentry, sexception, sfinally);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 Statement.scopeCode(sc, sentry, sexception, sfinally);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
97 override bool hasBreak()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 //printf("ForStatement.hasBreak()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
103 override bool hasContinue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
108 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 return (init && init.usesEH()) || body_.usesEH();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
113 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 BE result = BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 result = init.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 if (!(result & BE.BEfallthru))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if (condition.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 if (condition.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 result &= ~BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 else if (condition.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 result &= ~BE.BEfallthru; // the body must do the exiting
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 int r = body_.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (r & (BE.BEbreak | BE.BEgoto))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 result |= r & ~(BE.BEfallthru | BE.BEbreak | BE.BEcontinue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (increment && increment.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
146 override bool comeFrom()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 //printf("ForStatement.comeFrom()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 bool result = body_.comeFrom();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 //printf("result = %d\n", result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
158 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
160 version (LOG) {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
161 printf("ForStatement.interpret()\n");
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
162 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
163 if (istate.start == this)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
164 istate.start = null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
165
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
166 Expression e;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
167
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
168 if (init)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
169 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
170 e = init.interpret(istate);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
171 if (e is EXP_CANT_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
172 return e;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
173 assert(!e);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
174 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
175
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
176 if (istate.start)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
177 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
178 e = body_ ? body_.interpret(istate) : null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
179 if (istate.start)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
180 return null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
181 if (e is EXP_CANT_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
182 return e;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
183 if (e is EXP_BREAK_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
184 return null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
185 if (e is EXP_CONTINUE_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
186 goto Lcontinue;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
187 if (e)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
188 return e;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
189 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
190
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
191 while (true)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
192 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
193 if (!condition)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
194 goto Lhead;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
195 e = condition.interpret(istate);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
196 if (e is EXP_CANT_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
197 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
198 if (!e.isConst())
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
199 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
200 e = EXP_CANT_INTERPRET;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
201 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
202 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
203 if (e.isBool(true))
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
204 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
205 Lhead:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
206 e = body_ ? body_.interpret(istate) : null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
207 if (e is EXP_CANT_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
208 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
209 if (e is EXP_BREAK_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
210 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
211 e = null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
212 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
213 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
214 if (e && e !is EXP_CONTINUE_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
215 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
216 Lcontinue:
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
217 if (increment)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
218 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
219 e = increment.interpret(istate);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
220 if (e is EXP_CANT_INTERPRET)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
221 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
222 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
223 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
224 else if (e.isBool(false))
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
225 {
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
226 e = null;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
227 break;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
228 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
229 else
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
230 assert(0);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
231 }
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
232 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
235 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 buf.writestring("for (");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 hgs.FLinit.init++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 init.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 hgs.FLinit.init--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 buf.writebyte(';');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 { buf.writebyte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 condition.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 buf.writebyte(';');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 if (increment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 buf.writebyte(' ');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 increment.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 buf.writebyte(')');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 buf.writebyte('{');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 body_.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 buf.writebyte('}');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
265 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 init = init.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 condition = condition.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 if (increment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 increment = increment.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 body_ = body_.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 return this;
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 void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 IRState mystate = IRState(irs,this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 mystate.breakBlock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 mystate.contBlock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 if (init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 init.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 block* bpre = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 block_next(blx,BCgoto,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 block* bcond = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 list_append(&bpre.Bsucc, bcond);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 list_append(&mystate.contBlock.Bsucc, bcond);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 incUsage(irs, condition.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 block_appendexp(bcond, condition.toElem(&mystate));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 block_next(blx,BCiftrue,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 list_append(&bcond.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 list_append(&bcond.Bsucc, mystate.breakBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 /* No conditional, it's a straight goto
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 block_next(blx,BCgoto,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 list_append(&bcond.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 body_.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 /* End of the body goes to the continue block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 list_append(&blx.curblock.Bsucc, mystate.contBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 block_next(blx, BCgoto, mystate.contBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 if (increment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 incUsage(irs, increment.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 block_appendexp(mystate.contBlock, increment.toElem(&mystate));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 /* The 'break' block follows the for statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 block_next(blx,BCgoto, mystate.breakBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
326 }