Skip to content

Commit

Permalink
Merge pull request #1485 from viperproject/fix-normalization
Browse files Browse the repository at this point in the history
Fix normalization of ids in package statements
  • Loading branch information
fpoli authored Jan 8, 2024
2 parents 260594b + cf4ed1a commit cd736cc
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions vir/src/legacy/ast/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,29 +350,37 @@ impl Stmt {
/// Visit each position.
/// Note: statements like `Stmt::If` can contain multiple positions.
pub fn visit_positions<F: FnMut(&Position)>(&self, mut visitor: F) {
// Recursively visiting the statements of the nested Stmt::If statements is difficult; the
// recursive type constraints are hard to satisfy. So, here is an iterative implementation.
// Recursively visiting the statements of the nested statements is difficult; the recursive
// type constraints are hard to satisfy. So, here is an iterative implementation.
let mut queue = vec![self];
while let Some(stmt) = queue.pop() {
stmt.pos().into_iter().for_each(&mut visitor);
if let Stmt::If(_, then_stmts, else_stmts) = stmt {
queue.extend(then_stmts);
queue.extend(else_stmts);
match stmt {
Stmt::If(_, then_stmts, else_stmts) => {
queue.extend(then_stmts);
queue.extend(else_stmts);
}
Stmt::PackageMagicWand(_, body, _, _, _) => queue.extend(body),
_ => {}
}
}
}

/// Mutably visit each position.
/// Note: statements like `Stmt::If` can contain multiple positions.
pub fn visit_positions_mut<F: FnMut(&mut Position)>(&mut self, mut visitor: F) {
// Recursively visiting the statements of the nested Stmt::If statements is difficult; the
// recursive type constraints are hard to satisfy. So, here is an iterative implementation.
// Recursively visiting the statements of nested statements is difficult; the recursive
// type constraints are hard to satisfy. So, here is an iterative implementation.
let mut queue = vec![self];
while let Some(stmt) = queue.pop() {
stmt.pos_mut().into_iter().for_each(&mut visitor);
if let Stmt::If(_, then_stmts, else_stmts) = stmt {
queue.extend(then_stmts);
queue.extend(else_stmts);
match stmt {
Stmt::If(_, then_stmts, else_stmts) => {
queue.extend(then_stmts);
queue.extend(else_stmts);
}
Stmt::PackageMagicWand(_, body, _, _, _) => queue.extend(body),
_ => {}
}
}
}
Expand Down

0 comments on commit cd736cc

Please sign in to comment.