[gcc r14-7606] gccrs: ast: Add `outer_attrs` to all `Item`s

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:44:39 GMT 2024


https://gcc.gnu.org/g:f5d02c4f5592b717a3aad5304308df913bf4ab1b

commit r14-7606-gf5d02c4f5592b717a3aad5304308df913bf4ab1b
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Tue Apr 25 14:43:15 2023 +0200

    gccrs: ast: Add `outer_attrs` to all `Item`s
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast.h: Add `outer_attrs` to Item.
            * ast/rust-expr.h: Make use of new inheritance methods.
            * ast/rust-item.h: Likewise.
            * ast/rust-macro.h: Likewise.

Diff:
---
 gcc/rust/ast/rust-ast.h   |  5 +++++
 gcc/rust/ast/rust-expr.h  |  8 ++++----
 gcc/rust/ast/rust-item.h  |  7 +++++--
 gcc/rust/ast/rust-macro.h | 12 +++++++++---
 4 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 2945cc87883..09566575a85 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -933,6 +933,11 @@ public:
   // behavior that we have items that can also be expressions?
   bool is_item () const override { return true; }
 
+  virtual std::vector<Attribute> &get_outer_attrs () = 0;
+  virtual const std::vector<Attribute> &get_outer_attrs () const = 0;
+
+  virtual bool has_outer_attrs () const { return !get_outer_attrs ().empty (); }
+
 protected:
   // Clone function implementation as pure virtual method
   virtual Item *clone_item_impl () const = 0;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 2b23c246723..3e7c93c5098 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -2762,15 +2762,15 @@ protected:
 public:
   Location get_locus () const override final { return locus; }
 
-  // should never be called - error if called
-  void set_outer_attrs (std::vector<Attribute> /* new_attrs */) override
+  std::vector<Attribute> &get_outer_attrs () override final
   {
+    // RangeExpr cannot have any outer attributes
     rust_assert (false);
   }
 
-  std::vector<Attribute> &get_outer_attrs () override
+  // should never be called - error if called
+  void set_outer_attrs (std::vector<Attribute> /* new_attrs */) override
   {
-    // RangeExpr cannot have any outer attributes
     rust_assert (false);
   }
 };
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index a905914a58f..574f1fa3a65 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -979,8 +979,11 @@ public:
   Visibility &get_visibility () { return visibility; }
   const Visibility &get_visibility () const { return visibility; }
 
-  std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
-  const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+  std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
+  const std::vector<Attribute> &get_outer_attrs () const override
+  {
+    return outer_attrs;
+  }
 };
 
 // Rust module item - abstract base class
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index bdf3eff3dc6..076ab978bc3 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -541,8 +541,11 @@ public:
   bool is_marked_for_strip () const override { return rule_name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
-  std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
-  const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+  std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
+  const std::vector<Attribute> &get_outer_attrs () const override
+  {
+    return outer_attrs;
+  }
 
   std::vector<MacroRule> &get_macro_rules () { return rules; }
   const std::vector<MacroRule> &get_macro_rules () const { return rules; }
@@ -651,7 +654,10 @@ public:
     return invoc_data.is_marked_for_strip ();
   }
 
-  const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
+  const std::vector<Attribute> &get_outer_attrs () const override
+  {
+    return outer_attrs;
+  }
   std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
 
   void set_outer_attrs (std::vector<Attribute> new_attrs) override


More information about the Gcc-cvs mailing list