|
| 1 | +use crate::{visit, visit_list, visit_scope}; |
| 2 | +use fuse_ast::ast::*; |
| 3 | + |
| 4 | +pub trait VisitorMut<'ast>: Sized { |
| 5 | + fn enter_scope(&mut self) {} |
| 6 | + |
| 7 | + fn leave_scope(&mut self) {} |
| 8 | + |
| 9 | + fn visit_chunk(&mut self, chunk: &'ast mut Chunk) { |
| 10 | + walk_block_mut(self, &mut chunk.body) |
| 11 | + } |
| 12 | + |
| 13 | + fn visit_block(&mut self, block: &'ast mut Block) { |
| 14 | + walk_block_mut(self, block) |
| 15 | + } |
| 16 | + |
| 17 | + fn visit_statement_mut(&mut self, statement: &'ast mut Statement) { |
| 18 | + walk_statement_mut(self, statement) |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +pub fn walk_block_mut<'ast, V: VisitorMut<'ast>>(visitor: &mut V, block: &'ast mut Block) { |
| 23 | + visit_scope!(visitor => { |
| 24 | + visit_list!(visitor.visit_statement_mut(&mut block.statements)); |
| 25 | + }); |
| 26 | +} |
| 27 | + |
| 28 | +pub fn walk_statement_mut<'ast, V: VisitorMut<'ast>>( |
| 29 | + visitor: &mut V, |
| 30 | + statement: &'ast mut Statement, |
| 31 | +) { |
| 32 | + match statement { |
| 33 | + Statement::Empty(_) => {} |
| 34 | + // Statement::Expression(expr) => visit!(visitor.visit_expression(expr)), |
| 35 | + // Statement::VariableDeclaration(decl) => visit!(visitor.visit_variable_declaration(decl)), |
| 36 | + // Statement::FunctionDeclaration(func) => visit!(visitor.visit_function_declaration(func)), |
| 37 | + // Statement::EnumDeclaration(decl) => visit!(visitor.visit_enum_declaration(decl)), |
| 38 | + // Statement::StructDeclaration(Box<StructDeclaration>), |
| 39 | + // Statement::ImplStatement(Box<ImplStatement>), |
| 40 | + _ => todo!(), |
| 41 | + } |
| 42 | +} |
0 commit comments