public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8059] gccrs: Create base class AssociatedItem Date: Tue, 16 Jan 2024 18:15:04 +0000 (GMT) [thread overview] Message-ID: <20240116181504.15E6A385DC01@sourceware.org> (raw) https://gcc.gnu.org/g:9e7e3ea6380d4c8fe01740ce5278e84d2124fe93 commit r14-8059-g9e7e3ea6380d4c8fe01740ce5278e84d2124fe93 Author: Owen Avery <powerboat9.gamer@gmail.com> Date: Wed Oct 11 12:58:27 2023 -0400 gccrs: Create base class AssociatedItem gcc/rust/ChangeLog: * ast/rust-ast.h (class AssociatedItem): New, based on TraitItem, InherentImplItem, and TraitImplItem classes. (class TraitItem): Inherit from AssociatedItem. (class InherentImplItem): Likewise. (class TraitImplItem): Likewise. * ast/rust-item.h (class Method): Update cloning functions. (class Function): Likewise. (class TypeAlias): Likewise. (class ConstantItem): Likewise. (class TraitItemFunc): Likewise. (class TraitItemMethod): Likewise. (class TraitItemConst): Likewise. (class TraitItemType): Likewise. * ast/rust-macro.h (class MacroInvocation): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com> Diff: --- gcc/rust/ast/rust-ast.h | 63 +++++++++++++++++++++++------------------------ gcc/rust/ast/rust-item.h | 37 ++++++---------------------- gcc/rust/ast/rust-macro.h | 12 +-------- 3 files changed, 40 insertions(+), 72 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index b39d3cc1364..70277e76fcb 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1446,8 +1446,30 @@ protected: } }; +class AssociatedItem : public Visitable +{ +protected: + // Clone function implementation as pure virtual method + virtual AssociatedItem *clone_associated_item_impl () const = 0; + +public: + virtual ~AssociatedItem () {} + + std::unique_ptr<AssociatedItem> clone_associated_item () const + { + return std::unique_ptr<AssociatedItem> (clone_associated_item_impl ()); + } + + virtual std::string as_string () const = 0; + + virtual void mark_for_strip () = 0; + virtual bool is_marked_for_strip () const = 0; + + virtual location_t get_locus () const = 0; +}; + // Item used in trait declarations - abstract base class -class TraitItem : public Visitable +class TraitItem : virtual public AssociatedItem { protected: TraitItem (location_t locus) @@ -1455,73 +1477,50 @@ protected: {} // Clone function implementation as pure virtual method - virtual TraitItem *clone_trait_item_impl () const = 0; + virtual TraitItem *clone_associated_item_impl () const override = 0; NodeId node_id; location_t locus; public: - virtual ~TraitItem () {} - // Unique pointer custom clone function std::unique_ptr<TraitItem> clone_trait_item () const { - return std::unique_ptr<TraitItem> (clone_trait_item_impl ()); + return std::unique_ptr<TraitItem> (clone_associated_item_impl ()); } - virtual std::string as_string () const = 0; - - virtual void mark_for_strip () = 0; - virtual bool is_marked_for_strip () const = 0; - NodeId get_node_id () const { return node_id; } location_t get_locus () const { return locus; } }; /* Abstract base class for items used within an inherent impl block (the impl * name {} one) */ -class InherentImplItem : public Visitable +class InherentImplItem : virtual public AssociatedItem { protected: // Clone function implementation as pure virtual method - virtual InherentImplItem *clone_inherent_impl_item_impl () const = 0; + virtual InherentImplItem *clone_associated_item_impl () const override = 0; public: - virtual ~InherentImplItem () {} - // Unique pointer custom clone function std::unique_ptr<InherentImplItem> clone_inherent_impl_item () const { - return std::unique_ptr<InherentImplItem> (clone_inherent_impl_item_impl ()); + return std::unique_ptr<InherentImplItem> (clone_associated_item_impl ()); } - - virtual std::string as_string () const = 0; - - virtual void mark_for_strip () = 0; - virtual bool is_marked_for_strip () const = 0; - - virtual location_t get_locus () const = 0; }; // Abstract base class for items used in a trait impl -class TraitImplItem : public Visitable +class TraitImplItem : virtual public AssociatedItem { protected: - virtual TraitImplItem *clone_trait_impl_item_impl () const = 0; + virtual TraitImplItem *clone_associated_item_impl () const override = 0; public: - virtual ~TraitImplItem (){}; - // Unique pointer custom clone function std::unique_ptr<TraitImplItem> clone_trait_impl_item () const { - return std::unique_ptr<TraitImplItem> (clone_trait_impl_item_impl ()); + return std::unique_ptr<TraitImplItem> (clone_associated_item_impl ()); } - - virtual std::string as_string () const = 0; - - virtual void mark_for_strip () = 0; - virtual bool is_marked_for_strip () const = 0; }; // Abstract base class for an item used inside an extern block diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index dad20c7108c..b91e18dc035 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -923,14 +923,7 @@ public: protected: /* Use covariance to implement clone function as returning this object * rather than base */ - Method *clone_inherent_impl_item_impl () const final override - { - return clone_method_impl (); - } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - Method *clone_trait_impl_item_impl () const final override + Method *clone_associated_item_impl () const final override { return clone_method_impl (); } @@ -1703,14 +1696,7 @@ protected: /* Use covariance to implement clone function as returning this object * rather than base */ - Function *clone_inherent_impl_item_impl () const override - { - return new Function (*this); - } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - Function *clone_trait_impl_item_impl () const override + Function *clone_associated_item_impl () const override { return new Function (*this); } @@ -1834,7 +1820,7 @@ protected: /* Use covariance to implement clone function as returning this object * rather than base */ - TypeAlias *clone_trait_impl_item_impl () const override + TypeAlias *clone_associated_item_impl () const override { return new TypeAlias (*this); } @@ -2699,14 +2685,7 @@ protected: /* Use covariance to implement clone function as returning this object * rather than base */ - ConstantItem *clone_inherent_impl_item_impl () const override - { - return new ConstantItem (*this); - } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - ConstantItem *clone_trait_impl_item_impl () const override + ConstantItem *clone_associated_item_impl () const override { return new ConstantItem (*this); } @@ -3016,7 +2995,7 @@ public: protected: // Clone function implementation as (not pure) virtual method - TraitItemFunc *clone_trait_item_impl () const override + TraitItemFunc *clone_associated_item_impl () const override { return new TraitItemFunc (*this); } @@ -3232,7 +3211,7 @@ public: protected: // Clone function implementation as (not pure) virtual method - TraitItemMethod *clone_trait_item_impl () const override + TraitItemMethod *clone_associated_item_impl () const override { return new TraitItemMethod (*this); } @@ -3337,7 +3316,7 @@ public: protected: // Clone function implementation as (not pure) virtual method - TraitItemConst *clone_trait_item_impl () const override + TraitItemConst *clone_associated_item_impl () const override { return new TraitItemConst (*this); } @@ -3424,7 +3403,7 @@ public: protected: // Clone function implementation as (not pure) virtual method - TraitItemType *clone_trait_item_impl () const override + TraitItemType *clone_associated_item_impl () const override { return new TraitItemType (*this); } diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index c26318b54d2..b3fdcf71417 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -804,20 +804,10 @@ protected: bool is_item () const override { return !has_semicolon (); } - TraitItem *clone_trait_item_impl () const override + MacroInvocation *clone_associated_item_impl () const override { return clone_macro_invocation_impl (); }; - - TraitImplItem *clone_trait_impl_item_impl () const override - { - return clone_macro_invocation_impl (); - }; - - InherentImplItem *clone_inherent_impl_item_impl () const override - { - return clone_macro_invocation_impl (); - } }; // more generic meta item path-only form
reply other threads:[~2024-01-16 18:15 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240116181504.15E6A385DC01@sourceware.org \ --to=cohenarthur@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).