@@ -4556,6 +4556,29 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
4556
4556
ret result;
4557
4557
}
4558
4558
4559
+ // Finds the ValueRef associated with a variable in a function
4560
+ // context. It checks locals, upvars, and args.
4561
+ fn find_variable(&@fn_ctxt fcx, ast::node_id nid) -> ValueRef {
4562
+ ret
4563
+ alt (fcx.lllocals.find(nid)) {
4564
+ case (none) {
4565
+ alt (fcx.llupvars.find(nid)) {
4566
+ case (none) {
4567
+ alt (fcx.llargs.find(nid)) {
4568
+ case (some(?llval)) { llval }
4569
+ case (_) {
4570
+ fcx.lcx.ccx.sess.bug("unbound var \
4571
+ in build_environment " + int::str(nid))
4572
+ }
4573
+ }
4574
+ }
4575
+ case (some(?llval)) { llval }
4576
+ }
4577
+ }
4578
+ case (some(?llval)) { llval }
4579
+ }
4580
+ }
4581
+
4559
4582
// Given a block context and a list of upvars, construct a closure that
4560
4583
// contains pointers to all of the upvars and all of the tydescs in
4561
4584
// scope. Return the ValueRef and TypeRef corresponding to the closure.
@@ -4575,24 +4598,7 @@ fn build_environment(&@block_ctxt cx, &ast::node_id[] upvars) ->
4575
4598
llbindingtys += ~[val_ty(llbindings.(0))];
4576
4599
}
4577
4600
for (ast::node_id nid in upvars) {
4578
- auto llbinding;
4579
- alt (cx.fcx.lllocals.find(nid)) {
4580
- case (none) {
4581
- alt (cx.fcx.llupvars.find(nid)) {
4582
- case (none) {
4583
- alt (cx.fcx.llargs.find(nid)) {
4584
- case (some(?x)) { llbinding = x; }
4585
- case (_) {
4586
- cx.fcx.lcx.ccx.sess.bug("unbound var \
4587
- in build_environment " + int::str(nid));
4588
- }
4589
- }
4590
- }
4591
- case (some(?llval)) { llbinding = llval; }
4592
- }
4593
- }
4594
- case (some(?llval)) { llbinding = llval; }
4595
- }
4601
+ auto llbinding = find_variable(cx.fcx, nid);
4596
4602
llbindings += ~[llbinding];
4597
4603
llbindingtys += ~[val_ty(llbinding)];
4598
4604
}
0 commit comments