1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Namespace Handling.
13 use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
14 use super::utils::{DIB, debug_context};
15 use monomorphize::Instance;
19 use llvm::debuginfo::DIScope;
20 use rustc::hir::def_id::DefId;
21 use rustc::hir::map::DefPathData;
22 use common::CodegenCx;
24 use rustc_data_structures::small_c_str::SmallCStr;
26 pub fn mangled_name_of_instance<'a, 'tcx>(
27 cx: &CodegenCx<'a, 'tcx>,
28 instance: Instance<'tcx>,
31 tcx.symbol_name(instance)
34 pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
35 if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
39 let def_key = cx.tcx.def_key(def_id);
40 let parent_scope = def_key.parent.map(|parent| {
41 item_namespace(cx, DefId {
47 let namespace_name = match def_key.disambiguated_data.data {
48 DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
49 data => data.as_interned_str().as_str()
52 let namespace_name = SmallCStr::new(&namespace_name);
55 llvm::LLVMRustDIBuilderCreateNameSpace(
58 namespace_name.as_ptr(),
59 unknown_file_metadata(cx),
63 debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);