Skip to content

Commit d6f6955

Browse files
powerboat9dkm
authored andcommitted
Specialize ExpandVisitor::expand_macro_children
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_items): Adjust call to expand_macro_children. (ExpandVisitor::expand_inner_stmts): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::expand_macro_children): Take a pointer to member function instead of a std::function. Signed-off-by: Owen Avery <[email protected]>
1 parent 9526906 commit d6f6955

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

gcc/rust/expand/rust-expand-visitor.cc

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ ExpandVisitor::expand_inner_items (
233233
}
234234
}
235235

236-
std::function<std::unique_ptr<AST::Item> (AST::SingleASTNode)> extractor
237-
= [] (AST::SingleASTNode node) { return node.take_item (); };
238-
239-
expand_macro_children (items, extractor);
236+
expand_macro_children (items, &AST::SingleASTNode::take_item);
240237

241238
expander.pop_context ();
242239
}
@@ -324,10 +321,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr)
324321
if (!expr.has_tail_expr ())
325322
expr.normalize_tail_expr ();
326323

327-
std::function<std::unique_ptr<AST::Stmt> (AST::SingleASTNode)> extractor
328-
= [] (AST::SingleASTNode node) { return node.take_stmt (); };
329-
330-
expand_macro_children (stmts, extractor);
324+
expand_macro_children (stmts, &AST::SingleASTNode::take_stmt);
331325

332326
expander.pop_context ();
333327
}
@@ -866,12 +860,9 @@ ExpandVisitor::visit (AST::Trait &trait)
866860

867861
expander.push_context (MacroExpander::ContextType::TRAIT);
868862

869-
std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
870-
extractor
871-
= [] (AST::SingleASTNode node) { return node.take_assoc_item (); };
872-
873863
expand_macro_children (MacroExpander::ContextType::TRAIT,
874-
trait.get_trait_items (), extractor);
864+
trait.get_trait_items (),
865+
&AST::SingleASTNode::take_assoc_item);
875866

876867
expander.pop_context ();
877868
}
@@ -894,12 +885,9 @@ ExpandVisitor::visit (AST::InherentImpl &impl)
894885
if (impl.has_where_clause ())
895886
expand_where_clause (impl.get_where_clause ());
896887

897-
std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
898-
extractor
899-
= [] (AST::SingleASTNode node) { return node.take_assoc_item (); };
900-
901888
expand_macro_children (MacroExpander::ContextType::IMPL,
902-
impl.get_impl_items (), extractor);
889+
impl.get_impl_items (),
890+
&AST::SingleASTNode::take_assoc_item);
903891
}
904892

905893
void
@@ -922,12 +910,9 @@ ExpandVisitor::visit (AST::TraitImpl &impl)
922910
if (impl.has_where_clause ())
923911
expand_where_clause (impl.get_where_clause ());
924912

925-
std::function<std::unique_ptr<AST::AssociatedItem> (AST::SingleASTNode)>
926-
extractor
927-
= [] (AST::SingleASTNode node) { return node.take_assoc_item (); };
928-
929913
expand_macro_children (MacroExpander::ContextType::TRAIT_IMPL,
930-
impl.get_impl_items (), extractor);
914+
impl.get_impl_items (),
915+
&AST::SingleASTNode::take_assoc_item);
931916
}
932917

933918
void
@@ -944,12 +929,10 @@ void
944929
ExpandVisitor::visit (AST::ExternBlock &block)
945930
{
946931
visit_inner_attrs (block);
947-
std::function<std::unique_ptr<AST::ExternalItem> (AST::SingleASTNode)>
948-
extractor
949-
= [] (AST::SingleASTNode node) { return node.take_external_item (); };
950932

951933
expand_macro_children (MacroExpander::ContextType::EXTERN,
952-
block.get_extern_items (), extractor);
934+
block.get_extern_items (),
935+
&AST::SingleASTNode::take_external_item);
953936
}
954937

955938
void

gcc/rust/expand/rust-expand-visitor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ExpandVisitor : public AST::DefaultASTVisitor
105105
*/
106106
template <typename T, typename U>
107107
void expand_macro_children (MacroExpander::ContextType ctx, T &values,
108-
std::function<U (AST::SingleASTNode)> extractor)
108+
U (AST::SingleASTNode::*extractor) (void))
109109
{
110110
expander.push_context (ctx);
111111

@@ -121,7 +121,7 @@ class ExpandVisitor : public AST::DefaultASTVisitor
121121
*/
122122
template <typename T, typename U>
123123
void expand_macro_children (T &values,
124-
std::function<U (AST::SingleASTNode)> extractor)
124+
U (AST::SingleASTNode::*extractor) (void))
125125
{
126126
for (auto it = values.begin (); it != values.end ();)
127127
{
@@ -138,7 +138,7 @@ class ExpandVisitor : public AST::DefaultASTVisitor
138138
it = values.erase (it);
139139
for (auto &node : final_fragment.get_nodes ())
140140
{
141-
U new_node = extractor (node);
141+
U new_node = (node.*extractor) ();
142142
if (new_node != nullptr)
143143
{
144144
it = values.insert (it, std::move (new_node));

0 commit comments

Comments
 (0)