-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(visitor): add VisitorMut trait.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::{visit, visit_list, visit_scope}; | ||
use fuse_ast::ast::*; | ||
|
||
pub trait VisitorMut<'ast>: Sized { | ||
fn enter_scope(&mut self) {} | ||
|
||
fn leave_scope(&mut self) {} | ||
|
||
fn visit_chunk(&mut self, chunk: &'ast mut Chunk) { | ||
walk_block_mut(self, &mut chunk.body) | ||
} | ||
|
||
fn visit_block(&mut self, block: &'ast mut Block) { | ||
walk_block_mut(self, block) | ||
} | ||
|
||
fn visit_statement_mut(&mut self, statement: &'ast mut Statement) { | ||
walk_statement_mut(self, statement) | ||
} | ||
} | ||
|
||
pub fn walk_block_mut<'ast, V: VisitorMut<'ast>>(visitor: &mut V, block: &'ast mut Block) { | ||
visit_scope!(visitor => { | ||
visit_list!(visitor.visit_statement_mut(&mut block.statements)); | ||
}); | ||
} | ||
|
||
pub fn walk_statement_mut<'ast, V: VisitorMut<'ast>>( | ||
visitor: &mut V, | ||
statement: &'ast mut Statement, | ||
) { | ||
match statement { | ||
Statement::Empty(_) => {} | ||
// Statement::Expression(expr) => visit!(visitor.visit_expression(expr)), | ||
// Statement::VariableDeclaration(decl) => visit!(visitor.visit_variable_declaration(decl)), | ||
// Statement::FunctionDeclaration(func) => visit!(visitor.visit_function_declaration(func)), | ||
// Statement::EnumDeclaration(decl) => visit!(visitor.visit_enum_declaration(decl)), | ||
// Statement::StructDeclaration(Box<StructDeclaration>), | ||
// Statement::ImplStatement(Box<ImplStatement>), | ||
_ => todo!(), | ||
} | ||
} |