@@ -69,7 +69,7 @@ use std::libc::{c_uint, c_ulonglong, c_longlong};
69
69
use std:: ptr;
70
70
use std:: vec;
71
71
use syntax:: codemap:: span;
72
- use syntax:: { ast, codemap, ast_util, ast_map} ;
72
+ use syntax:: { ast, codemap, ast_util, ast_map, opt_vec } ;
73
73
use syntax:: parse:: token:: special_idents;
74
74
75
75
static DW_LANG_RUST : int = 0x9000 ;
@@ -334,12 +334,14 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
334
334
None => { /* fallthrough */ }
335
335
}
336
336
337
+ let empty_generics = ast:: Generics { lifetimes : opt_vec:: Empty , ty_params : opt_vec:: Empty } ;
338
+
337
339
let fnitem = cx. tcx . items . get_copy ( & fcx. id ) ;
338
- let ( ident, fn_decl, generics, span, is_trait_default_impl ) = match fnitem {
340
+ let ( ident, fn_decl, generics, span) = match fnitem {
339
341
ast_map:: node_item( ref item, _) => {
340
342
match item. node {
341
343
ast:: item_fn( ref fn_decl, _, _, ref generics, _) => {
342
- ( item. ident , fn_decl, Some ( generics) , item. span , false )
344
+ ( item. ident , fn_decl, generics, item. span )
343
345
}
344
346
_ => fcx. ccx . sess . span_bug ( item. span ,
345
347
"create_function_metadata: item bound to non-function" )
@@ -355,7 +357,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
355
357
} ,
356
358
_,
357
359
_) => {
358
- ( ident, fn_decl, Some ( generics) , span, false )
360
+ ( ident, fn_decl, generics, span)
359
361
}
360
362
ast_map:: node_expr( ref expr) => {
361
363
match expr. node {
@@ -364,9 +366,8 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
364
366
( name, fn_decl,
365
367
// This is not quite right. It should actually inherit the generics of the
366
368
// enclosing function.
367
- None ,
368
- expr. span ,
369
- false )
369
+ & empty_generics,
370
+ expr. span )
370
371
}
371
372
_ => fcx. ccx . sess . span_bug ( expr. span ,
372
373
"create_function_metadata: expected an expr_fn_block here" )
@@ -383,7 +384,7 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
383
384
} ) ,
384
385
_,
385
386
_) => {
386
- ( ident, fn_decl, Some ( generics) , span, true )
387
+ ( ident, fn_decl, generics, span)
387
388
}
388
389
_ => fcx. ccx . sess . bug ( fmt ! ( "create_function_metadata: unexpected sort of node: %?" , fnitem) )
389
390
} ;
@@ -404,7 +405,6 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
404
405
let mut function_name = cx. sess . str_of ( ident) . to_owned ( ) ;
405
406
let template_parameters = get_template_parameters ( fcx,
406
407
generics,
407
- is_trait_default_impl,
408
408
file_metadata,
409
409
span,
410
410
& mut function_name) ;
@@ -506,153 +506,101 @@ pub fn create_function_metadata(fcx: &mut FunctionContext) -> DISubprogram {
506
506
}
507
507
508
508
fn get_template_parameters ( fcx : & FunctionContext ,
509
- generics : Option < & ast:: Generics > ,
510
- is_trait_default_impl : bool ,
509
+ generics : & ast:: Generics ,
511
510
file_metadata : DIFile ,
512
511
span : span ,
513
512
name_to_append_suffix_to : & mut ~str )
514
513
-> DIArray {
515
- // Normalize cases
516
- let generics = match generics {
517
- Some ( generics_ref) if generics_ref. is_type_parameterized ( ) => Some ( generics_ref) ,
514
+ let cx = fcx. ccx ;
515
+
516
+ let self_type = match fcx. param_substs {
517
+ Some ( @param_substs { self_ty : self_type, _ } ) => self_type,
518
518
_ => None
519
519
} ;
520
520
521
- let cx = fcx. ccx ;
522
-
523
- match generics {
524
- None => {
525
- if ( !is_trait_default_impl && fcx. param_substs . is_some ( ) ) {
526
- cx. sess . span_bug ( span, "debuginfo::create_function_metadata() - \
527
- Mismatch between ast::Generics (does not exist) and \
528
- FunctionContext::param_substs (does exist)") ;
529
- }
521
+ // Only true for static default methods:
522
+ let has_self_type = self_type. is_some ( ) ;
530
523
531
- return ptr:: null ( ) ;
532
- }
524
+ if !generics. is_type_parameterized ( ) && !has_self_type {
525
+ return ptr:: null ( ) ;
526
+ }
533
527
534
- Some ( generics) => {
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
- }
528
+ name_to_append_suffix_to. push_char ( '<' ) ;
542
529
543
- ( types, self_type)
544
- }
545
- None => {
546
- cx. sess . span_bug ( span, "debuginfo::create_function_metadata() - \
547
- Mismatch between ast::Generics (does exist) and \
548
- FunctionContext::param_substs (does not exist)") ;
549
- }
550
- } ;
530
+ // The list to be filled with template parameters:
531
+ let mut template_params: ~[ DIDescriptor ] = vec:: with_capacity ( generics. ty_params . len ( ) + 1 ) ;
551
532
552
- name_to_append_suffix_to. push_char ( '<' ) ;
533
+ // Handle self type
534
+ if has_self_type {
535
+ let actual_self_type = self_type. unwrap ( ) ;
536
+ let actual_self_type_metadata = type_metadata ( cx,
537
+ actual_self_type,
538
+ codemap:: dummy_sp ( ) ) ;
553
539
554
- let mut template_params: ~[ DIDescriptor ] =
555
- vec:: with_capacity ( actual_types. len ( ) + 1 ) ;
540
+ // Add self type name to <...> clause of function name
541
+ let actual_self_type_name = ty_to_str ( cx. tcx , actual_self_type) ;
542
+ name_to_append_suffix_to. push_str ( actual_self_type_name) ;
543
+ if generics. is_type_parameterized ( ) {
544
+ name_to_append_suffix_to. push_str ( "," ) ;
545
+ }
556
546
557
- if is_trait_default_impl {
558
- let actual_self_type_metadata = type_metadata ( cx,
559
- actual_self_type. unwrap ( ) ,
560
- codemap:: dummy_sp ( ) ) ;
547
+ let ident = special_idents:: type_self;
561
548
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
- }
549
+ let param_metadata = do cx. sess . str_of ( ident) . to_c_str ( ) . with_ref |name| {
550
+ unsafe {
551
+ llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
552
+ DIB ( cx) ,
553
+ file_metadata,
554
+ name,
555
+ actual_self_type_metadata,
556
+ ptr:: null ( ) ,
557
+ 0 ,
558
+ 0 )
559
+ }
560
+ } ;
568
561
569
- let ident = special_idents:: type_self;
562
+ template_params. push ( param_metadata) ;
563
+ }
570
564
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 )
581
- }
582
- } ;
565
+ // Handle other generic parameters
566
+ let actual_types = match fcx. param_substs {
567
+ Some ( @param_substs { tys : ref types, _ } ) => types,
568
+ None => {
569
+ return create_DIArray ( DIB ( cx) , template_params) ;
570
+ }
571
+ } ;
583
572
584
- template_params. push ( param_metadata) ;
585
- }
573
+ for ( index, & ast:: TyParam { ident : ident, _ } ) in generics. ty_params . iter ( ) . enumerate ( ) {
574
+ let actual_type = actual_types[ index] ;
575
+ let actual_type_metadata = type_metadata ( cx, actual_type, codemap:: dummy_sp ( ) ) ;
586
576
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
- }
577
+ // Add actual type name to <...> clause of function name
578
+ let actual_type_name = ty_to_str ( cx. tcx , actual_type) ;
579
+ name_to_append_suffix_to. push_str ( actual_type_name) ;
602
580
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 )
613
- }
614
- } ;
581
+ if index != generics. ty_params . len ( ) - 1 {
582
+ name_to_append_suffix_to. push_str ( "," ) ;
583
+ }
615
584
616
- template_params. push ( param_metadata) ;
585
+ let param_metadata = do cx. sess . str_of ( ident) . to_c_str ( ) . with_ref |name| {
586
+ unsafe {
587
+ llvm:: LLVMDIBuilderCreateTemplateTypeParameter (
588
+ DIB ( cx) ,
589
+ file_metadata,
590
+ name,
591
+ actual_type_metadata,
592
+ ptr:: null ( ) ,
593
+ 0 ,
594
+ 0 )
617
595
}
596
+ } ;
618
597
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();
650
-
651
- name_to_append_suffix_to. push_char ( '>' ) ;
652
-
653
- return create_DIArray ( DIB ( cx) , template_params) ;
654
- }
598
+ template_params. push ( param_metadata) ;
655
599
}
600
+
601
+ name_to_append_suffix_to. push_char ( '>' ) ;
602
+
603
+ return create_DIArray ( DIB ( cx) , template_params) ;
656
604
}
657
605
}
658
606
0 commit comments