Skip to content

Commit

Permalink
borrowck: Implement method translation to BIR.
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
	Implement function.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
  • Loading branch information
braw-lee committed Apr 6, 2024
1 parent ff196e4 commit 02636bc
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,46 @@ ExprStmtBuilder::visit (HIR::CallExpr &expr)

void
ExprStmtBuilder::visit (HIR::MethodCallExpr &expr)
{}
{
// TODO : need ExprStmtBuilder::visit_expr (HIR::PathExprSegment)
PlaceId fn = visit_expr (expr.get_method_name ());

std::vector<PlaceId> arguments = visit_list (expr.get_arguments ());

const auto fn_type = ctx.place_db[fn].tyty->as<const TyTy::FnType> ();

// compile `self` and handle autoref
PlaceId self = visit_expr (*expr.get_receiver ());
auto ty = ctx.place_db[self].tyty;
if (ty->get_kind () == TyTy::REF)
{
if (ty->as<TyTy::ReferenceType> ()->is_mutable ())
self
= borrow_place (self,
new TyTy::ReferenceType (ty->get_ref (),
TyTy::TyVar (ty->get_ref ()),
Mutability::Mut));
else
self
= borrow_place (self,
new TyTy::ReferenceType (ty->get_ref (),
TyTy::TyVar (ty->get_ref ()),
Mutability::Imm));
}

arguments.insert (arguments.begin (), self);

// skip the first parameter i.e `self`
for (size_t i = 1; i < fn_type->get_num_params (); ++i)
{
coercion_site (arguments[i], fn_type->get_param_type_at (i));
}

move_all (arguments);

return_expr (new CallExpr (fn, std::move (arguments)), lookup_type (expr),
true);
}

void
ExprStmtBuilder::visit (HIR::FieldAccessExpr &expr)
Expand Down

0 comments on commit 02636bc

Please sign in to comment.