diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-05-26 15:36:23 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-06-13 11:52:56 +0000 |
commit | c021eef8aa73cc0a3a4e992018cab414a17db4c8 (patch) | |
tree | 6d714a47ee281dadb76bde7f3fb20e0d96dd7cf6 | |
parent | e43261892fb74f30639302eaff3eee6f626cc384 (diff) | |
download | gcc-c021eef8aa73cc0a3a4e992018cab414a17db4c8.zip gcc-c021eef8aa73cc0a3a4e992018cab414a17db4c8.tar.gz gcc-c021eef8aa73cc0a3a4e992018cab414a17db4c8.tar.bz2 |
derive: Factor common fields inside the base visitor
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.
-rw-r--r-- | gcc/rust/expand/rust-derive-clone.cc | 2 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive-clone.h | 5 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive-copy.cc | 3 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive-copy.h | 2 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive.cc | 4 | ||||
-rw-r--r-- | gcc/rust/expand/rust-derive.h | 7 |
6 files changed, 14 insertions, 9 deletions
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc index 8529bac5..2ffcafc 100644 --- a/gcc/rust/expand/rust-derive-clone.cc +++ b/gcc/rust/expand/rust-derive-clone.cc @@ -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> diff --git a/gcc/rust/expand/rust-derive-clone.h b/gcc/rust/expand/rust-derive-clone.h index 6c82a64..e1fadc7 100644 --- a/gcc/rust/expand/rust-derive-clone.h +++ b/gcc/rust/expand/rust-derive-clone.h @@ -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 diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc index d578849..bc5db62 100644 --- a/gcc/rust/expand/rust-derive-copy.cc +++ b/gcc/rust/expand/rust-derive-copy.cc @@ -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> diff --git a/gcc/rust/expand/rust-derive-copy.h b/gcc/rust/expand/rust-derive-copy.h index dce1f5e..0e1e207 100644 --- a/gcc/rust/expand/rust-derive-copy.h +++ b/gcc/rust/expand/rust-derive-copy.h @@ -32,8 +32,6 @@ public: std::unique_ptr<Item> go (Item &); private: - Location loc; - AstBuilder builder; std::unique_ptr<Item> expanded; /** diff --git a/gcc/rust/expand/rust-derive.cc b/gcc/rust/expand/rust-derive.cc index 8f9b206..1a7413b 100644 --- a/gcc/rust/expand/rust-derive.cc +++ b/gcc/rust/expand/rust-derive.cc @@ -23,6 +23,10 @@ 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) diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index 9a62c29..01f3f02 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -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; |