From: Jakub Dupak Date: Thu, 27 Oct 2022 20:27:55 +0000 (+0200) Subject: gccrs: ast: visitor pattern -> overload syntax compatibility layer X-Git-Tag: basepoints/gcc-14~989 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aedd97a537cbf12ad775504a71e5901ea2dacdad;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 4817962f7678..9771f432ea04 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 9fe8ee954937..7cd922e0ac93 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -72,6 +72,14 @@ private: std::ostream &stream; 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 */