2015-04-24 05:25:35 +00:00
|
|
|
// Namespace Handling.
|
2015-04-24 04:00:47 +00:00
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
use super::utils::{debug_context, DIB};
|
2020-03-29 14:41:09 +00:00
|
|
|
use rustc_middle::ty::{self, Instance};
|
2015-04-24 04:00:47 +00:00
|
|
|
|
2019-12-22 22:42:04 +00:00
|
|
|
use crate::common::CodegenCx;
|
2019-02-17 18:58:58 +00:00
|
|
|
use crate::llvm;
|
|
|
|
use crate::llvm::debuginfo::DIScope;
|
2020-01-05 01:37:57 +00:00
|
|
|
use rustc_hir::def_id::DefId;
|
2020-09-01 12:11:28 +00:00
|
|
|
use rustc_hir::definitions::DefPathData;
|
2015-04-24 04:00:47 +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>,
|
2020-07-10 05:45:05 +00:00
|
|
|
) -> ty::SymbolName<'tcx> {
|
2019-12-22 22:42:04 +00:00
|
|
|
let tcx = cx.tcx;
|
|
|
|
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);
|
2019-12-22 22:42:04 +00:00
|
|
|
let parent_scope = def_key
|
|
|
|
.parent
|
|
|
|
.map(|parent| item_namespace(cx, DefId { krate: def_id.krate, index: parent }));
|
2016-04-06 12:37:19 +00:00
|
|
|
|
2020-09-23 22:38:38 +00:00
|
|
|
let crate_name_as_str;
|
|
|
|
let name_to_string;
|
2016-04-06 12:37:19 +00:00
|
|
|
let namespace_name = match def_key.disambiguated_data.data {
|
2020-09-23 22:38:38 +00:00
|
|
|
DefPathData::CrateRoot => {
|
|
|
|
crate_name_as_str = cx.tcx.crate_name(def_id.krate).as_str();
|
|
|
|
&*crate_name_as_str
|
|
|
|
}
|
|
|
|
data => {
|
|
|
|
name_to_string = data.to_string();
|
|
|
|
&*name_to_string
|
|
|
|
}
|
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,
|
2020-03-06 00:00:00 +00:00
|
|
|
namespace_name.as_ptr().cast(),
|
|
|
|
namespace_name.len(),
|
|
|
|
false, // ExportSymbols (only relevant for C++ anonymous namespaces)
|
2019-12-22 22:42:04 +00:00
|
|
|
)
|
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
|
|
|
}
|