@@ -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 => ( )
@@ -1414,6 +1419,10 @@ fn compile_submatch(bcx: @mut Block,
1414
1419
}
1415
1420
if m[ 0 ] . pats . len ( ) == 0 u {
1416
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
+ }
1417
1426
match data. arm . guard {
1418
1427
Some ( guard_expr) => {
1419
1428
bcx = compile_guard ( bcx,
@@ -1839,6 +1848,7 @@ fn trans_match_inner(scope_cx: @mut Block,
1839
1848
matches. push ( Match {
1840
1849
pats : ~[ * p] ,
1841
1850
data : arm_data. clone ( ) ,
1851
+ bound_ptrs : ~[ ] ,
1842
1852
} ) ;
1843
1853
}
1844
1854
}
0 commit comments