gccrs: ast: dump: add emit_generic_params helper
authorDavid Faust <david.faust@oracle.com>
Thu, 6 Oct 2022 18:32:02 +0000 (11:32 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 21 Feb 2023 11:36:32 +0000 (12:36 +0100)
gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): move generic params dump ...
(Dump::emit_generic_params): ... here.
* ast/rust-ast-dump.h (emit_generic_params): New.

gcc/rust/ast/rust-ast-dump.cc
gcc/rust/ast/rust-ast-dump.h

index bc4f7a3..b192556 100644 (file)
@@ -141,6 +141,22 @@ Dump::emit_indented_string (const std::string &value,
 }
 
 void
+Dump::emit_generic_params (std::vector<std::unique_ptr<GenericParam>> &params)
+{
+  stream << "<";
+  for (size_t i = 0; i < params.size (); i++)
+    {
+      auto &param = params.at (i);
+      param->accept_vis (*this);
+
+      bool has_next = (i + 1) < params.size ();
+      if (has_next)
+       stream << ", ";
+    }
+  stream << ">";
+}
+
+void
 Dump::visit (Token &tok)
 {}
 
@@ -679,19 +695,7 @@ Dump::visit (Function &function)
   stream << "fn " << function.get_function_name ();
 
   if (function.has_generics ())
-    {
-      stream << "<";
-      for (size_t i = 0; i < function.get_generic_params ().size (); i++)
-       {
-         auto &param = function.get_generic_params ().at (i);
-         param->accept_vis (*this);
-
-         bool has_next = (i + 1) < function.get_generic_params ().size ();
-         if (has_next)
-           stream << ", ";
-       }
-      stream << ">";
-    }
+    emit_generic_params (function.get_generic_params ());
 
   stream << '(';
   auto &params = function.get_function_params ();
index a5a99f2..1bbefb3 100644 (file)
@@ -97,6 +97,9 @@ private:
   std::ostream &emit_indented_string (const std::string &value,
                                      const std::string &comment = "");
 
+  // Emit formatted string for generic parameters.
+  void emit_generic_params (std::vector<std::unique_ptr<GenericParam>> &params);
+
   // rust-ast.h
   void visit (Token &tok);
   void visit (DelimTokenTree &delim_tok_tree);