]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: derive: Factor common fields inside the base visitor
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 26 May 2023 13:36:23 +0000 (15:36 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:27 +0000 (18:46 +0100)
gcc/rust/ChangeLog:

* expand/rust-derive.h: Store AstBuilder and location.
* expand/rust-derive.cc (DeriveVisitor::DeriveVisitor): Update constructor.
* expand/rust-derive-clone.h: Remove members now stored in `DeriveVisitor`.
* expand/rust-derive-copy.h: Likewise.
* expand/rust-derive-clone.cc (DeriveClone::DeriveClone): Update constructor.
* expand/rust-derive-copy.cc (DeriveCopy::DeriveCopy): Likewise.

gcc/rust/expand/rust-derive-clone.cc
gcc/rust/expand/rust-derive-clone.h
gcc/rust/expand/rust-derive-copy.cc
gcc/rust/expand/rust-derive-copy.h
gcc/rust/expand/rust-derive.cc
gcc/rust/expand/rust-derive.h

index 8529bac50193628662b45caa8c7ab9e5c12cda2e..2ffcafc957b118d9f4871e2e7ace284a2a242a6e 100644 (file)
@@ -88,7 +88,7 @@ DeriveClone::clone_impl (std::unique_ptr<TraitImplItem> &&clone_fn,
 // TODO: Create new `make_qualified_call` helper function
 
 DeriveClone::DeriveClone (Location loc)
-  : loc (loc), expanded (nullptr), builder (AstBuilder (loc))
+  : DeriveVisitor (loc), expanded (nullptr)
 {}
 
 std::unique_ptr<AST::Item>
index 6c82a6478851fa00cd8b0e8e9385181a2646501c..e1fadc7916343c40c136553c0d785d8bfd46af1a 100644 (file)
@@ -20,7 +20,6 @@
 #define RUST_DERIVE_CLONE_H
 
 #include "rust-derive.h"
-#include "rust-ast-builder.h"
 
 namespace Rust {
 namespace AST {
@@ -33,9 +32,7 @@ public:
   std::unique_ptr<AST::Item> go (Item &item);
 
 private:
-  Location loc;
-  std::unique_ptr<AST::Item> expanded;
-  AstBuilder builder;
+  std::unique_ptr<Item> expanded;
 
   /**
    * Create a call to "clone". For now, this creates a call to
index d578849c06b87b193a5f73f26b99052a9616e2a0..bc5db626fbaeda9b8a00a25d5620d325d6049937 100644 (file)
@@ -22,8 +22,7 @@
 namespace Rust {
 namespace AST {
 
-DeriveCopy::DeriveCopy (Location loc)
-  : loc (loc), builder (AstBuilder (loc)), expanded (nullptr)
+DeriveCopy::DeriveCopy (Location loc) : DeriveVisitor (loc), expanded (nullptr)
 {}
 
 std::unique_ptr<AST::Item>
index dce1f5e9a950b6b6f4a8471cd17c278dab66d651..0e1e2076066d9a24b456d1e5ee529132ae0f4436 100644 (file)
@@ -32,8 +32,6 @@ public:
   std::unique_ptr<Item> go (Item &);
 
 private:
-  Location loc;
-  AstBuilder builder;
   std::unique_ptr<Item> expanded;
 
   /**
index 8f9b206da4be1dc93eb1bd6a63256d8d4714af18..1a7413b359b2e406acad47728db877c063cdf5c4 100644 (file)
 namespace Rust {
 namespace AST {
 
+DeriveVisitor::DeriveVisitor (Location loc)
+  : loc (loc), builder (AstBuilder (loc))
+{}
+
 std::unique_ptr<Item>
 DeriveVisitor::derive (Item &item, const Attribute &attr,
                       BuiltinMacro to_derive)
index 9a62c29e58f3b4d408e79763e9df42d57e602c14..01f3f024712ec9448c79522f2c8a58cac69ef504 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "rust-ast-full.h"
 #include "rust-ast-visitor.h"
+#include "rust-ast-builder.h"
 #include "rust-macro-builtins.h"
 
 namespace Rust {
@@ -36,6 +37,12 @@ public:
   static std::unique_ptr<Item> derive (Item &item, const Attribute &derive,
                                       BuiltinMacro to_derive);
 
+protected:
+  DeriveVisitor (Location loc);
+
+  Location loc;
+  AstBuilder builder;
+
 private:
   // the 4 "allowed" visitors, which a derive-visitor can specify and override
   virtual void visit_struct (StructStruct &struct_item) = 0;