]> git.proxmox.com Git - rustc.git/blob - src/librustc_codegen_llvm/debuginfo/namespace.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_codegen_llvm / debuginfo / namespace.rs
1 // Namespace Handling.
2
3 use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
4 use super::utils::{DIB, debug_context};
5 use rustc::ty::{self, Instance};
6
7 use crate::llvm;
8 use crate::llvm::debuginfo::DIScope;
9 use crate::common::CodegenCx;
10 use rustc::hir::def_id::DefId;
11 use rustc::hir::map::DefPathData;
12
13 use rustc_data_structures::small_c_str::SmallCStr;
14
15 pub fn mangled_name_of_instance<'a, 'tcx>(
16 cx: &CodegenCx<'a, 'tcx>,
17 instance: Instance<'tcx>,
18 ) -> ty::SymbolName {
19 let tcx = cx.tcx;
20 tcx.symbol_name(instance)
21 }
22
23 pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
24 if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
25 return scope;
26 }
27
28 let def_key = cx.tcx.def_key(def_id);
29 let parent_scope = def_key.parent.map(|parent| {
30 item_namespace(cx, DefId {
31 krate: def_id.krate,
32 index: parent
33 })
34 });
35
36 let namespace_name = match def_key.disambiguated_data.data {
37 DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
38 data => data.as_symbol()
39 };
40
41 let namespace_name = SmallCStr::new(&namespace_name.as_str());
42
43 let scope = unsafe {
44 llvm::LLVMRustDIBuilderCreateNameSpace(
45 DIB(cx),
46 parent_scope,
47 namespace_name.as_ptr(),
48 unknown_file_metadata(cx),
49 UNKNOWN_LINE_NUMBER)
50 };
51
52 debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
53 scope
54 }