]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: visitor pattern -> overload syntax compatibility layer
authorJakub Dupak <dev@jakubdupak.com>
Thu, 27 Oct 2022 20:27:55 +0000 (22:27 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 21 Feb 2023 11:36:43 +0000 (12:36 +0100)
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 <dev@jakubdupak.com>
gcc/rust/ast/rust-ast-dump.cc
gcc/rust/ast/rust-ast-dump.h

index 4817962f76781ac997b6162d126afcf7dc39f0f7..9771f432ea04a7fa129b8eca43898354c8814cbd 100644 (file)
@@ -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)
 {
index 9fe8ee954937b0c3ae5fb657763fb87c417ab6de..7cd922e0ac936b03a855584185891924e49b8654 100644 (file)
@@ -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
    */