diff options
author | Marc Poulhiès <dkm@kataplop.net> | 2023-04-06 19:20:55 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:28:46 +0100 |
commit | cd773704975f399a8c736a84509dfe2e106412a7 (patch) | |
tree | 715cceae0c9950946dcfa86ee8857d242a47f074 /gcc/rust/ast/rust-ast-dump.h | |
parent | e64909cebf611f469ed0fea3083a567274b340ad (diff) | |
download | gcc-cd773704975f399a8c736a84509dfe2e106412a7.zip gcc-cd773704975f399a8c736a84509dfe2e106412a7.tar.gz gcc-cd773704975f399a8c736a84509dfe2e106412a7.tar.bz2 |
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>
Diffstat (limited to 'gcc/rust/ast/rust-ast-dump.h')
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.h | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 4128733..26f7208 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -38,21 +38,8 @@ public: void go (AST::Crate &crate); void go (AST::Item &item); - /** - * Use the AST Dump as a debugging tool - */ - template <typename T> static void debug (T &instance) - { - auto dump = Dump (std::cerr); - - std::cerr << '\n'; - instance.accept_vis (dump); - std::cerr << '\n'; - } - template <typename T> static void debug (std::unique_ptr<T> &instance) - { - debug (*instance); - } + // Helper method to get a quick debug dump to standard error output + static void debug (Visitable &v); private: std::ostream &stream; @@ -309,4 +296,8 @@ private: } // namespace AST } // namespace Rust +// In the global namespace to make it easier to call from debugger +void +debug (Rust::AST::Visitable &v); + #endif // !RUST_AST_DUMP_H |