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 std::ffi::CString;
27 pub fn mangled_name_of_instance<'a, 'tcx>(
28 cx: &CodegenCx<'a, 'tcx>,
29 instance: Instance<'tcx>,
32 tcx.symbol_name(instance)
35 pub fn item_namespace(cx: &CodegenCx, def_id: DefId) -> DIScope {
36 if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
40 let def_key = cx.tcx.def_key(def_id);
41 let parent_scope = def_key.parent.map_or(ptr::null_mut(), |parent| {
42 item_namespace(cx, DefId {
48 let namespace_name = match def_key.disambiguated_data.data {
49 DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
50 data => data.as_interned_str().as_str()
53 let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
56 llvm::LLVMRustDIBuilderCreateNameSpace(
59 namespace_name.as_ptr(),
60 unknown_file_metadata(cx),
64 debug_context(cx).namespace_map.borrow_mut().insert(def_id, scope);