Skip to content

Commit

Permalink
Replace unique_ptr references with references
Browse files Browse the repository at this point in the history
This kind of double indirection is pointless and prone to error. This
commit change the api of all getters from the AST to use references
directly instead of references to unique pointers.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Remove reference
	to unique pointer and replace it with a direct reference to the wrapped
	data.
	* ast/rust-ast.cc (VariadicParam::as_string): Likewise.
	(BlockExpr::normalize_tail_expr): Likewise.
	* ast/rust-expr.h: Likewise and add pointer getter in order to allow
	pointer reseat.
	* ast/rust-item.h: Likewise and add pointer getter for reseat.
	* ast/rust-path.h: Likewise.
	* ast/rust-pattern.h: Likewise.
	* ast/rust-stmt.h: Likewise.
	* ast/rust-type.h: Likewise.
	* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_struct_fields):
	Remove references to unique pointers and replace it with direct
	references to the wrapped object.
	(CfgStrip::maybe_strip_tuple_fields): Likewise.
	(CfgStrip::maybe_strip_generic_args): Likewise.
	(CfgStrip::maybe_strip_qualified_path_type): Likewise.
	(CfgStrip::visit): Likewise.
	* expand/rust-expand-visitor.cc (ExpandVisitor::maybe_expand_expr):
	Likewise.
	(ExpandVisitor::maybe_expand_type): Likewise.
	(ExpandVisitor::visit): Likewise.
	* expand/rust-expand-visitor.h: Likewise.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_binding):
	Likewise.
	(ASTLoweringBase::lower_generic_args): Likewise.
	(ASTLoweringBase::lower_self): Likewise.
	(ASTLoweringBase::lower_type_no_bounds): Likewise.
	(ASTLoweringBase::lower_bound): Likewise.
	(ASTLoweringBase::lower_range_pattern_bound): Likewise.
	* hir/rust-ast-lower-base.h: Likewise.
	* hir/rust-ast-lower-block.h: Likewise.
	* hir/rust-ast-lower-enumitem.h: Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::translate): Likewise.
	(ASTLoweringExpr::visit): Likewise.
	* hir/rust-ast-lower-expr.h: Likewise.
	* hir/rust-ast-lower-extern.h: Likewise.
	* hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::translate):
	Likewise.
	(ASTLowerImplItem::visit): Likewise.
	(ASTLowerTraitItem::translate): Likewise.
	(ASTLowerTraitItem::visit): Likewise.
	* hir/rust-ast-lower-implitem.h: Likewise.
	* hir/rust-ast-lower-item.cc (ASTLoweringItem::translate): Likewise.
	(ASTLoweringItem::visit): Likewise.
	* hir/rust-ast-lower-item.h: Likewise.
	* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate):
	Likewise.
	(ASTLoweringPattern::visit): Likewise.
	* hir/rust-ast-lower-pattern.h: Likewise.
	* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise.
	* hir/rust-ast-lower-struct-field-expr.h: Likewise.
	* hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Likewise.
	(ASTLowerQualifiedPathInType::visit): Likewise.
	(ASTLoweringType::translate): Likewise.
	(ASTLoweringType::visit): Likewise.
	(ASTLowerGenericParam::translate): Likewise.
	(ASTLowerGenericParam::visit): Likewise.
	(ASTLoweringTypeBounds::translate): Likewise.
	(ASTLoweringTypeBounds::visit): Likewise.
	(ASTLowerWhereClauseItem::visit): Likewise.
	* hir/rust-ast-lower-type.h: Likewise.
	* hir/rust-ast-lower.cc (ASTLowering::go): Likewise.
	(ASTLoweringBlock::visit): Likewise.
	(ASTLoweringIfBlock::visit): Likewise.
	(ASTLoweringIfLetBlock::visit): Likewise.
	(ASTLowerStructExprField::visit): Likewise.
	(ASTLoweringExprWithBlock::visit): Likewise.
	(ASTLoweringBase::lower_qual_path_type): Likewise.
	(ASTLoweringBase::lower_closure_param): Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::resolve_visibility):
	Likewise.
	* resolve/rust-ast-resolve-expr.cc (ResolveExpr::go): Likewise.
	(ResolveExpr::visit): Likewise.
	(ResolveExpr::resolve_closure_param): Likewise.
	* resolve/rust-ast-resolve-expr.h: Likewise.
	* resolve/rust-ast-resolve-implitem.h: Likewise.
	* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
	Likewise.
	(ResolveItem::go): Likewise.
	(ResolveItem::visit): Likewise.
	(ResolveItem::resolve_impl_item): Likewise.
	(ResolveItem::resolve_extern_item): Likewise.
	(ResolveImplItems::go): Likewise.
	(ResolveExternItem::go): Likewise.
	(ResolveExternItem::visit): Likewise.
	* resolve/rust-ast-resolve-item.h: Likewise.
	* resolve/rust-ast-resolve-path.cc (ResolvePath::go): Likewise.
	(ResolvePath::resolve_path): Likewise.
	* resolve/rust-ast-resolve-path.h: Likewise.
	* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go):
	Likewise.
	(PatternDeclaration::visit): Likewise.
	(resolve_range_pattern_bound): Likewise.
	* resolve/rust-ast-resolve-pattern.h: Likewise.
	* resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): Likewise.
	* resolve/rust-ast-resolve-stmt.h: Likewise.
	* resolve/rust-ast-resolve-struct-expr-field.cc (ResolveStructExprField::go):
	Likewise.
	(ResolveStructExprField::visit): Likewise.
	* resolve/rust-ast-resolve-struct-expr-field.h: Likewise.
	* resolve/rust-ast-resolve-toplevel.h: Likewise.
	* resolve/rust-ast-resolve-type.cc (ResolveType::visit): Likewise.
	(ResolveRelativeTypePath::go): Likewise.
	(ResolveRelativeQualTypePath::resolve_qual_seg): Likewise.
	(ResolveTypeToCanonicalPath::go): Likewise.
	(ResolveTypeToCanonicalPath::visit): Likewise.
	(ResolveGenericArgs::resolve_disambiguated_generic): Likewise.
	(ResolveGenericArgs::go): Likewise.
	* resolve/rust-ast-resolve-type.h: Likewise.
	* resolve/rust-ast-resolve.cc (NameResolution::go): Likewise.
	* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_qualified_path_type):
	Likewise.
	(EarlyNameResolver::visit): Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Likewise.
	* checks/errors/rust-ast-validation.cc: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P committed Mar 13, 2024
1 parent 843d7d7 commit 75dc005
Show file tree
Hide file tree
Showing 51 changed files with 1,418 additions and 1,207 deletions.
3 changes: 1 addition & 2 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2546,8 +2546,7 @@ TokenCollector::visit (LetStmt &stmt)
{
push (Rust::Token::make (LET, stmt.get_locus ()));
auto &pattern = stmt.get_pattern ();
if (pattern)
visit (pattern);
visit (pattern);

if (stmt.has_type ())
{
Expand Down
4 changes: 2 additions & 2 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ std::string
VariadicParam::as_string () const
{
if (has_pattern ())
return get_pattern ()->as_string () + " : ...";
return get_pattern ().as_string () + " : ...";
else
return "...";
}
Expand Down Expand Up @@ -4258,7 +4258,7 @@ BlockExpr::normalize_tail_expr ()

if (!stmt.is_semicolon_followed ())
{
expr = std::move (stmt.get_expr ());
expr = std::move (stmt.take_expr ());
statements.pop_back ();
}
}
Expand Down
Loading

0 comments on commit 75dc005

Please sign in to comment.