@@ -14,11 +14,13 @@ mod doc;
14
14
pub mod gdb;
15
15
mod utils;
16
16
mod create;
17
+ mod namespace;
17
18
18
19
use self :: utils:: { debug_context, DIB , span_start, bytes_to_bits, size_and_align_of,
19
20
assert_type_for_node_id, get_namespace_and_span_for_item, fn_should_be_ignored,
20
21
contains_nodebug_attribute, create_scope_map} ;
21
22
use self :: create:: { declare_local, create_DIArray, is_node_local_to_unit} ;
23
+ use self :: namespace:: { namespace_for_item, NamespaceTreeNode , crate_root_namespace} ;
22
24
23
25
use self :: VariableAccess :: * ;
24
26
use self :: VariableKind :: * ;
@@ -51,7 +53,7 @@ use std::cell::{Cell, RefCell};
51
53
use std:: ffi:: CString ;
52
54
use std:: path:: Path ;
53
55
use std:: ptr;
54
- use std:: rc:: { Rc , Weak } ;
56
+ use std:: rc:: Rc ;
55
57
use syntax:: util:: interner:: Interner ;
56
58
use syntax:: codemap:: { Span , Pos } ;
57
59
use syntax:: { ast, codemap, ast_util, ast_map} ;
@@ -3108,118 +3110,3 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
3108
3110
output. push ( '>' ) ;
3109
3111
}
3110
3112
}
3111
-
3112
-
3113
- //=-----------------------------------------------------------------------------
3114
- // Namespace Handling
3115
- //=-----------------------------------------------------------------------------
3116
-
3117
- struct NamespaceTreeNode {
3118
- name : ast:: Name ,
3119
- scope : DIScope ,
3120
- parent : Option < Weak < NamespaceTreeNode > > ,
3121
- }
3122
-
3123
- impl NamespaceTreeNode {
3124
- fn mangled_name_of_contained_item ( & self , item_name : & str ) -> String {
3125
- fn fill_nested ( node : & NamespaceTreeNode , output : & mut String ) {
3126
- match node. parent {
3127
- Some ( ref parent) => fill_nested ( & * parent. upgrade ( ) . unwrap ( ) , output) ,
3128
- None => { }
3129
- }
3130
- let string = token:: get_name ( node. name ) ;
3131
- output. push_str ( & format ! ( "{}" , string. len( ) ) ) ;
3132
- output. push_str ( & string) ;
3133
- }
3134
-
3135
- let mut name = String :: from_str ( "_ZN" ) ;
3136
- fill_nested ( self , & mut name) ;
3137
- name. push_str ( & format ! ( "{}" , item_name. len( ) ) ) ;
3138
- name. push_str ( item_name) ;
3139
- name. push ( 'E' ) ;
3140
- name
3141
- }
3142
- }
3143
-
3144
- fn crate_root_namespace < ' a > ( cx : & ' a CrateContext ) -> & ' a str {
3145
- & cx. link_meta ( ) . crate_name
3146
- }
3147
-
3148
- fn namespace_for_item ( cx : & CrateContext , def_id : ast:: DefId ) -> Rc < NamespaceTreeNode > {
3149
- ty:: with_path ( cx. tcx ( ) , def_id, |path| {
3150
- // prepend crate name if not already present
3151
- let krate = if def_id. krate == ast:: LOCAL_CRATE {
3152
- let crate_namespace_name = token:: intern ( crate_root_namespace ( cx) ) ;
3153
- Some ( ast_map:: PathMod ( crate_namespace_name) )
3154
- } else {
3155
- None
3156
- } ;
3157
- let mut path = krate. into_iter ( ) . chain ( path) . peekable ( ) ;
3158
-
3159
- let mut current_key = Vec :: new ( ) ;
3160
- let mut parent_node: Option < Rc < NamespaceTreeNode > > = None ;
3161
-
3162
- // Create/Lookup namespace for each element of the path.
3163
- loop {
3164
- // Emulate a for loop so we can use peek below.
3165
- let path_element = match path. next ( ) {
3166
- Some ( e) => e,
3167
- None => break
3168
- } ;
3169
- // Ignore the name of the item (the last path element).
3170
- if path. peek ( ) . is_none ( ) {
3171
- break ;
3172
- }
3173
-
3174
- let name = path_element. name ( ) ;
3175
- current_key. push ( name) ;
3176
-
3177
- let existing_node = debug_context ( cx) . namespace_map . borrow ( )
3178
- . get ( & current_key) . cloned ( ) ;
3179
- let current_node = match existing_node {
3180
- Some ( existing_node) => existing_node,
3181
- None => {
3182
- // create and insert
3183
- let parent_scope = match parent_node {
3184
- Some ( ref node) => node. scope ,
3185
- None => ptr:: null_mut ( )
3186
- } ;
3187
- let namespace_name = token:: get_name ( name) ;
3188
- let namespace_name = CString :: new ( namespace_name. as_bytes ( ) ) . unwrap ( ) ;
3189
- let scope = unsafe {
3190
- llvm:: LLVMDIBuilderCreateNameSpace (
3191
- DIB ( cx) ,
3192
- parent_scope,
3193
- namespace_name. as_ptr ( ) ,
3194
- // cannot reconstruct file ...
3195
- ptr:: null_mut ( ) ,
3196
- // ... or line information, but that's not so important.
3197
- 0 )
3198
- } ;
3199
-
3200
- let node = Rc :: new ( NamespaceTreeNode {
3201
- name : name,
3202
- scope : scope,
3203
- parent : parent_node. map ( |parent| parent. downgrade ( ) ) ,
3204
- } ) ;
3205
-
3206
- debug_context ( cx) . namespace_map . borrow_mut ( )
3207
- . insert ( current_key. clone ( ) , node. clone ( ) ) ;
3208
-
3209
- node
3210
- }
3211
- } ;
3212
-
3213
- parent_node = Some ( current_node) ;
3214
- }
3215
-
3216
- match parent_node {
3217
- Some ( node) => node,
3218
- None => {
3219
- cx. sess ( ) . bug ( & format ! ( "debuginfo::namespace_for_item(): \
3220
- path too short for {:?}",
3221
- def_id) ) ;
3222
- }
3223
- }
3224
- } )
3225
- }
0 commit comments