public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7670] gccrs: derive: Factor common fields inside the base visitor
@ 2024-01-16 17:52 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:52 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:00539210bfad17fec1ddc0bd55b213ef3da0471e
commit r14-7670-g00539210bfad17fec1ddc0bd55b213ef3da0471e
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Fri May 26 15:36:23 2023 +0200
gccrs: 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.
Diff:
---
gcc/rust/expand/rust-derive-clone.cc | 2 +-
gcc/rust/expand/rust-derive-clone.h | 5 +----
gcc/rust/expand/rust-derive-copy.cc | 3 +--
gcc/rust/expand/rust-derive-copy.h | 2 --
gcc/rust/expand/rust-derive.cc | 4 ++++
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 8529bac5019..2ffcafc957b 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 6c82a647885..e1fadc79163 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 d578849c06b..bc5db626fba 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 dce1f5e9a95..0e1e2076066 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 8f9b206da4b..1a7413b359b 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 9a62c29e58f..01f3f024712 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 17:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:52 [gcc r14-7670] gccrs: derive: Factor common fields inside the base visitor Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).