annotate dmd/ForStatement.d @ 178:e3afd1303184

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