mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
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> {
|
||||
p: &'self fn(&ast::Expr_) -> bool
|
||||
p: &'self fn(&ast::Expr_) -> bool,
|
||||
flag: bool,
|
||||
}
|
||||
|
||||
impl<'self> Visitor<@mut bool> for LoopQueryVisitor<'self> {
|
||||
fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
|
||||
*flag |= (self.p)(&e.node);
|
||||
impl<'self> Visitor<()> for LoopQueryVisitor<'self> {
|
||||
fn visit_expr(&mut self, e: @ast::Expr, _: ()) {
|
||||
self.flag |= (self.p)(&e.node);
|
||||
match e.node {
|
||||
// Skip inner loops, since a break in the inner loop isn't a
|
||||
// break inside the outer loop
|
||||
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
|
||||
// of b -- skipping any inner loops (loop, while, loop_body)
|
||||
pub fn loop_query(b: &ast::Block, p: &fn(&ast::Expr_) -> bool) -> bool {
|
||||
let rs = @mut false;
|
||||
let mut v = LoopQueryVisitor {
|
||||
p: p,
|
||||
flag: false,
|
||||
};
|
||||
visit::walk_block(&mut v, b, rs);
|
||||
return *rs;
|
||||
visit::walk_block(&mut v, b, ());
|
||||
return v.flag;
|
||||
}
|
||||
|
||||
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> {
|
||||
fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
|
||||
*flag |= (self.p)(e);
|
||||
visit::walk_expr(self, e, flag)
|
||||
impl<'self> Visitor<()> for BlockQueryVisitor<'self> {
|
||||
fn visit_expr(&mut self, e: @ast::Expr, _:()) {
|
||||
self.flag |= (self.p)(e);
|
||||
visit::walk_expr(self, e, ())
|
||||
}
|
||||
}
|
||||
|
||||
// Takes a predicate p, returns true iff p is true for any subexpressions
|
||||
// of b -- skipping any inner loops (loop, while, loop_body)
|
||||
pub fn block_query(b: &ast::Block, p: &fn(@ast::Expr) -> bool) -> bool {
|
||||
let rs = @mut false;
|
||||
let mut v = BlockQueryVisitor {
|
||||
p: p,
|
||||
flag: false,
|
||||
};
|
||||
visit::walk_block(&mut v, b, rs);
|
||||
return *rs;
|
||||
visit::walk_block(&mut v, b, ());
|
||||
return v.flag;
|
||||
}
|
||||
|
||||
pub fn local_rhs_span(l: @ast::Local, def: Span) -> Span {
|
||||
|
Loading…
Reference in New Issue
Block a user