2015-04-24 04:00:47 +00:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
2015-04-24 05:25:35 +00:00
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
2015-04-24 04:00:47 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
2015-04-24 05:25:35 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
2015-04-24 04:00:47 +00:00
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
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};
|
2017-12-21 05:28:10 +00:00
|
|
|
use monomorphize::Instance;
|
|
|
|
use rustc::ty;
|
2015-04-24 04:00:47 +00:00
|
|
|
|
|
|
|
use llvm;
|
|
|
|
use llvm::debuginfo::DIScope;
|
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;
|
2018-01-05 05:01:54 +00:00
|
|
|
use common::CodegenCx;
|
2015-04-24 04:00:47 +00:00
|
|
|
|
|
|
|
use std::ffi::CString;
|
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(),
|
2018-04-11 21:02:41 +00:00
|
|
|
data => data.as_interned_str().as_str()
|
2016-04-06 12:37:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
|
|
|
|
|
|
|
|
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
|
|
|
}
|