From d123f43e42f623dfd7dbe63f484197a99ea7f9ed Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 8 Mar 2024 14:42:10 +0100 Subject: gccrs: Refactor HIR with optionals, references & newtypes The HIR made heavy use of pair and other unamed types which can be difficult to read. gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Use FnParam getter. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-intrinsic.cc: Likewise. * backend/rust-compile-type.cc: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Only visit childrens if not missing. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use a reference instead of a raw pointer. * hir/tree/rust-hir-expr.h: Add presence function for return expression. * hir/tree/rust-hir-item.h: Remove take_param_name. * hir/tree/rust-hir.h: Make mapping getter const. * typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use getter. * typecheck/rust-hir-type-check-expr.cc: Likewise. * typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector instead of std::pair of Pattern and BaseType. * typecheck/rust-hir-type-check-item.cc: Likewise. * typecheck/rust-hir-type-check.cc: Likewise. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use getters. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-cmp.h: Likewise. * typecheck/rust-tyty.cc: Use FnParam. * typecheck/rust-tyty.h (class FnParam): Add FnParam to handle function parameters instead of handling std::pairs. * typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters. (UnifyRules::expect_fnptr): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/backend/rust-compile-expr.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/rust/backend/rust-compile-expr.cc') diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index c46bda9..107ca2e 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1267,7 +1267,7 @@ CompileExpr::visit (HIR::CallExpr &expr) const TyTy::FnType *fn = static_cast (base); auto ¶m = fn->param_at (index); - *result = param.second; + *result = param.get_type (); return true; }; @@ -1401,7 +1401,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) // assignments are coercion sites so lets convert the rvalue if // necessary, offset from the already adjusted implicit self bool ok; - TyTy::BaseType *expected = fntype->param_at (i + 1).second; + TyTy::BaseType *expected = fntype->param_at (i + 1).get_type (); TyTy::BaseType *actual = nullptr; ok = ctx->get_tyctx ()->lookup_type ( -- cgit v1.1