diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-20 15:28:19 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:32 +0100 |
commit | fc1712be9ffde5049cd35aa281a931bc64775b68 (patch) | |
tree | 843f4bbd75c0754539196a65b147208110425c4b /gcc/rust/ast/rust-expr.h | |
parent | 997fa94b5276766acb40dd502eb606d5e220e918 (diff) | |
download | gcc-fc1712be9ffde5049cd35aa281a931bc64775b68.zip gcc-fc1712be9ffde5049cd35aa281a931bc64775b68.tar.gz gcc-fc1712be9ffde5049cd35aa281a931bc64775b68.tar.bz2 |
gccrs: Add outer attributes to struct expr fields
Struct fields can have outer attributes on their field for various
purpose, this behavior should be reflected upon struct expr fields.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Output field
attributes.
* ast/rust-expr.h (class StructExprField): Add outer attributes member.
* parse/rust-parse-impl.h (Parser::parse_struct_expr_field): Parse
outer attributes and store them in the appropriate AST node.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/ast/rust-expr.h')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index c3b93d4..50c0cb1 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -1758,6 +1758,13 @@ public: NodeId get_node_id () const { return node_id; } + const std::vector<AST::Attribute> &get_outer_attrs () const + { + return outer_attrs; + } + + std::vector<AST::Attribute> &get_outer_attrs () { return outer_attrs; } + protected: // pure virtual clone implementation virtual StructExprField *clone_struct_expr_field_impl () const = 0; @@ -1765,6 +1772,12 @@ protected: StructExprField () : node_id (Analysis::Mappings::get ().get_next_node_id ()) {} + StructExprField (AST::AttrVec outer_attrs) + : outer_attrs (std::move (outer_attrs)), + node_id (Analysis::Mappings::get ().get_next_node_id ()) + {} + + AST::AttrVec outer_attrs; NodeId node_id; }; @@ -1775,9 +1788,10 @@ class StructExprFieldIdentifier : public StructExprField location_t locus; public: - StructExprFieldIdentifier (Identifier field_identifier, location_t locus) - : StructExprField (), field_name (std::move (field_identifier)), - locus (locus) + StructExprFieldIdentifier (Identifier field_identifier, + AST::AttrVec outer_attrs, location_t locus) + : StructExprField (std::move (outer_attrs)), + field_name (std::move (field_identifier)), locus (locus) {} std::string as_string () const override { return field_name.as_string (); } @@ -1804,19 +1818,22 @@ class StructExprFieldWithVal : public StructExprField std::unique_ptr<Expr> value; protected: - StructExprFieldWithVal (std::unique_ptr<Expr> field_value) - : StructExprField (), value (std::move (field_value)) + StructExprFieldWithVal (std::unique_ptr<Expr> field_value, + AST::AttrVec outer_attrs) + : StructExprField (std::move (outer_attrs)), value (std::move (field_value)) {} // Copy constructor requires clone StructExprFieldWithVal (StructExprFieldWithVal const &other) - : value (other.value->clone_expr ()) + : StructExprField (other.get_outer_attrs ()), + value (other.value->clone_expr ()) {} // Overload assignment operator to clone unique_ptr StructExprFieldWithVal &operator= (StructExprFieldWithVal const &other) { value = other.value->clone_expr (); + outer_attrs = other.get_outer_attrs (); return *this; } @@ -1845,8 +1862,15 @@ class StructExprFieldIdentifierValue : public StructExprFieldWithVal public: StructExprFieldIdentifierValue (Identifier field_identifier, std::unique_ptr<Expr> field_value, + AST::AttrVec outer_attrs, location_t locus) + : StructExprFieldWithVal (std::move (field_value), std::move (outer_attrs)), + field_name (std::move (field_identifier)), locus (locus) + {} + + StructExprFieldIdentifierValue (Identifier field_identifier, + std::unique_ptr<Expr> field_value, location_t locus) - : StructExprFieldWithVal (std::move (field_value)), + : StructExprFieldWithVal (std::move (field_value), {}), field_name (std::move (field_identifier)), locus (locus) {} @@ -1876,9 +1900,9 @@ class StructExprFieldIndexValue : public StructExprFieldWithVal public: StructExprFieldIndexValue (TupleIndex tuple_index, std::unique_ptr<Expr> field_value, - location_t locus) - : StructExprFieldWithVal (std::move (field_value)), index (tuple_index), - locus (locus) + AST::AttrVec outer_attrs, location_t locus) + : StructExprFieldWithVal (std::move (field_value), std::move (outer_attrs)), + index (tuple_index), locus (locus) {} std::string as_string () const override; |