|
11 | 11 | use llvm::ValueRef;
|
12 | 12 | use middle::def;
|
13 | 13 | use middle::lang_items::{PanicFnLangItem, PanicBoundsCheckFnLangItem};
|
14 |
| -use trans::_match; |
15 |
| -use trans::adt; |
16 | 14 | use trans::base::*;
|
17 | 15 | use trans::build::*;
|
18 | 16 | use trans::callee;
|
19 | 17 | use trans::cleanup::CleanupMethods;
|
20 | 18 | use trans::cleanup;
|
21 | 19 | use trans::common::*;
|
22 | 20 | use trans::consts;
|
23 |
| -use trans::datum; |
24 | 21 | use trans::debuginfo;
|
25 | 22 | use trans::debuginfo::{DebugLoc, ToDebugLoc};
|
26 | 23 | use trans::expr;
|
27 |
| -use trans::meth; |
28 |
| -use trans::type_::Type; |
29 | 24 | use trans;
|
30 | 25 | use middle::ty;
|
31 |
| -use middle::ty::MethodCall; |
32 | 26 | use util::ppaux::Repr;
|
33 |
| -use util::ppaux; |
34 | 27 |
|
35 | 28 | use syntax::ast;
|
36 | 29 | use syntax::ast::Ident;
|
@@ -259,135 +252,6 @@ pub fn trans_while<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
259 | 252 | return next_bcx_in;
|
260 | 253 | }
|
261 | 254 |
|
262 |
| -/// Translates a `for` loop. |
263 |
| -pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, |
264 |
| - loop_info: NodeIdAndSpan, |
265 |
| - pat: &ast::Pat, |
266 |
| - head: &ast::Expr, |
267 |
| - body: &ast::Block) |
268 |
| - -> Block<'blk, 'tcx> |
269 |
| -{ |
270 |
| - let _icx = push_ctxt("trans_for"); |
271 |
| - |
272 |
| - // bcx |
273 |
| - // | |
274 |
| - // loopback_bcx_in <-------+ |
275 |
| - // | | |
276 |
| - // loopback_bcx_out | |
277 |
| - // | | | |
278 |
| - // | body_bcx_in | |
279 |
| - // cleanup_blk | | |
280 |
| - // | body_bcx_out --+ |
281 |
| - // next_bcx_in |
282 |
| - |
283 |
| - // Codegen the head to create the iterator value. |
284 |
| - let iterator_datum = |
285 |
| - unpack_datum!(bcx, expr::trans_to_lvalue(bcx, head, "for_head")); |
286 |
| - let iterator_type = node_id_type(bcx, head.id); |
287 |
| - debug!("iterator type is {}, datum type is {}", |
288 |
| - ppaux::ty_to_string(bcx.tcx(), iterator_type), |
289 |
| - ppaux::ty_to_string(bcx.tcx(), iterator_datum.ty)); |
290 |
| - |
291 |
| - let lliterator = load_ty(bcx, iterator_datum.val, iterator_datum.ty); |
292 |
| - |
293 |
| - // Create our basic blocks and set up our loop cleanups. |
294 |
| - let next_bcx_in = bcx.fcx.new_id_block("for_exit", loop_info.id); |
295 |
| - let loopback_bcx_in = bcx.fcx.new_id_block("for_loopback", head.id); |
296 |
| - let body_bcx_in = bcx.fcx.new_id_block("for_body", body.id); |
297 |
| - bcx.fcx.push_loop_cleanup_scope(loop_info.id, |
298 |
| - [next_bcx_in, loopback_bcx_in]); |
299 |
| - Br(bcx, loopback_bcx_in.llbb, DebugLoc::None); |
300 |
| - let cleanup_llbb = bcx.fcx.normal_exit_block(loop_info.id, |
301 |
| - cleanup::EXIT_BREAK); |
302 |
| - |
303 |
| - // Set up the method call (to `.next()`). |
304 |
| - let method_call = MethodCall::expr(loop_info.id); |
305 |
| - let method_type = (*loopback_bcx_in.tcx() |
306 |
| - .method_map |
307 |
| - .borrow())[method_call] |
308 |
| - .ty; |
309 |
| - let method_type = monomorphize_type(loopback_bcx_in, method_type); |
310 |
| - let method_result_type = |
311 |
| - ty::assert_no_late_bound_regions( // LB regions are instantiated in invoked methods |
312 |
| - loopback_bcx_in.tcx(), &ty::ty_fn_ret(method_type)).unwrap(); |
313 |
| - let option_cleanup_scope = body_bcx_in.fcx.push_custom_cleanup_scope(); |
314 |
| - let option_cleanup_scope_id = cleanup::CustomScope(option_cleanup_scope); |
315 |
| - |
316 |
| - // Compile the method call (to `.next()`). |
317 |
| - let mut loopback_bcx_out = loopback_bcx_in; |
318 |
| - let option_datum = |
319 |
| - unpack_datum!(loopback_bcx_out, |
320 |
| - datum::lvalue_scratch_datum(loopback_bcx_out, |
321 |
| - method_result_type, |
322 |
| - "loop_option", |
323 |
| - false, |
324 |
| - option_cleanup_scope_id, |
325 |
| - (), |
326 |
| - |(), bcx, lloption| { |
327 |
| - let Result { |
328 |
| - bcx, |
329 |
| - val: _ |
330 |
| - } = callee::trans_call_inner(bcx, |
331 |
| - Some(loop_info), |
332 |
| - method_type, |
333 |
| - |bcx, arg_cleanup_scope| { |
334 |
| - meth::trans_method_callee( |
335 |
| - bcx, |
336 |
| - method_call, |
337 |
| - None, |
338 |
| - arg_cleanup_scope) |
339 |
| - }, |
340 |
| - callee::ArgVals(&[lliterator]), |
341 |
| - Some(expr::SaveIn(lloption))); |
342 |
| - bcx |
343 |
| - })); |
344 |
| - |
345 |
| - // Check the discriminant; if the `None` case, exit the loop. |
346 |
| - let option_representation = adt::represent_type(loopback_bcx_out.ccx(), |
347 |
| - method_result_type); |
348 |
| - let lldiscriminant = adt::trans_get_discr(loopback_bcx_out, |
349 |
| - &*option_representation, |
350 |
| - option_datum.val, |
351 |
| - None); |
352 |
| - let i1_type = Type::i1(loopback_bcx_out.ccx()); |
353 |
| - let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type); |
354 |
| - CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb, DebugLoc::None); |
355 |
| - |
356 |
| - // Now we're in the body. Unpack the `Option` value into the programmer- |
357 |
| - // supplied pattern. |
358 |
| - let llpayload = adt::trans_field_ptr(body_bcx_in, |
359 |
| - &*option_representation, |
360 |
| - option_datum.val, |
361 |
| - 1, |
362 |
| - 0); |
363 |
| - let binding_cleanup_scope = body_bcx_in.fcx.push_custom_cleanup_scope(); |
364 |
| - let binding_cleanup_scope_id = |
365 |
| - cleanup::CustomScope(binding_cleanup_scope); |
366 |
| - let mut body_bcx_out = |
367 |
| - _match::store_for_loop_binding(body_bcx_in, |
368 |
| - pat, |
369 |
| - llpayload, |
370 |
| - binding_cleanup_scope_id); |
371 |
| - |
372 |
| - debuginfo::create_for_loop_var_metadata(body_bcx_in, pat); |
373 |
| - |
374 |
| - // Codegen the body. |
375 |
| - body_bcx_out = trans_block(body_bcx_out, body, expr::Ignore); |
376 |
| - body_bcx_out = |
377 |
| - body_bcx_out.fcx |
378 |
| - .pop_and_trans_custom_cleanup_scope(body_bcx_out, |
379 |
| - binding_cleanup_scope); |
380 |
| - body_bcx_out = |
381 |
| - body_bcx_out.fcx |
382 |
| - .pop_and_trans_custom_cleanup_scope(body_bcx_out, |
383 |
| - option_cleanup_scope); |
384 |
| - Br(body_bcx_out, loopback_bcx_in.llbb, DebugLoc::None); |
385 |
| - |
386 |
| - // Codegen cleanups and leave. |
387 |
| - next_bcx_in.fcx.pop_loop_cleanup_scope(loop_info.id); |
388 |
| - next_bcx_in |
389 |
| -} |
390 |
| - |
391 | 255 | pub fn trans_loop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
392 | 256 | loop_expr: &ast::Expr,
|
393 | 257 | body: &ast::Block)
|
|
0 commit comments