diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-11-24 11:17:52 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-30 12:36:48 +0100 |
commit | 9f6d3010047d417f54c439db42f111fa61b216df (patch) | |
tree | dabd91f99c521bd07787549c83340de53ff7fb8f | |
parent | ab257dcd66cd2532beb0c74b836147d02a9ed3bb (diff) | |
download | gcc-9f6d3010047d417f54c439db42f111fa61b216df.zip gcc-9f6d3010047d417f54c439db42f111fa61b216df.tar.gz gcc-9f6d3010047d417f54c439db42f111fa61b216df.tar.bz2 |
gccrs: 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 <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/checks/errors/rust-feature-gate.cc | 37 | ||||
-rw-r--r-- | 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 a531d037..3c94302 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -18,12 +18,19 @@ #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 (); for (const auto &attr : crate.inner_attrs) @@ -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 @@ -130,24 +129,6 @@ FeatureGate::visit (AST::MacroRulesDefinition &rules_def) } 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) { check_rustc_attri (function.get_outer_attrs ()); diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 1ebd3c9..8d1a26a 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 {} |