@@ -360,7 +360,31 @@ fn create_basic_type(cx: @CrateContext, t: ty::t, span: span)
360
360
option:: None => ( )
361
361
}
362
362
363
- let ( name, encoding) = ( ~"uint", DW_ATE_unsigned ) ;
363
+ let ( name, encoding) = match ty:: get ( t) . sty {
364
+ ty:: ty_nil | ty:: ty_bot => ( ~"uint", DW_ATE_unsigned ) ,
365
+ ty:: ty_bool => ( ~"bool", DW_ATE_boolean ) ,
366
+ ty:: ty_int( int_ty) => match int_ty {
367
+ ast:: ty_i => ( ~"int", DW_ATE_signed ) ,
368
+ ast:: ty_char => ( ~"char", DW_ATE_signed_char ) ,
369
+ ast:: ty_i8 => ( ~"i8", DW_ATE_signed ) ,
370
+ ast:: ty_i16 => ( ~"i16", DW_ATE_signed ) ,
371
+ ast:: ty_i32 => ( ~"i32", DW_ATE_signed ) ,
372
+ ast:: ty_i64 => ( ~"i64", DW_ATE_signed )
373
+ } ,
374
+ ty:: ty_uint( uint_ty) => match uint_ty {
375
+ ast:: ty_u => ( ~"uint", DW_ATE_unsigned ) ,
376
+ ast:: ty_u8 => ( ~"u8", DW_ATE_unsigned ) ,
377
+ ast:: ty_u16 => ( ~"i16", DW_ATE_unsigned ) ,
378
+ ast:: ty_u32 => ( ~"u32", DW_ATE_unsigned ) ,
379
+ ast:: ty_u64 => ( ~"u64", DW_ATE_unsigned )
380
+ } ,
381
+ ty:: ty_float( float_ty) => match float_ty {
382
+ ast:: ty_f => ( ~"float", DW_ATE_float ) ,
383
+ ast:: ty_f32 => ( ~"f32", DW_ATE_float ) ,
384
+ ast:: ty_f64 => ( ~"f64", DW_ATE_float )
385
+ } ,
386
+ _ => cx. sess . bug ( ~"debuginfo:: create_basic_type - t is invalid type")
387
+ } ;
364
388
365
389
let fname = filename_from_span ( cx, span) ;
366
390
let file_node = create_file ( cx, fname) ;
@@ -477,22 +501,42 @@ fn add_member(cx: @mut StructCtxt,
477
501
cx. total_size += size * 8 ;
478
502
}
479
503
480
- fn create_record ( cx : @CrateContext , t : ty:: t , fields : ~[ ast :: ty_field ] ,
504
+ fn create_struct ( cx : @CrateContext , t : ty:: t , fields : ~[ ty :: field ] ,
481
505
span : span ) -> @Metadata < TyDescMetadata > {
482
506
let fname = filename_from_span ( cx, span) ;
483
507
let file_node = create_file ( cx, fname) ;
508
+ let scx = create_structure ( file_node, @ty_to_str ( cx. tcx , t) ,
509
+ line_from_span ( cx. sess . codemap , span) as int ) ;
510
+ for fields. each |field| {
511
+ let field_t = field. mt . ty ;
512
+ let ty_md = create_ty ( cx, field_t, span) ;
513
+ let ( size, align) = size_and_align_of ( cx, field_t) ;
514
+ add_member ( scx, * cx. sess . str_of ( field. ident ) ,
515
+ line_from_span ( cx. sess . codemap , span) as int ,
516
+ size as int , align as int , ty_md. node ) ;
517
+ }
518
+ let mdval = @Metadata {
519
+ node : finish_structure ( scx) ,
520
+ data : TyDescMetadata {
521
+ hash : ty:: type_id ( t)
522
+ }
523
+ } ;
524
+ return mdval;
525
+ }
526
+
527
+ fn create_tuple ( cx : @CrateContext , t : ty:: t , elements : ~[ ty:: t ] , span : span )
528
+ -> @Metadata < TyDescMetadata > {
529
+ let fname = filename_from_span ( cx, span) ;
530
+ let file_node = create_file ( cx, fname) ;
484
531
let scx = create_structure ( file_node,
485
532
cx. sess . str_of (
486
533
( ( /*bad*/ copy cx. dbg_cx ) . get ( ) . names )
487
- ( ~"rec") ) ,
488
- line_from_span ( cx. sess . codemap ,
489
- span) as int ) ;
490
- for fields. each |field| {
491
- let field_t = ty:: get_field ( cx. tcx , t, field. node . ident ) . mt . ty ;
492
- let ty_md = create_ty ( cx, field_t, field. node . mt . ty ) ;
493
- let ( size, align) = size_and_align_of ( cx, field_t) ;
494
- add_member ( scx, * cx. sess . str_of ( field. node . ident ) ,
495
- line_from_span ( cx. sess . codemap , field. span ) as int ,
534
+ ( ~"tuple") ) ,
535
+ line_from_span ( cx. sess . codemap , span) as int ) ;
536
+ for elements. each |element| {
537
+ let ty_md = create_ty ( cx, * element, span) ;
538
+ let ( size, align) = size_and_align_of ( cx, * element) ;
539
+ add_member ( scx, ~"", line_from_span ( cx. sess . codemap , span) as int ,
496
540
size as int , align as int , ty_md. node ) ;
497
541
}
498
542
let mdval = @Metadata {
@@ -569,11 +613,10 @@ fn create_composite_type(type_tag: int, name: &str, file: ValueRef,
569
613
}
570
614
571
615
fn create_vec ( cx : @CrateContext , vec_t : ty:: t , elem_t : ty:: t ,
572
- vec_ty_span : codemap:: span , elem_ty : @ast:: Ty )
573
- -> @Metadata < TyDescMetadata > {
616
+ vec_ty_span : codemap:: span ) -> @Metadata < TyDescMetadata > {
574
617
let fname = filename_from_span ( cx, vec_ty_span) ;
575
618
let file_node = create_file ( cx, fname) ;
576
- let elem_ty_md = create_ty ( cx, elem_t, elem_ty ) ;
619
+ let elem_ty_md = create_ty ( cx, elem_t, vec_ty_span ) ;
577
620
let scx = create_structure ( file_node,
578
621
@/* bad* / copy ty_to_str ( cx. tcx , vec_t) , 0 ) ;
579
622
let size_t_type = create_basic_type ( cx, ty:: mk_uint ( cx. tcx ) , vec_ty_span) ;
@@ -598,108 +641,60 @@ fn create_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
598
641
}
599
642
}
600
643
601
- fn create_ty ( _cx : @CrateContext , _t : ty:: t , _ty : @ast :: Ty )
644
+ fn create_ty( cx : @CrateContext , t : ty:: t , span : span )
602
645
-> @Metadata < TyDescMetadata > {
646
+ debug ! ( "create_ty: %?" , ty:: get( t) ) ;
603
647
/*let cache = get_cache(cx);
604
648
match cached_metadata::<@Metadata<TyDescMetadata>>(
605
649
cache, tg, {|md| t == md.data.hash}) {
606
650
option::Some(md) { return md; }
607
651
option::None {}
608
652
}*/
609
653
610
- /* FIXME (#2012): disabled this code as part of the patch that moves
611
- * recognition of named builtin types into resolve. I tried to fix
612
- * it, but it seems to already be broken -- it's only called when
613
- * --xg is given, and compiling with --xg fails on trivial programs.
614
- *
615
- * Generating an ast::ty from a ty::t seems like it should not be
616
- * needed. It is only done to track spans, but you will not get the
617
- * right spans anyway -- types tend to refer to stuff defined
618
- * elsewhere, not be self-contained.
619
- */
620
-
621
- fail ! ( ) ;
622
- /*
623
- fn t_to_ty(cx: CrateContext, t: ty::t, span: span) -> @ast::ty {
624
- let ty = match ty::get(t).struct {
625
- ty::ty_nil { ast::ty_nil }
626
- ty::ty_bot { ast::ty_bot }
627
- ty::ty_bool { ast::ty_bool }
628
- ty::ty_int(t) { ast::ty_int(t) }
629
- ty::ty_float(t) { ast::ty_float(t) }
630
- ty::ty_uint(t) { ast::ty_uint(t) }
631
- ty::ty_box(mt) { ast::ty_box({ty: t_to_ty(cx, mt.ty, span),
632
- mutbl: mt.mutbl}) }
633
- ty::ty_uniq(mt) { ast::ty_uniq({ty: t_to_ty(cx, mt.ty, span),
634
- mutbl: mt.mutbl}) }
635
- ty::ty_rec(fields) {
636
- let fs = ~[];
637
- for field in fields {
638
- fs.push({node: {ident: field.ident,
639
- mt: {ty: t_to_ty(cx, field.mt.ty, span),
640
- mutbl: field.mt.mutbl}},
641
- span: span});
642
- }
643
- ast::ty_rec(fs)
644
- }
645
- ty::ty_vec(mt) { ast::ty_vec({ty: t_to_ty(cx, mt.ty, span),
646
- mutbl: mt.mutbl}) }
647
- _ {
648
- cx.sess.span_bug(span, "t_to_ty: Can't handle this type");
649
- }
650
- };
651
- return @{node: ty, span: span};
652
- }
653
-
654
- match ty.node {
655
- ast::ty_box(mt) {
656
- let inner_t = match ty::get(t).struct {
657
- ty::ty_box(boxed) { boxed.ty }
658
- _ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); }
659
- };
660
- let md = create_ty(cx, inner_t, mt.ty);
661
- let box = create_boxed_type(cx, t, inner_t, ty.span, md);
662
- return create_pointer_type(cx, t, ty.span, box);
663
- }
664
-
665
- ast::ty_uniq(mt) {
666
- let inner_t = match ty::get(t).struct {
667
- ty::ty_uniq(boxed) { boxed.ty }
668
- // Hoping we'll have a way to eliminate this check soon.
669
- _ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); }
670
- };
671
- let md = create_ty(cx, inner_t, mt.ty);
672
- return create_pointer_type(cx, t, ty.span, md);
673
- }
674
-
675
- ast::ty_infer {
676
- let inferred = t_to_ty(cx, t, ty.span);
677
- return create_ty(cx, t, inferred);
678
- }
679
-
680
- ast::ty_rec(fields) {
681
- return create_record(cx, t, fields, ty.span);
682
- }
683
-
684
- ast::ty_vec(mt) {
685
- let inner_t = ty::sequence_element_type(cx.tcx, t);
686
- let inner_ast_t = t_to_ty(cx, inner_t, mt.ty.span);
687
- let v = create_vec(cx, t, inner_t, ty.span, inner_ast_t);
688
- return create_pointer_type(cx, t, ty.span, v);
689
- }
690
-
691
- ast::ty_path(_, id) {
692
- match cx.tcx.def_map.get(id) {
693
- ast::def_prim_ty(pty) {
694
- return create_basic_type(cx, t, pty, ty.span);
695
- }
696
- _ {}
654
+ let sty = copy ty:: get ( t) . sty ;
655
+ match copy sty {
656
+ ty:: ty_nil | ty:: ty_bot | ty:: ty_bool | ty:: ty_int( _) | ty:: ty_uint( _)
657
+ | ty:: ty_float( _) => create_basic_type ( cx, t, span) ,
658
+ ty:: ty_estr( _vstore) => {
659
+ cx. sess . span_bug ( span, ~"debuginfo for estr NYI ")
660
+ } ,
661
+ ty:: ty_enum( _did, _substs) => {
662
+ cx. sess . span_bug ( span, ~"debuginfo for enum NYI ")
697
663
}
698
- }
699
-
700
- _ {}
701
- };
702
- */
664
+ ty:: ty_box( _mt) => {
665
+ cx. sess . span_bug ( span, ~"debuginfo for box NYI ")
666
+ } ,
667
+ ty:: ty_uniq( _mt) => {
668
+ cx. sess . span_bug ( span, ~"debuginfo for uniq NYI ")
669
+ } ,
670
+ ty:: ty_evec( _mt, _vstore) => {
671
+ cx. sess . span_bug ( span, ~"debuginfo for evec NYI ")
672
+ } ,
673
+ ty:: ty_ptr( mt) => {
674
+ let pointee = create_ty ( cx, mt. ty , span) ;
675
+ create_pointer_type ( cx, t, span, pointee)
676
+ } ,
677
+ ty:: ty_rptr ( _region, _mt) => {
678
+ cx. sess . span_bug ( span, ~"debuginfo for rptr NYI ")
679
+ } ,
680
+ ty:: ty_bare_fn( _barefnty) => {
681
+ cx. sess . span_bug ( span, ~"debuginfo for bare_fn NYI ")
682
+ } ,
683
+ ty:: ty_closure( _closurety) => {
684
+ cx. sess . span_bug ( span, ~"debuginfo for closure NYI ")
685
+ } ,
686
+ ty:: ty_trait( _did, _substs, _vstore) => {
687
+ cx. sess . span_bug ( span, ~"debuginfo for trait NYI ")
688
+ } ,
689
+ ty:: ty_struct( did, substs) => {
690
+ let fields = ty:: struct_fields ( cx. tcx , did, & substs) ;
691
+ create_struct ( cx, t, fields, span)
692
+ } ,
693
+ ty:: ty_tup ( elements) => {
694
+ create_tuple ( cx, t, elements, span)
695
+ } ,
696
+ _ => cx. sess . bug ( ~"debuginfo: unexpected type in create_ty")
697
+ }
703
698
}
704
699
705
700
fn filename_from_span ( cx: @CrateContext , sp: codemap:: span) -> ~str {
@@ -738,7 +733,7 @@ pub fn create_local_var(bcx: block, local: @ast::local)
738
733
};
739
734
let loc = cx.sess.codemap.lookup_char_pos(local.span.lo);
740
735
let ty = node_id_type(bcx, local.node.id);
741
- let tymd = create_ty(cx, ty, local.node.ty);
736
+ let tymd = create_ty(cx, ty, local.node.ty.span );
742
737
let filemd = create_file(cx, /*bad*/copy loc.file.name);
743
738
let context = match bcx.parent {
744
739
None => create_function(bcx.fcx).node,
@@ -788,8 +783,11 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
788
783
}
789
784
790
785
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
786
+ if loc.file.name == ~" <intrinsic>" {
787
+ return None;
788
+ }
791
789
let ty = node_id_type(bcx, arg.id);
792
- let tymd = create_ty(cx, ty, arg.ty);
790
+ let tymd = create_ty(cx, ty, arg.ty.span );
793
791
let filemd = create_file(cx, /*bad*/copy loc.file.name);
794
792
let context = create_function(bcx.fcx);
795
793
@@ -902,7 +900,8 @@ pub fn create_function(fcx: fn_ctxt) -> @Metadata<SubProgramMetadata> {
902
900
let ty_node = if cx. sess . opts . extra_debuginfo {
903
901
match ret_ty. node {
904
902
ast:: ty_nil => llnull ( ) ,
905
- _ => create_ty ( cx, ty:: node_id_to_type ( cx. tcx , id) , ret_ty) . node
903
+ _ => create_ty ( cx, ty:: node_id_to_type ( cx. tcx , id) ,
904
+ ret_ty. span ) . node
906
905
}
907
906
} else {
908
907
llnull ( )
0 commit comments