@@ -271,32 +271,32 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
271
271
let cx = fcx. ccx ;
272
272
273
273
let fnitem = cx. tcx . items . get_copy ( & fcx. id ) ;
274
- let ( ident, ret_ty , id) = match fnitem {
274
+ let ( ident, fn_decl , id) = match fnitem {
275
275
ast_map:: node_item( ref item, _) => {
276
276
match item. node {
277
- ast:: item_fn( ast :: fn_decl { output : ref ty , _ } , _, _, _, _) => {
278
- ( item. ident , ty , item. id )
277
+ ast:: item_fn( ref fn_decl , _, _, _, _) => {
278
+ ( item. ident , fn_decl , item. id )
279
279
}
280
280
_ => fcx. ccx . sess . span_bug ( item. span ,
281
281
"create_function_metadata: item bound to non-function" )
282
282
}
283
283
}
284
284
ast_map:: node_method(
285
285
@ast:: method {
286
- decl : ast :: fn_decl { output : ref ty , _ } ,
286
+ decl : ref fn_decl ,
287
287
id : id,
288
288
ident : ident,
289
289
_
290
290
} ,
291
291
_,
292
292
_) => {
293
- ( ident, ty , id)
293
+ ( ident, fn_decl , id)
294
294
}
295
295
ast_map:: node_expr( ref expr) => {
296
296
match expr. node {
297
- ast:: expr_fn_block( ref decl , _) => {
297
+ ast:: expr_fn_block( ref fn_decl , _) => {
298
298
let name = gensym_name ( "fn" ) ;
299
- ( name, & decl . output , expr. id )
299
+ ( name, fn_decl , expr. id )
300
300
}
301
301
_ => fcx. ccx . sess . span_bug ( expr. span ,
302
302
"create_function_metadata: expected an expr_fn_block here" )
@@ -305,14 +305,14 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
305
305
ast_map:: node_trait_method(
306
306
@ast:: provided(
307
307
@ast:: method {
308
- decl : ast :: fn_decl { output : ref ty , _ } ,
308
+ decl : ref fn_decl ,
309
309
id : id,
310
310
ident : ident,
311
311
_
312
312
} ) ,
313
313
_,
314
314
_) => {
315
- ( ident, ty , id)
315
+ ( ident, fn_decl , id)
316
316
}
317
317
_ => fcx. ccx . sess . bug ( fmt ! ( "create_function_metadata: unexpected sort of node: %?" , fnitem) )
318
318
} ;
@@ -335,9 +335,9 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
335
335
let file_metadata = file_metadata ( cx, loc. file . name ) ;
336
336
337
337
let return_type_metadata = if cx. sess . opts . extra_debuginfo {
338
- match ret_ty . node {
338
+ match fn_decl . output . node {
339
339
ast:: ty_nil => ptr:: null ( ) ,
340
- _ => type_metadata ( cx, ty:: node_id_to_type ( cx. tcx , id) , ret_ty . span )
340
+ _ => type_metadata ( cx, ty:: node_id_to_type ( cx. tcx , id) , fn_decl . output . span )
341
341
}
342
342
} else {
343
343
ptr:: null ( )
@@ -382,7 +382,9 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
382
382
match * entry_block {
383
383
ast_map:: node_block( ref block) => {
384
384
let scope_map = & mut fn_debug_context. scope_map ;
385
- populate_scope_map ( cx, block, fn_metadata, scope_map) ;
385
+ let arg_pats = do fn_decl. inputs . map |arg_ref| { arg_ref. pat } ;
386
+
387
+ populate_scope_map ( cx, arg_pats, block, fn_metadata, scope_map) ;
386
388
}
387
389
_ => cx. sess . span_bug ( span,
388
390
fmt ! ( "debuginfo::create_function_metadata() - \
@@ -1278,9 +1280,11 @@ fn DIB(cx: &CrateContext) -> DIBuilderRef {
1278
1280
// descriptors where necessary. These artificial scopes allow GDB to correctly handle name
1279
1281
// shadowing.
1280
1282
fn populate_scope_map( cx : & mut CrateContext ,
1283
+ arg_pats : & [ @ast:: pat ] ,
1281
1284
fn_entry_block : & ast:: Block ,
1282
1285
fn_metadata : DISubprogram ,
1283
1286
scope_map : & mut HashMap < ast:: NodeId , DIScope > ) {
1287
+ let def_map = cx. tcx . def_map ;
1284
1288
1285
1289
struct ScopeStackEntry {
1286
1290
scope_metadata : DIScope ,
@@ -1289,6 +1293,15 @@ fn populate_scope_map(cx: &mut CrateContext,
1289
1293
1290
1294
let mut scope_stack = ~[ ScopeStackEntry { scope_metadata : fn_metadata, ident : None } ] ;
1291
1295
1296
+ // Push argument identifiers onto the stack so arguments integrate nicely with variable
1297
+ // shadowing.
1298
+ for & arg_pat in arg_pats. iter ( ) {
1299
+ do pat_util:: pat_bindings ( def_map, arg_pat) |_, _, _, path_ref| {
1300
+ let ident = ast_util:: path_to_ident ( path_ref) ;
1301
+ scope_stack. push ( ScopeStackEntry { scope_metadata : fn_metadata, ident : Some ( ident) } ) ;
1302
+ }
1303
+ }
1304
+
1292
1305
walk_block ( cx, fn_entry_block, & mut scope_stack, scope_map) ;
1293
1306
1294
1307
// local helper functions for walking the AST.
@@ -1300,7 +1313,6 @@ fn populate_scope_map(cx: &mut CrateContext,
1300
1313
inner_walk : & fn ( & mut CrateContext ,
1301
1314
& mut ~[ ScopeStackEntry ] ,
1302
1315
& mut HashMap < ast:: NodeId , DIScope > ) ) {
1303
-
1304
1316
// Create a new lexical scope and push it onto the stack
1305
1317
let loc = cx. sess . codemap . lookup_char_pos ( scope_span. lo ) ;
1306
1318
let file_metadata = file_metadata ( cx, loc. file . name ) ;
@@ -1335,7 +1347,6 @@ fn populate_scope_map(cx: &mut CrateContext,
1335
1347
block : & ast:: Block ,
1336
1348
scope_stack : & mut ~[ ScopeStackEntry ] ,
1337
1349
scope_map : & mut HashMap < ast:: NodeId , DIScope > ) {
1338
-
1339
1350
scope_map. insert ( block. id , scope_stack. last ( ) . scope_metadata ) ;
1340
1351
1341
1352
// The interesting things here are statements and the concluding expression.
@@ -1361,7 +1372,6 @@ fn populate_scope_map(cx: &mut CrateContext,
1361
1372
scope_map : & mut HashMap < ast:: NodeId , DIScope > ) {
1362
1373
match * decl {
1363
1374
codemap:: spanned { node : ast:: decl_local( @ref local) , _ } => {
1364
-
1365
1375
scope_map. insert ( local. id , scope_stack. last ( ) . scope_metadata ) ;
1366
1376
1367
1377
walk_pattern ( cx, local. pat , scope_stack, scope_map) ;
@@ -1383,7 +1393,7 @@ fn populate_scope_map(cx: &mut CrateContext,
1383
1393
1384
1394
// Unfortunately, we cannot just use pat_util::pat_bindings() or ast_util::walk_pat() here
1385
1395
// because we have to visit *all* nodes in order to put them into the scope map. The above
1386
- // function don't do that.
1396
+ // functions don't do that.
1387
1397
match pat. node {
1388
1398
ast:: pat_ident( _, ref path_ref, ref sub_pat_opt) => {
1389
1399
@@ -1412,9 +1422,8 @@ fn populate_scope_map(cx: &mut CrateContext,
1412
1422
1413
1423
// Is there already a binding with that name?
1414
1424
let need_new_scope = scope_stack
1415
- . rev_iter ( )
1416
- . find_ ( |entry| entry. ident . iter ( ) . any ( |i| * i == ident) )
1417
- . is_some ( ) ;
1425
+ . iter ( )
1426
+ . any ( |entry| entry. ident . iter ( ) . any ( |i| * i == ident) ) ;
1418
1427
1419
1428
if need_new_scope {
1420
1429
// Create a new lexical scope and push it onto the stack
@@ -1574,8 +1583,10 @@ fn populate_scope_map(cx: &mut CrateContext,
1574
1583
ast:: expr_if( @ref cond_exp, ref then_block, ref opt_else_exp) => {
1575
1584
walk_expr ( cx, cond_exp, scope_stack, scope_map) ;
1576
1585
1577
- do with_new_scope ( cx, then_block. span , scope_stack, scope_map) |c, s, m| {
1578
- walk_block( c, then_block, s, m) ;
1586
+ do with_new_scope ( cx, then_block. span , scope_stack, scope_map) |cx,
1587
+ scope_stack,
1588
+ scope_map| {
1589
+ walk_block( cx, then_block, scope_stack, scope_map) ;
1579
1590
}
1580
1591
1581
1592
match * opt_else_exp {
@@ -1587,8 +1598,10 @@ fn populate_scope_map(cx: &mut CrateContext,
1587
1598
ast:: expr_while ( @ref cond_exp, ref loop_body) => {
1588
1599
walk_expr ( cx, cond_exp, scope_stack, scope_map) ;
1589
1600
1590
- do with_new_scope ( cx, loop_body. span , scope_stack, scope_map) |c, s, m| {
1591
- walk_block ( c, loop_body, s, m) ;
1601
+ do with_new_scope ( cx, loop_body. span , scope_stack, scope_map) |cx,
1602
+ scope_stack,
1603
+ scope_map| {
1604
+ walk_block ( cx, loop_body, scope_stack, scope_map) ;
1592
1605
}
1593
1606
}
1594
1607
@@ -1604,20 +1617,22 @@ fn populate_scope_map(cx: &mut CrateContext,
1604
1617
1605
1618
ast:: expr_loop ( ref block, _) |
1606
1619
ast:: expr_block ( ref block) => {
1607
- do with_new_scope ( cx, block. span , scope_stack, scope_map) |c, s, m| {
1608
- walk_block ( c, block, s, m) ;
1620
+ do with_new_scope ( cx, block. span , scope_stack, scope_map) |cx,
1621
+ scope_stack,
1622
+ scope_map| {
1623
+ walk_block ( cx, block, scope_stack, scope_map) ;
1609
1624
}
1610
1625
}
1611
1626
1612
1627
ast:: expr_fn_block( ast:: fn_decl { inputs : ref inputs, _ } , ref block) => {
1613
-
1614
- do with_new_scope ( cx , block . span , scope_stack , scope_map ) |c , s , m| {
1615
-
1628
+ do with_new_scope ( cx , block . span , scope_stack , scope_map ) |cx ,
1629
+ scope_stack ,
1630
+ scope_map| {
1616
1631
for & ast:: arg { pat : pattern, _ } in inputs. iter ( ) {
1617
- walk_pattern ( c , pattern, s , m ) ;
1632
+ walk_pattern ( cx , pattern, scope_stack , scope_map ) ;
1618
1633
}
1619
1634
1620
- walk_block ( c , block, s , m ) ;
1635
+ walk_block ( cx , block, scope_stack , scope_map ) ;
1621
1636
}
1622
1637
}
1623
1638
@@ -1663,14 +1678,16 @@ fn populate_scope_map(cx: &mut CrateContext,
1663
1678
for arm_ref in arms. iter ( ) {
1664
1679
let arm_span = arm_ref. pats [ 0 ] . span ;
1665
1680
1666
- do with_new_scope ( cx, arm_span, scope_stack, scope_map) |c, s, m| {
1667
- walk_pattern ( c, arm_ref. pats [ 0 ] , s, m) ;
1681
+ do with_new_scope ( cx, arm_span, scope_stack, scope_map) |cx,
1682
+ scope_stack,
1683
+ scope_map| {
1684
+ walk_pattern ( cx, arm_ref. pats [ 0 ] , scope_stack, scope_map) ;
1668
1685
1669
1686
for & @ref guard_exp in arm_ref. guard . iter ( ) {
1670
- walk_expr ( c , guard_exp, s , m )
1687
+ walk_expr ( cx , guard_exp, scope_stack , scope_map )
1671
1688
}
1672
1689
1673
- walk_block ( c , & arm_ref. body , s , m ) ;
1690
+ walk_block ( cx , & arm_ref. body , scope_stack , scope_map ) ;
1674
1691
}
1675
1692
}
1676
1693
}
0 commit comments