From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 28B023857726 for ; Tue, 30 Jan 2024 12:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 28B023857726 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 28B023857726 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616771; cv=none; b=MQpBuWlk9tLB6CjnOB11ZrRMSngBw7m2OBT5hMy2Bz8YvHiA1TEH1ewlhbu/R/VmAFcG2ObZj2aBoJIV8dred4gWXqGy9VNQg/74iSy6bbPeHCelB1r6+aCTlnkZvIQNw67NAxL9/xdeT+YOs+d5UHQ96uXWV7M6ZBM6TR4qBz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616771; c=relaxed/simple; bh=vCxFZSPTW+ykoRr/P6jhVLvC3eO1SFwaKltRh1N42Ew=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ktI25Pl1V+IWfStRq8J6CZxJRuscfwTL7kl8aSHwhVLCh3qlomfHVBRBhlJAmANvD++tg6H6RJAmqVGgts3OmErZF7fwLJENJAhMxD8dNK+ETffmmJ6tEW1Fw4Ml2qShiqwKzabAJn9OzUDFc2h67zQzGFOmYPXiJ6v7fHHvNv0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33ae51f8111so1920286f8f.2 for ; Tue, 30 Jan 2024 04:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616717; x=1707221517; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=rIl4sUgeF7lBVV18Twl5+mzytH36KT82hzDudQWjV4Q=; b=Sr+cbF6NKxAgXlGaMpCczj8Cfs12teLARQUQ+F0BF3m8hWH9NfP/o793HjW0rGNHwE ABaZ7kPt95xubkMixFEx0YtxeYTrfYgcNZ4H/9es2Syo0iy1F/Jw5V1nPpsIwxLPUAVR +sIzh4k8y5FX6Ba1KdeKwQpz7NuNeel2AMSKrkdWu+esK10VVGgk0pxR8+sEAURUwH7w 8SfNKnRFYm1Nhd7mr5wADDERCSPHw3vVPYvIj4mi81UgGgRmvAms64y3907Ax2xTtG3e wWI5b5Xhk6lIBSTU5u9c2mGQZXMZ2nrI1nYCoHLByXJv5lttGghmDaek6iTkEI6zaN+b Ysig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616717; x=1707221517; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rIl4sUgeF7lBVV18Twl5+mzytH36KT82hzDudQWjV4Q=; b=BOkckjh5LQmclDvJUuVViaPutT2Av9BGDzQ7ucAhUVrD61VCYvSYFzBEFQMXIa9f5R umfaUULSu40e7ZI8/PsbqCqhLPb/KA3l3iygHqRGvrwFEdMtrCqufDebbuOwAeTXqs6c GoLWStHepvtGa0wMES2egvkkeuqAi9HakfHWz5kAlNEY7lz9FAzgB+6n5LZDItwJnVl2 7t1/gLnaKsEkxe+QlzD8+rYcaKqEwkYwaVX/wHIA8kd1napkyaYGQsZzjl5VWiClZSkr NEFSR9UOe62RNwLx+/xTFHMTHaNxSdQ2Gr4Dsp2WPMjhPpaWECVlGWvqr1CSYEWB7cJD siyw== X-Gm-Message-State: AOJu0Yy0XNKVt/MRgGw9OeRrArmi1wKKaTH4VuEs2B/+7HvQEkImZ4uA ikZ46sTE8BH3kOgGem7z0NYgkhGFGP5HrTMXVdQkCJCbNx5wd0SEvSCBGzToMa4/qPFoVfuuDir kig== X-Google-Smtp-Source: AGHT+IFNXCi2bLlL7UE6P6XcGfgQYl08veoLm8+4WHFVxoBOKvt0sZvSu1vHbANz9+3XtXmAOzrHZA== X-Received: by 2002:adf:a446:0:b0:33a:e6f2:4a37 with SMTP id e6-20020adfa446000000b0033ae6f24a37mr4614106wra.63.1706616716917; Tue, 30 Jan 2024 04:11:56 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:56 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 093/101] gccrs: Unify storage of associated items in SingleASTNode Date: Tue, 30 Jan 2024 13:07:49 +0100 Message-ID: <20240130121026.807464-96-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Owen Avery gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc (Fragment::assert_single_fragment): Update. * ast/rust-ast.h (class TraitImplItem): Move definition before that of TraitItem. (class TraitItem): Inherit from TraitImplItem instead of AssociatedItem. (class SingleASTNode): Unify handling of associated items. (SingleASTNode::take_assoc_item): Move from... (SingleASTNode::take_impl_item): ...here, but leave stub calling take_assoc_item behind. (SingleASTNode::take_trait_item): Cast associated item to TraitItem. (SingleASTNode::take_trait_impl_item): Cast associated item to TraitImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Unify handling of associated items. (SingleASTNode::operator=): Likewise. (SingleASTNode::accept_vis): Likewise. (SingleASTNode::is_error): Likewise. (SingleASTNode::as_string): Likewise. * ast/rust-item.h (class Function): Remove direct inheritence from AssociatedItem. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Remove direct inheritence from AssociatedItem and TraitImplItem. --- gcc/rust/ast/rust-ast-fragment.cc | 4 +- gcc/rust/ast/rust-ast.cc | 52 +++++-------------------- gcc/rust/ast/rust-ast.h | 63 ++++++++++++++----------------- gcc/rust/ast/rust-item.h | 8 +--- gcc/rust/ast/rust-macro.h | 2 - 5 files changed, 42 insertions(+), 87 deletions(-) diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc index e7574519465..d8bf4aa213b 100644 --- a/gcc/rust/ast/rust-ast-fragment.cc +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -153,14 +153,12 @@ void Fragment::assert_single_fragment (SingleASTNode::NodeType expected) const { static const std::map str_map = { - {SingleASTNode::NodeType::IMPL, "impl"}, + {SingleASTNode::NodeType::ASSOC_ITEM, "associated item"}, {SingleASTNode::NodeType::ITEM, "item"}, {SingleASTNode::NodeType::TYPE, "type"}, {SingleASTNode::NodeType::EXPRESSION, "expr"}, {SingleASTNode::NodeType::STMT, "stmt"}, {SingleASTNode::NodeType::EXTERN, "extern"}, - {SingleASTNode::NodeType::TRAIT, "trait"}, - {SingleASTNode::NodeType::TRAIT_IMPL, "trait impl"}, }; auto actual = nodes[0].get_kind (); diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index b9096032d41..360a9ceb6db 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -60,16 +60,8 @@ SingleASTNode::SingleASTNode (SingleASTNode const &other) external_item = other.external_item->clone_external_item (); break; - case TRAIT: - trait_item = other.trait_item->clone_trait_item (); - break; - - case IMPL: - impl_item = other.impl_item->clone_associated_item (); - break; - - case TRAIT_IMPL: - trait_impl_item = other.trait_impl_item->clone_trait_impl_item (); + case ASSOC_ITEM: + assoc_item = other.assoc_item->clone_associated_item (); break; case TYPE: @@ -100,16 +92,8 @@ SingleASTNode::operator= (SingleASTNode const &other) external_item = other.external_item->clone_external_item (); break; - case TRAIT: - trait_item = other.trait_item->clone_trait_item (); - break; - - case IMPL: - impl_item = other.impl_item->clone_associated_item (); - break; - - case TRAIT_IMPL: - trait_impl_item = other.trait_impl_item->clone_trait_impl_item (); + case ASSOC_ITEM: + assoc_item = other.assoc_item->clone_associated_item (); break; case TYPE: @@ -140,16 +124,8 @@ SingleASTNode::accept_vis (ASTVisitor &vis) external_item->accept_vis (vis); break; - case TRAIT: - trait_item->accept_vis (vis); - break; - - case IMPL: - impl_item->accept_vis (vis); - break; - - case TRAIT_IMPL: - trait_impl_item->accept_vis (vis); + case ASSOC_ITEM: + assoc_item->accept_vis (vis); break; case TYPE: @@ -171,12 +147,8 @@ SingleASTNode::is_error () return stmt == nullptr; case EXTERN: return external_item == nullptr; - case TRAIT: - return trait_item == nullptr; - case IMPL: - return impl_item == nullptr; - case TRAIT_IMPL: - return trait_impl_item == nullptr; + case ASSOC_ITEM: + return assoc_item == nullptr; case TYPE: return type == nullptr; } @@ -198,12 +170,8 @@ SingleASTNode::as_string () const return "Stmt: " + stmt->as_string (); case EXTERN: return "External Item: " + external_item->as_string (); - case TRAIT: - return "Trait Item: " + trait_item->as_string (); - case IMPL: - return "Impl Item: " + impl_item->as_string (); - case TRAIT_IMPL: - return "Trait Impl Item: " + trait_impl_item->as_string (); + case ASSOC_ITEM: + return "Associated Item: " + assoc_item->as_string (); case TYPE: return "Type: " + type->as_string (); } diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index a45085489e8..256a527118a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1657,8 +1657,22 @@ public: virtual location_t get_locus () const = 0; }; +// Abstract base class for items used in a trait impl +class TraitImplItem : public AssociatedItem +{ +protected: + virtual TraitImplItem *clone_associated_item_impl () const override = 0; + +public: + // Unique pointer custom clone function + std::unique_ptr clone_trait_impl_item () const + { + return std::unique_ptr (clone_associated_item_impl ()); + } +}; + // Item used in trait declarations - abstract base class -class TraitItem : virtual public AssociatedItem +class TraitItem : public TraitImplItem { protected: TraitItem (location_t locus) @@ -1689,20 +1703,6 @@ public: location_t get_locus () const override { return locus; } }; -// Abstract base class for items used in a trait impl -class TraitImplItem : virtual public AssociatedItem -{ -protected: - virtual TraitImplItem *clone_associated_item_impl () const override = 0; - -public: - // Unique pointer custom clone function - std::unique_ptr clone_trait_impl_item () const - { - return std::unique_ptr (clone_associated_item_impl ()); - } -}; - // Abstract base class for an item used inside an extern block class ExternalItem : public Visitable { @@ -1831,9 +1831,7 @@ public: ITEM, STMT, EXTERN, - TRAIT, - IMPL, - TRAIT_IMPL, + ASSOC_ITEM, TYPE, }; @@ -1845,9 +1843,7 @@ private: std::unique_ptr item; std::unique_ptr stmt; std::unique_ptr external_item; - std::unique_ptr trait_item; - std::unique_ptr impl_item; - std::unique_ptr trait_impl_item; + std::unique_ptr assoc_item; std::unique_ptr type; public: @@ -1867,16 +1863,8 @@ public: : kind (EXTERN), external_item (std::move (item)) {} - SingleASTNode (std::unique_ptr item) - : kind (TRAIT), trait_item (std::move (item)) - {} - SingleASTNode (std::unique_ptr item) - : kind (IMPL), impl_item (std::move (item)) - {} - - SingleASTNode (std::unique_ptr trait_impl_item) - : kind (TRAIT_IMPL), trait_impl_item (std::move (trait_impl_item)) + : kind (ASSOC_ITEM), assoc_item (std::move (item)) {} SingleASTNode (std::unique_ptr type) @@ -1936,7 +1924,8 @@ public: std::unique_ptr take_trait_item () { rust_assert (!is_error ()); - return std::move (trait_item); + return std::unique_ptr ( + static_cast (assoc_item.release ())); } std::unique_ptr take_external_item () @@ -1945,16 +1934,22 @@ public: return std::move (external_item); } - std::unique_ptr take_impl_item () + std::unique_ptr take_assoc_item () { rust_assert (!is_error ()); - return std::move (impl_item); + return std::move (assoc_item); + } + + std::unique_ptr take_impl_item () + { + return take_assoc_item (); } std::unique_ptr take_trait_impl_item () { rust_assert (!is_error ()); - return std::move (trait_impl_item); + return std::unique_ptr ( + static_cast (assoc_item.release ())); } std::unique_ptr take_type () diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index a995273de12..5b9eb64560d 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1289,9 +1289,7 @@ protected: class LetStmt; // Rust function declaration AST node -class Function : public VisItem, - virtual public AssociatedItem, - public TraitImplItem +class Function : public VisItem, public TraitImplItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -2314,9 +2312,7 @@ protected: /* "Constant item" AST node - used for constant, compile-time expressions * within module scope (like constexpr) */ -class ConstantItem : public VisItem, - virtual public AssociatedItem, - public TraitImplItem +class ConstantItem : public VisItem, public TraitImplItem { // either has an identifier or "_" - maybe handle in identifier? // bool identifier_is_underscore; diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 41c21cffa95..bcf5b0b5a99 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -598,8 +598,6 @@ class MacroInvocation : public TypeNoBounds, public Pattern, public Item, public TraitItem, - public TraitImplItem, - virtual public AssociatedItem, public ExternalItem, public ExprWithoutBlock { -- 2.42.1