diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-04-18 14:38:22 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:37:14 +0100 |
commit | ebbb3d2d5f74f4c00132df085fe7829abba4fe1c (patch) | |
tree | 881637a5461f7759089de28f91469149022430b3 /gcc | |
parent | c532c201b360fcddc84f687e795248c132ba4787 (diff) | |
download | gcc-ebbb3d2d5f74f4c00132df085fe7829abba4fe1c.zip gcc-ebbb3d2d5f74f4c00132df085fe7829abba4fe1c.tar.gz gcc-ebbb3d2d5f74f4c00132df085fe7829abba4fe1c.tar.bz2 |
gccrs: ast: Add take_items() and set_items() methods for Item containers
Both the AST::Crate and AST::Module class are std::unique_ptr<AST::Item>
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 10 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 8dfdba0..2077a81 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<Attribute> &get_inner_attrs () const { return inner_attrs; } + + std::vector<std::unique_ptr<AST::Item>> take_items () + { + return std::move (items); + } + + void set_items (std::vector<std::unique_ptr<AST::Item>> &&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 dec8ab7..a905914 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1114,6 +1114,16 @@ public: const std::vector<std::unique_ptr<Item>> &get_items () const { return items; } std::vector<std::unique_ptr<Item>> &get_items () { return items; } + std::vector<std::unique_ptr<AST::Item>> take_items () + { + return std::move (items); + } + + void set_items (std::vector<std::unique_ptr<AST::Item>> &&new_items) + { + items = std::move (new_items); + } + // move constructors Module (Module &&other) = default; Module &operator= (Module &&other) = default; |