Skip to content

Commit

Permalink
Change cfg stripper to use default visitor
Browse files Browse the repository at this point in the history
Cfg visitor used it's own visit patterns, this made the code longer than
required.

gcc/rust/ChangeLog:

	* expand/rust-cfg-strip.cc (CfgStrip::visit): Change calls from visitor
	to default visitor.
	(CfgStrip::go): Add call to visit crate.
	* expand/rust-cfg-strip.h (class CfgStrip): Update prototypes and
	remove empty ones.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Dec 12, 2023
1 parent 61d4955 commit b402748
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 576 deletions.
30 changes: 20 additions & 10 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,8 @@ DefaultASTVisitor::visit (AST::Function &function)
visit (param);
if (function.has_return_type ())
visit (function.get_return_type ());
visit (function.get_where_clause ());
if (function.has_where_clause ())
visit (function.get_where_clause ());
if (function.has_body ())
visit (*function.get_definition ());
}
Expand All @@ -788,7 +789,8 @@ DefaultASTVisitor::visit (AST::TypeAlias &type_alias)
visit (type_alias.get_visibility ());
for (auto &generic : type_alias.get_generic_params ())
visit (generic);
visit (type_alias.get_where_clause ());
if (type_alias.has_where_clause ())
visit (type_alias.get_where_clause ());
visit (type_alias.get_type_aliased ());
}

Expand All @@ -807,7 +809,8 @@ DefaultASTVisitor::visit (AST::StructStruct &struct_item)
visit (struct_item.get_visibility ());
for (auto &generic : struct_item.get_generic_params ())
visit (generic);
visit (struct_item.get_where_clause ());
if (struct_item.has_where_clause ())
visit (struct_item.get_where_clause ());
for (auto &field : struct_item.get_fields ())
visit (field);
}
Expand All @@ -827,7 +830,8 @@ DefaultASTVisitor::visit (AST::TupleStruct &tuple_struct)
visit (tuple_struct.get_visibility ());
for (auto &generic : tuple_struct.get_generic_params ())
visit (generic);
visit (tuple_struct.get_where_clause ());
if (tuple_struct.has_where_clause ())
visit (tuple_struct.get_where_clause ());
for (auto &field : tuple_struct.get_fields ())
visit (field);
}
Expand Down Expand Up @@ -869,7 +873,8 @@ DefaultASTVisitor::visit (AST::Enum &enum_item)
visit (enum_item.get_visibility ());
for (auto &generic : enum_item.get_generic_params ())
visit (generic);
visit (enum_item.get_where_clause ());
if (enum_item.has_where_clause ())
visit (enum_item.get_where_clause ());
for (auto &item : enum_item.get_variants ())
visit (item);
}
Expand All @@ -881,7 +886,8 @@ DefaultASTVisitor::visit (AST::Union &union_item)
visit (union_item.get_visibility ());
for (auto &generic : union_item.get_generic_params ())
visit (generic);
visit (union_item.get_where_clause ());
if (union_item.has_where_clause ())
visit (union_item.get_where_clause ());
for (auto &variant : union_item.get_variants ())
visit (variant);
}
Expand Down Expand Up @@ -978,7 +984,8 @@ DefaultASTVisitor::visit (AST::Trait &trait)
for (auto &generic : trait.get_generic_params ())
visit (generic);

visit (trait.get_where_clause ());
if (trait.has_where_clause ())
visit (trait.get_where_clause ());

for (auto &bound : trait.get_type_param_bounds ())
visit (bound);
Expand All @@ -995,7 +1002,8 @@ DefaultASTVisitor::visit (AST::InherentImpl &impl)

for (auto &generic : impl.get_generic_params ())
visit (generic);
visit (impl.get_where_clause ());
if (impl.has_where_clause ())
visit (impl.get_where_clause ());
visit (impl.get_type ());
visit_inner_attrs (impl);
for (auto &item : impl.get_impl_items ())
Expand All @@ -1010,7 +1018,8 @@ DefaultASTVisitor::visit (AST::TraitImpl &impl)

for (auto &generic : impl.get_generic_params ())
visit (generic);
visit (impl.get_where_clause ());
if (impl.has_where_clause ())
visit (impl.get_where_clause ());
visit (impl.get_type ());
visit_inner_attrs (impl);
for (auto &item : impl.get_impl_items ())
Expand Down Expand Up @@ -1048,7 +1057,8 @@ DefaultASTVisitor::visit (AST::ExternalFunctionItem &item)
for (auto &generic : item.get_generic_params ())
visit (generic);

visit (item.get_where_clause ());
if (item.has_where_clause ())
visit (item.get_where_clause ());

for (auto &param : item.get_function_params ())
visit (param);
Expand Down
Loading

0 comments on commit b402748

Please sign in to comment.