@@ -399,10 +399,17 @@ struct ArmData<'self> {
399
399
bindings_map : @BindingsMap
400
400
}
401
401
402
+ /**
403
+ * Info about Match.
404
+ * If all `pats` are matched then arm `data` will be executed.
405
+ * As we proceed `bound_ptrs` are filled with pointers to values to be bound,
406
+ * these pointers are stored in llmatch variables just before executing `data` arm.
407
+ */
402
408
#[ deriving( Clone ) ]
403
409
struct Match < ' self > {
404
410
pats : ~[ @ast:: pat ] ,
405
- data : ArmData < ' self >
411
+ data : ArmData < ' self > ,
412
+ bound_ptrs : ~[ ( ident , ValueRef ) ]
406
413
}
407
414
408
415
impl < ' self > Repr for Match < ' self > {
@@ -447,14 +454,13 @@ fn expand_nested_bindings<'r>(bcx: @mut Block,
447
454
br. pats . slice ( col + 1 u,
448
455
br. pats . len ( ) ) ) ) ;
449
456
450
- let binding_info =
451
- br. data . bindings_map . get ( & path_to_ident ( path) ) ;
452
-
453
- Store ( bcx, val, binding_info. llmatch ) ;
454
- Match {
457
+ let mut res = Match {
455
458
pats : pats,
456
- data : br. data . clone ( )
457
- }
459
+ data : br. data . clone ( ) ,
460
+ bound_ptrs : br. bound_ptrs . clone ( )
461
+ } ;
462
+ res. bound_ptrs . push ( ( path_to_ident ( path) , val) ) ;
463
+ res
458
464
}
459
465
_ => ( * br) . clone ( ) ,
460
466
}
@@ -496,21 +502,20 @@ fn enter_match<'r>(bcx: @mut Block,
496
502
br. pats . slice ( col + 1 u, br. pats . len ( ) ) ) ;
497
503
498
504
let this = br. pats [ col] ;
505
+ let mut bound_ptrs = br. bound_ptrs . clone ( ) ;
499
506
match this. node {
500
507
ast:: pat_ident( _, ref path, None ) => {
501
508
if pat_is_binding ( dm, this) {
502
- let binding_info =
503
- br. data . bindings_map . get (
504
- & path_to_ident ( path) ) ;
505
- Store ( bcx, val, binding_info. llmatch ) ;
509
+ bound_ptrs. push ( ( path_to_ident ( path) , val) ) ;
506
510
}
507
511
}
508
512
_ => { }
509
513
}
510
514
511
515
result. push ( Match {
512
516
pats : pats,
513
- data : br. data . clone ( )
517
+ data : br. data . clone ( ) ,
518
+ bound_ptrs : bound_ptrs
514
519
} ) ;
515
520
}
516
521
None => ( )
@@ -1294,18 +1299,14 @@ fn store_non_ref_bindings(bcx: @mut Block,
1294
1299
1295
1300
fn insert_lllocals ( bcx : @mut Block ,
1296
1301
bindings_map : & BindingsMap ,
1297
- binding_mode : IrrefutablePatternBindingMode ,
1298
1302
add_cleans : bool ) -> @mut Block {
1299
1303
/*!
1300
1304
* For each binding in `data.bindings_map`, adds an appropriate entry into
1301
1305
* the `fcx.lllocals` map. If add_cleans is true, then adds cleanups for
1302
1306
* the bindings.
1303
1307
*/
1304
1308
1305
- let llmap = match binding_mode {
1306
- BindLocal => bcx. fcx . lllocals ,
1307
- BindArgument => bcx. fcx . llargs
1308
- } ;
1309
+ let llmap = bcx. fcx . lllocals ;
1309
1310
1310
1311
for ( & ident, & binding_info) in bindings_map. iter ( ) {
1311
1312
let llval = match binding_info. trmode {
@@ -1358,7 +1359,7 @@ fn compile_guard(bcx: @mut Block,
1358
1359
bcx = store_non_ref_bindings ( bcx,
1359
1360
data. bindings_map ,
1360
1361
Some ( & mut temp_cleanups) ) ;
1361
- bcx = insert_lllocals ( bcx, data. bindings_map , BindLocal , false ) ;
1362
+ bcx = insert_lllocals ( bcx, data. bindings_map , false ) ;
1362
1363
1363
1364
let val = unpack_result ! ( bcx, {
1364
1365
do with_scope_result( bcx, guard_expr. info( ) ,
@@ -1418,6 +1419,10 @@ fn compile_submatch(bcx: @mut Block,
1418
1419
}
1419
1420
if m[ 0 ] . pats . len ( ) == 0 u {
1420
1421
let data = & m[ 0 ] . data ;
1422
+ for & ( ref ident, ref value_ptr) in m[ 0 ] . bound_ptrs . iter ( ) {
1423
+ let llmatch = data. bindings_map . get ( ident) . llmatch ;
1424
+ Store ( bcx, * value_ptr, llmatch) ;
1425
+ }
1421
1426
match data. arm . guard {
1422
1427
Some ( guard_expr) => {
1423
1428
bcx = compile_guard ( bcx,
@@ -1843,6 +1848,7 @@ fn trans_match_inner(scope_cx: @mut Block,
1843
1848
matches. push ( Match {
1844
1849
pats : ~[ * p] ,
1845
1850
data : arm_data. clone ( ) ,
1851
+ bound_ptrs : ~[ ] ,
1846
1852
} ) ;
1847
1853
}
1848
1854
}
@@ -1875,7 +1881,7 @@ fn trans_match_inner(scope_cx: @mut Block,
1875
1881
}
1876
1882
1877
1883
// insert bindings into the lllocals map and add cleanups
1878
- bcx = insert_lllocals ( bcx, arm_data. bindings_map , BindLocal , true ) ;
1884
+ bcx = insert_lllocals ( bcx, arm_data. bindings_map , true ) ;
1879
1885
1880
1886
bcx = controlflow:: trans_block ( bcx, & arm_data. arm . body , dest) ;
1881
1887
bcx = trans_block_cleanups ( bcx, block_cleanups ( arm_data. bodycx ) ) ;
0 commit comments