YUL tree visitor interface (#369)

- Implement the visitor interface. This simplifies working with the AST,
for example transformations into other IRs or collecting and analyzing
various statistics.
- Switch the explorer to use the visitor interface.
- Add the reciprocal function name conversion for function names.
- Some drive-by cosmetic fixes.

---------

Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
xermicus
2025-08-10 00:08:25 +02:00
committed by GitHub
parent 72f9e4f66e
commit 903cbd7159
24 changed files with 1303 additions and 162 deletions
+16
View File
@@ -13,6 +13,8 @@ use crate::lexer::token::Token;
use crate::lexer::Lexer;
use crate::parser::error::Error as ParserError;
use crate::parser::statement::block::Block;
use crate::visitor::AstNode;
use crate::visitor::AstVisitor;
/// The YUL code entity, which is the first block of the object.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
@@ -66,6 +68,20 @@ where
}
}
impl AstNode for Code {
fn accept(&self, ast_visitor: &mut impl AstVisitor) {
ast_visitor.visit_code(self);
}
fn visit_children(&self, ast_visitor: &mut impl AstVisitor) {
self.block.accept(ast_visitor);
}
fn location(&self) -> Location {
self.location
}
}
#[cfg(test)]
mod tests {
use crate::lexer::token::location::Location;