Skip to content

Commit c57cf83

Browse files
Pasta-coderCohenArthur
authored andcommitted
expand: Refactor field expansion and add documentation
This patch refactors and in to use a common template helper , reducing code duplication as requested by the FIXME. It also adds missing documentation for . gcc/rust/ChangeLog: * expand/rust-expand-visitor.h (expand_closure_params): Add documentation. (expand_fields): New private template helper. * expand/rust-expand-visitor.cc (expand_struct_fields): Use helper. (expand_tuple_fields): Use helper. Signed-off-by: Jayant Chauhan <[email protected]>
1 parent c9980b8 commit c57cf83

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,16 @@ ExpandVisitor::maybe_expand_pattern (std::unique_ptr<AST::Pattern> &pattern)
404404
pattern = final_fragment.take_pattern_fragment ();
405405
}
406406

407-
// FIXME: Can this be refactored into a `scoped` method? Which takes a
408-
// ContextType as parameter and a lambda? And maybe just an std::vector<T>&?
409407
void
410408
ExpandVisitor::expand_struct_fields (std::vector<AST::StructField> &fields)
411409
{
412-
for (auto &field : fields)
413-
{
414-
maybe_expand_type (field.get_field_type_ptr ());
415-
}
410+
expand_fields (fields);
416411
}
417412

418413
void
419414
ExpandVisitor::expand_tuple_fields (std::vector<AST::TupleField> &fields)
420415
{
421-
for (auto &field : fields)
422-
maybe_expand_type (field.get_field_type_ptr ());
416+
expand_fields (fields);
423417
}
424418

425419
// FIXME: This can definitely be refactored with the method above

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ class ExpandVisitor : public AST::PointerVisitor
105105
*/
106106
void expand_qualified_path_type (AST::QualifiedPathType &path_type);
107107

108-
// FIXME: Add documentation
108+
/**
109+
* Expand all macro invocations in lieu of types within a list of closure
110+
* parameters
111+
*/
109112
void expand_closure_params (std::vector<AST::ClosureParam> &params);
110113
void expand_where_clause (AST::WhereClause &where_clause);
111114

@@ -315,6 +318,16 @@ class ExpandVisitor : public AST::PointerVisitor
315318
private:
316319
MacroExpander &expander;
317320
NodeId macro_invoc_expect_id;
321+
322+
/**
323+
* Helper to expand all macro invocations in lieu of types within a vector of
324+
* fields (StructField or TupleField).
325+
*/
326+
template <typename T> void expand_fields (std::vector<T> &fields)
327+
{
328+
for (auto &field : fields)
329+
maybe_expand_type (field.get_field_type_ptr ());
330+
}
318331
};
319332

320333
} // namespace Rust

0 commit comments

Comments
 (0)