Skip to content

Commit 08b8316

Browse files
Remove iterate_params from AST::CallExpr and AST::MethodCallExpr
These lambda iterators are removed because they make working with IR more complex. Instead, we are using the get_params () to access the parameters with the help of a for loop. Fixes #722 #723 Signed-off-by: Nirmal Patel <[email protected]>
1 parent e28c43f commit 08b8316

File tree

3 files changed

+19
-36
lines changed

3 files changed

+19
-36
lines changed

gcc/rust/ast/rust-expr.h

-18
Original file line numberDiff line numberDiff line change
@@ -1916,15 +1916,6 @@ class CallExpr : public ExprWithoutBlock
19161916
void mark_for_strip () override { function = nullptr; }
19171917
bool is_marked_for_strip () const override { return function == nullptr; }
19181918

1919-
void iterate_params (std::function<bool (Expr *)> cb)
1920-
{
1921-
for (auto &param : params)
1922-
{
1923-
if (!cb (param.get ()))
1924-
return;
1925-
}
1926-
}
1927-
19281919
// TODO: this mutable getter seems really dodgy. Think up better way.
19291920
const std::vector<std::unique_ptr<Expr> > &get_params () const
19301921
{
@@ -2025,15 +2016,6 @@ class MethodCallExpr : public ExprWithoutBlock
20252016
void mark_for_strip () override { receiver = nullptr; }
20262017
bool is_marked_for_strip () const override { return receiver == nullptr; }
20272018

2028-
void iterate_params (std::function<bool (Expr *)> cb)
2029-
{
2030-
for (auto &param : params)
2031-
{
2032-
if (!cb (param.get ()))
2033-
return;
2034-
}
2035-
}
2036-
20372019
// TODO: this mutable getter seems really dodgy. Think up better way.
20382020
const std::vector<std::unique_ptr<Expr> > &get_params () const
20392021
{

gcc/rust/hir/rust-ast-lower-expr.h

+13-10
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,14 @@ class ASTLoweringExpr : public ASTLoweringBase
192192
{
193193
HIR::Expr *func
194194
= ASTLoweringExpr::translate (expr.get_function_expr ().get ());
195+
196+
auto const &in_params = expr.get_params ();
195197
std::vector<std::unique_ptr<HIR::Expr> > params;
196-
expr.iterate_params ([&] (AST::Expr *p) mutable -> bool {
197-
auto trans = ASTLoweringExpr::translate (p);
198-
params.push_back (std::unique_ptr<HIR::Expr> (trans));
199-
return true;
200-
});
198+
for (auto &param : in_params)
199+
{
200+
auto trans = ASTLoweringExpr::translate (param.get ());
201+
params.push_back (std::unique_ptr<HIR::Expr> (trans));
202+
}
201203

202204
auto crate_num = mappings->get_current_crate ();
203205
Analysis::NodeMapping mapping (
@@ -217,12 +219,13 @@ class ASTLoweringExpr : public ASTLoweringBase
217219
HIR::Expr *receiver
218220
= ASTLoweringExpr::translate (expr.get_receiver_expr ().get ());
219221

222+
auto const &in_params = expr.get_params ();
220223
std::vector<std::unique_ptr<HIR::Expr> > params;
221-
expr.iterate_params ([&] (AST::Expr *p) mutable -> bool {
222-
auto trans = ASTLoweringExpr::translate (p);
223-
params.push_back (std::unique_ptr<HIR::Expr> (trans));
224-
return true;
225-
});
224+
for (auto &param : in_params)
225+
{
226+
auto trans = ASTLoweringExpr::translate (param.get ());
227+
params.push_back (std::unique_ptr<HIR::Expr> (trans));
228+
}
226229

227230
auto crate_num = mappings->get_current_crate ();
228231
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),

gcc/rust/resolve/rust-ast-resolve-expr.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ class ResolveExpr : public ResolverBase
101101
void visit (AST::CallExpr &expr) override
102102
{
103103
ResolveExpr::go (expr.get_function_expr ().get (), expr.get_node_id ());
104-
expr.iterate_params ([&] (AST::Expr *p) mutable -> bool {
105-
ResolveExpr::go (p, expr.get_node_id ());
106-
return true;
107-
});
104+
auto const &in_params = expr.get_params ();
105+
for (auto &param : in_params)
106+
ResolveExpr::go (param.get (), expr.get_node_id ());
108107
}
109108

110109
void visit (AST::MethodCallExpr &expr) override
@@ -117,10 +116,9 @@ class ResolveExpr : public ResolverBase
117116
ResolveTypeToCanonicalPath::type_resolve_generic_args (args);
118117
}
119118

120-
expr.iterate_params ([&] (AST::Expr *p) mutable -> bool {
121-
ResolveExpr::go (p, expr.get_node_id ());
122-
return true;
123-
});
119+
auto const &in_params = expr.get_params ();
120+
for (auto &param : in_params)
121+
ResolveExpr::go (param.get (), expr.get_node_id ());
124122
}
125123

126124
void visit (AST::AssignmentExpr &expr) override

0 commit comments

Comments
 (0)