Skip to content

Commit

Permalink
Make feature gate visitor inherit from default one
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
P-E-P committed Dec 1, 2023
1 parent 0d6d394 commit 48942f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
37 changes: 9 additions & 28 deletions gcc/rust/checks/errors/rust-feature-gate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down
7 changes: 4 additions & 3 deletions gcc/rust/checks/errors/rust-feature-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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 {}
Expand Down

0 comments on commit 48942f6

Please sign in to comment.