From: Arthur Cohen Date: Tue, 25 Apr 2023 12:43:15 +0000 (+0200) Subject: gccrs: ast: Add `outer_attrs` to all `Item`s X-Git-Tag: basepoints/gcc-15~2533 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f5d02c4f5592b717a3aad5304308df913bf4ab1b;p=thirdparty%2Fgcc.git 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 --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 2945cc87883f..09566575a85e 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 &get_outer_attrs () = 0; + virtual const std::vector &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 2b23c2467239..3e7c93c5098f 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 /* new_attrs */) override + std::vector &get_outer_attrs () override final { + // RangeExpr cannot have any outer attributes rust_assert (false); } - std::vector &get_outer_attrs () override + // should never be called - error if called + void set_outer_attrs (std::vector /* 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 a905914a58f8..574f1fa3a653 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 &get_outer_attrs () { return outer_attrs; } - const std::vector &get_outer_attrs () const { return outer_attrs; } + std::vector &get_outer_attrs () override { return outer_attrs; } + const std::vector &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 bdf3eff3dc66..076ab978bc35 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 &get_outer_attrs () { return outer_attrs; } - const std::vector &get_outer_attrs () const { return outer_attrs; } + std::vector &get_outer_attrs () override { return outer_attrs; } + const std::vector &get_outer_attrs () const override + { + return outer_attrs; + } std::vector &get_macro_rules () { return rules; } const std::vector &get_macro_rules () const { return rules; } @@ -651,7 +654,10 @@ public: return invoc_data.is_marked_for_strip (); } - const std::vector &get_outer_attrs () const { return outer_attrs; } + const std::vector &get_outer_attrs () const override + { + return outer_attrs; + } std::vector &get_outer_attrs () override { return outer_attrs; } void set_outer_attrs (std::vector new_attrs) override