annotate dmd/ForStatement.d @ 187:b0d41ff5e0df

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