From patchwork Tue Feb 21 12:02:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1839620wrn; Tue, 21 Feb 2023 04:43:37 -0800 (PST) X-Google-Smtp-Source: AK7set8dGfuLFGSpIgLFqUULGoh8KdWOSPmc0a/xUwYQf88qoy+aKkf1oJwFHqqZBvwDAZdQP4Hv X-Received: by 2002:a17:907:c689:b0:8b1:23cf:13dc with SMTP id ue9-20020a170907c68900b008b123cf13dcmr13345822ejc.16.1676983417523; Tue, 21 Feb 2023 04:43:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983417; cv=none; d=google.com; s=arc-20160816; b=H1APj6blVJ8PfemMBg1cZolfGuf+I4+kB+qZuzmY7tMEgPsF773nRBXcFXZWdlJEZC jLJ32m7F7qsdRHb7HvSAROqUFcadOFK8NXfOI5yzho0xceHRXVP7Ll+QvVZxINekTHWB VvVqDY2QEFOkchNkhsZ1u+W+L7GyzYdLG8AoQ7Dx0gU2Kel/FoAfTtK70YGUNeGYNs06 SHrGb/GkZcAkinqnb3gCSaMOKTUTRjllk2Y5x2EJoJFnOnXrAh4oTY/QLvhFH/g9gJ33 Qx9SE0It4zwC7qJTM/0BP+hMpEuJDiUjveqGLzE7Pz+mRdlJ9VCOidyJ6r4EPbb7bNmk XGXg== 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=LoBWNt2H423ffTCV+quVu51FTvLZC+vkHJ/9OLOj3J4=; b=Do1sOZftZtJCnFOPLkKy1TtBeR+VoVYQ7jzjaCSr5CX1NMUodZiUMsij30bAi8VS/d sdwLTUFzW+R1dtJxCUjbQUn+bBg2ge6nyprfiiXgm6WWnKFK5MFsUZp/SpEbSyKvI6SY 498ctEp9sV60LDT8fyA4LWihHBm/9B29RIqaCyo/NJQYo8PnF6Zz+XvtSwbiAckyXsEy OFTExV6ZD/LjLG6nwkdaoNqYVVeC1jgHY4k4np/iWV+it3TEd5B/3Wpoqp1/k0qaU5Ul qSARwrlaz1f8EotJO+AznGdxY0nzWU0KemQQ8fnZm5pTg37uaHqpiFLgcw67iybbTMCN EhDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=T7WIADgg; 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 18-20020a170906209200b008dc4d55dda4si5372475ejq.705.2023.02.21.04.43.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:43:37 -0800 (PST) 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=T7WIADgg; 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 705BF38DC344 for ; Tue, 21 Feb 2023 12:14:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 1CC96388211C for ; Tue, 21 Feb 2023 12:04:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CC96388211C 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-wr1-x42a.google.com with SMTP id l25so3759664wrb.3 for ; Tue, 21 Feb 2023 04:04:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; 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=LoBWNt2H423ffTCV+quVu51FTvLZC+vkHJ/9OLOj3J4=; b=T7WIADggMD+SNs+g/HkviHoWfwGcLJ1bV0NvB+GFHElmj4sm3haYYdwRYSmVBiw1o+ gIFE+t21xCJaFwLVnZspydpGZuzESNXQjkhMBNroexas4Vyjaun7aU4WdlMRI8je/Gdk BWXpyX0bS573ECIhtg3AxF5EYwUhqA9jEE5qzgPjcmnBvxY5hdPPAJXJKeIzkum4DeHF FfXNd/rDXxewX4eA0KFZP6CTCG0XVEBHegqXGPVmtsdJFrC5HOWROpCnaGonTLUturmf wf0IzECS11NpjiTfsbstxB3g7wesYhiFtJ4pY+M8IUPO5JUQybP0V+U9rbJbGGJY/bCd Cz0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=LoBWNt2H423ffTCV+quVu51FTvLZC+vkHJ/9OLOj3J4=; b=CPigckgS0u+lXtMUGRVLXqSgiqAl1PWE0iUqjoIFIhTh+uW914BzG11jaqVaC9Bv1X P0Lg6fxU3uLLwATZxBO0MUFej+vk6lhS4cR6sTdjplLAlQH7zJ8Q59x1ac7uxlVGAU/B v3+WetHGyrtKNbMVD3796Fa5MaLfm3gHhuXyRgboJlAfkHmOCzRuBkTtByTcx+ETzOO8 eAhTs9k2m6F9chC+Do4Hld6+8MVDdX62gG6RiaFod4gjZSMzyYgGktAKGF7Hu5e7jTrG mJ42gwnlhxCWnxAPe/ge38b3VYf3ILda7gJv0bVPSJDZ9swoCW7aLeQ8SjqIsH5f9+eT U7OQ== X-Gm-Message-State: AO0yUKX/Tg0on2kkYaRVi4MFQGsm2kbqjMh1XdruWorVTIBpBsBQF41V sNNZa4DErCvVeuxSUkk0FVNbRrzmytwNa8AEvg== X-Received: by 2002:a5d:6501:0:b0:2c5:5701:8d03 with SMTP id x1-20020a5d6501000000b002c557018d03mr4270174wru.13.1676981061421; Tue, 21 Feb 2023 04:04:21 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:20 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Dave Subject: [committed 070/103] gccrs: add Location to AST::Visibility Date: Tue, 21 Feb 2023 13:02:00 +0100 Message-Id: <20230221120230.596966-71-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.8 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?1758444564289734841?= X-GMAIL-MSGID: =?utf-8?q?1758444564289734841?= From: Dave gcc/rust/ChangeLog: * ast/rust-item.h: Add location member. * hir/rust-ast-lower.cc (translate_visibility): Pass location argument. * hir/tree/rust-hir-item.h: Fix constructor to accept Location argument. --- gcc/rust/ast/rust-item.h | 19 +++++++++++++------ gcc/rust/hir/rust-ast-lower.cc | 3 ++- gcc/rust/hir/tree/rust-hir-item.h | 6 ++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index d66dd615319..17d11e4de38 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -625,13 +625,15 @@ private: VisType vis_type; // Only assigned if vis_type is IN_PATH SimplePath in_path; + Location locus; // should this store location info? public: // Creates a Visibility - TODO make constructor protected or private? - Visibility (VisType vis_type, SimplePath in_path) - : vis_type (vis_type), in_path (std::move (in_path)) + Visibility (VisType vis_type, SimplePath in_path, + Location locus = Location ()) + : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) {} VisType get_vis_type () const { return vis_type; } @@ -648,6 +650,8 @@ public: // Returns whether visibility is public or not. bool is_public () const { return vis_type != PRIV && !is_error (); } + Location get_locus () const { return locus; } + // Creates an error visibility. static Visibility create_error () { @@ -672,21 +676,24 @@ public: static Visibility create_crate (Location crate_tok_location) { return Visibility (PUB_CRATE, - SimplePath::from_str ("crate", crate_tok_location)); + SimplePath::from_str ("crate", crate_tok_location), + crate_tok_location); } // Creates a public visibility with self-relative paths static Visibility create_self (Location self_tok_location) { return Visibility (PUB_SELF, - SimplePath::from_str ("self", self_tok_location)); + SimplePath::from_str ("self", self_tok_location), + self_tok_location); } // Creates a public visibility with parent module-relative paths static Visibility create_super (Location super_tok_location) { return Visibility (PUB_SUPER, - SimplePath::from_str ("super", super_tok_location)); + SimplePath::from_str ("super", super_tok_location), + super_tok_location); } // Creates a private visibility @@ -698,7 +705,7 @@ public: // Creates a public visibility with a given path or whatever. static Visibility create_in_path (SimplePath in_path) { - return Visibility (PUB_IN_PATH, std::move (in_path)); + return Visibility (PUB_IN_PATH, std::move (in_path), in_path.get_locus ()); } std::string as_string () const; diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index fdf8abe3ed3..2e25be75a5a 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -50,7 +50,8 @@ translate_visibility (const AST::Visibility &vis) case AST::Visibility::PUB_SUPER: case AST::Visibility::PUB_IN_PATH: return Visibility (Visibility::VisType::RESTRICTED, - ASTLoweringSimplePath::translate (vis.get_path ())); + ASTLoweringSimplePath::translate (vis.get_path ()), + vis.get_locus ()); break; } diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 7f665159572..f7bf1f879c8 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -571,13 +571,15 @@ public: private: VisType vis_type; HIR::SimplePath path; + Location locus; // should this store location info? public: Visibility (VisType vis_type, - HIR::SimplePath path = HIR::SimplePath::create_empty ()) - : vis_type (vis_type), path (std::move (path)) + HIR::SimplePath path = HIR::SimplePath::create_empty (), + Location locus = Location ()) + : vis_type (vis_type), path (std::move (path)), locus (locus) {} // Returns whether visibility is in an error state.