public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: visitor pattern -> overload syntax compatibility layer
@ 2022-11-08 9:28 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-11-08 9:28 UTC (permalink / raw)
To: gcc-cvs
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 ¶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 <typename T> void visit (std::unique_ptr<T> &node);
+
/**
* Format together common items of functions: Parameters, return type, block
*/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-08 9:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 9:28 [gcc/devel/rust/master] ast: visitor pattern -> overload syntax compatibility layer Thomas Schwinge
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).