From patchwork Tue Feb 21 12:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1840523wrn; Tue, 21 Feb 2023 04:45:49 -0800 (PST) X-Google-Smtp-Source: AK7set9tt4HGlfI61XUTpI27JN9QDFEfzCAfghY900/oM0hx29fmFlC6hLllCJvOfk8aZ8jfPrN7 X-Received: by 2002:a17:907:c927:b0:8b2:7150:dd03 with SMTP id ui39-20020a170907c92700b008b27150dd03mr12445922ejc.35.1676983549232; Tue, 21 Feb 2023 04:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983549; cv=none; d=google.com; s=arc-20160816; b=G/iL14Nc1/U2eWFOkfVvQYi4dmmal3iO0Nuq+SlJCOY+Fz+M2ZL97Zx8z1Mmxgkb8C sWNAsEQ+4aaxl9/ZvKE5/hcO+J4HBOefi2HzrM85Ii+QujQ0nZIueqHJr3FXNmML8pU+ ZD5Xahcdwq6pnSWOQC8HEH7pbGaRqJB3BfLVgxAzF4F3U9rzaEaHqYe0xvqEiD+qepkt pRmlhpVg/tiP/OBl+cJ7zX0+81pj+0q6xGVxFoZwx51uJMGJiUcfhDv8C27+ftuy6GKK VF6OtoKI+Va3yUU3Q1wdBJLEPw/zc64/aktWKSqudrkTG9PHGBRccpDFXemrbsbeVRx2 80Fg== 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=bbTFlyVGb4/Tv1FCbgCtCDXG3KrMOnEdeqrM2eVcyng=; b=EZQHyMPkra9FWJYMDtsJwtiRhsgcK0wpXjkcNlE3addEDqgBuMxTnybxTVx33CjM42 gH1OqeNMEZK+/FZhMZ5RPERC5UNqC5bU+oA0ISKMLpb6X1Uf4qppVgcUJY6dnSa+MQzL F4y95beV7rZk0JLV0Ef/ZGTT7POWdCn+tDJzvvHlztrXg+zMggmPaRRviDa8Ziyl7RCi m6cUocfvBtvV2USn5bFm7wRo6oel/FisPeS9dhyqRmgbja4bhFXennrIusu/hG4T0OjQ vQ7aXyeioGGErX1+URYg3Y8e1n15e4spFKG5Wa1O9OwFas+vJy4VXRTGWahlgqAjSqQL EO3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=ESp7OeQW; 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 30-20020a170906029e00b008b123fe4f19si22876662ejf.984.2023.02.21.04.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:45:49 -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=ESp7OeQW; 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 C65C938ED07F for ; Tue, 21 Feb 2023 12:15:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 755F738323FC for ; Tue, 21 Feb 2023 12:04:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 755F738323FC 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-x429.google.com with SMTP id v3so4086080wrp.2 for ; Tue, 21 Feb 2023 04:04:23 -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=bbTFlyVGb4/Tv1FCbgCtCDXG3KrMOnEdeqrM2eVcyng=; b=ESp7OeQWZyZgS91Kx+rzcuPWZ6ywB1dDjYsjgBcIY4+OTUmFuCl6/TKDCfqG3ILwuL jfOyxcmlA/tZOJ8hpc5Cjduygsj6h2FVweUZLNaDl4EyomwwyYIFdb5CgxlcVrbCT+H/ rRjZBihmK3SeZmWEkli3q9ScKK/WFIpTiFnYBL7V9/pyNw0XZv4SAvprDKvSuAntl/GC T/TusU3DuG5sgbGy1ZbSo9bJ4d90olVyoPQg4BPpkSSiNsHJ6z555PfLWmXeTAQLPVGY L3EfrQL8xY0sS1zZ7faDwXrMdZUA1hKpj7FiO6fVTg5VByCGoZRKcxjbYRgwpMXa9gHB YUzQ== 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=bbTFlyVGb4/Tv1FCbgCtCDXG3KrMOnEdeqrM2eVcyng=; b=aza9C2IOeIYXTjYROdFkKdIBwgbVDWvjf9OvXd04gMNskMSEehQDr6o8q7wDMYBCIk 5Mla1Y+19hhVa1L/cexp3jIxaDQu3yfWWl5c6mfsXKUNke+qiTXp8JTu9hLaYIqKS/np lZfZ5tqbxGb412EwKomoFkWZhKZrArJ0omo2ax/7d3GuNzBuwbuSFb/CsjAxHDsShjBa gkXDj/arZP3Qpwjnn9bM3hnhcB43+ViCln6QUgNXvyOKwrH+bVoVR54U0N2nrizoQzcb +4oLOy5fU++CcKsf2GCgdYz13W+vCcRWoNwUnur2JbR6WNbD2hh3rbo7fM+RMwyQmsWM unzA== X-Gm-Message-State: AO0yUKXzbAPeyBa+MRVJhmPz1Rt5wrpA1LWHO9s/d73F4jZw128IorJA 661XYtn67MoHEBQpBlza7YaIZCQqUT1o7uM6VA== X-Received: by 2002:a5d:6092:0:b0:2bf:ee65:b0b0 with SMTP id w18-20020a5d6092000000b002bfee65b0b0mr5388189wrt.41.1676981062819; Tue, 21 Feb 2023 04:04:22 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:22 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [committed 072/103] gccrs: ast: add visit overload for references Date: Tue, 21 Feb 2023 13:02:02 +0100 Message-Id: <20230221120230.596966-73-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.3 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?1758444702192433779?= X-GMAIL-MSGID: =?utf-8?q?1758444702192433779?= From: Jakub Dupak This is currently needed for lifetimes to use the existing infrastructure. gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::visit): Add new reference visitor wrapper. * ast/rust-ast-dump.h: Declare it. * ast/rust-item.h: Add mutable visibility getters. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast-dump.cc | 15 +++++++++++---- gcc/rust/ast/rust-ast-dump.h | 11 ++++++++--- gcc/rust/ast/rust-item.h | 4 ++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index df42481c248..16c4a79dc6e 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -64,6 +64,13 @@ Dump::visit (std::unique_ptr &node) node->accept_vis (*this); } +template +void +Dump::visit (T &node) +{ + node.accept_vis (*this); +} + template void Dump::visit_items_joined_by_separator (T &collection, @@ -129,7 +136,7 @@ Dump::visit (FunctionParam ¶m) } void -Dump::visit (const Attribute &attrib) +Dump::visit (Attribute &attrib) { stream << "#["; visit_items_joined_by_separator (attrib.get_path ().get_segments (), "::"); @@ -158,13 +165,13 @@ Dump::visit (const Attribute &attrib) } void -Dump::visit (const SimplePathSegment &segment) +Dump::visit (SimplePathSegment &segment) { stream << segment.get_segment_name (); } void -Dump::visit (const Visibility &vis) +Dump::visit (Visibility &vis) { switch (vis.get_vis_type ()) { @@ -1099,7 +1106,7 @@ Dump::visit (TraitItemType &item) void Dump::visit (Trait &trait) { - for (const auto &attr : trait.get_outer_attrs ()) + for (auto &attr : trait.get_outer_attrs ()) { visit (attr); stream << "\n" << indentation; diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index 13c92123ea9..57419b75347 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -80,6 +80,11 @@ private: */ template void visit (std::unique_ptr &node); + /** + * @see visit> + */ + template void visit (T &node); + /** * Visit all items in given @collection, placing the separator in between but * not at the end. @@ -122,12 +127,12 @@ private: std::unique_ptr &block); void visit (FunctionParam ¶m); - void visit (const Attribute &attrib); - void visit (const Visibility &vis); + void visit (Attribute &attrib); + void visit (Visibility &vis); void visit (std::vector> ¶ms); void visit (TupleField &field); void visit (StructField &field); - void visit (const SimplePathSegment &segment); + void visit (SimplePathSegment &segment); void visit (NamedFunctionParam ¶m); void visit (MacroRule &rule); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 17d11e4de38..4e237f2e21e 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -908,6 +908,7 @@ public: FunctionQualifiers get_qualifiers () { return qualifiers; } + Visibility &get_visibility () { return vis; } const Visibility &get_visibility () const { return vis; } protected: @@ -1982,6 +1983,7 @@ public: return field_type; } + Visibility &get_visibility () { return visibility; } const Visibility &get_visibility () const { return visibility; } NodeId get_node_id () const { return node_id; } @@ -2116,6 +2118,7 @@ public: NodeId get_node_id () const { return node_id; } + Visibility &get_visibility () { return visibility; } const Visibility &get_visibility () const { return visibility; } Location get_locus () const { return locus; } @@ -4157,6 +4160,7 @@ public: Location get_locus () const { return locus; } + Visibility &get_visibility () { return visibility; } const Visibility &get_visibility () const { return visibility; } ExternalFunctionItem (