Skip to content

Commit 652064f

Browse files
committed
---
yaml --- r: 207772 b: refs/heads/snap-stage3 c: 488694c h: refs/heads/master v: v3
1 parent f5f0316 commit 652064f

File tree

4 files changed

+140
-118
lines changed

4 files changed

+140
-118
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 5b53de17752a11c52679dca46e8a4b4ea3fe1354
4+
refs/heads/snap-stage3: 488694cf0d44671972c57fb48973ed379fbe3fff
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/librustc_trans/trans/debuginfo/mod.rs

Lines changed: 3 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ mod doc;
1414
pub mod gdb;
1515
mod utils;
1616
mod create;
17+
mod namespace;
1718

1819
use self::utils::{debug_context, DIB, span_start, bytes_to_bits, size_and_align_of,
1920
assert_type_for_node_id, get_namespace_and_span_for_item, fn_should_be_ignored,
2021
contains_nodebug_attribute, create_scope_map};
2122
use self::create::{declare_local, create_DIArray, is_node_local_to_unit};
23+
use self::namespace::{namespace_for_item, NamespaceTreeNode, crate_root_namespace};
2224

2325
use self::VariableAccess::*;
2426
use self::VariableKind::*;
@@ -51,7 +53,7 @@ use std::cell::{Cell, RefCell};
5153
use std::ffi::CString;
5254
use std::path::Path;
5355
use std::ptr;
54-
use std::rc::{Rc, Weak};
56+
use std::rc::Rc;
5557
use syntax::util::interner::Interner;
5658
use syntax::codemap::{Span, Pos};
5759
use syntax::{ast, codemap, ast_util, ast_map};
@@ -3103,118 +3105,3 @@ fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
31033105
output.push('>');
31043106
}
31053107
}
3106-
3107-
3108-
//=-----------------------------------------------------------------------------
3109-
// Namespace Handling
3110-
//=-----------------------------------------------------------------------------
3111-
3112-
struct NamespaceTreeNode {
3113-
name: ast::Name,
3114-
scope: DIScope,
3115-
parent: Option<Weak<NamespaceTreeNode>>,
3116-
}
3117-
3118-
impl NamespaceTreeNode {
3119-
fn mangled_name_of_contained_item(&self, item_name: &str) -> String {
3120-
fn fill_nested(node: &NamespaceTreeNode, output: &mut String) {
3121-
match node.parent {
3122-
Some(ref parent) => fill_nested(&*parent.upgrade().unwrap(), output),
3123-
None => {}
3124-
}
3125-
let string = token::get_name(node.name);
3126-
output.push_str(&format!("{}", string.len()));
3127-
output.push_str(&string);
3128-
}
3129-
3130-
let mut name = String::from_str("_ZN");
3131-
fill_nested(self, &mut name);
3132-
name.push_str(&format!("{}", item_name.len()));
3133-
name.push_str(item_name);
3134-
name.push('E');
3135-
name
3136-
}
3137-
}
3138-
3139-
fn crate_root_namespace<'a>(cx: &'a CrateContext) -> &'a str {
3140-
&cx.link_meta().crate_name
3141-
}
3142-
3143-
fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> Rc<NamespaceTreeNode> {
3144-
ty::with_path(cx.tcx(), def_id, |path| {
3145-
// prepend crate name if not already present
3146-
let krate = if def_id.krate == ast::LOCAL_CRATE {
3147-
let crate_namespace_name = token::intern(crate_root_namespace(cx));
3148-
Some(ast_map::PathMod(crate_namespace_name))
3149-
} else {
3150-
None
3151-
};
3152-
let mut path = krate.into_iter().chain(path).peekable();
3153-
3154-
let mut current_key = Vec::new();
3155-
let mut parent_node: Option<Rc<NamespaceTreeNode>> = None;
3156-
3157-
// Create/Lookup namespace for each element of the path.
3158-
loop {
3159-
// Emulate a for loop so we can use peek below.
3160-
let path_element = match path.next() {
3161-
Some(e) => e,
3162-
None => break
3163-
};
3164-
// Ignore the name of the item (the last path element).
3165-
if path.peek().is_none() {
3166-
break;
3167-
}
3168-
3169-
let name = path_element.name();
3170-
current_key.push(name);
3171-
3172-
let existing_node = debug_context(cx).namespace_map.borrow()
3173-
.get(&current_key).cloned();
3174-
let current_node = match existing_node {
3175-
Some(existing_node) => existing_node,
3176-
None => {
3177-
// create and insert
3178-
let parent_scope = match parent_node {
3179-
Some(ref node) => node.scope,
3180-
None => ptr::null_mut()
3181-
};
3182-
let namespace_name = token::get_name(name);
3183-
let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
3184-
let scope = unsafe {
3185-
llvm::LLVMDIBuilderCreateNameSpace(
3186-
DIB(cx),
3187-
parent_scope,
3188-
namespace_name.as_ptr(),
3189-
// cannot reconstruct file ...
3190-
ptr::null_mut(),
3191-
// ... or line information, but that's not so important.
3192-
0)
3193-
};
3194-
3195-
let node = Rc::new(NamespaceTreeNode {
3196-
name: name,
3197-
scope: scope,
3198-
parent: parent_node.map(|parent| parent.downgrade()),
3199-
});
3200-
3201-
debug_context(cx).namespace_map.borrow_mut()
3202-
.insert(current_key.clone(), node.clone());
3203-
3204-
node
3205-
}
3206-
};
3207-
3208-
parent_node = Some(current_node);
3209-
}
3210-
3211-
match parent_node {
3212-
Some(node) => node,
3213-
None => {
3214-
cx.sess().bug(&format!("debuginfo::namespace_for_item(): \
3215-
path too short for {:?}",
3216-
def_id));
3217-
}
3218-
}
3219-
})
3220-
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
// Namespace Handling
12+
13+
use super::utils::{DIB, debug_context};
14+
15+
use llvm;
16+
use llvm::debuginfo::DIScope;
17+
use trans::common::CrateContext;
18+
use middle::ty::{self, ClosureTyper};
19+
20+
use std::ffi::CString;
21+
use std::ptr;
22+
use std::rc::{Rc, Weak};
23+
use syntax::{ast, ast_map};
24+
use syntax::parse::token;
25+
26+
pub struct NamespaceTreeNode {
27+
pub name: ast::Name,
28+
pub scope: DIScope,
29+
pub parent: Option<Weak<NamespaceTreeNode>>,
30+
}
31+
32+
impl NamespaceTreeNode {
33+
pub fn mangled_name_of_contained_item(&self, item_name: &str) -> String {
34+
fn fill_nested(node: &NamespaceTreeNode, output: &mut String) {
35+
match node.parent {
36+
Some(ref parent) => fill_nested(&*parent.upgrade().unwrap(), output),
37+
None => {}
38+
}
39+
let string = token::get_name(node.name);
40+
output.push_str(&format!("{}", string.len()));
41+
output.push_str(&string);
42+
}
43+
44+
let mut name = String::from_str("_ZN");
45+
fill_nested(self, &mut name);
46+
name.push_str(&format!("{}", item_name.len()));
47+
name.push_str(item_name);
48+
name.push('E');
49+
name
50+
}
51+
}
52+
53+
pub fn crate_root_namespace<'a>(cx: &'a CrateContext) -> &'a str {
54+
&cx.link_meta().crate_name
55+
}
56+
57+
pub fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> Rc<NamespaceTreeNode> {
58+
ty::with_path(cx.tcx(), def_id, |path| {
59+
// prepend crate name if not already present
60+
let krate = if def_id.krate == ast::LOCAL_CRATE {
61+
let crate_namespace_name = token::intern(crate_root_namespace(cx));
62+
Some(ast_map::PathMod(crate_namespace_name))
63+
} else {
64+
None
65+
};
66+
let mut path = krate.into_iter().chain(path).peekable();
67+
68+
let mut current_key = Vec::new();
69+
let mut parent_node: Option<Rc<NamespaceTreeNode>> = None;
70+
71+
// Create/Lookup namespace for each element of the path.
72+
loop {
73+
// Emulate a for loop so we can use peek below.
74+
let path_element = match path.next() {
75+
Some(e) => e,
76+
None => break
77+
};
78+
// Ignore the name of the item (the last path element).
79+
if path.peek().is_none() {
80+
break;
81+
}
82+
83+
let name = path_element.name();
84+
current_key.push(name);
85+
86+
let existing_node = debug_context(cx).namespace_map.borrow()
87+
.get(&current_key).cloned();
88+
let current_node = match existing_node {
89+
Some(existing_node) => existing_node,
90+
None => {
91+
// create and insert
92+
let parent_scope = match parent_node {
93+
Some(ref node) => node.scope,
94+
None => ptr::null_mut()
95+
};
96+
let namespace_name = token::get_name(name);
97+
let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
98+
let scope = unsafe {
99+
llvm::LLVMDIBuilderCreateNameSpace(
100+
DIB(cx),
101+
parent_scope,
102+
namespace_name.as_ptr(),
103+
// cannot reconstruct file ...
104+
ptr::null_mut(),
105+
// ... or line information, but that's not so important.
106+
0)
107+
};
108+
109+
let node = Rc::new(NamespaceTreeNode {
110+
name: name,
111+
scope: scope,
112+
parent: parent_node.map(|parent| parent.downgrade()),
113+
});
114+
115+
debug_context(cx).namespace_map.borrow_mut()
116+
.insert(current_key.clone(), node.clone());
117+
118+
node
119+
}
120+
};
121+
122+
parent_node = Some(current_node);
123+
}
124+
125+
match parent_node {
126+
Some(node) => node,
127+
None => {
128+
cx.sess().bug(&format!("debuginfo::namespace_for_item(): \
129+
path too short for {:?}",
130+
def_id));
131+
}
132+
}
133+
})
134+
}

branches/snap-stage3/src/librustc_trans/trans/debuginfo/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
// Utility Functions.
1212

13-
use super::{FunctionDebugContext, CrateDebugContext, namespace_for_item, file_metadata};
13+
use super::{FunctionDebugContext, CrateDebugContext, file_metadata};
14+
use super::namespace::namespace_for_item;
1415

1516
use llvm;
1617
use llvm::debuginfo::{DIScope, DISubprogram, DIBuilderRef};

0 commit comments

Comments
 (0)