From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 4A8533882AC7 for ; Wed, 5 Apr 2023 14:06:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A8533882AC7 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-x334.google.com with SMTP id he13so1341953wmb.2 for ; Wed, 05 Apr 2023 07:06:27 -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=HX6vDd5vEy2kCWqsUBczdk4LqijW5bOBEsWge5Rg5N80jKCV/imkIYr5wbo8OGhCTr gHnWzLixQxNmQ9MojHG7457Nu3q3ho7jqlr47JQIVjZqGnZjZmrCtR0K0plECV4C+i5M bcYB0GXrqUowaaMlKOA9C++lQJ+2DCl2xQxpp6vH6KowPUGU9UQ596/2S2XXdVn+PD1s cAY50c0VJoauRae6q2xiIxgbtrB2q9MfAKcohLIxxfwMEm5QEt3rlrE0XhyEXHxGWqnr n62QaxguldeSRqpxcvoQk677BwBn7hyhc3EyRbmfvahGHdhh6ex+DtyAS1ABJibGFiER xHDg== X-Gm-Message-State: AAQBX9egfbKo5Z7XpBPFhw/q2PN0LkSfn2fEftYn6q2hdDwuZwmyyD61 7X4WqdD0M+BebwCelms33+Gn X-Google-Smtp-Source: AKy350YRF5cLx2PHK7rPjVDb0MMrIsqogEnb2LCNBsUdPRjRfDihNxQ7j3E/Fl/uI9WowkhGOcWPPA== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=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: 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) -- 2.40.0