Skip to content

Commit cda7413

Browse files
committed
---
yaml --- r: 145377 b: refs/heads/try2 c: 3e5de06 h: refs/heads/master i: 145375: 6b59e8f v: v3
1 parent c556859 commit cda7413

File tree

14 files changed

+1292
-1217
lines changed

14 files changed

+1292
-1217
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 348d8446739f9633897a3d728d265ee6ac59c8fb
8+
refs/heads/try2: 3e5de06135fa9a857931191101d61a4abe149c96
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/front/assign_node_ids.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,22 @@
1111
use driver::session::Session;
1212

1313
use syntax::ast;
14-
use syntax::ast_util;
14+
use syntax::fold::ast_fold;
15+
16+
struct NodeIdAssigner {
17+
sess: Session,
18+
}
19+
20+
impl ast_fold for NodeIdAssigner {
21+
fn new_id(&self, old_id: ast::NodeId) -> ast::NodeId {
22+
assert_eq!(old_id, ast::DUMMY_NODE_ID);
23+
self.sess.next_node_id()
24+
}
25+
}
1526

1627
pub fn assign_node_ids(sess: Session, crate: @ast::Crate) -> @ast::Crate {
17-
let fold = ast_util::node_id_assigner(|| sess.next_node_id());
28+
let fold = NodeIdAssigner {
29+
sess: sess,
30+
};
1831
@fold.fold_crate(crate)
1932
}

branches/try2/src/librustc/front/config.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
use std::option;
13+
use syntax::fold::ast_fold;
1314
use syntax::{ast, fold, attr};
1415

1516
type in_cfg_pred = @fn(attrs: &[ast::Attribute]) -> bool;
@@ -26,21 +27,34 @@ pub fn strip_unconfigured_items(crate: @ast::Crate) -> @ast::Crate {
2627
}
2728
}
2829

29-
pub fn strip_items(crate: &ast::Crate, in_cfg: in_cfg_pred)
30-
-> @ast::Crate {
30+
struct ItemRemover {
31+
ctxt: @Context,
32+
}
3133

32-
let ctxt = @Context { in_cfg: in_cfg };
34+
impl fold::ast_fold for ItemRemover {
35+
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
36+
fold_mod(self.ctxt, module, self)
37+
}
38+
fn fold_block(&self, block: &ast::Block) -> ast::Block {
39+
fold_block(self.ctxt, block, self)
40+
}
41+
fn fold_foreign_mod(&self, foreign_module: &ast::foreign_mod)
42+
-> ast::foreign_mod {
43+
fold_foreign_mod(self.ctxt, foreign_module, self)
44+
}
45+
fn fold_item_underscore(&self, item: &ast::item_) -> ast::item_ {
46+
fold_item_underscore(self.ctxt, item, self)
47+
}
48+
}
3349

34-
let precursor = @fold::AstFoldFns {
35-
fold_mod: |a,b| fold_mod(ctxt, a, b),
36-
fold_block: |a,b| fold_block(ctxt, a, b),
37-
fold_foreign_mod: |a,b| fold_foreign_mod(ctxt, a, b),
38-
fold_item_underscore: |a,b| fold_item_underscore(ctxt, a, b),
39-
.. *fold::default_ast_fold()
50+
pub fn strip_items(crate: &ast::Crate, in_cfg: in_cfg_pred) -> @ast::Crate {
51+
let ctxt = @Context {
52+
in_cfg: in_cfg,
4053
};
41-
42-
let fold = fold::make_fold(precursor);
43-
@fold.fold_crate(crate)
54+
let precursor = ItemRemover {
55+
ctxt: ctxt,
56+
};
57+
@precursor.fold_crate(crate)
4458
}
4559

4660
fn filter_item(cx: @Context, item: @ast::item) ->
@@ -56,7 +70,7 @@ fn filter_view_item<'r>(cx: @Context, view_item: &'r ast::view_item)-> Option<&'
5670
}
5771
}
5872

59-
fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
73+
fn fold_mod(cx: @Context, m: &ast::_mod, fld: &ItemRemover) -> ast::_mod {
6074
let filtered_items = do m.items.iter().filter_map |a| {
6175
filter_item(cx, *a).and_then(|x| fld.fold_item(x))
6276
}.collect();
@@ -78,12 +92,12 @@ fn filter_foreign_item(cx: @Context, item: @ast::foreign_item) ->
7892
} else { option::None }
7993
}
8094

