Move the linearly-updated flag state into the Visitor.
This commit is contained in:
parent
6ed338caa7
commit
eac429cc9e
|
@ -61,17 +61,18 @@ pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::Expr] {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LoopQueryVisitor<'self> {
|
struct LoopQueryVisitor<'self> {
|
||||||
p: &'self fn(&ast::Expr_) -> bool
|
p: &'self fn(&ast::Expr_) -> bool,
|
||||||
|
flag: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'self> Visitor<@mut bool> for LoopQueryVisitor<'self> {
|
impl<'self> Visitor<()> for LoopQueryVisitor<'self> {
|
||||||
fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
|
fn visit_expr(&mut self, e: @ast::Expr, _: ()) {
|
||||||
*flag |= (self.p)(&e.node);
|
self.flag |= (self.p)(&e.node);
|
||||||
match e.node {
|
match e.node {
|
||||||
// Skip inner loops, since a break in the inner loop isn't a
|
// Skip inner loops, since a break in the inner loop isn't a
|
||||||
// break inside the outer loop
|
// break inside the outer loop
|
||||||
ast::ExprLoop(*) | ast::ExprWhile(*) => {}
|
ast::ExprLoop(*) | ast::ExprWhile(*) => {}
|
||||||
_ => visit::walk_expr(self, e, flag)
|
_ => visit::walk_expr(self, e, ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,34 +80,35 @@ impl<'self> Visitor<@mut bool> for LoopQueryVisitor<'self> {
|
||||||
// Takes a predicate p, returns true iff p is true for any subexpressions
|
// Takes a predicate p, returns true iff p is true for any subexpressions
|
||||||
// of b -- skipping any inner loops (loop, while, loop_body)
|
// of b -- skipping any inner loops (loop, while, loop_body)
|
||||||
pub fn loop_query(b: &ast::Block, p: &fn(&ast::Expr_) -> bool) -> bool {
|
pub fn loop_query(b: &ast::Block, p: &fn(&ast::Expr_) -> bool) -> bool {
|
||||||
let rs = @mut false;
|
|
||||||
let mut v = LoopQueryVisitor {
|
let mut v = LoopQueryVisitor {
|
||||||
p: p,
|
p: p,
|
||||||
|
flag: false,
|
||||||
};
|
};
|
||||||
visit::walk_block(&mut v, b, rs);
|
visit::walk_block(&mut v, b, ());
|
||||||
return *rs;
|
return v.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockQueryVisitor<'self> {
|
struct BlockQueryVisitor<'self> {
|
||||||
p: &'self fn(@ast::Expr) -> bool
|
p: &'self fn(@ast::Expr) -> bool,
|
||||||
|
flag: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'self> Visitor<@mut bool> for BlockQueryVisitor<'self> {
|
impl<'self> Visitor<()> for BlockQueryVisitor<'self> {
|
||||||
fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
|
fn visit_expr(&mut self, e: @ast::Expr, _:()) {
|
||||||
*flag |= (self.p)(e);
|
self.flag |= (self.p)(e);
|
||||||
visit::walk_expr(self, e, flag)
|
visit::walk_expr(self, e, ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a predicate p, returns true iff p is true for any subexpressions
|
// Takes a predicate p, returns true iff p is true for any subexpressions
|
||||||
// of b -- skipping any inner loops (loop, while, loop_body)
|
// of b -- skipping any inner loops (loop, while, loop_body)
|
||||||
pub fn block_query(b: &ast::Block, p: &fn(@ast::Expr) -> bool) -> bool {
|
pub fn block_query(b: &ast::Block, p: &fn(@ast::Expr) -> bool) -> bool {
|
||||||
let rs = @mut false;
|
|
||||||
let mut v = BlockQueryVisitor {
|
let mut v = BlockQueryVisitor {
|
||||||
p: p,
|
p: p,
|
||||||
|
flag: false,
|
||||||
};
|
};
|
||||||
visit::walk_block(&mut v, b, rs);
|
visit::walk_block(&mut v, b, ());
|
||||||
return *rs;
|
return v.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_rhs_span(l: @ast::Local, def: Span) -> Span {
|
pub fn local_rhs_span(l: @ast::Local, def: Span) -> Span {
|
||||||
|
|
Loading…
Reference in New Issue