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