Skip to content

Commit 5c78ef9

Browse files
CohenArthurphilberty
authored andcommitted
ast: Add outer_attrs to all Items
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.
1 parent ad7c998 commit 5c78ef9

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,11 @@ class Item : public Stmt
933933
// behavior that we have items that can also be expressions?
934934
bool is_item () const override { return true; }
935935

936+
virtual std::vector<Attribute> &get_outer_attrs () = 0;
937+
virtual const std::vector<Attribute> &get_outer_attrs () const = 0;
938+
939+
virtual bool has_outer_attrs () const { return !get_outer_attrs ().empty (); }
940+
936941
protected:
937942
// Clone function implementation as pure virtual method
938943
virtual Item *clone_item_impl () const = 0;

gcc/rust/ast/rust-expr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,15 +2762,15 @@ class RangeExpr : public ExprWithoutBlock
27622762
public:
27632763
Location get_locus () const override final { return locus; }
27642764

2765-
// should never be called - error if called
2766-
void set_outer_attrs (std::vector<Attribute> /* new_attrs */) override
2765+
std::vector<Attribute> &get_outer_attrs () override final
27672766
{
2767+
// RangeExpr cannot have any outer attributes
27682768
rust_assert (false);
27692769
}
27702770

2771-
std::vector<Attribute> &get_outer_attrs () override
2771+
// should never be called - error if called
2772+
void set_outer_attrs (std::vector<Attribute> /* new_attrs */) override
27722773
{
2773-
// RangeExpr cannot have any outer attributes
27742774
rust_assert (false);
27752775
}
27762776
};

gcc/rust/ast/rust-item.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,11 @@ class VisItem : public Item
979979
Visibility &get_visibility () { return visibility; }
980980
const Visibility &get_visibility () const { return visibility; }
981981

982-
std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
983-
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
982+
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
983+
const std::vector<Attribute> &get_outer_attrs () const override
984+
{
985+
return outer_attrs;
986+
}
984987
};
985988

986989
// Rust module item - abstract base class

gcc/rust/ast/rust-macro.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,11 @@ class MacroRulesDefinition : public VisItem
541541
bool is_marked_for_strip () const override { return rule_name.empty (); }
542542

543543
// TODO: this mutable getter seems really dodgy. Think up better way.
544-
std::vector<Attribute> &get_outer_attrs () { return outer_attrs; }
545-
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
544+
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
545+
const std::vector<Attribute> &get_outer_attrs () const override
546+
{
547+
return outer_attrs;
548+
}
546549

547550
std::vector<MacroRule> &get_macro_rules () { return rules; }
548551
const std::vector<MacroRule> &get_macro_rules () const { return rules; }
@@ -651,7 +654,10 @@ class MacroInvocation : public TypeNoBounds,
651654
return invoc_data.is_marked_for_strip ();
652655
}
653656

654-
const std::vector<Attribute> &get_outer_attrs () const { return outer_attrs; }
657+
const std::vector<Attribute> &get_outer_attrs () const override
658+
{
659+
return outer_attrs;
660+
}
655661
std::vector<Attribute> &get_outer_attrs () override { return outer_attrs; }
656662

657663
void set_outer_attrs (std::vector<Attribute> new_attrs) override

0 commit comments

Comments
 (0)