diff options
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 23 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 16 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.cc | 6 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 42 |
4 files changed, 39 insertions, 48 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index d6c6066..d1fd064 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -224,12 +224,12 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) std::vector<Bexpression *> args; args.push_back (self_argument); - expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool { - Bexpression *compiled_expr = CompileExpr::Compile (p, ctx); - rust_assert (compiled_expr != nullptr); - args.push_back (compiled_expr); - return true; - }); + for (auto &argument : expr.get_arguments ()) + { + Bexpression *compiled_expr + = CompileExpr::Compile (argument.get (), ctx); + args.push_back (compiled_expr); + } Bexpression *fn_expr = ctx->get_backend ()->var_expression (fn_convert_expr_tmp, @@ -414,12 +414,11 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) args.push_back (self); // normal args - expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool { - Bexpression *compiled_expr = CompileExpr::Compile (p, ctx); - rust_assert (compiled_expr != nullptr); - args.push_back (compiled_expr); - return true; - }); + for (auto &argument : expr.get_arguments ()) + { + Bexpression *compiled_expr = CompileExpr::Compile (argument.get (), ctx); + args.push_back (compiled_expr); + } auto fncontext = ctx->peek_fn (); translated diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index d66640d..1d8af6b 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -1725,21 +1725,13 @@ public: PathExprSegment get_method_name () const { return method_name; }; - std::vector<std::unique_ptr<Expr> > &get_params () { return params; } - const std::vector<std::unique_ptr<Expr> > &get_params () const - { - return params; - } - size_t num_params () const { return params.size (); } - void iterate_params (std::function<bool (Expr *)> cb) + std::vector<std::unique_ptr<Expr> > &get_arguments () { return params; } + + const std::vector<std::unique_ptr<Expr> > &get_arguments () const { - for (auto ¶m : params) - { - if (!cb (param.get ())) - return; - } + return params; } protected: diff --git a/gcc/rust/lint/rust-lint-marklive.cc b/gcc/rust/lint/rust-lint-marklive.cc index 0871291..4b095ab4 100644 --- a/gcc/rust/lint/rust-lint-marklive.cc +++ b/gcc/rust/lint/rust-lint-marklive.cc @@ -149,10 +149,8 @@ MarkLive::visit (HIR::MethodCallExpr &expr) { expr.get_receiver ()->accept_vis (*this); visit_path_segment (expr.get_method_name ()); - expr.iterate_params ([&] (HIR::Expr *param) -> bool { - param->accept_vis (*this); - return true; - }); + for (auto &argument : expr.get_arguments ()) + argument->accept_vis (*this); // Trying to find the method definition and mark it alive. NodeId ast_node_id = expr.get_mappings ().get_nodeid (); diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 8de9d9d..64eab30 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -2561,29 +2561,31 @@ TypeCheckMethodCallExpr::visit (FnType &type) } size_t i = 1; - call.iterate_params ([&] (HIR::Expr *param) mutable -> bool { - auto fnparam = type.param_at (i); - auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false); - if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at (param->get_locus (), - "failed to resolve type for argument expr in CallExpr"); - return false; - } + for (auto &argument : call.get_arguments ()) + { + auto fnparam = type.param_at (i); + auto argument_expr_tyty + = Resolver::TypeCheckExpr::Resolve (argument.get (), false); + if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at ( + argument->get_locus (), + "failed to resolve type for argument expr in CallExpr"); + return; + } - auto resolved_argument_type = fnparam.second->coerce (argument_expr_tyty); - if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) - { - rust_error_at (param->get_locus (), - "Type Resolution failure on parameter"); - return false; - } + auto resolved_argument_type = fnparam.second->coerce (argument_expr_tyty); + if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) + { + rust_error_at (argument->get_locus (), + "Type Resolution failure on parameter"); + return; + } - context->insert_type (param->get_mappings (), resolved_argument_type); + context->insert_type (argument->get_mappings (), resolved_argument_type); - i++; - return true; - }); + i++; + } if (i != num_args_to_call) { |