From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 0BC2B385803E for ; Tue, 30 Jan 2024 12:11:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BC2B385803E 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 0BC2B385803E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616720; cv=none; b=p0T/9GD/E94WUqgarhAd1TGPbsgMzD0bhxgNMI3uqc3LwO+l0HC7cpRFRp+TxohQD//cZ/L1mQbKKRfUk0qep5XkRh9JKSjGRbuMe2Co+c3aHFBLZPvPTmxM5m7JAsuYlnfENX72KOYxmQhQ8rXWtbhljPgjo6Up0bh3CrTJ6OE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616720; c=relaxed/simple; bh=8qnxuxIPqs9VFhApEK9K7HTMhvi5o+J6NuIczvaRW7A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=j8FB0XM1btMpfmONBaSTGzs/HSvbSWfqHCxG9Yrkf9GGVo7YJOaEhJXoVMAY/6Ie168ZdqZ9rvqpdoQ7sMTp2FrpIdVxc/Bdv7aSjmsUbbs9Ck+fm821G5ahHbhgoyoUiKa+8HX8/g4cFdKxjempCYaH2sKr/unuJgRaZYmCCPw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-5110fae7af5so2386596e87.0 for ; Tue, 30 Jan 2024 04:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616687; x=1707221487; 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=BHJWowi8D0l7QMwpZo+lP25+Y+BYCP/pZpmnk1kK5XQ=; b=f9XLDx2RhoYx2NrdQkQoK03BrwGRmZELjHD1ons+S23/hJCyEtVVd0DM6gNdxsleld NGNWtsSs1zEpx0lzkrNcvhnAWLySRgDfcmrg6gKm72ByBiesu7xxCR8ATuTYpoOaLHJ7 WkInRc01cixihP4UAX9T9v8H82vSfc61XPez8E97nP+4hW2S3eioK1GdfkChXeD/juwW yzZTxZm+6wJ216wymxyCDibz7zxQxk12Z2nFXvetHhYPx3Y7C/kUpXw//duch1uBGDUT Lzd67J6SVDs114J7DhwTQdYH0WB34TZgS1La9pmNvZnYYGSxamU4vhNRV+XTWOTE6kyz rL0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616687; x=1707221487; 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=BHJWowi8D0l7QMwpZo+lP25+Y+BYCP/pZpmnk1kK5XQ=; b=Sz/mGe9ZpjQtex8LOJySbWz5AOA8Gjczh7m8R16HJ1ZflWAjYkYCnG54L0+xRpBczR lkX2qsmUEylIOl5DOd0B6pD2etkU8QELCUNH9peja1HpLBEEcVbJjMQanXPCvdNO/Ye4 JDmruvIWUzzHGiSCjRfuo/n6r3kDdwBTSrjVSZvr8JrjNB5WncHOiNjaSWS+4K5sYHfH jF8iwn3CNIa9b3y1RFtwENad7TfMjq4hLC5p86PPEVC83MAf3IEhmqHizquB0CXt8vfF EpbKadig/MRbFmDMpRoyguCTfTn3ipkhulLdz67wIFSrApZfEPT7oWUMnAQeHxUdoMGL C9IQ== X-Gm-Message-State: AOJu0YzBP8DgLMG8hdmNhL3GlM1TNmmut+okKmZG5jKCc2MypCB45pcy 6bimR9iTnUQGA9C70Ag92ivsi1otXey+tI1s1nSid70Khh7uPUq389lJRB1I/rqTz2J8SkxpHin PTQ== X-Google-Smtp-Source: AGHT+IGXPjJQwkwzHDZAJMogRweDmoRP7J41qwuZqplarvwEnUpkI4e+fik3tES0rWDKM/8rZIpBeA== X-Received: by 2002:a05:6512:1599:b0:510:286b:8882 with SMTP id bp25-20020a056512159900b00510286b8882mr6555781lfb.3.1706616687511; Tue, 30 Jan 2024 04:11:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:27 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 050/101] gccrs: Remove class AST::InherentImplItem Date: Tue, 30 Jan 2024 13:07:06 +0100 Message-ID: <20240130121026.807464-53-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-full-decls.h (class InherentImplItem): Remove. * ast/rust-ast.h (class InherentImplItem): Remove. (class SingleASTNode): Store pointer to AssociatedItem instead of InherentImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Use clone_associated_item instead of clone_inherent_impl_item. (SingleASTNode::operator=): Likewise. * ast/rust-item.h (class InherentImpl): Use AssociatedItem rather than InherentImplItem. (class Function): Likewise. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_impl): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_inherent_impl_function_or_method): Likewise. * parse/rust-parse.h (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_inherent_impl_function_or_method): Likewise. Signed-off-by: Owen Avery --- gcc/rust/ast/rust-ast-full-decls.h | 1 - gcc/rust/ast/rust-ast.cc | 4 ++-- gcc/rust/ast/rust-ast.h | 22 +++------------------- gcc/rust/ast/rust-item.h | 18 ++++++++++-------- gcc/rust/ast/rust-macro.h | 2 +- gcc/rust/expand/rust-expand-visitor.cc | 2 +- gcc/rust/parse/rust-parse-impl.h | 8 ++++---- gcc/rust/parse/rust-parse.h | 4 ++-- 8 files changed, 23 insertions(+), 38 deletions(-) diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index e2d05bae0c4..5bfaaa8ba3c 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -52,7 +52,6 @@ class GenericParam; class LifetimeParam; class ConstGenericParam; class TraitItem; -class InherentImplItem; class TraitImplItem; struct Crate; class PathExpr; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 43820d38e28..17f82d67430 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -64,7 +64,7 @@ SingleASTNode::SingleASTNode (SingleASTNode const &other) break; case IMPL: - impl_item = other.impl_item->clone_inherent_impl_item (); + impl_item = other.impl_item->clone_associated_item (); break; case TRAIT_IMPL: @@ -104,7 +104,7 @@ SingleASTNode::operator= (SingleASTNode const &other) break; case IMPL: - impl_item = other.impl_item->clone_inherent_impl_item (); + impl_item = other.impl_item->clone_associated_item (); break; case TRAIT_IMPL: diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 4049e4d2607..b193c67c69e 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1687,22 +1687,6 @@ public: location_t get_locus () const override { return locus; } }; -/* Abstract base class for items used within an inherent impl block (the impl - * name {} one) */ -class InherentImplItem : virtual public AssociatedItem -{ -protected: - // Clone function implementation as pure virtual method - virtual InherentImplItem *clone_associated_item_impl () const override = 0; - -public: - // Unique pointer custom clone function - std::unique_ptr clone_inherent_impl_item () const - { - return std::unique_ptr (clone_associated_item_impl ()); - } -}; - // Abstract base class for items used in a trait impl class TraitImplItem : virtual public AssociatedItem { @@ -1860,7 +1844,7 @@ private: std::unique_ptr stmt; std::unique_ptr external_item; std::unique_ptr trait_item; - std::unique_ptr impl_item; + std::unique_ptr impl_item; std::unique_ptr trait_impl_item; std::unique_ptr type; @@ -1885,7 +1869,7 @@ public: : kind (TRAIT), trait_item (std::move (item)) {} - SingleASTNode (std::unique_ptr item) + SingleASTNode (std::unique_ptr item) : kind (IMPL), impl_item (std::move (item)) {} @@ -1959,7 +1943,7 @@ public: return std::move (external_item); } - std::unique_ptr take_impl_item () + std::unique_ptr take_impl_item () { rust_assert (!is_error ()); return std::move (impl_item); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 3bf023b3c5a..b34aca0d56c 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1285,7 +1285,9 @@ protected: class LetStmt; // Rust function declaration AST node -class Function : public VisItem, public InherentImplItem, public TraitImplItem +class Function : public VisItem, + virtual public AssociatedItem, + public TraitImplItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -2308,7 +2310,7 @@ protected: /* "Constant item" AST node - used for constant, compile-time expressions * within module scope (like constexpr) */ class ConstantItem : public VisItem, - public InherentImplItem, + virtual public AssociatedItem, public TraitImplItem { // either has an identifier or "_" - maybe handle in identifier? @@ -3408,7 +3410,7 @@ protected: class InherentImpl : public Impl { // bool has_impl_items; - std::vector> impl_items; + std::vector> impl_items; public: std::string as_string () const override; @@ -3417,7 +3419,7 @@ public: bool has_impl_items () const { return !impl_items.empty (); } // Mega-constructor - InherentImpl (std::vector> impl_items, + InherentImpl (std::vector> impl_items, std::vector> generic_params, std::unique_ptr trait_type, WhereClause where_clause, Visibility vis, std::vector inner_attrs, @@ -3433,7 +3435,7 @@ public: { impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_inherent_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); } // Overloaded assignment operator with vector clone @@ -3443,7 +3445,7 @@ public: impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_inherent_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); return *this; } @@ -3455,11 +3457,11 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: think of better way to do this - const std::vector> &get_impl_items () const + const std::vector> &get_impl_items () const { return impl_items; } - std::vector> &get_impl_items () + std::vector> &get_impl_items () { return impl_items; } diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index b3fdcf71417..41c21cffa95 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -599,7 +599,7 @@ class MacroInvocation : public TypeNoBounds, public Item, public TraitItem, public TraitImplItem, - public InherentImplItem, + virtual public AssociatedItem, public ExternalItem, public ExprWithoutBlock { diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 3f598b7f21c..1745af06174 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -1180,7 +1180,7 @@ ExpandVisitor::visit (AST::InherentImpl &impl) if (impl.has_where_clause ()) expand_where_clause (impl.get_where_clause ()); - std::function (AST::SingleASTNode)> + std::function (AST::SingleASTNode)> extractor = [] (AST::SingleASTNode node) { return node.take_impl_item (); }; expand_macro_children (MacroExpander::ContextType::IMPL, diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index f83cc122c89..a9af7dc3f38 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5388,12 +5388,12 @@ Parser::parse_impl (AST::Visibility vis, AST::AttrVec inner_attrs = parse_inner_attributes (); // parse inherent impl items - std::vector> impl_items; + std::vector> impl_items; const_TokenPtr t = lexer.peek_token (); while (t->get_id () != RIGHT_CURLY) { - std::unique_ptr impl_item + std::unique_ptr impl_item = parse_inherent_impl_item (); if (impl_item == nullptr) @@ -5512,7 +5512,7 @@ Parser::parse_impl (AST::Visibility vis, // Parses a single inherent impl item (item inside an inherent impl block). template -std::unique_ptr +std::unique_ptr Parser::parse_inherent_impl_item () { // parse outer attributes (if they exist) @@ -5629,7 +5629,7 @@ Parser::parse_inherent_impl_item () // InherentImplItem is this specialisation of the template while TraitImplItem // will be the other. template -std::unique_ptr +std::unique_ptr Parser::parse_inherent_impl_function_or_method ( AST::Visibility vis, AST::AttrVec outer_attrs) { diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index d3718467b48..4291e4198a5 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -170,7 +170,7 @@ public: std::unique_ptr parse_type (bool save_errors = true); std::unique_ptr parse_external_item (); std::unique_ptr parse_trait_item (); - std::unique_ptr parse_inherent_impl_item (); + std::unique_ptr parse_inherent_impl_item (); std::unique_ptr parse_trait_impl_item (); AST::PathInExpression parse_path_in_expression (); std::vector> parse_lifetime_params (); @@ -348,7 +348,7 @@ private: std::unique_ptr parse_impl (AST::Visibility vis, AST::AttrVec outer_attrs); - std::unique_ptr + std::unique_ptr parse_inherent_impl_function_or_method (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr -- 2.42.1