]> git.proxmox.com Git - rustc.git/blob - src/librustc_trans/debuginfo/utils.rs
New upstream version 1.25.0+dfsg1
[rustc.git] / src / librustc_trans / debuginfo / utils.rs
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.
4 //
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.
10
11 // Utility Functions.
12
13 use super::{CrateDebugContext};
14 use super::namespace::item_namespace;
15
16 use rustc::hir::def_id::DefId;
17 use rustc::ty::DefIdTree;
18
19 use llvm;
20 use llvm::debuginfo::{DIScope, DIBuilderRef, DIDescriptor, DIArray};
21 use common::{CodegenCx};
22
23 use syntax_pos::{self, Span};
24 use syntax::ast;
25
26 pub fn is_node_local_to_unit(cx: &CodegenCx, node_id: ast::NodeId) -> bool
27 {
28 // The is_local_to_unit flag indicates whether a function is local to the
29 // current compilation unit (i.e. if it is *static* in the C-sense). The
30 // *reachable* set should provide a good approximation of this, as it
31 // contains everything that might leak out of the current crate (by being
32 // externally visible or by being inlined into something externally
33 // visible). It might better to use the `exported_items` set from
34 // `driver::CrateAnalysis` in the future, but (atm) this set is not
35 // available in the translation pass.
36 let def_id = cx.tcx.hir.local_def_id(node_id);
37 !cx.tcx.is_exported_symbol(def_id)
38 }
39
40 #[allow(non_snake_case)]
41 pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
42 return unsafe {
43 llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
44 };
45 }
46
47 /// Return syntax_pos::Loc corresponding to the beginning of the span
48 pub fn span_start(cx: &CodegenCx, span: Span) -> syntax_pos::Loc {
49 cx.sess().codemap().lookup_char_pos(span.lo())
50 }
51
52 #[inline]
53 pub fn debug_context<'a, 'tcx>(cx: &'a CodegenCx<'a, 'tcx>)
54 -> &'a CrateDebugContext<'tcx> {
55 cx.dbg_cx.as_ref().unwrap()
56 }
57
58 #[inline]
59 #[allow(non_snake_case)]
60 pub fn DIB(cx: &CodegenCx) -> DIBuilderRef {
61 cx.dbg_cx.as_ref().unwrap().builder
62 }
63
64 pub fn get_namespace_for_item(cx: &CodegenCx, def_id: DefId) -> DIScope {
65 item_namespace(cx, cx.tcx.parent(def_id)
66 .expect("get_namespace_for_item: missing parent?"))
67 }