rust/src/librustc_codegen_llvm/debuginfo/namespace.rs

56 lines
1.5 KiB
Rust
Raw Normal View History

2015-04-24 17:25:35 +12:00
// Namespace Handling.
2015-04-24 16:00:47 +12:00
use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
use super::utils::{DIB, debug_context};
use monomorphize::Instance;
use rustc::ty;
2015-04-24 16:00:47 +12:00
use llvm;
use llvm::debuginfo::DIScope;
use rustc::hir::def_id::DefId;
use rustc::hir::map::DefPathData;
use common::CodegenCx;
2015-04-24 16:00:47 +12:00
use rustc_data_structures::small_c_str::SmallCStr;
pub fn mangled_name_of_instance<'a, 'tcx>(
2018-01-05 07:04:08 +02:00
cx: &CodegenCx<'a, 'tcx>,
instance: Instance<'tcx>,
) -> ty::SymbolName {
2018-01-05 07:04:08 +02:00
let tcx = cx.tcx;
tcx.symbol_name(instance)
}
2016-04-06 13:51:55 +03:00
pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
2018-01-05 07:04:08 +02:00
if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
return scope;
2016-04-06 13:51:55 +03:00
}
2018-01-05 07:04:08 +02:00
let def_key = cx.tcx.def_key(def_id);
let parent_scope = def_key.parent.map(|parent| {
item_namespace(cx, DefId {
krate: def_id.krate,
index: parent
})
});
let namespace_name = match def_key.disambiguated_data.data {
2018-01-05 07:04:08 +02:00
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
data => data.as_interned_str().as_str()
};
let namespace_name = SmallCStr::new(&namespace_name);
let scope = unsafe {
llvm::LLVMRustDIBuilderCreateNameSpace(
2018-01-05 07:04:08 +02:00
DIB(cx),
parent_scope,
namespace_name.as_ptr(),
2018-01-05 07:04:08 +02:00
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER)
};
2018-01-05 07:04:08 +02:00
debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
scope
2015-04-24 16:00:47 +12:00
}