From 48942f64d51d215d6b8b1d84bbd648960afaaf60 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 24 Nov 2023 11:17:52 +0100 Subject: [PATCH] Make feature gate visitor inherit from default one 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 91ef85edfba7..f1f82edfa043 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 ca61199403f1..a6380854bc36 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 @@ class FeatureGate : public AST::ASTVisitor 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 {}