[committed,072/103] gccrs: ast: add visit overload for references

Message ID 20230221120230.596966-73-arthur.cohen@embecosm.com
State Unresolved
Headers
Series [committed,001/103] gccrs: Fix missing dead code analysis ICE on local enum definition |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Arthur Cohen Feb. 21, 2023, 12:02 p.m. UTC
  From: Jakub Dupak <dev@jakubdupak.com>

This is currently needed for lifetimes to use the existing infrastructure.

gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::visit): Add new reference visitor wrapper.
	* ast/rust-ast-dump.h: Declare it.
	* ast/rust-item.h: Add mutable visibility getters.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
---
 gcc/rust/ast/rust-ast-dump.cc | 15 +++++++++++----
 gcc/rust/ast/rust-ast-dump.h  | 11 ++++++++---
 gcc/rust/ast/rust-item.h      |  4 ++++
 3 files changed, 23 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index df42481c248..16c4a79dc6e 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -64,6 +64,13 @@  Dump::visit (std::unique_ptr<T> &node)
   node->accept_vis (*this);
 }
 
+template <typename T>
+void
+Dump::visit (T &node)
+{
+  node.accept_vis (*this);
+}
+
 template <typename T>
 void
 Dump::visit_items_joined_by_separator (T &collection,
@@ -129,7 +136,7 @@  Dump::visit (FunctionParam &param)
 }
 
 void
-Dump::visit (const Attribute &attrib)
+Dump::visit (Attribute &attrib)
 {
   stream << "#[";
   visit_items_joined_by_separator (attrib.get_path ().get_segments (), "::");
@@ -158,13 +165,13 @@  Dump::visit (const Attribute &attrib)
 }
 
 void
-Dump::visit (const SimplePathSegment &segment)
+Dump::visit (SimplePathSegment &segment)
 {
   stream << segment.get_segment_name ();
 }
 
 void
-Dump::visit (const Visibility &vis)
+Dump::visit (Visibility &vis)
 {
   switch (vis.get_vis_type ())
     {
@@ -1099,7 +1106,7 @@  Dump::visit (TraitItemType &item)
 void
 Dump::visit (Trait &trait)
 {
-  for (const auto &attr : trait.get_outer_attrs ())
+  for (auto &attr : trait.get_outer_attrs ())
     {
       visit (attr);
       stream << "\n" << indentation;
diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h
index 13c92123ea9..57419b75347 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -80,6 +80,11 @@  private:
    */
   template <typename T> void visit (std::unique_ptr<T> &node);
 
+  /**
+   * @see visit<std::unique_ptr<T>>
+   */
+  template <typename T> void visit (T &node);
+
   /**
    * Visit all items in given @collection, placing the separator in between but
    * not at the end.
@@ -122,12 +127,12 @@  private:
 			      std::unique_ptr<BlockExpr> &block);
 
   void visit (FunctionParam &param);
-  void visit (const Attribute &attrib);
-  void visit (const Visibility &vis);
+  void visit (Attribute &attrib);
+  void visit (Visibility &vis);
   void visit (std::vector<std::unique_ptr<GenericParam>> &params);
   void visit (TupleField &field);
   void visit (StructField &field);
-  void visit (const SimplePathSegment &segment);
+  void visit (SimplePathSegment &segment);
   void visit (NamedFunctionParam &param);
   void visit (MacroRule &rule);
 
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 17d11e4de38..4e237f2e21e 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -908,6 +908,7 @@  public:
 
   FunctionQualifiers get_qualifiers () { return qualifiers; }
 
+  Visibility &get_visibility () { return vis; }
   const Visibility &get_visibility () const { return vis; }
 
 protected:
@@ -1982,6 +1983,7 @@  public:
     return field_type;
   }
 
+  Visibility &get_visibility () { return visibility; }
   const Visibility &get_visibility () const { return visibility; }
 
   NodeId get_node_id () const { return node_id; }
@@ -2116,6 +2118,7 @@  public:
 
   NodeId get_node_id () const { return node_id; }
 
+  Visibility &get_visibility () { return visibility; }
   const Visibility &get_visibility () const { return visibility; }
 
   Location get_locus () const { return locus; }
@@ -4157,6 +4160,7 @@  public:
 
   Location get_locus () const { return locus; }
 
+  Visibility &get_visibility () { return visibility; }
   const Visibility &get_visibility () const { return visibility; }
 
   ExternalFunctionItem (