2015-04-24 05:25:35 +00:00
|
|
|
// Namespace Handling.
|
2015-04-24 04:00:47 +00:00
|
|
|
|
2017-07-07 12:23:38 +00:00
|
|
|
use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
|
|
|
|
use super::utils::{DIB, debug_context};
|
2019-05-24 17:32:53 +00:00
|
|
|
use rustc::ty::{self, Instance};
|
2015-04-24 04:00:47 +00:00
|
|
|
|
2019-02-17 18:58:58 +00:00
|
|
|
use crate::llvm;
|
|
|
|
use crate::llvm::debuginfo::DIScope;
|
|
|
|
use crate::common::CodegenCx;
|
2016-03-29 09:54:26 +00:00
|
|
|
use rustc::hir::def_id::DefId;
|
2016-04-06 12:37:19 +00:00
|
|
|
use rustc::hir::map::DefPathData;
|
2015-04-24 04:00:47 +00:00
|
|
|
|
2018-08-07 14:04:34 +00:00
|
|
|
use rustc_data_structures::small_c_str::SmallCStr;
|
2016-04-06 12:37:19 +00:00
|
|
|
|
2017-12-21 05:28:10 +00:00
|
|
|
pub fn mangled_name_of_instance<'a, 'tcx>(
|
2018-01-05 05:04:08 +00:00
|
|
|
cx: &CodegenCx<'a, 'tcx>,
|
2017-12-21 05:28:10 +00:00
|
|
|
instance: Instance<'tcx>,
|
|
|
|
) -> ty::SymbolName {
|
2018-01-05 05:04:08 +00:00
|
|
|
let tcx = cx.tcx;
|
2017-12-21 05:28:10 +00:00
|
|
|
tcx.symbol_name(instance)
|
2016-04-06 12:37:19 +00:00
|
|
|
}
|
2016-04-06 10:51:55 +00:00
|
|
|
|
2018-07-04 13:36:49 +00:00
|
|
|
pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
2018-01-05 05:04:08 +00:00
|
|
|
if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
|
2016-04-06 12:37:19 +00:00
|
|
|
return scope;
|
2016-04-06 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 05:04:08 +00:00
|
|
|
let def_key = cx.tcx.def_key(def_id);
|
2018-07-04 13:36:49 +00:00
|
|
|
let parent_scope = def_key.parent.map(|parent| {
|
|
|
|
item_namespace(cx, DefId {
|
2016-04-06 12:37:19 +00:00
|
|
|
krate: def_id.krate,
|
|
|
|
index: parent
|
2018-07-04 13:36:49 +00:00
|
|
|
})
|
2016-04-06 12:37:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let namespace_name = match def_key.disambiguated_data.data {
|
2018-01-05 05:04:08 +00:00
|
|
|
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
|
2019-10-21 03:25:08 +00:00
|
|
|
data => data.as_symbol().as_str()
|
2016-04-06 12:37:19 +00:00
|
|
|
};
|
|
|
|
|
2018-08-07 14:04:34 +00:00
|
|
|
let namespace_name = SmallCStr::new(&namespace_name);
|
2016-04-06 12:37:19 +00:00
|
|
|
|
|
|
|
let scope = unsafe {
|
2016-08-01 23:35:09 +00:00
|
|
|
llvm::LLVMRustDIBuilderCreateNameSpace(
|
2018-01-05 05:04:08 +00:00
|
|
|
DIB(cx),
|
2016-04-06 12:37:19 +00:00
|
|
|
parent_scope,
|
|
|
|
namespace_name.as_ptr(),
|
2018-01-05 05:04:08 +00:00
|
|
|
unknown_file_metadata(cx),
|
2017-07-07 12:23:38 +00:00
|
|
|
UNKNOWN_LINE_NUMBER)
|
2016-04-06 12:37:19 +00:00
|
|
|
};
|
|
|
|
|
2018-01-05 05:04:08 +00:00
|
|
|
debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
|
2016-04-06 12:37:19 +00:00
|
|
|
scope
|
2015-04-24 04:00:47 +00:00
|
|
|
}
|