Skip to content

Commit 4c81795

Browse files
Pasta-coderP-E-P
authored andcommitted
ast: Add qualified_call helper to Builder
This patch implements the `qualified_call` helper method in the `Builder` class. This logic was previously intended to be a local helper in `DeriveClone`, but moving it to the `Builder` allows it to be reused across the compiler for constructing qualified function calls. It updates `DeriveClone::clone_call` to use this new `Builder` method, simplifying the code and resolving the TODO. Fixes #4393 gcc/rust/ChangeLog: * ast/rust-ast-builder.h (Builder::qualified_call): New method declaration. * ast/rust-ast-builder.cc (Builder::qualified_call): Implement new method. * expand/rust-derive-clone.cc (DeriveClone::clone_call): Use builder.qualified_call. Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
1 parent cb12ae0 commit 4c81795

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

gcc/rust/ast/rust-ast-builder.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,15 @@ Builder::new_generic_args (GenericArgs &args)
737737
std::move (binding_args), locus);
738738
}
739739

740+
std::unique_ptr<Expr>
741+
Builder::qualified_call (std::vector<std::string> &&segments,
742+
std::vector<std::unique_ptr<Expr>> &&args) const
743+
{
744+
auto path = std::unique_ptr<Expr> (
745+
new PathInExpression (path_in_expression (std::move (segments))));
746+
747+
return call (std::move (path), std::move (args));
748+
}
749+
740750
} // namespace AST
741751
} // namespace Rust

gcc/rust/ast/rust-ast-builder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ class Builder
169169
std::vector<PathExprSegment> &&segments
170170
= {}) const;
171171

172+
std::unique_ptr<Expr>
173+
qualified_call (std::vector<std::string> &&segments,
174+
std::vector<std::unique_ptr<Expr>> &&args) const;
175+
172176
/* Self parameter for a function definition (`&self`) */
173177
std::unique_ptr<Param> self_ref_param (bool mutability = false) const;
174178
/* A regular named function parameter for a definition (`a: type`) */

gcc/rust/expand/rust-derive-clone.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ DeriveClone::clone_call (std::unique_ptr<Expr> &&to_clone)
4242

4343
// Not sure how to call it properly in the meantime...
4444

45-
auto path = std::unique_ptr<Expr> (
46-
new PathInExpression (builder.path_in_expression ({"Clone", "clone"})));
47-
4845
auto args = std::vector<std::unique_ptr<Expr>> ();
4946
args.emplace_back (std::move (to_clone));
5047

51-
return builder.call (std::move (path), std::move (args));
48+
return builder.qualified_call ({"Clone", "clone"}, std::move (args));
5249
}
5350

5451
/**
@@ -104,8 +101,6 @@ DeriveClone::clone_impl (
104101
std::move (generics.impl));
105102
}
106103

107-
// TODO: Create new `make_qualified_call` helper function
108-
109104
DeriveClone::DeriveClone (location_t loc)
110105
: DeriveVisitor (loc), expanded (nullptr)
111106
{}

0 commit comments

Comments
 (0)