@@ -15,12 +15,14 @@ pub mod gdb;
15
15
mod utils;
16
16
mod create;
17
17
mod namespace;
18
+ mod types;
18
19
19
20
use self :: utils:: { debug_context, DIB , span_start, bytes_to_bits, size_and_align_of,
20
21
assert_type_for_node_id, get_namespace_and_span_for_item, fn_should_be_ignored,
21
22
contains_nodebug_attribute, create_scope_map} ;
22
23
use self :: create:: { declare_local, create_DIArray, is_node_local_to_unit} ;
23
- use self :: namespace:: { namespace_for_item, NamespaceTreeNode , crate_root_namespace} ;
24
+ use self :: namespace:: { namespace_for_item, NamespaceTreeNode } ;
25
+ use self :: types:: { compute_debuginfo_type_name, push_debuginfo_type_name} ;
24
26
25
27
use self :: VariableAccess :: * ;
26
28
use self :: VariableKind :: * ;
@@ -2893,215 +2895,3 @@ fn set_debug_location(cx: &CrateContext, debug_location: InternalDebugLocation)
2893
2895
2894
2896
debug_context ( cx) . current_debug_location . set ( debug_location) ;
2895
2897
}
2896
-
2897
- //=-----------------------------------------------------------------------------
2898
- // Type Names for Debug Info
2899
- //=-----------------------------------------------------------------------------
2900
-
2901
- // Compute the name of the type as it should be stored in debuginfo. Does not do
2902
- // any caching, i.e. calling the function twice with the same type will also do
2903
- // the work twice. The `qualified` parameter only affects the first level of the
2904
- // type name, further levels (i.e. type parameters) are always fully qualified.
2905
- fn compute_debuginfo_type_name < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
2906
- t : Ty < ' tcx > ,
2907
- qualified : bool )
2908
- -> String {
2909
- let mut result = String :: with_capacity ( 64 ) ;
2910
- push_debuginfo_type_name ( cx, t, qualified, & mut result) ;
2911
- result
2912
- }
2913
-
2914
- // Pushes the name of the type as it should be stored in debuginfo on the
2915
- // `output` String. See also compute_debuginfo_type_name().
2916
- fn push_debuginfo_type_name < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
2917
- t : Ty < ' tcx > ,
2918
- qualified : bool ,
2919
- output : & mut String ) {
2920
- match t. sty {
2921
- ty:: ty_bool => output. push_str ( "bool" ) ,
2922
- ty:: ty_char => output. push_str ( "char" ) ,
2923
- ty:: ty_str => output. push_str ( "str" ) ,
2924
- ty:: ty_int( ast:: TyIs ) => output. push_str ( "isize" ) ,
2925
- ty:: ty_int( ast:: TyI8 ) => output. push_str ( "i8" ) ,
2926
- ty:: ty_int( ast:: TyI16 ) => output. push_str ( "i16" ) ,
2927
- ty:: ty_int( ast:: TyI32 ) => output. push_str ( "i32" ) ,
2928
- ty:: ty_int( ast:: TyI64 ) => output. push_str ( "i64" ) ,
2929
- ty:: ty_uint( ast:: TyUs ) => output. push_str ( "usize" ) ,
2930
- ty:: ty_uint( ast:: TyU8 ) => output. push_str ( "u8" ) ,
2931
- ty:: ty_uint( ast:: TyU16 ) => output. push_str ( "u16" ) ,
2932
- ty:: ty_uint( ast:: TyU32 ) => output. push_str ( "u32" ) ,
2933
- ty:: ty_uint( ast:: TyU64 ) => output. push_str ( "u64" ) ,
2934
- ty:: ty_float( ast:: TyF32 ) => output. push_str ( "f32" ) ,
2935
- ty:: ty_float( ast:: TyF64 ) => output. push_str ( "f64" ) ,
2936
- ty:: ty_struct( def_id, substs) |
2937
- ty:: ty_enum( def_id, substs) => {
2938
- push_item_name ( cx, def_id, qualified, output) ;
2939
- push_type_params ( cx, substs, output) ;
2940
- } ,
2941
- ty:: ty_tup( ref component_types) => {
2942
- output. push ( '(' ) ;
2943
- for & component_type in component_types {
2944
- push_debuginfo_type_name ( cx, component_type, true , output) ;
2945
- output. push_str ( ", " ) ;
2946
- }
2947
- if !component_types. is_empty ( ) {
2948
- output. pop ( ) ;
2949
- output. pop ( ) ;
2950
- }
2951
- output. push ( ')' ) ;
2952
- } ,
2953
- ty:: ty_uniq( inner_type) => {
2954
- output. push_str ( "Box<" ) ;
2955
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2956
- output. push ( '>' ) ;
2957
- } ,
2958
- ty:: ty_ptr( ty:: mt { ty : inner_type, mutbl } ) => {
2959
- output. push ( '*' ) ;
2960
- match mutbl {
2961
- ast:: MutImmutable => output. push_str ( "const " ) ,
2962
- ast:: MutMutable => output. push_str ( "mut " ) ,
2963
- }
2964
-
2965
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2966
- } ,
2967
- ty:: ty_rptr( _, ty:: mt { ty : inner_type, mutbl } ) => {
2968
- output. push ( '&' ) ;
2969
- if mutbl == ast:: MutMutable {
2970
- output. push_str ( "mut " ) ;
2971
- }
2972
-
2973
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2974
- } ,
2975
- ty:: ty_vec( inner_type, optional_length) => {
2976
- output. push ( '[' ) ;
2977
- push_debuginfo_type_name ( cx, inner_type, true , output) ;
2978
-
2979
- match optional_length {
2980
- Some ( len) => {
2981
- output. push_str ( & format ! ( "; {}" , len) ) ;
2982
- }
2983
- None => { /* nothing to do */ }
2984
- } ;
2985
-
2986
- output. push ( ']' ) ;
2987
- } ,
2988
- ty:: ty_trait( ref trait_data) => {
2989
- let principal = ty:: erase_late_bound_regions ( cx. tcx ( ) , & trait_data. principal ) ;
2990
- push_item_name ( cx, principal. def_id , false , output) ;
2991
- push_type_params ( cx, principal. substs , output) ;
2992
- } ,
2993
- ty:: ty_bare_fn( _, & ty:: BareFnTy { unsafety, abi, ref sig } ) => {
2994
- if unsafety == ast:: Unsafety :: Unsafe {
2995
- output. push_str ( "unsafe " ) ;
2996
- }
2997
-
2998
- if abi != :: syntax:: abi:: Rust {
2999
- output. push_str ( "extern \" " ) ;
3000
- output. push_str ( abi. name ( ) ) ;
3001
- output. push_str ( "\" " ) ;
3002
- }
3003
-
3004
- output. push_str ( "fn(" ) ;
3005
-
3006
- let sig = ty:: erase_late_bound_regions ( cx. tcx ( ) , sig) ;
3007
- if !sig. inputs . is_empty ( ) {
3008
- for & parameter_type in & sig. inputs {
3009
- push_debuginfo_type_name ( cx, parameter_type, true , output) ;
3010
- output. push_str ( ", " ) ;
3011
- }
3012
- output. pop ( ) ;
3013
- output. pop ( ) ;
3014
- }
3015
-
3016
- if sig. variadic {
3017
- if !sig. inputs . is_empty ( ) {
3018
- output. push_str ( ", ..." ) ;
3019
- } else {
3020
- output. push_str ( "..." ) ;
3021
- }
3022
- }
3023
-
3024
- output. push ( ')' ) ;
3025
-
3026
- match sig. output {
3027
- ty:: FnConverging ( result_type) if ty:: type_is_nil ( result_type) => { }
3028
- ty:: FnConverging ( result_type) => {
3029
- output. push_str ( " -> " ) ;
3030
- push_debuginfo_type_name ( cx, result_type, true , output) ;
3031
- }
3032
- ty:: FnDiverging => {
3033
- output. push_str ( " -> !" ) ;
3034
- }
3035
- }
3036
- } ,
3037
- ty:: ty_closure( ..) => {
3038
- output. push_str ( "closure" ) ;
3039
- }
3040
- ty:: ty_err |
3041
- ty:: ty_infer( _) |
3042
- ty:: ty_projection( ..) |
3043
- ty:: ty_param( _) => {
3044
- cx. sess ( ) . bug ( & format ! ( "debuginfo: Trying to create type name for \
3045
- unexpected type: {}", ppaux:: ty_to_string( cx. tcx( ) , t) ) ) ;
3046
- }
3047
- }
3048
-
3049
- fn push_item_name ( cx : & CrateContext ,
3050
- def_id : ast:: DefId ,
3051
- qualified : bool ,
3052
- output : & mut String ) {
3053
- ty:: with_path ( cx. tcx ( ) , def_id, |path| {
3054
- if qualified {
3055
- if def_id. krate == ast:: LOCAL_CRATE {
3056
- output. push_str ( crate_root_namespace ( cx) ) ;
3057
- output. push_str ( "::" ) ;
3058
- }
3059
-
3060
- let mut path_element_count = 0 ;
3061
- for path_element in path {
3062
- let name = token:: get_name ( path_element. name ( ) ) ;
3063
- output. push_str ( & name) ;
3064
- output. push_str ( "::" ) ;
3065
- path_element_count += 1 ;
3066
- }
3067
-
3068
- if path_element_count == 0 {
3069
- cx. sess ( ) . bug ( "debuginfo: Encountered empty item path!" ) ;
3070
- }
3071
-
3072
- output. pop ( ) ;
3073
- output. pop ( ) ;
3074
- } else {
3075
- let name = token:: get_name ( path. last ( )
3076
- . expect ( "debuginfo: Empty item path?" )
3077
- . name ( ) ) ;
3078
- output. push_str ( & name) ;
3079
- }
3080
- } ) ;
3081
- }
3082
-
3083
- // Pushes the type parameters in the given `Substs` to the output string.
3084
- // This ignores region parameters, since they can't reliably be
3085
- // reconstructed for items from non-local crates. For local crates, this
3086
- // would be possible but with inlining and LTO we have to use the least
3087
- // common denominator - otherwise we would run into conflicts.
3088
- fn push_type_params < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
3089
- substs : & subst:: Substs < ' tcx > ,
3090
- output : & mut String ) {
3091
- if substs. types . is_empty ( ) {
3092
- return ;
3093
- }
3094
-
3095
- output. push ( '<' ) ;
3096
-
3097
- for & type_parameter in substs. types . iter ( ) {
3098
- push_debuginfo_type_name ( cx, type_parameter, true , output) ;
3099
- output. push_str ( ", " ) ;
3100
- }
3101
-
3102
- output. pop ( ) ;
3103
- output. pop ( ) ;
3104
-
3105
- output. push ( '>' ) ;
3106
- }
3107
- }
0 commit comments