]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: Add `outer_attrs` to all `Item`s
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 25 Apr 2023 12:43:15 +0000 (14:43 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:20 +0000 (18:37 +0100)
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.

gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-expr.h
gcc/rust/ast/rust-item.h
gcc/rust/ast/rust-macro.h

index 2945cc87883f9ea89933e22a2d1c63edef23919b..09566575a85eb501029820e0b592ecbb5141167d 100644 (file)
@@ -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;
index 2b23c24672392721a51b08ec6d7217e1c2194a76..3e7c93c5098fde159a05cc858ab9538c7a948b7a 100644 (file)
@@ -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);
   }
 };
index a905914a58f8653c64acbec0c86ecde97429d96f..574f1fa3a653c2bea7415a53a62eb0138d636939 100644 (file)
@@ -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
index bdf3eff3dc665e7116b7b8ca21751f1155fa5e6b..076ab978bc35f7e7e6a9e1743ca446ec0db5dec9 100644 (file)
@@ -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