2015-04-24 17:25:35 +12:00
|
|
|
// Namespace Handling.
|
2015-04-24 16:00:47 +12:00
|
|
|
|
2017-07-07 14:23:38 +02:00
|
|
|
use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
|
|
|
|
use super::utils::{DIB, debug_context};
|
2017-12-20 21:28:10 -08:00
|
|
|
use monomorphize::Instance;
|
|
|
|
use rustc::ty;
|
2015-04-24 16:00:47 +12:00
|
|
|
|
|
|
|
use llvm;
|
|
|
|
use llvm::debuginfo::DIScope;
|
2016-03-29 12:54:26 +03:00
|
|
|
use rustc::hir::def_id::DefId;
|
2016-04-06 15:37:19 +03:00
|
|
|
use rustc::hir::map::DefPathData;
|
2018-01-05 07:01:54 +02:00
|
|
|
use common::CodegenCx;
|
2015-04-24 16:00:47 +12:00
|
|
|
|
2018-08-07 16:04:34 +02:00
|
|
|
use rustc_data_structures::small_c_str::SmallCStr;
|
2016-04-06 15:37:19 +03:00
|
|
|
|
2017-12-20 21:28:10 -08:00
|
|
|
pub fn mangled_name_of_instance<'a, 'tcx>(
|
2018-01-05 07:04:08 +02:00
|
|
|
cx: &CodegenCx<'a, 'tcx>,
|
2017-12-20 21:28:10 -08:00
|
|
|
instance: Instance<'tcx>,
|
|
|
|
) -> ty::SymbolName {
|
2018-01-05 07:04:08 +02:00
|
|
|
let tcx = cx.tcx;
|
2017-12-20 21:28:10 -08:00
|
|
|
tcx.symbol_name(instance)
|
2016-04-06 15:37:19 +03:00
|
|
|
}
|
2016-04-06 13:51:55 +03:00
|
|
|
|
2018-07-04 16:36:49 +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) {
|
2016-04-06 15:37:19 +03:00
|
|
|
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);
|
2018-07-04 16:36:49 +03:00
|
|
|
let parent_scope = def_key.parent.map(|parent| {
|
|
|
|
item_namespace(cx, DefId {
|
2016-04-06 15:37:19 +03:00
|
|
|
krate: def_id.krate,
|
|
|
|
index: parent
|
2018-07-04 16:36:49 +03:00
|
|
|
})
|
2016-04-06 15:37:19 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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(),
|
2018-04-11 23:02:41 +02:00
|
|
|
data => data.as_interned_str().as_str()
|
2016-04-06 15:37:19 +03:00
|
|
|
};
|
|
|
|
|
2018-08-07 16:04:34 +02:00
|
|
|
let namespace_name = SmallCStr::new(&namespace_name);
|
2016-04-06 15:37:19 +03:00
|
|
|
|
|
|
|
let scope = unsafe {
|
2016-08-02 02:35:09 +03:00
|
|
|
llvm::LLVMRustDIBuilderCreateNameSpace(
|
2018-01-05 07:04:08 +02:00
|
|
|
DIB(cx),
|
2016-04-06 15:37:19 +03:00
|
|
|
parent_scope,
|
|
|
|
namespace_name.as_ptr(),
|
2018-01-05 07:04:08 +02:00
|
|
|
unknown_file_metadata(cx),
|
2017-07-07 14:23:38 +02:00
|
|
|
UNKNOWN_LINE_NUMBER)
|
2016-04-06 15:37:19 +03:00
|
|
|
};
|
|
|
|
|
2018-01-05 07:04:08 +02:00
|
|
|
debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
|
2016-04-06 15:37:19 +03:00
|
|
|
scope
|
2015-04-24 16:00:47 +12:00
|
|
|
}
|