mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 17:18:01 +00:00
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:
@@ -18,6 +18,8 @@ use crate::parser::error::Error as ParserError;
|
||||
use crate::parser::identifier::Identifier;
|
||||
use crate::parser::statement::block::Block;
|
||||
use crate::parser::statement::expression::function_call::name::Name as FunctionName;
|
||||
use crate::visitor::AstNode;
|
||||
use crate::visitor::AstVisitor;
|
||||
|
||||
/// The function definition statement.
|
||||
/// All functions are translated in two steps:
|
||||
@@ -329,6 +331,28 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl AstNode for FunctionDefinition {
|
||||
fn accept(&self, ast_visitor: &mut impl AstVisitor) {
|
||||
ast_visitor.visit_function_definition(self);
|
||||
}
|
||||
|
||||
fn visit_children(&self, ast_visitor: &mut impl AstVisitor) {
|
||||
for argument in &self.arguments {
|
||||
argument.accept(ast_visitor);
|
||||
}
|
||||
|
||||
self.body.accept(ast_visitor);
|
||||
|
||||
for result in &self.result {
|
||||
result.accept(ast_visitor);
|
||||
}
|
||||
}
|
||||
|
||||
fn location(&self) -> Location {
|
||||
self.location
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
Reference in New Issue
Block a user