From 56a227a63b3843fd5eadc093079b833fe1f93ef9 Mon Sep 17 00:00:00 2001 From: Jakub Dupak Date: Thu, 27 Oct 2022 22:27:55 +0200 Subject: ast: visitor pattern -> overload syntax compatibility layer Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 7 +++++++ gcc/rust/ast/rust-ast-dump.h | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'gcc/rust/ast') 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 +void +Dump::visit (std::unique_ptr &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 void visit (std::unique_ptr &node); + + /** * Format together common items of functions: Parameters, return type, block */ void format_function_common (std::unique_ptr &return_type, -- cgit v1.1