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