From ebbb3d2d5f74f4c00132df085fe7829abba4fe1c Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Tue, 18 Apr 2023 14:38:22 +0200 Subject: [PATCH] gccrs: ast: Add take_items() and set_items() methods for Item containers Both the AST::Crate and AST::Module class are std::unique_ptr containers, and may require spurious insertions in these containers, for example when expanding a procedural macro, or in our case, escaping macros through the #[macro_use] attribute. These functions allow you to replace *all* of the items contained in such a container. gcc/rust/ChangeLog: * ast/rust-ast.h: Add take_items() and set_items() method to Crate. * ast/rust-item.h: Add take_items() and set_items() method to Module. --- gcc/rust/ast/rust-ast.h | 10 ++++++++++ gcc/rust/ast/rust-item.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 8dfdba08cfa7..2077a8109e46 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1931,6 +1931,16 @@ public: NodeId get_node_id () const { return node_id; } const std::vector &get_inner_attrs () const { return inner_attrs; } + + std::vector> take_items () + { + return std::move (items); + } + + void set_items (std::vector> &&new_items) + { + items = std::move (new_items); + } }; // Base path expression AST node - abstract diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index dec8ab7fc448..a905914a58f8 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1114,6 +1114,16 @@ public: const std::vector> &get_items () const { return items; } std::vector> &get_items () { return items; } + std::vector> take_items () + { + return std::move (items); + } + + void set_items (std::vector> &&new_items) + { + items = std::move (new_items); + } + // move constructors Module (Module &&other) = default; Module &operator= (Module &&other) = default; -- 2.47.2