diff options
author | Jakub Dupak <dev@jakubdupak.com> | 2022-10-27 22:27:55 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-02-21 12:36:43 +0100 |
commit | aedd97a537cbf12ad775504a71e5901ea2dacdad (patch) | |
tree | 41ae6690f4ae5de97bec12e0d92f2d5b1960466d | |
parent | 5b5a0ca771797e99de80876b5504e1792bbca7ce (diff) | |
download | gcc-aedd97a537cbf12ad775504a71e5901ea2dacdad.zip gcc-aedd97a537cbf12ad775504a71e5901ea2dacdad.tar.gz gcc-aedd97a537cbf12ad775504a71e5901ea2dacdad.tar.bz2 |
gccrs: ast: visitor pattern -> overload syntax compatibility layer
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add new visit function for overloading.
* ast/rust-ast-dump.h: Add documentation for layer.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.cc | 7 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.h | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 4817962..9771f43 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -62,6 +62,13 @@ Dump::go (AST::Item &item) item.accept_vis (*this); } +template <typename T> +void +Dump::visit (std::unique_ptr<T> &node) +{ + node->accept_vis (*this); +} + void Dump::format_function_param (FunctionParam ¶m) { diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 9fe8ee9..7cd922e 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -73,6 +73,14 @@ private: Indent indentation; /** + * Compatibility layer for using the visitor pattern on polymorphic classes + * with a unified overload syntax. This allows us to call `visit` both on + * types implementing `accept_vis` method and for classes for which the + * `visit` method is directly implemented. + */ + template <typename T> void visit (std::unique_ptr<T> &node); + + /** * Format together common items of functions: Parameters, return type, block */ void format_function_common (std::unique_ptr<Type> &return_type, |