From patchwork Tue Jan 30 12:07:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 194144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1191469dyb; Tue, 30 Jan 2024 04:43:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOT49QzKWb+OBrXOSGx9tiGFrZs12nSxsUw6FTz6ry+ON5hpuPeLsbSSsmvtFyZGnF1VEF X-Received: by 2002:ac8:5908:0:b0:42a:a582:912 with SMTP id 8-20020ac85908000000b0042aa5820912mr4855390qty.58.1706618630634; Tue, 30 Jan 2024 04:43:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706618630; cv=pass; d=google.com; s=arc-20160816; b=rmnv+5+erZ7w+UOf7podB0oVHy1E0/5q2B2IPswl79OrFniq6BXnXZ0za/siATFvBj 1hOOF4Gp5d8+grLAg3MZCJicG8K+kFgv0OpOphX8ZMQ9njQRL1vjIyhXwfUcUEfLUYL2 8VlPqZwTwo6tyWigYkHZe3Jr9YJFZug1FeSmEk0a/h93TphbgTmINDnONT9XHDUt/yGv 3G+1hiM438P7QfUnHttjosrNPmfFycPIjHUiDQuQPIbI83h1C6AHBBSdduYdS+kChmww /jh+Xibn6QZEaaZW2FGIx6Gi9XNDE1bHd0OsLSfp3+jYHMpgBH/t8c8dwqQU2QrZupZj faJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=HEJuZnnuKQuxQNKOVvXiYIxb18W3B/fbTUp/CKwGKHk=; fh=s1GzlUPo1djGkCl3rkRJI30hDOSCVwGp0RAbVwQ8dxQ=; b=ys1kg5AGh7G1hmPG17nN/kjK6BnwrDlsFMPgN/FMd/KxRvHsig0ekBdUga9KCrtdVM 8YGaZfNK8BadNHh32nreXJHR7EY/pAGI+MqpwNilsv2YPXJeijxJYxUvTz69PW5t+eCv dNqX4dt0pYbmxPMwhQVEbSsyqdVb6SnZnwGLT7vhdaabxCMBLr9AHZA/fFna3L84XiDD 6DLtaAbLmVEh3RBlIj+Tt/FGn3S5WCS52dqA1y5qsHjp0sMIs4OeGhPopuBA5u2CYjze rGCT/ZO7Wra5Ygy0kj+RHYBM9YBBRUH1YJb4aEJDg+SVfyYTCVozsccEVGJglySWOX0R yPmg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=THt3UyXD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id iv11-20020a05622a6f0b00b0042a7e2a02adsi8956663qtb.126.2024.01.30.04.43.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:43:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=THt3UyXD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 0938138319CA for ; Tue, 30 Jan 2024 12:42:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id B1344385770D for ; Tue, 30 Jan 2024 12:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1344385770D 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 B1344385770D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; cv=none; b=sZ71YNxkmBDWZTD6tEWxXH9LcwZq2nXhmjFVChNAyx/TLNjhGD4FhCepkwK+5Mri7EqGMAyAtFCWmW7gYMh23kBSYp4pdCOUpajAP95guYTOZnfFArWu84FpAsRoFfae4IeS35W9q6zBMsFRXvj5eLIchEY+UzMwu3p+M1QXPJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; c=relaxed/simple; bh=ctd8ivjFMtrALJ3zsFFRd4Bj5Sg7cn/kM96vKfhu5jc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xGER4WCMgnhuZ69eu8plUV0D11uayGb8124q9tyVyTdvRfJFCJwQj3jk+W1zm5i2pQvWZL8yNUOPihthu74tgp0rePSc5Sp11auDRNfTj0KsXBaWhQ0UKHMWwItTnIslswi4/gjiHDWdCAa/mLr48dgi8+b7eeZoImqn5xFeong= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40e5afc18f5so41946525e9.3 for ; Tue, 30 Jan 2024 04:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616692; x=1707221492; 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=HEJuZnnuKQuxQNKOVvXiYIxb18W3B/fbTUp/CKwGKHk=; b=THt3UyXDRqro8Yt/+FIFDkocJ3EfJ3PHMo0iH2Tw3bhhn76iDQXzmonjFvdlPbDVVn 4GNSaQO/eBxJPnZoaPvqH9Q+Dqr8X8AQ5bXyBlAra9MnbOdeFmqgY1jCU/GVd+9BvlWZ tS04+H97TRGjjST24H3HfJxZxmxhI2meysrDEU0wj07LbF4Lkn1JkfL/ZWewQGApplM8 KKlPk6SZ5V55vxzbMMm0VhNFDCmCVdzCcu0nSxLjrQcT2nby0CwNXLgLkkDd8jBQW8Aj WCiq2Ag1JyX8IvlMlVK/YiaaYGzaCJhcE486XGqwc346LzsyVJAl+iGr3RkL1Xsd3T/S GXeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616692; x=1707221492; 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=HEJuZnnuKQuxQNKOVvXiYIxb18W3B/fbTUp/CKwGKHk=; b=uAERCooX3pY6HCKbS7lkuy3HmcHGoDf7zlW/FdFMTIpi5O93BTJ5ALQE0cPU9zZzUq MN3zOCzUVAlxwipu0tEKJeF+xeVeDtlv1e06oypU14k8RIpQ78/I60sviTEM/5VKE5Rk eNpb2LqXePXUPnG8RW3cCoyIce7qcvDs2w1cOiAOyJJSOxXAy6rRDXnjQH1cs6wFZFJO ggIEjOjEGltgNKSsUowGEVxTyuYrRo06Z2oE9mNzuM0+ew058c5L9RRQXon+Zmk0ov8A amVtuPW900vbANHVVvgamtF24xWC36CdslQN/Yxx6mkXIcyqrKWTfTtuMnZQEMT0nAqK 0Fzw== X-Gm-Message-State: AOJu0YyGGi+/OsNVctd0AqPH27d7HkLuUePzRkwCk+REiiEcQneVv4FN JH/0jRHhP5bodS/8MhSDLWTosL2axHJd52mnu0ERRDf1/iimdXmFkCZKgBJUtzVSeITMFry54xw 9hA== X-Received: by 2002:a5d:62cc:0:b0:33a:f4b4:8023 with SMTP id o12-20020a5d62cc000000b0033af4b48023mr3158076wrv.7.1706616692247; Tue, 30 Jan 2024 04:11:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 057/101] gccrs: Make feature gate visitor inherit from default one Date: Tue, 30 Jan 2024 13:07:13 +0100 Message-ID: <20240130121026.807464-60-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> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 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=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.30 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789519337078141680 X-GMAIL-MSGID: 1789519337078141680 From: Pierre-Emmanuel Patry The feature gating behavior may be shortened and kept cleaner using the default visitor. This means less maintenance on visit functions as the traversal is shared by multiple visitors. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add a visit function for the crate level. (FeatureGate::check): Add call to crate visit. * checks/errors/rust-feature-gate.h (class FeatureGate): Remove now useless visit functions (traversal only). Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-feature-gate.cc | 37 +++++---------------- gcc/rust/checks/errors/rust-feature-gate.h | 7 ++-- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index a531d0370f0..3c943022f05 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -18,11 +18,18 @@ #include "rust-feature-gate.h" #include "rust-abi.h" +#include "rust-ast-visitor.h" namespace Rust { void FeatureGate::check (AST::Crate &crate) +{ + visit (crate); +} + +void +FeatureGate::visit (AST::Crate &crate) { valid_features.clear (); @@ -56,12 +63,7 @@ FeatureGate::check (AST::Crate &crate) } } - auto &items = crate.items; - for (auto it = items.begin (); it != items.end (); it++) - { - auto &item = *it; - item->accept_vis (*this); - } + AST::DefaultASTVisitor::visit (crate); } void @@ -103,10 +105,7 @@ FeatureGate::visit (AST::ExternBlock &block) gate (Feature::Name::INTRINSICS, block.get_locus (), "intrinsics are subject to change"); } - for (const auto &item : block.get_extern_items ()) - { - item->accept_vis (*this); - } + AST::DefaultASTVisitor::visit (block); } void @@ -129,24 +128,6 @@ FeatureGate::visit (AST::MacroRulesDefinition &rules_def) check_rustc_attri (rules_def.get_outer_attrs ()); } -void -FeatureGate::visit (AST::InherentImpl &impl) -{ - for (const auto &item : impl.get_impl_items ()) - { - item->accept_vis (*this); - } -} - -void -FeatureGate::visit (AST::TraitImpl &impl) -{ - for (const auto &item : impl.get_impl_items ()) - { - item->accept_vis (*this); - } -} - void FeatureGate::visit (AST::Function &function) { diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 1ebd3c9e05f..8d1a26a1361 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -25,12 +25,15 @@ namespace Rust { -class FeatureGate : public AST::ASTVisitor +class FeatureGate : public AST::DefaultASTVisitor { public: FeatureGate () {} + using AST::DefaultASTVisitor::visit; + void check (AST::Crate &crate); + void visit (AST::Crate &crate) override; void visit (AST::Token &tok) override {} void visit (AST::DelimTokenTree &delim_tok_tree) override {} @@ -127,8 +130,6 @@ public: void visit (AST::TraitItemConst &item) override {} void visit (AST::TraitItemType &item) override {} void visit (AST::Trait &trait) override {} - void visit (AST::InherentImpl &impl) override; - void visit (AST::TraitImpl &impl) override; void visit (AST::ExternalTypeItem &item) override; void visit (AST::ExternalStaticItem &item) override {} void visit (AST::ExternalFunctionItem &item) override {}