rust/src/librustc_codegen_llvm/debuginfo/namespace.rs

66 lines
1.9 KiB
Rust
Raw Normal View History

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
use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
use super::utils::{DIB, debug_context};
use monomorphize::Instance;
use rustc::ty;
2015-04-24 04:00:47 +00:00
use llvm;
use llvm::debuginfo::DIScope;
use rustc::hir::def_id::DefId;
use rustc::hir::map::DefPathData;
use common::CodegenCx;
2015-04-24 04:00:47 +00:00
use std::ffi::CString;
pub fn mangled_name_of_instance<'a, 'tcx>(
2018-01-05 05:04:08 +00:00
cx: &CodegenCx<'a, 'tcx>,
instance: Instance<'tcx>,
) -> ty::SymbolName {
2018-01-05 05:04:08 +00:00
let tcx = cx.tcx;
tcx.symbol_name(instance)
}
2016-04-06 10:51:55 +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) {
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);
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 05:04:08 +00:00
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
data => data.as_interned_str().as_str()
};
let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
let scope = unsafe {
llvm::LLVMRustDIBuilderCreateNameSpace(
2018-01-05 05:04:08 +00:00
DIB(cx),
parent_scope,
namespace_name.as_ptr(),
2018-01-05 05:04:08 +00:00
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER)
};
2018-01-05 05:04:08 +00:00
debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);
scope
2015-04-24 04:00:47 +00:00
}