aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Dupak <dev@jakubdupak.com>2022-10-27 22:27:55 +0200
committerJakub Dupak <dev@jakubdupak.com>2022-10-28 17:14:53 +0200
commit56a227a63b3843fd5eadc093079b833fe1f93ef9 (patch)
tree191be3e8d80b1b380d4c8c83563335f28e4550ce
parent2d1c287af3a074d40e84234be9feca904af627d5 (diff)
downloadgcc-56a227a63b3843fd5eadc093079b833fe1f93ef9.zip
gcc-56a227a63b3843fd5eadc093079b833fe1f93ef9.tar.gz
gcc-56a227a63b3843fd5eadc093079b833fe1f93ef9.tar.bz2
ast: visitor pattern -> overload syntax compatibility layer
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc7
-rw-r--r--gcc/rust/ast/rust-ast-dump.h8
2 files changed, 15 insertions, 0 deletions
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 <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 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 <typename T> void visit (std::unique_ptr<T> &node);
+
+ /**
* Format together common items of functions: Parameters, return type, block
*/
void format_function_common (std::unique_ptr<Type> &return_type,