gccrs: Introduce AST::Visitable class for AST#2107
Merged
Conversation
CohenArthur
approved these changes
Apr 7, 2023
CohenArthur
left a comment
Member
There was a problem hiding this comment.
Great idea and great execution :) thank you!
AST::Visitable is an abstract class with a unique accept_vis() method. Make all abstract AST node class inherit from this class. Allows for easy definition of operations on nodes that must accept a visitor. The static Dump::dump() is an example of such use: the static method accepts any AST node, creates a Dump visitor and have it visit the AST starting at the node. This change also inserts a debug(Visitable&) function in the global namespace to make it easy to call from the debugger (similar to debug_tree or debug(rtx*) functions). gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::debug): New. * ast/rust-ast-dump.h (Dump::debug): Untemplate it. (debug): New. * ast/rust-ast.h (class Visitable): New. (class TokenTree): Inherit from Visitable. (class MacroMatch): Likewise. (class AttrInput): Likewise. (class MetaItemInner): Likewise. (class Pattern): Likewise. (classTypeParamBound): Likewise. (class GenericParam): Likewise. (class TraitItem): Likewise. (classInherentImplItem): Likewise. (class TraitImplItem): Likewise. (class ExternalItem): Likewise. (class SingleASTNode): Likewise. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Member
Author
|
Implemented your suggestion @CohenArthur |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AST::Visitable is an abstract class with a unique accept_vis() method.
Make all abstract AST node class inherit from this class.
Allows for easy definition of operations on nodes that must accept a
visitor.
The static Dump::dump() is an example of such use: the static method
accepts any AST node, creates a Dump visitor and have it visit the AST
starting at the node.
This change also inserts a debug(Visitable&) function in the global
namespace to make it easy to call from the debugger (similar to
debug_tree or debug(rtx*) functions).