-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(AST): introduce AstVisitor trait #1231
Conversation
6d6a228
to
ebae171
Compare
The AST-Visitor trait allows generic visiting of AST-nodes. A default Walking behavior is implemented for each AstStatement but it can be altered by any implementor. When overriding a visit_XXX method, the implementation can decide to continue with the default walking behavior (by calling the walk function on the passed AstStatement-Struct, to skip it, or to continue with an alternative walking bahavior.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1231 +/- ##
==========================================
- Coverage 95.62% 90.88% -4.74%
==========================================
Files 150 154 +4
Lines 42657 45149 +2492
==========================================
+ Hits 40789 41033 +244
- Misses 1868 4116 +2248 ☔ View full report in Codecov by Sentry. |
the visitor can now be called on the CompilationUnit and it will visit all GlobalVariables, all Pous, all UserTypes and Implementations
removed unused AST element CastStatement
I improved the code coverage quite a bit, I think the codecov comment above (64.9%) is outdated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig this, especially after seeing how easy and seamless implementing extensions(?) like the IdentifierCollector
and FieldCollector
appears to be. Really cool to see 🥳
What's the next step? Integrating it into modules like the resolver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean! I love it.
The AST-Visitor trait allows generic visiting of AST-nodes. A default Walking behavior is implemented for each AstStatement but it can be altered by any implementor. When overriding a visit_XXX method, the implementation can decide to continue with the default walking behavior (by calling the walk function on the passed AstStatement-Struct, to skip it, or to continue with an alternative walking bahavior.
The code could be improved with a derive-macro for the walker trait