@@ -70,7 +70,7 @@ use std::ptr;
70
70
use std:: vec;
71
71
use syntax:: codemap:: span;
72
72
use syntax:: { ast, codemap, ast_util, ast_map} ;
73
- use syntax:: parse:: token:: keywords ;
73
+ use syntax:: parse:: token:: special_idents ;
74
74
75
75
static DW_LANG_RUST : int = 0x9000 ;
76
76
@@ -195,9 +195,8 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
195
195
let loc = span_start ( cx, span) ;
196
196
let type_metadata = type_metadata ( cx, variable_type, span) ;
197
197
let scope = create_function_metadata ( bcx. fcx ) ;
198
- let self_ident = keywords:: Self . to_ident ( ) ;
199
198
200
- let var_metadata = do cx. sess . str_of ( self_ident ) . to_c_str ( ) . with_ref |name| {
199
+ let var_metadata = do cx. sess . str_of ( special_idents :: self_ ) . to_c_str ( ) . with_ref |name| {
201
200
unsafe {
202
201
llvm:: LLVMDIBuilderCreateLocalVariable (
203
202
DIB ( cx) ,
@@ -229,8 +228,7 @@ pub fn create_self_argument_metadata(bcx: @mut Block,
229
228
///
230
229
/// Adds the created metadata nodes directly to the crate's IR.
231
230
pub fn create_argument_metadata ( bcx : @mut Block ,
232
- arg : & ast:: arg ,
233
- needs_deref : bool ) {
231
+ arg : & ast:: arg ) {
234
232
let fcx = bcx. fcx ;
235
233
let cx = fcx. ccx ;
236
234
@@ -337,11 +335,11 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
337
335
}
338
336
339
337
let fnitem = cx. tcx . items . get_copy ( & fcx. id ) ;
340
- let ( ident, fn_decl, generics, span) = match fnitem {
338
+ let ( ident, fn_decl, generics, span, is_trait_default_impl ) = match fnitem {
341
339
ast_map:: node_item( ref item, _) => {
342
340
match item. node {
343
341
ast:: item_fn( ref fn_decl, _, _, ref generics, _) => {
344
- ( item. ident , fn_decl, Some ( generics) , item. span )
342
+ ( item. ident , fn_decl, Some ( generics) , item. span , false )
345
343
}
346
344
_ => fcx. ccx . sess . span_bug ( item. span ,
347
345
"create_function_metadata: item bound to non-function" )
@@ -357,7 +355,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
357
355
} ,
358
356
_,
359
357
_) => {
360
- ( ident, fn_decl, Some ( generics) , span)
358
+ ( ident, fn_decl, Some ( generics) , span, false )
361
359
}
362
360
ast_map:: node_expr( ref expr) => {
363
361
match expr. node {
@@ -367,7 +365,8 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
367
365
// This is not quite right. It should actually inherit the generics of the
368
366
// enclosing function.
369
367
None ,
370
- expr. span )
368
+ expr. span ,
369
+ false )
371
370
}
372
371
_ => fcx. ccx . sess . span_bug ( expr. span ,
373
372
"create_function_metadata: expected an expr_fn_block here" )
@@ -384,7 +383,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
384
383
} ) ,
385
384
_,
386
385
_) => {
387
- ( ident, fn_decl, Some ( generics) , span)
386
+ ( ident, fn_decl, Some ( generics) , span, true )
388
387
}
389
388
_ => fcx. ccx . sess . bug ( fmt ! ( "create_function_metadata: unexpected sort of node: %?" , fnitem) )
390
389
} ;
@@ -405,6 +404,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
405
404
let mut function_name = cx. sess . str_of ( ident) . to_owned ( ) ;
406
405
let template_parameters = get_template_parameters ( fcx,
407
406
generics,
407
+ is_trait_default_impl,
408
408
file_metadata,
409
409
span,
410
410
& mut function_name) ;
@@ -507,6 +507,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
507
507
508
508
fn get_template_parameters ( fcx : & FunctionContext ,
509
509
generics : Option < & ast:: Generics > ,
510
+ is_trait_default_impl : bool ,
510
511
file_metadata : DIFile ,
511
512
span : span ,
512
513
name_to_append_suffix_to : & mut ~str )
@@ -521,58 +522,131 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
521
522
522
523
match generics {
523
524
None => {
524
- if ( fcx. param_substs . is_some ( ) ) {
525
+ if ( !is_trait_default_impl && fcx. param_substs . is_some ( ) ) {
525
526
cx. sess . span_bug ( span, "debuginfo::create_function_metadata() - \
526
- Mismatch between ast::Generics and FunctionContext::param_substs") ;
527
+ Mismatch between ast::Generics (does not exist) and \
528
+ FunctionContext::param_substs (does exist)") ;
527
529
}
528
530
529
531
return ptr:: null ( ) ;
530
532
}
531
533
532
534
Some ( generics) => {
533
- let actual_types = match fcx. param_substs {
534
- Some ( @param_substs { tys : ref actual_types, _} ) => {
535
- actual_types
535
+ let ( actual_types, actual_self_type) = match fcx. param_substs {
536
+ Some ( @param_substs { tys : ref types, self_ty : ref self_type, _ } ) => {
537
+ if is_trait_default_impl && self_type. is_none ( ) {
538
+ cx. sess . span_bug ( span, "debuginfo::create_function_metadata() - \
539
+ Expected self type parameter substitution for default \
540
+ implementation of trait method") ;
541
+ }
542
+
543
+ ( types, self_type)
536
544
}
537
545
None => {
538
546
cx. sess . span_bug ( span, "debuginfo::create_function_metadata() - \
539
- Mismatch between ast::Generics and FunctionContext::param_substs") ;
547
+ Mismatch between ast::Generics (does exist) and \
548
+ FunctionContext::param_substs (does not exist)") ;
540
549
}
541
550
} ;
542
551
543
552
name_to_append_suffix_to. push_char ( '<' ) ;
544
553
545
- let template_params: ~[ DIDescriptor ] = do generics
546
- . ty_params
547
- . iter ( )
548
- . enumerate ( )
549
- . map |( index, & ast:: TyParam { ident : ident, _ } ) | {
550
-
551
- let actual_type = actual_types[ index] ;
552
- let actual_type_metadata = type_metadata ( cx,
553
- actual_type,
554
- codemap:: dummy_sp ( ) ) ;
555
-
556
- // Add actual type name to <...> clause of function name
557
- let actual_type_name = ty_to_str ( cx. tcx , actual_type) ;
558
- name_to_append_suffix_to. push_str ( actual_type_name) ;
559
- if index != generics. ty_params . len ( ) - 1 {
560
- name_to_append_suffix_to. push_str ( "," ) ;
554
+ let mut template_params: ~[ DIDescriptor ] =
555
+ vec:: with_capacity ( actual_types. len ( ) + 1 ) ;
556
+
557
+ if is_trait_default_impl {
558
+ let actual_self_type_metadata = type_metadata ( cx,
559
+ actual_self_type. unwrap ( ) ,
560
+ codemap:: dummy_sp ( ) ) ;
561
+
562
+ // Add self type name to <...> clause of function name
563
+ let actual_self_type_name = ty_to_str ( cx. tcx , actual_self_type. unwrap ( ) ) ;
564
+ name_to_append_suffix_to. push_str ( actual_self_type_name) ;
565
+ if actual_types. len ( ) > 0 {
566
+ name_to_append_suffix_to. push_str ( "," ) ;
567
+ }
568
+
569
+ let ident = special_idents:: type_self;
570
+
571
+ let param_metadata = do cx. sess . str_of ( ident) . to_c_str ( ) . with_ref |name| {
572
+ unsafe {
573
+ llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
574
+ DIB ( cx) ,
575
+ file_metadata,
576
+ name,
577
+ actual_self_type_metadata,
578
+ ptr:: null ( ) ,
579
+ 0 ,
580
+ 0 )
561
581
}
582
+ } ;
583
+
584
+ template_params. push ( param_metadata) ;
585
+ }
562
586
563
- do cx. sess . str_of ( ident) . to_c_str ( ) . with_ref |name| {
564
- unsafe {
565
- llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
566
- DIB ( cx) ,
567
- file_metadata,
568
- name,
569
- actual_type_metadata,
570
- ptr:: null ( ) ,
571
- 0 ,
572
- 0 )
573
- }
587
+ for ( index, & ast:: TyParam { ident : ident, _ } ) in generics
588
+ . ty_params
589
+ . iter ( )
590
+ . enumerate ( ) {
591
+ let actual_type = actual_types[ index] ;
592
+ let actual_type_metadata = type_metadata ( cx,
593
+ actual_type,
594
+ codemap:: dummy_sp ( ) ) ;
595
+
596
+ // Add actual type name to <...> clause of function name
597
+ let actual_type_name = ty_to_str ( cx. tcx , actual_type) ;
598
+ name_to_append_suffix_to. push_str ( actual_type_name) ;
599
+ if index != generics. ty_params . len ( ) - 1 {
600
+ name_to_append_suffix_to. push_str ( "," ) ;
601
+ }
602
+
603
+ let param_metadata = do cx. sess . str_of ( ident) . to_c_str ( ) . with_ref |name| {
604
+ unsafe {
605
+ llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
606
+ DIB ( cx) ,
607
+ file_metadata,
608
+ name,
609
+ actual_type_metadata,
610
+ ptr:: null ( ) ,
611
+ 0 ,
612
+ 0 )
574
613
}
575
- } . collect ( ) ;
614
+ } ;
615
+
616
+ template_params. push ( param_metadata) ;
617
+ }
618
+
619
+ // let template_params: ~[DIDescriptor] = do generics
620
+ // .ty_params
621
+ // .iter()
622
+ // .enumerate()
623
+ // .map |(index, &ast::TyParam{ ident: ident, _ })| {
624
+
625
+ // let actual_type = actual_types[index];
626
+ // let actual_type_metadata = type_metadata(cx,
627
+ // actual_type,
628
+ // codemap::dummy_sp());
629
+
630
+ // // Add actual type name to <...> clause of function name
631
+ // let actual_type_name = ty_to_str(cx.tcx, actual_type);
632
+ // name_to_append_suffix_to.push_str(actual_type_name);
633
+ // if index != generics.ty_params.len() - 1 {
634
+ // name_to_append_suffix_to.push_str(",");
635
+ // }
636
+
637
+ // do cx.sess.str_of(ident).to_c_str().with_ref |name| {
638
+ // unsafe {
639
+ // llvm::LLVMDIBuilderCreateTemplateTypeParameter(
640
+ // DIB(cx),
641
+ // file_metadata,
642
+ // name,
643
+ // actual_type_metadata,
644
+ // ptr::null(),
645
+ // 0,
646
+ // 0)
647
+ // }
648
+ // }
649
+ // }.collect();
576
650
577
651
name_to_append_suffix_to. push_char ( '>' ) ;
578
652
@@ -795,7 +869,13 @@ fn struct_metadata(cx: &mut CrateContext,
795
869
let struct_llvm_type = type_of:: type_of ( cx, struct_type) ;
796
870
797
871
let field_llvm_types = do fields. map |field| { type_of:: type_of ( cx, field. mt . ty ) } ;
798
- let field_names = do fields. map |field| { cx. sess . str_of ( field. ident ) . to_owned ( ) } ;
872
+ let field_names = do fields. map |field| {
873
+ if field. ident == special_idents:: unnamed_field {
874
+ ~""
875
+ } else {
876
+ cx. sess . str_of ( field. ident ) . to_owned ( )
877
+ }
878
+ } ;
799
879
let field_types_metadata = do fields. map |field| {
800
880
type_metadata ( cx, field. mt . ty , span)
801
881
} ;
0 commit comments