From fba0a7b945036ce83a38f9111772bf48adced92a Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 24 Nov 2023 14:09:23 +0100 Subject: [PATCH] Change the attribute checker visitor to default one Make the attribute checker visitor inherit from the default visitor in order to keep visit behavior shared. gcc/rust/ChangeLog: * util/rust-attributes.cc (AttributeChecker::visit): Add visit function for crates. * util/rust-attributes.h (class AttributeChecker): Update function prototypes. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-attributes.cc | 23 ++- gcc/rust/util/rust-attributes.h | 319 ++++++++++++++++--------------- 2 files changed, 171 insertions(+), 171 deletions(-) diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 99931ff16785..5a43224f01c7 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -16,6 +16,7 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-ast-visitor.h" #include "rust-system.h" #include "rust-session-manager.h" #include "rust-attributes.h" @@ -94,6 +95,12 @@ AttributeChecker::AttributeChecker () {} void AttributeChecker::go (AST::Crate &crate) +{ + visit (crate); +} + +void +AttributeChecker::visit (AST::Crate &crate) { check_attributes (crate.get_inner_attrs ()); @@ -468,8 +475,8 @@ AttributeChecker::visit (AST::BlockExpr &expr) check_proc_macro_non_root (item->get_outer_attrs (), item->get_locus ()); } - stmt->accept_vis (*this); } + AST::DefaultASTVisitor::visit (expr); } void @@ -512,12 +519,6 @@ void AttributeChecker::visit (AST::ReturnExpr &) {} -void -AttributeChecker::visit (AST::UnsafeBlockExpr &expr) -{ - expr.get_block_expr ()->accept_vis (*this); -} - void AttributeChecker::visit (AST::LoopExpr &) {} @@ -582,8 +583,8 @@ AttributeChecker::visit (AST::Module &module) for (auto &item : module.get_items ()) { check_proc_macro_non_root (item->get_outer_attrs (), item->get_locus ()); - item->accept_vis (*this); } + AST::DefaultASTVisitor::visit (module); } void @@ -754,16 +755,14 @@ void AttributeChecker::visit (AST::InherentImpl &impl) { check_proc_macro_non_function (impl.get_outer_attrs ()); - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + AST::DefaultASTVisitor::visit (impl); } void AttributeChecker::visit (AST::TraitImpl &impl) { check_proc_macro_non_function (impl.get_outer_attrs ()); - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + AST::DefaultASTVisitor::visit (impl); } void diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index 70cac30c2f49..5853661d6912 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -77,7 +77,7 @@ class BuiltinAttributeMappings * as checking the "arguments" or input given to these attributes, making sure * it is appropriate and valid. */ -class AttributeChecker : public AST::ASTVisitor +class AttributeChecker : public AST::DefaultASTVisitor { public: AttributeChecker (); @@ -88,6 +88,7 @@ class AttributeChecker : public AST::ASTVisitor void go (AST::Crate &crate); private: + using AST::DefaultASTVisitor::visit; /* Check the validity of a given attribute */ void check_attribute (const AST::Attribute &attribute); @@ -95,178 +96,178 @@ class AttributeChecker : public AST::ASTVisitor void check_attributes (const AST::AttrVec &attributes); // rust-ast.h - void visit (AST::Token &tok); - void visit (AST::DelimTokenTree &delim_tok_tree); - void visit (AST::AttrInputMetaItemContainer &input); - void visit (AST::IdentifierExpr &ident_expr); - void visit (AST::Lifetime &lifetime); - void visit (AST::LifetimeParam &lifetime_param); - void visit (AST::ConstGenericParam &const_param); + void visit (AST::Crate &crate) override; + void visit (AST::Token &tok) override; + void visit (AST::DelimTokenTree &delim_tok_tree) override; + void visit (AST::AttrInputMetaItemContainer &input) override; + void visit (AST::IdentifierExpr &ident_expr) override; + void visit (AST::Lifetime &lifetime) override; + void visit (AST::LifetimeParam &lifetime_param) override; + void visit (AST::ConstGenericParam &const_param) override; // rust-path.h - void visit (AST::PathInExpression &path); - void visit (AST::TypePathSegment &segment); - void visit (AST::TypePathSegmentGeneric &segment); - void visit (AST::TypePathSegmentFunction &segment); - void visit (AST::TypePath &path); - void visit (AST::QualifiedPathInExpression &path); - void visit (AST::QualifiedPathInType &path); + void visit (AST::PathInExpression &path) override; + void visit (AST::TypePathSegment &segment) override; + void visit (AST::TypePathSegmentGeneric &segment) override; + void visit (AST::TypePathSegmentFunction &segment) override; + void visit (AST::TypePath &path) override; + void visit (AST::QualifiedPathInExpression &path) override; + void visit (AST::QualifiedPathInType &path) override; // rust-expr.h - void visit (AST::LiteralExpr &expr); - void visit (AST::AttrInputLiteral &attr_input); - void visit (AST::AttrInputMacro &attr_input); - void visit (AST::MetaItemLitExpr &meta_item); - void visit (AST::MetaItemPathLit &meta_item); - void visit (AST::BorrowExpr &expr); - void visit (AST::DereferenceExpr &expr); - void visit (AST::ErrorPropagationExpr &expr); - void visit (AST::NegationExpr &expr); - void visit (AST::ArithmeticOrLogicalExpr &expr); - void visit (AST::ComparisonExpr &expr); - void visit (AST::LazyBooleanExpr &expr); - void visit (AST::TypeCastExpr &expr); - void visit (AST::AssignmentExpr &expr); - void visit (AST::CompoundAssignmentExpr &expr); - void visit (AST::GroupedExpr &expr); - void visit (AST::ArrayElemsValues &elems); - void visit (AST::ArrayElemsCopied &elems); - void visit (AST::ArrayExpr &expr); - void visit (AST::ArrayIndexExpr &expr); - void visit (AST::TupleExpr &expr); - void visit (AST::TupleIndexExpr &expr); - void visit (AST::StructExprStruct &expr); - void visit (AST::StructExprFieldIdentifier &field); - void visit (AST::StructExprFieldIdentifierValue &field); - void visit (AST::StructExprFieldIndexValue &field); - void visit (AST::StructExprStructFields &expr); - void visit (AST::StructExprStructBase &expr); - void visit (AST::CallExpr &expr); - void visit (AST::MethodCallExpr &expr); - void visit (AST::FieldAccessExpr &expr); - void visit (AST::ClosureExprInner &expr); - void visit (AST::BlockExpr &expr); - void visit (AST::ClosureExprInnerTyped &expr); - void visit (AST::ContinueExpr &expr); - void visit (AST::BreakExpr &expr); - void visit (AST::RangeFromToExpr &expr); - void visit (AST::RangeFromExpr &expr); - void visit (AST::RangeToExpr &expr); - void visit (AST::RangeFullExpr &expr); - void visit (AST::RangeFromToInclExpr &expr); - void visit (AST::RangeToInclExpr &expr); - void visit (AST::ReturnExpr &expr); - void visit (AST::UnsafeBlockExpr &expr); - void visit (AST::LoopExpr &expr); - void visit (AST::WhileLoopExpr &expr); - void visit (AST::WhileLetLoopExpr &expr); - void visit (AST::ForLoopExpr &expr); - void visit (AST::IfExpr &expr); - void visit (AST::IfExprConseqElse &expr); - void visit (AST::IfLetExpr &expr); - void visit (AST::IfLetExprConseqElse &expr); - void visit (AST::MatchExpr &expr); - void visit (AST::AwaitExpr &expr); - void visit (AST::AsyncBlockExpr &expr); + void visit (AST::LiteralExpr &expr) override; + void visit (AST::AttrInputLiteral &attr_input) override; + void visit (AST::AttrInputMacro &attr_input) override; + void visit (AST::MetaItemLitExpr &meta_item) override; + void visit (AST::MetaItemPathLit &meta_item) override; + void visit (AST::BorrowExpr &expr) override; + void visit (AST::DereferenceExpr &expr) override; + void visit (AST::ErrorPropagationExpr &expr) override; + void visit (AST::NegationExpr &expr) override; + void visit (AST::ArithmeticOrLogicalExpr &expr) override; + void visit (AST::ComparisonExpr &expr) override; + void visit (AST::LazyBooleanExpr &expr) override; + void visit (AST::TypeCastExpr &expr) override; + void visit (AST::AssignmentExpr &expr) override; + void visit (AST::CompoundAssignmentExpr &expr) override; + void visit (AST::GroupedExpr &expr) override; + void visit (AST::ArrayElemsValues &elems) override; + void visit (AST::ArrayElemsCopied &elems) override; + void visit (AST::ArrayExpr &expr) override; + void visit (AST::ArrayIndexExpr &expr) override; + void visit (AST::TupleExpr &expr) override; + void visit (AST::TupleIndexExpr &expr) override; + void visit (AST::StructExprStruct &expr) override; + void visit (AST::StructExprFieldIdentifier &field) override; + void visit (AST::StructExprFieldIdentifierValue &field) override; + void visit (AST::StructExprFieldIndexValue &field) override; + void visit (AST::StructExprStructFields &expr) override; + void visit (AST::StructExprStructBase &expr) override; + void visit (AST::CallExpr &expr) override; + void visit (AST::MethodCallExpr &expr) override; + void visit (AST::FieldAccessExpr &expr) override; + void visit (AST::ClosureExprInner &expr) override; + void visit (AST::BlockExpr &expr) override; + void visit (AST::ClosureExprInnerTyped &expr) override; + void visit (AST::ContinueExpr &expr) override; + void visit (AST::BreakExpr &expr) override; + void visit (AST::RangeFromToExpr &expr) override; + void visit (AST::RangeFromExpr &expr) override; + void visit (AST::RangeToExpr &expr) override; + void visit (AST::RangeFullExpr &expr) override; + void visit (AST::RangeFromToInclExpr &expr) override; + void visit (AST::RangeToInclExpr &expr) override; + void visit (AST::ReturnExpr &expr) override; + void visit (AST::LoopExpr &expr) override; + void visit (AST::WhileLoopExpr &expr) override; + void visit (AST::WhileLetLoopExpr &expr) override; + void visit (AST::ForLoopExpr &expr) override; + void visit (AST::IfExpr &expr) override; + void visit (AST::IfExprConseqElse &expr) override; + void visit (AST::IfLetExpr &expr) override; + void visit (AST::IfLetExprConseqElse &expr) override; + void visit (AST::MatchExpr &expr) override; + void visit (AST::AwaitExpr &expr) override; + void visit (AST::AsyncBlockExpr &expr) override; // rust-item.h - void visit (AST::TypeParam ¶m); - void visit (AST::LifetimeWhereClauseItem &item); - void visit (AST::TypeBoundWhereClauseItem &item); - void visit (AST::Module &module); - void visit (AST::ExternCrate &crate); - void visit (AST::UseTreeGlob &use_tree); - void visit (AST::UseTreeList &use_tree); - void visit (AST::UseTreeRebind &use_tree); - void visit (AST::UseDeclaration &use_decl); - void visit (AST::Function &function); - void visit (AST::TypeAlias &type_alias); - void visit (AST::StructStruct &struct_item); - void visit (AST::TupleStruct &tuple_struct); - void visit (AST::EnumItem &item); - void visit (AST::EnumItemTuple &item); - void visit (AST::EnumItemStruct &item); - void visit (AST::EnumItemDiscriminant &item); - void visit (AST::Enum &enum_item); - void visit (AST::Union &union_item); - void visit (AST::ConstantItem &const_item); - void visit (AST::StaticItem &static_item); - void visit (AST::TraitItemFunc &item); - void visit (AST::TraitItemMethod &item); - void visit (AST::TraitItemConst &item); - void visit (AST::TraitItemType &item); - void visit (AST::Trait &trait); - void visit (AST::InherentImpl &impl); - void visit (AST::TraitImpl &impl); - void visit (AST::ExternalTypeItem &item); - void visit (AST::ExternalStaticItem &item); - void visit (AST::ExternalFunctionItem &item); - void visit (AST::ExternBlock &block); + void visit (AST::TypeParam ¶m) override; + void visit (AST::LifetimeWhereClauseItem &item) override; + void visit (AST::TypeBoundWhereClauseItem &item) override; + void visit (AST::Module &module) override; + void visit (AST::ExternCrate &crate) override; + void visit (AST::UseTreeGlob &use_tree) override; + void visit (AST::UseTreeList &use_tree) override; + void visit (AST::UseTreeRebind &use_tree) override; + void visit (AST::UseDeclaration &use_decl) override; + void visit (AST::Function &function) override; + void visit (AST::TypeAlias &type_alias) override; + void visit (AST::StructStruct &struct_item) override; + void visit (AST::TupleStruct &tuple_struct) override; + void visit (AST::EnumItem &item) override; + void visit (AST::EnumItemTuple &item) override; + void visit (AST::EnumItemStruct &item) override; + void visit (AST::EnumItemDiscriminant &item) override; + void visit (AST::Enum &enum_item) override; + void visit (AST::Union &union_item) override; + void visit (AST::ConstantItem &const_item) override; + void visit (AST::StaticItem &static_item) override; + void visit (AST::TraitItemFunc &item) override; + void visit (AST::TraitItemMethod &item) override; + 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; + void visit (AST::ExternBlock &block) override; // rust-macro.h - void visit (AST::MacroMatchFragment &match); - void visit (AST::MacroMatchRepetition &match); - void visit (AST::MacroMatcher &matcher); - void visit (AST::MacroRulesDefinition &rules_def); - void visit (AST::MacroInvocation ¯o_invoc); - void visit (AST::MetaItemPath &meta_item); - void visit (AST::MetaItemSeq &meta_item); - void visit (AST::MetaWord &meta_item); - void visit (AST::MetaNameValueStr &meta_item); - void visit (AST::MetaListPaths &meta_item); - void visit (AST::MetaListNameValueStr &meta_item); + void visit (AST::MacroMatchFragment &match) override; + void visit (AST::MacroMatchRepetition &match) override; + void visit (AST::MacroMatcher &matcher) override; + void visit (AST::MacroRulesDefinition &rules_def) override; + void visit (AST::MacroInvocation ¯o_invoc) override; + void visit (AST::MetaItemPath &meta_item) override; + void visit (AST::MetaItemSeq &meta_item) override; + void visit (AST::MetaWord &meta_item) override; + void visit (AST::MetaNameValueStr &meta_item) override; + void visit (AST::MetaListPaths &meta_item) override; + void visit (AST::MetaListNameValueStr &meta_item) override; // rust-pattern.h - void visit (AST::LiteralPattern &pattern); - void visit (AST::IdentifierPattern &pattern); - void visit (AST::WildcardPattern &pattern); - void visit (AST::RestPattern &pattern); - // void visit(RangePatternBound& bound); - void visit (AST::RangePatternBoundLiteral &bound); - void visit (AST::RangePatternBoundPath &bound); - void visit (AST::RangePatternBoundQualPath &bound); - void visit (AST::RangePattern &pattern); - void visit (AST::ReferencePattern &pattern); - // void visit(StructPatternField& field); - void visit (AST::StructPatternFieldTuplePat &field); - void visit (AST::StructPatternFieldIdentPat &field); - void visit (AST::StructPatternFieldIdent &field); - void visit (AST::StructPattern &pattern); - // void visit(TupleStructItems& tuple_items); - void visit (AST::TupleStructItemsNoRange &tuple_items); - void visit (AST::TupleStructItemsRange &tuple_items); - void visit (AST::TupleStructPattern &pattern); - // void visit(TuplePatternItems& tuple_items); - void visit (AST::TuplePatternItemsMultiple &tuple_items); - void visit (AST::TuplePatternItemsRanged &tuple_items); - void visit (AST::TuplePattern &pattern); - void visit (AST::GroupedPattern &pattern); - void visit (AST::SlicePattern &pattern); - void visit (AST::AltPattern &pattern); + void visit (AST::LiteralPattern &pattern) override; + void visit (AST::IdentifierPattern &pattern) override; + void visit (AST::WildcardPattern &pattern) override; + void visit (AST::RestPattern &pattern) override; + // void visit(RangePatternBound& bound) override; + void visit (AST::RangePatternBoundLiteral &bound) override; + void visit (AST::RangePatternBoundPath &bound) override; + void visit (AST::RangePatternBoundQualPath &bound) override; + void visit (AST::RangePattern &pattern) override; + void visit (AST::ReferencePattern &pattern) override; + // void visit(StructPatternField& field) override; + void visit (AST::StructPatternFieldTuplePat &field) override; + void visit (AST::StructPatternFieldIdentPat &field) override; + void visit (AST::StructPatternFieldIdent &field) override; + void visit (AST::StructPattern &pattern) override; + // void visit(TupleStructItems& tuple_items) override; + void visit (AST::TupleStructItemsNoRange &tuple_items) override; + void visit (AST::TupleStructItemsRange &tuple_items) override; + void visit (AST::TupleStructPattern &pattern) override; + // void visit(TuplePatternItems& tuple_items) override; + void visit (AST::TuplePatternItemsMultiple &tuple_items) override; + void visit (AST::TuplePatternItemsRanged &tuple_items) override; + void visit (AST::TuplePattern &pattern) override; + void visit (AST::GroupedPattern &pattern) override; + void visit (AST::SlicePattern &pattern) override; + void visit (AST::AltPattern &pattern) override; // rust-stmt.h - void visit (AST::EmptyStmt &stmt); - void visit (AST::LetStmt &stmt); - void visit (AST::ExprStmt &stmt); + void visit (AST::EmptyStmt &stmt) override; + void visit (AST::LetStmt &stmt) override; + void visit (AST::ExprStmt &stmt) override; // rust-type.h - void visit (AST::TraitBound &bound); - void visit (AST::ImplTraitType &type); - void visit (AST::TraitObjectType &type); - void visit (AST::ParenthesisedType &type); - void visit (AST::ImplTraitTypeOneBound &type); - void visit (AST::TraitObjectTypeOneBound &type); - void visit (AST::TupleType &type); - void visit (AST::NeverType &type); - void visit (AST::RawPointerType &type); - void visit (AST::ReferenceType &type); - void visit (AST::ArrayType &type); - void visit (AST::SliceType &type); - void visit (AST::InferredType &type); - void visit (AST::BareFunctionType &type); - void visit (AST::FunctionParam ¶m); - void visit (AST::VariadicParam ¶m); - void visit (AST::SelfParam ¶m); + void visit (AST::TraitBound &bound) override; + void visit (AST::ImplTraitType &type) override; + void visit (AST::TraitObjectType &type) override; + void visit (AST::ParenthesisedType &type) override; + void visit (AST::ImplTraitTypeOneBound &type) override; + void visit (AST::TraitObjectTypeOneBound &type) override; + void visit (AST::TupleType &type) override; + void visit (AST::NeverType &type) override; + void visit (AST::RawPointerType &type) override; + void visit (AST::ReferenceType &type) override; + void visit (AST::ArrayType &type) override; + void visit (AST::SliceType &type) override; + void visit (AST::InferredType &type) override; + void visit (AST::BareFunctionType &type) override; + void visit (AST::FunctionParam ¶m) override; + void visit (AST::VariadicParam ¶m) override; + void visit (AST::SelfParam ¶m) override; }; } // namespace Analysis