Skip to content

Commit 0751efe

Browse files
committed
---
yaml --- r: 85371 b: refs/heads/dist-snap c: b97cc95 h: refs/heads/master i: 85369: a3b2d57 85367: 305e813 v: v3
1 parent a47eeb3 commit 0751efe

File tree

7 files changed

+226
-148
lines changed

7 files changed

+226
-148
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 0983ebe5310d4eb6d289f636f7ed0536c08bbc0e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 0d85928e37dec4795cf288e9f0bbe23d7a100b7a
9+
refs/heads/dist-snap: b97cc955c2b2d9494607434352e0898ee0eca0b8
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/borrowck/mod.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ use std::ops::{BitOr, BitAnd};
2626
use std::result::{Result};
2727
use syntax::ast;
2828
use syntax::ast_map;
29-
use syntax::oldvisit;
3029
use syntax::codemap::span;
3130
use syntax::parse::token;
31+
use syntax::visit;
32+
use syntax::visit::{Visitor,fn_kind};
33+
use syntax::ast::{fn_decl,Block,NodeId};
3234

3335
macro_rules! if_ok(
3436
($inp: expr) => (
@@ -59,6 +61,15 @@ impl Clone for LoanDataFlowOperator {
5961

6062
pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>;
6163

64+
struct BorrowckVisitor;
65+
66+
impl Visitor<@BorrowckCtxt> for BorrowckVisitor {
67+
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl,
68+
b:&Block, s:span, n:NodeId, e:@BorrowckCtxt) {
69+
borrowck_fn(self, fk, fd, b, s, n, e);
70+
}
71+
}
72+
6273
pub fn check_crate(
6374
tcx: ty::ctxt,
6475
method_map: typeck::method_map,
@@ -86,9 +97,8 @@ pub fn check_crate(
8697
}
8798
};
8899

89-
let v = oldvisit::mk_vt(@oldvisit::Visitor {visit_fn: borrowck_fn,
90-
..*oldvisit::default_visitor()});
91-
oldvisit::visit_crate(crate, (bccx, v));
100+
let mut v = BorrowckVisitor;
101+
visit::walk_crate(&mut v, crate, bccx);
92102

93103
if tcx.sess.borrowck_stats() {
94104
io::println("--- borrowck stats ---");
@@ -113,21 +123,21 @@ pub fn check_crate(
113123
}
114124
}
115125

116-
fn borrowck_fn(fk: &oldvisit::fn_kind,
126+
fn borrowck_fn(v: &mut BorrowckVisitor,
127+
fk: &visit::fn_kind,
117128
decl: &ast::fn_decl,
118129
body: &ast::Block,
119130
sp: span,
120131
id: ast::NodeId,
121-
(this, v): (@BorrowckCtxt,
122-
oldvisit::vt<@BorrowckCtxt>)) {
132+
this: @BorrowckCtxt) {
123133
match fk {
124-
&oldvisit::fk_anon(*) |
125-
&oldvisit::fk_fn_block(*) => {
134+
&visit::fk_anon(*) |
135+
&visit::fk_fn_block(*) => {
126136
// Closures are checked as part of their containing fn item.
127137
}
128138

129-
&oldvisit::fk_item_fn(*) |
130-
&oldvisit::fk_method(*) => {
139+
&visit::fk_item_fn(*) |
140+
&visit::fk_method(*) => {
131141
debug!("borrowck_fn(id=%?)", id);
132142

133143
// Check the body of fn items.
@@ -156,7 +166,7 @@ fn borrowck_fn(fk: &oldvisit::fn_kind,
156166
}
157167
}
158168

159-
oldvisit::visit_fn(fk, decl, body, sp, id, (this, v));
169+
visit::walk_fn(v, fk, decl, body, sp, id, this);
160170
}
161171

162172
// ----------------------------------------------------------------------

branches/dist-snap/src/librustc/middle/check_const.rs

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,71 @@ use util::ppaux;
1717

1818
use syntax::ast::*;
1919
use syntax::codemap;
20-
use syntax::{oldvisit, ast_util, ast_map};
20+
use syntax::{ast_util, ast_map};
21+
use syntax::visit::Visitor;
22+
use syntax::visit;
23+
24+
struct CheckCrateVisitor {
25+
sess: Session,
26+
ast_map: ast_map::map,
27+
def_map: resolve::DefMap,
28+
method_map: typeck::method_map,
29+
tcx: ty::ctxt,
30+
}
31+
32+
impl Visitor<bool> for CheckCrateVisitor {
33+
fn visit_item(&mut self, i:@item, env:bool) {
34+
check_item(self, self.sess, self.ast_map, self.def_map, i, env);
35+
}
36+
fn visit_pat(&mut self, p:@pat, env:bool) {
37+
check_pat(self, p, env);
38+
}
39+
fn visit_expr(&mut self, ex:@expr, env:bool) {
40+
check_expr(self, self.sess, self.def_map, self.method_map,
41+
self.tcx, ex, env);
42+
}
43+
}
2144

2245
pub fn check_crate(sess: Session,
2346
crate: &Crate,
2447
ast_map: ast_map::map,
2548
def_map: resolve::DefMap,
2649
method_map: typeck::method_map,
2750
tcx: ty::ctxt) {
28-
oldvisit::visit_crate(crate, (false, oldvisit::mk_vt(@oldvisit::Visitor {
29-
visit_item: |a,b| check_item(sess, ast_map, def_map, a, b),
30-
visit_pat: check_pat,
31-
visit_expr: |a,b|
32-
check_expr(sess, def_map, method_map, tcx, a, b),
33-
.. *oldvisit::default_visitor()
34-
})));
51+
let mut v = CheckCrateVisitor {
52+
sess: sess,
53+
ast_map: ast_map,
54+
def_map: def_map,
55+
method_map: method_map,
56+
tcx: tcx,
57+
};
58+
visit::walk_crate(&mut v, crate, false);
3559
sess.abort_if_errors();
3660
}
3761

38-
pub fn check_item(sess: Session,
62+
pub fn check_item(v: &mut CheckCrateVisitor,
63+
sess: Session,
3964
ast_map: ast_map::map,
4065
def_map: resolve::DefMap,
4166
it: @item,
42-
(_is_const, v): (bool,
43-
oldvisit::vt<bool>)) {
67+
_is_const: bool) {
4468
match it.node {
4569
item_static(_, _, ex) => {
46-
(v.visit_expr)(ex, (true, v));
70+
v.visit_expr(ex, true);
4771
check_item_recursion(sess, ast_map, def_map, it);
4872
}
4973
item_enum(ref enum_definition, _) => {
5074
for var in (*enum_definition).variants.iter() {
5175
for ex in var.node.disr_expr.iter() {
52-
(v.visit_expr)(*ex, (true, v));
76+
v.visit_expr(*ex, true);
5377
}
5478
}
5579
}
56-
_ => oldvisit::visit_item(it, (false, v))
80+
_ => visit::walk_item(v, it, false)
5781
}
5882
}
5983

60-
pub fn check_pat(p: @pat, (_is_const, v): (bool, oldvisit::vt<bool>)) {
84+
pub fn check_pat(v: &mut CheckCrateVisitor, p: @pat, _is_const: bool) {
6185
fn is_str(e: @expr) -> bool {
6286
match e.node {
6387
expr_vstore(
@@ -72,22 +96,22 @@ pub fn check_pat(p: @pat, (_is_const, v): (bool, oldvisit::vt<bool>)) {
7296
}
7397
match p.node {
7498
// Let through plain ~-string literals here
75-
pat_lit(a) => if !is_str(a) { (v.visit_expr)(a, (true, v)); },
99+
pat_lit(a) => if !is_str(a) { v.visit_expr(a, true); },
76100
pat_range(a, b) => {
77-
if !is_str(a) { (v.visit_expr)(a, (true, v)); }
78-
if !is_str(b) { (v.visit_expr)(b, (true, v)); }
101+
if !is_str(a) { v.visit_expr(a, true); }
102+
if !is_str(b) { v.visit_expr(b, true); }
79103
}
80-
_ => oldvisit::visit_pat(p, (false, v))
104+
_ => visit::walk_pat(v, p, false)
81105
}
82106
}
83107

84-
pub fn check_expr(sess: Session,
108+
pub fn check_expr(v: &mut CheckCrateVisitor,
109+
sess: Session,
85110
def_map: resolve::DefMap,
86111
method_map: typeck::method_map,
87112
tcx: ty::ctxt,
88113
e: @expr,
89-
(is_const, v): (bool,
90-
oldvisit::vt<bool>)) {
114+
is_const: bool) {
91115
if is_const {
92116
match e.node {
93117
expr_unary(_, deref, _) => { }
@@ -152,8 +176,8 @@ pub fn check_expr(sess: Session,
152176
}
153177
}
154178
}
155-
expr_paren(e) => { check_expr(sess, def_map, method_map,
156-
tcx, e, (is_const, v)); }
179+
expr_paren(e) => { check_expr(v, sess, def_map, method_map,
180+
tcx, e, is_const); }
157181
expr_vstore(_, expr_vstore_slice) |
158182
expr_vec(_, m_imm) |
159183
expr_addr_of(m_imm, _) |
@@ -191,7 +215,7 @@ pub fn check_expr(sess: Session,
191215
}
192216
_ => ()
193217
}
194-
oldvisit::visit_expr(e, (is_const, v));
218+
visit::walk_expr(v, e, is_const);
195219
}
196220

197221
#[deriving(Clone)]
@@ -203,6 +227,8 @@ struct env {
203227
idstack: @mut ~[NodeId]
204228
}
205229

230+
struct CheckItemRecursionVisitor;
231+
206232
// Make sure a const item doesn't recursively refer to itself
207233
// FIXME: Should use the dependency graph when it's available (#1356)
208234
pub fn check_item_recursion(sess: Session,
@@ -217,36 +243,34 @@ pub fn check_item_recursion(sess: Session,
217243
idstack: @mut ~[]
218244
};
219245

220-
let visitor = oldvisit::mk_vt(@oldvisit::Visitor {
221-
visit_item: visit_item,
222-
visit_expr: visit_expr,
223-
.. *oldvisit::default_visitor()
224-
});
225-
(visitor.visit_item)(it, (env, visitor));
246+
let mut visitor = CheckItemRecursionVisitor;
247+
visitor.visit_item(it, env);
248+
}
226249

227-
fn visit_item(it: @item, (env, v): (env, oldvisit::vt<env>)) {
250+
impl Visitor<env> for CheckItemRecursionVisitor {
251+
fn visit_item(&mut self, it: @item, env: env) {
228252
if env.idstack.iter().any(|x| x == &(it.id)) {
229253
env.sess.span_fatal(env.root_it.span, "recursive constant");
230254
}
231255
env.idstack.push(it.id);
232-
oldvisit::visit_item(it, (env, v));
256+
visit::walk_item(self, it, env);
233257
env.idstack.pop();
234258
}
235259

236-
fn visit_expr(e: @expr, (env, v): (env, oldvisit::vt<env>)) {
260+
fn visit_expr(&mut self, e: @expr, env: env) {
237261
match e.node {
238262
expr_path(*) => match env.def_map.find(&e.id) {
239263
Some(&def_static(def_id, _)) if ast_util::is_local(def_id) =>
240264
match env.ast_map.get_copy(&def_id.node) {
241265
ast_map::node_item(it, _) => {
242-
(v.visit_item)(it, (env, v));
266+
self.visit_item(it, env);
243267
}
244268
_ => fail!("const not bound to an item")
245269
},
246270
_ => ()
247271
},
248272
_ => ()
249273
}
250-
oldvisit::visit_expr(e, (env, v));
274+
visit::walk_expr(self, e, env);
251275
}
252276
}

branches/dist-snap/src/librustc/middle/check_loop.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,64 @@
1212
use middle::ty;
1313

1414
use syntax::ast::*;
15-
use syntax::oldvisit;
15+
use syntax::visit;
16+
use syntax::visit::Visitor;
1617

1718
#[deriving(Clone)]
1819
pub struct Context {
1920
in_loop: bool,
2021
can_ret: bool
2122
}
2223

24+
struct CheckLoopVisitor {
25+
tcx: ty::ctxt,
26+
}
27+
2328
pub fn check_crate(tcx: ty::ctxt, crate: &Crate) {
24-
oldvisit::visit_crate(crate,
25-
(Context { in_loop: false, can_ret: true },
26-
oldvisit::mk_vt(@oldvisit::Visitor {
27-
visit_item: |i, (_cx, v)| {
28-
oldvisit::visit_item(i, (Context {
29+
visit::walk_crate(&mut CheckLoopVisitor { tcx: tcx },
30+
crate,
31+
Context { in_loop: false, can_ret: true });
32+
}
33+
34+
impl Visitor<Context> for CheckLoopVisitor {
35+
fn visit_item(&mut self, i:@item, _cx:Context) {
36+
visit::walk_item(self, i, Context {
2937
in_loop: false,
3038
can_ret: true
31-
}, v));
32-
},
33-
visit_expr: |e: @expr, (cx, v): (Context, oldvisit::vt<Context>)| {
39+
});
40+
}
41+
42+
fn visit_expr(&mut self, e:@expr, cx:Context) {
43+
3444
match e.node {
3545
expr_while(e, ref b) => {
36-
(v.visit_expr)(e, (cx, v));
37-
(v.visit_block)(b, (Context { in_loop: true,.. cx }, v));
46+
self.visit_expr(e, cx);
47+
self.visit_block(b, Context { in_loop: true,.. cx });
3848
}
3949
expr_loop(ref b, _) => {
40-
(v.visit_block)(b, (Context { in_loop: true,.. cx }, v));
50+
self.visit_block(b, Context { in_loop: true,.. cx });
4151
}
4252
expr_fn_block(_, ref b) => {
43-
(v.visit_block)(b, (Context {
44-
in_loop: false,
45-
can_ret: false
46-
}, v));
53+
self.visit_block(b, Context { in_loop: false, can_ret: false });
4754
}
4855
expr_break(_) => {
4956
if !cx.in_loop {
50-
tcx.sess.span_err(e.span, "`break` outside of loop");
57+
self.tcx.sess.span_err(e.span, "`break` outside of loop");
5158
}
5259
}
5360
expr_again(_) => {
5461
if !cx.in_loop {
55-
tcx.sess.span_err(e.span, "`loop` outside of loop");
62+
self.tcx.sess.span_err(e.span, "`loop` outside of loop");
5663
}
5764
}
5865
expr_ret(oe) => {
5966
if !cx.can_ret {
60-
tcx.sess.span_err(e.span, "`return` in block function");
67+
self.tcx.sess.span_err(e.span, "`return` in block function");
6168
}
62-
oldvisit::visit_expr_opt(oe, (cx, v));
69+
visit::walk_expr_opt(self, oe, cx);
6370
}
64-
_ => oldvisit::visit_expr(e, (cx, v))
71+
_ => visit::walk_expr(self, e, cx)
6572
}
66-
},
67-
.. *oldvisit::default_visitor()
68-
})));
73+
74+
}
6975
}

0 commit comments

Comments
 (0)