comparison ast/Stmt.d @ 143:d76cc5cad4fc

Added partial support for switches. Added support for extern(C) in CodeGen.
author Anders Johnsen <skabet@gmail.com>
date Mon, 21 Jul 2008 01:05:20 +0200
parents a22e3663de89
children 393a1f47a6d2 6c5a3c0bb4fb
comparison
equal deleted inserted replaced
142:1e48315c36fc 143:d76cc5cad4fc
173 { 173 {
174 super(StmtType.Switch); 174 super(StmtType.Switch);
175 cond = target; 175 cond = target;
176 } 176 }
177 177
178 void addCase(IntegerLit[] values, Stmt[] stmts) 178 void addCase(Exp[] values, Stmt[] stmts)
179 { 179 {
180 long[] new_values; 180 // long[] new_values;
181 foreach (lit; values) 181 // foreach (lit; values)
182 new_values ~= Integer.parse(lit.get); 182 // new_values ~= Integer.parse(lit.get);
183 cases ~= Case(values, stmts, new_values); 183 // cases ~= Case(values, stmts, new_values);
184 cases ~= Case(values, stmts);
184 185
185 // Make sure there is no two cases with the same value 186 // Make sure there is no two cases with the same value
186 // Does it belong here? 187 // Does it belong here?
187 new_values = new_values.dup; 188 /+ new_values = new_values.dup;
188 Array.sort(new_values); 189 Array.sort(new_values);
189 long[] all_values = Array.unionOf(old_values, new_values); 190 long[] all_values = Array.unionOf(old_values, new_values);
190 if (all_values.length != old_values.length + new_values.length) 191 if (all_values.length != old_values.length + new_values.length)
191 { 192 {
192 // overlap! 193 // overlap!
209 e.tok(c.values[i].token); 210 e.tok(c.values[i].token);
210 */ 211 */
211 throw e;+/ 212 throw e;+/
212 } 213 }
213 old_values = all_values; 214 old_values = all_values;
215 +/
214 } 216 }
215 217
216 void setDefault(Stmt[] stmts) 218 void setDefault(Stmt[] stmts)
217 { 219 {
218 // TODO: Move this to another sema file where it can be enforced. 220 // TODO: Move this to another sema file where it can be enforced.
239 Case[] cases; 241 Case[] cases;
240 Stmt[] defaultBlock; 242 Stmt[] defaultBlock;
241 243
242 struct Case 244 struct Case
243 { 245 {
244 IntegerLit[] values; 246 Exp[] values;
245 Stmt[] stmts; 247 Stmt[] stmts;
246 long[] values_converted; 248 long[] values_converted;
247 bool followedByDefault = false; 249 bool followedByDefault = false;
248 } 250 }
249 251