public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/rust/master] ast: visitor pattern -> overload syntax compatibility layer
Date: Tue,  8 Nov 2022 09:28:49 +0000 (GMT)	[thread overview]
Message-ID: <20221108092854.E3DD13858413@sourceware.org> (raw)

https://gcc.gnu.org/g:56a227a63b3843fd5eadc093079b833fe1f93ef9

commit 56a227a63b3843fd5eadc093079b833fe1f93ef9
Author: Jakub Dupak <dev@jakubdupak.com>
Date:   Thu Oct 27 22:27:55 2022 +0200

    ast: visitor pattern -> overload syntax compatibility layer
    
    Signed-off-by: Jakub Dupak <dev@jakubdupak.com>

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 <typename T>
+void
+Dump::visit (std::unique_ptr<T> &node)
+{
+  node->accept_vis (*this);
+}
+
 void
 Dump::format_function_param (FunctionParam &param)
 {
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 <typename T> void visit (std::unique_ptr<T> &node);
+
   /**
    * Format together common items of functions: Parameters, return type, block
    */

                 reply	other threads:[~2022-11-08  9:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221108092854.E3DD13858413@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).