81-
fn fold_foreign_mod(
82-
cx: @Context,
83-
nm: &ast::foreign_mod,
84-
fld: @fold::ast_fold
85-
) -> ast::foreign_mod {
86-
let filtered_items = nm.items.iter().filter_map(|a| filter_foreign_item(cx, *a)).collect();
95+
fn fold_foreign_mod(cx: @Context, nm: &ast::foreign_mod, fld: &ItemRemover)
96+
-> ast::foreign_mod {
97+
let filtered_items = nm.items
98+
.iter()
99+
.filter_map(|a| filter_foreign_item(cx, *a))
100+
.collect();
87101
let filtered_view_items = do nm.view_items.iter().filter_map |a| {
88102
do filter_view_item(cx, a).map_move |x| {
89103
fld.fold_view_item(x)
@@ -97,8 +111,8 @@ fn fold_foreign_mod(
97111
}
98112
}
99113

100-
fn fold_item_underscore(cx: @Context, item: &ast::item_,
101-
fld: @fold::ast_fold) -> ast::item_ {
114+
fn fold_item_underscore(cx: @Context, item: &ast::item_, fld: &ItemRemover)
115+
-> ast::item_ {
102116
let item = match *item {
103117
ast::item_impl(ref a, ref b, ref c, ref methods) => {
104118
let methods = methods.iter().filter(|m| method_in_cfg(cx, **m))
@@ -133,11 +147,7 @@ fn filter_stmt(cx: @Context, stmt: @ast::Stmt) ->
133147
}
134148
}
135149

136-
fn fold_block(
137-
cx: @Context,
138-
b: &ast::Block,
139-
fld: @fold::ast_fold
140-
) -> ast::Block {
150+
fn fold_block(cx: @Context, b: &ast::Block, fld: &ItemRemover) -> ast::Block {
141151
let resulting_stmts = do b.stmts.iter().filter_map |a| {
142152
filter_stmt(cx, *a).and_then(|stmt| fld.fold_stmt(stmt))
143153
}.collect();

branches/try2/src/librustc/front/std_inject.rs

Lines changed: 96 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use syntax::ast;
1616
use syntax::attr;
1717
use syntax::codemap::dummy_sp;
1818
use syntax::codemap;
19+
use syntax::fold::ast_fold;
1920
use syntax::fold;
2021
use syntax::opt_vec;
2122

@@ -38,91 +39,103 @@ fn no_prelude(attrs: &[ast::Attribute]) -> bool {
3839
attr::contains_name(attrs, "no_implicit_prelude")
3940
}
4041

41-
fn inject_libstd_ref(sess: Session, crate: &ast::Crate) -> @ast::Crate {
42-
fn spanned<T>(x: T) -> codemap::Spanned<T> {
43-
codemap::Spanned { node: x, span: dummy_sp() }
42+
fn spanned<T>(x: T) -> codemap::Spanned<T> {
43+
codemap::Spanned {
44+
node: x,
45+
span: dummy_sp(),
4446
}
47+
}
4548

46-
let precursor = @fold::AstFoldFns {
47-
fold_crate: |crate, fld| {
48-
let n1 = ast::DUMMY_NODE_ID;
49-
let vi1 = ast::view_item {
50-
node: ast::view_item_extern_mod(
51-
sess.ident_of("std"), None, ~[], n1),
52-
attrs: ~[
53-
attr::mk_attr(
54-
attr::mk_name_value_item_str(@"vers", STD_VERSION.to_managed()))
55-
],
56-
vis: ast::private,
57-
span: dummy_sp()
58-
};
59-
60-
let vis = vec::append(~[vi1], crate.module.view_items);
61-
let mut new_module = ast::_mod {
62-
view_items: vis,
63-
..crate.module.clone()
64-
};
65-
66-
if !no_prelude(crate.attrs) {
67-
// only add `use std::prelude::*;` if there wasn't a
68-
// `#[no_implicit_prelude];` at the crate level.
69-
new_module = fld.fold_mod(&new_module);
70-
}
71-
72-
// FIXME #2543: Bad copy.
73-
ast::Crate {
74-
module: new_module,
75-
..(*crate).clone()
76-
}
77-
},
78-
fold_item: |item, fld| {
79-
if !no_prelude(item.attrs) {
80-
// only recur if there wasn't `#[no_implicit_prelude];`
81-
// on this item, i.e. this means that the prelude is not
82-
// implicitly imported though the whole subtree
83-
fold::noop_fold_item(item, fld)
84-
} else {
85-
Some(item)
86-
}
87-
},
88-
fold_mod: |module, fld| {
89-
let n2 = ast::DUMMY_NODE_ID;
90-
91-
let prelude_path = ast::Path {
92-
span: dummy_sp(),
93-
global: false,
94-
segments: ~[
95-
ast::PathSegment {
96-
identifier: sess.ident_of("std"),
97-
lifetime: None,
98-
types: opt_vec::Empty,
99-
},
100-
ast::PathSegment {
101-
identifier: sess.ident_of("prelude"),
102-
lifetime: None,
103-
types: opt_vec::Empty,
104-
},
105-
],
106-
};
107-
108-
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
109-
let vi2 = ast::view_item { node: ast::view_item_use(~[vp]),
110-
attrs: ~[],
111-
vis: ast::private,
112-
span: dummy_sp() };
113-
114-
let vis = vec::append(~[vi2], module.view_items);
115-
116-
// FIXME #2543: Bad copy.
117-
let new_module = ast::_mod {
118-
view_items: vis,
119-
..(*module).clone()
120-
};
121-
fold::noop_fold_mod(&new_module, fld)
122-
},
123-
..*fold::default_ast_fold()
124-
};
49+
struct StandardLibraryInjector {
50+
sess: Session,
51+
}
12552

126-
let fold = fold::make_fold(precursor);
53+
impl fold::ast_fold for StandardLibraryInjector {
54+
fn fold_crate(&self, crate: &ast::Crate) -> ast::Crate {
55+
let version = STD_VERSION.to_managed();
56+
let vi1 = ast::view_item {
57+
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
58+
None,
59+
~[],
60+
ast::DUMMY_NODE_ID),
61+
attrs: ~[
62+
attr::mk_attr(attr::mk_name_value_item_str(@"vers", version))
63+
],
64+
vis: ast::private,
65+
span: dummy_sp()
66+
};
67+
68+
let vis = vec::append(~[vi1], crate.module.view_items);
69+
let mut new_module = ast::_mod {
70+
view_items: vis,
71+
..crate.module.clone()
72+
};
73+
74+
if !no_prelude(crate.attrs) {
75+
// only add `use std::prelude::*;` if there wasn't a
76+
// `#[no_implicit_prelude];` at the crate level.
77+
new_module = self.fold_mod(&new_module);
78+
}
79+
80+
// FIXME #2543: Bad copy.
81+
ast::Crate {
82+
module: new_module,
83+
..(*crate).clone()
84+
}
85+
}
86+
87+
fn fold_item(&self, item: @ast::item) -> Option<@ast::item> {
88+
if !no_prelude(item.attrs) {
89+
// only recur if there wasn't `#[no_implicit_prelude];`
90+
// on this item, i.e. this means that the prelude is not
91+
// implicitly imported though the whole subtree
92+
fold::noop_fold_item(item, self)
93+
} else {
94+
Some(item)
95+
}
96+
}
97+
98+
fn fold_mod(&self, module: &ast::_mod) -> ast::_mod {
99+
let prelude_path = ast::Path {
100+
span: dummy_sp(),
101+
global: false,
102+
segments: ~[
103+
ast::PathSegment {
104+
identifier: self.sess.ident_of("std"),
105+
lifetime: None,
106+
types: opt_vec::Empty,
107+
},
108+
ast::PathSegment {
109+
identifier: self.sess.ident_of("prelude"),
110+
lifetime: None,
111+
types: opt_vec::Empty,
112+
},
113+
],
114+
};
115+
116+
let vp = @spanned(ast::view_path_glob(prelude_path,
117+
ast::DUMMY_NODE_ID));
118+
let vi2 = ast::view_item {
119+
node: ast::view_item_use(~[vp]),
120+
attrs: ~[],
121+
vis: ast::private,
122+
span: dummy_sp(),
123+
};
124+
125+
let vis = vec::append(~[vi2], module.view_items);
126+
127+
// FIXME #2543: Bad copy.
128+
let new_module = ast::_mod {
129+
view_items: vis,
130+
..(*module).clone()
131+
};
132+
fold::noop_fold_mod(&new_module, self)
133+
}
134+
}
135+
136+
fn inject_libstd_ref(sess: Session, crate: &ast::Crate) -> @ast::Crate {
137+
let fold = StandardLibraryInjector {
138+
sess: sess,
139+
};
127140
@fold.fold_crate(crate)
128141
}

0 commit comments

Comments
 (0)