annotate dmd/IfStatement.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children 14feb7ae01a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
5 import dmd.Parameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.ScopeDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.CondExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.AndAndExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.OrOrExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.AssignExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 class IfStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
35 Parameter arg;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Expression condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 Statement ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 Statement elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 VarDeclaration match; // for MatchExpression results
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
42 this(Loc loc, Parameter arg, Expression condition, Statement ifbody, Statement elsebody)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 this.arg = arg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 this.condition = condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 this.ifbody = ifbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 this.elsebody = elsebody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
51 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
53 Statement i = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
54 if (ifbody)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
55 i = ifbody.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
56
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
57 Statement e = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
58 if (elsebody)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
59 e = elsebody.syntaxCopy();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
60
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
61 Parameter a = arg ? arg.syntaxCopy() : null;
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
62 IfStatement s = new IfStatement(loc, a, condition.syntaxCopy(), i, e);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
63 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
66 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 condition = condition.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 condition = resolveProperties(sc, condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 condition = condition.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 // If we can short-circuit evaluate the if statement, don't do the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 // semantic analysis of the skipped code.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 // This feature allows a limited form of conditional compilation.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 condition = condition.optimize(WANT.WANTflags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 // Evaluate at runtime
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 uint cs0 = sc.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 uint cs1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Scope scd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 /* Declare arg, which we will set to be the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 * result of condition.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 ScopeDsymbol sym = new ScopeDsymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 sym.parent = sc.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 scd = sc.push(sym);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 Type t = arg.type ? arg.type : condition.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 match = new VarDeclaration(loc, t, arg.ident, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 match.noauto = true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 match.semantic(scd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (!scd.insert(match))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 match.parent = sc.func;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 /* Generate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 * (arg = condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 VarExp v = new VarExp(Loc(0), match);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 condition = new AssignExp(loc, v, condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 condition = condition.semantic(scd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 scd = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 ifbody = ifbody.semantic(scd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 scd.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 cs1 = sc.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 sc.callSuper = cs0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 elsebody = elsebody.semanticScope(sc, null, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 sc.mergeCallSuper(loc, cs1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
123 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
128 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
133 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
138 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 //printf("IfStatement::blockExit(%p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 BE result = BE.BEnone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (condition.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 if (condition.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (ifbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 result |= ifbody.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 else if (condition.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 result |= elsebody.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 if (ifbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 result |= ifbody.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 result |= elsebody.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 //printf("IfStatement::blockExit(%p) = x%x\n", this, result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
176 override IfStatement isIfStatement() { return this; }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
178 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 int cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 /* Can't declare variables inside ?: expressions, so
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 * we cannot inline if a variable is declared.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 if (arg)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 return COST_MAX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 cost = condition.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 /* Specifically allow:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 * if (condition)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 * return exp1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 * else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 * return exp2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 * Otherwise, we can't handle return statements nested in if's.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 if (elsebody && ifbody &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 ifbody.isReturnStatement() &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 elsebody.isReturnStatement())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 cost += ifbody.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 cost += elsebody.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 //printf("cost = %d\n", cost);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 ics.nested += 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 if (ifbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 cost += ifbody.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 cost += elsebody.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 ics.nested -= 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 return cost;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
218 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 Expression econd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 Expression e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 Expression e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 assert(!arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 econd = condition.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 assert(econd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 if (ifbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 e1 = ifbody.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 e1 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 e2 = elsebody.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 e2 = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 if (e1 && e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 e = new CondExp(econd.loc, econd, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 e.type = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 else if (e1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 e = new AndAndExp(econd.loc, econd, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 e.type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 else if (e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 e = new OrOrExp(econd.loc, econd, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 e.type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 e = econd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
258 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 condition = condition.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 if (ifbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 ifbody = ifbody.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 elsebody = elsebody.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
268 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 //printf("IfStatement::toIR('%s')\n", condition.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 IRState mystate = IRState(irs, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 // bexit is the block that gets control after this IfStatement is done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 block* bexit = mystate.breakBlock ? mystate.breakBlock : block_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 if (match)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 /* Generate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 * if (match = RTLSYM_IFMATCH(string, pattern)) ...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 assert(condition.op == TOK.TOKmatch);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 e = matchexp_toelem(cast(MatchExp)condition, &mystate, RTLSYM.RTLSYM_IFMATCH);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 Symbol *s = match.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 symbol_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 e = el_bin(OPeq, TYnptr, el_var(s), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 e = condition.toElem(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 e = condition.toElem(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 block_appendexp(blx.curblock, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 block* bcond = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 block_next(blx, BC.BCiftrue, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 list_append(&bcond.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 if (ifbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 ifbody.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 list_append(&blx.curblock.Bsucc, bexit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 if (elsebody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 block_next(blx, BC.BCgoto, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 list_append(&bcond.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 elsebody.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 list_append(&blx.curblock.Bsucc, bexit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 list_append(&bcond.Bsucc, bexit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 block_next(blx, BC.BCgoto, bexit);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
322 }