From patchwork Wed Apr 5 14:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp368905vqo; Wed, 5 Apr 2023 07:57:29 -0700 (PDT) X-Google-Smtp-Source: AKy350bmUZBqeAUx8g5OdKEP50OedQA6yIqXdEbo418V8Wpsk3B3KaWBN6avvJxc6ZmehWa7fYVX X-Received: by 2002:a17:906:524e:b0:93b:943f:6261 with SMTP id y14-20020a170906524e00b0093b943f6261mr2861337ejm.74.1680706649575; Wed, 05 Apr 2023 07:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680706649; cv=none; d=google.com; s=arc-20160816; b=p5cg0ycV5jG7BmwFwK7kDIShKakyXip/2YjDWQT0sRjXAwjrsemYk1VVLZPwdGeSxr TWPc1jXY1UZj8nynWswjy0w+peWVfpLLW1vISrtITJyF/sBxn1Em1o/fXImNpO9uJAhn fglqn02qW5doRK66mV0dWfDGlgaOmuL02pmT9qgwwl237EeyYc6OUJjAaxY8CU1S/Wl5 KzUxdkGwwCJ1a4AjNpdWX+ZKVN1OeJ1Nke4dHhfx6gLfjOWctHRjEv0yhGyWL/uqRfTQ +XMPIPx8DULxm+o4vXYHMRwL+EqrIRvwl6f+i6w2gIXEXrv8urQEClN9xVVPSe5v/1t5 cUHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=njUcQqBimkpLKTwc8Og86EtdMLWVhaNHx6/saxnMWII=; b=xRZXNG2NdaQWBLhXo3gzjHA5gmFhCmF9TmVUD7oI1oiFkbAIbUYQ15Q7YnmD6OSIQu IdoyBKBH9nNU3IsDQaTan9RO7yZBrjgKKLClcYEbEhfCgM8fb/xHubeElQcMq4uqTpqW pWJw10WnkS1g/WGYD1SyxxXK3c5KA3DjtuTgnPiMBPEh3nAyEn4FzC4fhbQKQgkRmkvT ba09VTfpKp4zD0sP4MrLsGCQTo/myQrhJ+CCxK6kNPHzCS67Pj1AGzPatgwSHZOM8Zoh cf0ghYJeom1fKRF+HZKiZH6GS7Zt/OzWxMBsxFfmz3/HIHXcaPowAR5SbCgosfpVJxAg zFDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IFj0sgND; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bx25-20020a170906a1d900b0093183fdc438si11029303ejb.104.2023.04.05.07.57.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:57:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=IFj0sgND; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65B8B39286CE for ; Wed, 5 Apr 2023 14:21:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 6E5D0385414F for ; Wed, 5 Apr 2023 14:06:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E5D0385414F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x32a.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18507596wmq.3 for ; Wed, 05 Apr 2023 07:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703587; 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=njUcQqBimkpLKTwc8Og86EtdMLWVhaNHx6/saxnMWII=; b=IFj0sgNDehhxA3xDJRGykN6oEI88GS1kNM8rKdPaMyYfFF3KjD7v4JeVneQxOci6Ju ORg0lkB9evvzIZBHl47ukWDLu0vZIQpcAE8HS4V2ZTb/EF2Wg4T5kkyZzrh1/Nx2Q4ap 7c8uSdV5k1Ol6XS7noUPRwCJZTX/41OANswGNgmwoeUrysCy6M1n/4nF56zfSx3ctK56 RnAyxU9BFa/yHceZ2qKPYoFrSEzcOCoFoMBTAEBLwwPFVz5+Kuf2S+upp7EeqFLfCnei +YG/QuEtTII1KVfn8BIB11AMUg3HFlhG2MHn/xylRKus540GqCqqE04riYPiPpvROX9P zGdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703587; 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=njUcQqBimkpLKTwc8Og86EtdMLWVhaNHx6/saxnMWII=; b=1F9faevso9Hy13pa3BU01k6K+ITUTavtJfyeeIxrJvFk5LGcvgjRvFSDzN11u+pUy8 tM9IkWjIkWr9y7u/RA3mQazj9Csv0YWrvynroxWkQgJHHTEZwaRA0CEYKCMiLBtT0BOv wX1H3Uy59OnSptpX9iTFxPRCqxjfbbi09zfhNriXqR1n2Hz5ZrNBaEp1l4Rrqj+j7vrN 3FDqP9pcAC4ipPrb2jYGHbrfKC4LNZe7XraVXcSZSj0GtHGLYYcui0dccAjsYKbeUuLc 88v6ntXB6vWnTkEhn4mVc7/6dBLAbTOpg6KheGJMAtgyRXBFfs9DC4caPkHEIDZz+JNN BY0g== X-Gm-Message-State: AAQBX9f3frvoOjMfaCfVo/DS7SqjAOgIkRfZRpzOkAQrR6Q3+cszZFqp PzQAkEMvNjVn7fj8RtZ1Ik1BhOUQ+INpKXO3cg== X-Received: by 2002:a7b:c3d9:0:b0:3ed:da74:ab0c with SMTP id t25-20020a7bc3d9000000b003edda74ab0cmr4911136wmj.19.1680703586866; Wed, 05 Apr 2023 07:06:26 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:26 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [committed 84/88] gccrs: ast: Refactor TraitItem to keep Location info Date: Wed, 5 Apr 2023 16:04:08 +0200 Message-Id: <20230405140411.3016563-85-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.5 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762348655360415790?= X-GMAIL-MSGID: =?utf-8?q?1762348655360415790?= From: Arthur Cohen gcc/rust/ChangeLog: * ast/rust-ast.h: Keep location in TraitItem base class * ast/rust-item.h (class TraitItemFunc): Use base class location instead. (class TraitItemMethod): Likewise. (class TraitItemConst): Likewise. (class TraitItemType): Likewise. * ast/rust-macro.h: Likewise. --- gcc/rust/ast/rust-ast.h | 6 +++++- gcc/rust/ast/rust-item.h | 44 ++++++++++++++------------------------- gcc/rust/ast/rust-macro.h | 10 ++++----- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index d986fdf9368..585bdb09e68 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1358,12 +1358,15 @@ protected: class TraitItem { protected: - TraitItem () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} + TraitItem (Location locus) + : node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus) + {} // Clone function implementation as pure virtual method virtual TraitItem *clone_trait_item_impl () const = 0; NodeId node_id; + Location locus; public: virtual ~TraitItem () {} @@ -1382,6 +1385,7 @@ public: virtual bool is_marked_for_strip () const = 0; NodeId get_node_id () const { return node_id; } + Location get_locus () const { return locus; } }; /* Abstract base class for items used within an inherent impl block (the impl diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 51ed815c700..16209613881 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -2908,7 +2908,6 @@ class TraitItemFunc : public TraitItem std::vector outer_attrs; TraitFunctionDecl decl; std::unique_ptr block_expr; - Location locus; public: // Returns whether function has a definition or is just a declaration. @@ -2916,14 +2915,14 @@ public: TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr block_expr, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - decl (std::move (decl)), block_expr (std::move (block_expr)), - locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + decl (std::move (decl)), block_expr (std::move (block_expr)) {} // Copy constructor with clone TraitItemFunc (TraitItemFunc const &other) - : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + decl (other.decl) { node_id = other.node_id; @@ -2956,8 +2955,6 @@ public: std::string as_string () const override; - Location get_locus () const { return locus; } - void accept_vis (ASTVisitor &vis) override; // Invalid if trait decl is empty, so base stripping on that. @@ -3128,7 +3125,6 @@ class TraitItemMethod : public TraitItem std::vector outer_attrs; TraitMethodDecl decl; std::unique_ptr block_expr; - Location locus; public: // Returns whether method has a definition or is just a declaration. @@ -3136,14 +3132,14 @@ public: TraitItemMethod (TraitMethodDecl decl, std::unique_ptr block_expr, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - decl (std::move (decl)), block_expr (std::move (block_expr)), - locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + decl (std::move (decl)), block_expr (std::move (block_expr)) {} // Copy constructor with clone TraitItemMethod (TraitItemMethod const &other) - : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + decl (other.decl) { node_id = other.node_id; @@ -3176,8 +3172,6 @@ public: std::string as_string () const override; - Location get_locus () const { return locus; } - void accept_vis (ASTVisitor &vis) override; // Invalid if trait decl is empty, so base stripping on that. @@ -3219,8 +3213,6 @@ class TraitItemConst : public TraitItem // bool has_expression; std::unique_ptr expr; - Location locus; - public: // Whether the constant item has an associated expression. bool has_expression () const { return expr != nullptr; } @@ -3228,14 +3220,14 @@ public: TraitItemConst (Identifier name, std::unique_ptr type, std::unique_ptr expr, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - name (std::move (name)), type (std::move (type)), expr (std::move (expr)), - locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + name (std::move (name)), type (std::move (type)), expr (std::move (expr)) {} // Copy constructor with clones TraitItemConst (TraitItemConst const &other) - : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + name (other.name) { node_id = other.node_id; @@ -3328,8 +3320,6 @@ class TraitItemType : public TraitItem std::vector> type_param_bounds; // inlined form - Location locus; - public: // Returns whether trait item type has type param bounds. bool has_type_param_bounds () const { return !type_param_bounds.empty (); } @@ -3337,14 +3327,14 @@ public: TraitItemType (Identifier name, std::vector> type_param_bounds, std::vector outer_attrs, Location locus) - : TraitItem (), outer_attrs (std::move (outer_attrs)), - name (std::move (name)), - type_param_bounds (std::move (type_param_bounds)), locus (locus) + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + name (std::move (name)), type_param_bounds (std::move (type_param_bounds)) {} // Copy constructor with vector clone TraitItemType (TraitItemType const &other) - : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + name (other.name) { node_id = other.node_id; type_param_bounds.reserve (other.type_param_bounds.size ()); @@ -3374,8 +3364,6 @@ public: std::string as_string () const override; - Location get_locus () const { return locus; } - void accept_vis (ASTVisitor &vis) override; // Invalid if name is empty, so base stripping on that. diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 1a1a32da34c..be8ed560913 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -723,7 +723,7 @@ private: MacroInvocData invoc_data, std::vector outer_attrs, Location locus, bool is_semi_coloned, std::vector> &&pending_eager_invocs) - : outer_attrs (std::move (outer_attrs)), locus (locus), + : TraitItem (locus), outer_attrs (std::move (outer_attrs)), locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ()), invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned), kind (kind), builtin_kind (builtin_kind), @@ -731,10 +731,10 @@ private: {} MacroInvocation (const MacroInvocation &other) - : outer_attrs (other.outer_attrs), locus (other.locus), - node_id (other.node_id), invoc_data (other.invoc_data), - is_semi_coloned (other.is_semi_coloned), kind (other.kind), - builtin_kind (other.builtin_kind) + : TraitItem (other.locus), outer_attrs (other.outer_attrs), + locus (other.locus), node_id (other.node_id), + invoc_data (other.invoc_data), is_semi_coloned (other.is_semi_coloned), + kind (other.kind), builtin_kind (other.builtin_kind) { if (other.kind == InvocKind::Builtin) for (auto &pending : other.pending_eager_invocs)