]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: Add take_items() and set_items() methods for Item containers
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 18 Apr 2023 12:38:22 +0000 (14:38 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:14 +0000 (18:37 +0100)
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.

gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-item.h

index 8dfdba08cfa758b60b10768e043ac6ad1d17bdb4..2077a8109e465cc75bebaab0337d7cbfad909ace 100644 (file)
@@ -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
index dec8ab7fc448530b1e9891c46798255925b3040d..a905914a58f8653c64acbec0c86ecde97429d96f 100644 (file)
@@ -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;