From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id E3DD13858413; Tue, 8 Nov 2022 09:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3DD13858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667899734; bh=szIuDWbcMCfAHgOLM/96/zNnlVAPfKt8arGFAn6G7PE=; h=From:To:Subject:Date:From; b=By+7aqfi0XzhOz9AFyy5BPDZT7S6cFAEtOYWoAxkCUz6ikO4sN1NipnMJ5iQQX9ko vHswYNmn8PzrnldUfqCUkKASE9wlmaE6VXlWZUbK2Yaxyy8EKSMj8hlPFmtuYcGp9h t7IFCy9BE9zsdlJw2bvHd2DwX926KNAXnohZ+n5s= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] ast: visitor pattern -> overload syntax compatibility layer X-Act-Checkin: gcc X-Git-Author: Jakub Dupak X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 2d1c287af3a074d40e84234be9feca904af627d5 X-Git-Newrev: 56a227a63b3843fd5eadc093079b833fe1f93ef9 Message-Id: <20221108092854.E3DD13858413@sourceware.org> Date: Tue, 8 Nov 2022 09:28:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:56a227a63b3843fd5eadc093079b833fe1f93ef9 commit 56a227a63b3843fd5eadc093079b833fe1f93ef9 Author: Jakub Dupak Date: Thu Oct 27 22:27:55 2022 +0200 ast: visitor pattern -> overload syntax compatibility layer Signed-off-by: Jakub Dupak Diff: --- gcc/rust/ast/rust-ast-dump.cc | 7 +++++++ gcc/rust/ast/rust-ast-dump.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 4817962f767..9771f432ea0 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 9fe8ee95493..7cd922e0ac9 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 */