]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Introduce AST::Visitable class for AST
authorMarc Poulhiès <dkm@kataplop.net>
Thu, 6 Apr 2023 17:20:55 +0000 (19:20 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:46 +0000 (18:28 +0100)
commitcd773704975f399a8c736a84509dfe2e106412a7
tree715cceae0c9950946dcfa86ee8857d242a47f074
parente64909cebf611f469ed0fea3083a567274b340ad
gccrs: Introduce AST::Visitable class for AST

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>
gcc/rust/ast/rust-ast-dump.cc
gcc/rust/ast/rust-ast-dump.h
gcc/rust/ast/rust-ast.h