From 265d8555fe3ad38755e64a6b9880521c7f3a3cc7 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Wed, 15 Mar 2023 16:35:47 -0400 Subject: gccrs: Unify HIR::IfExprConseqIf{,Let} into HIR::IfExprConseqElse This should simplify 'if' expression handling to match future simplifications to 'if let' expression handling. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Remove IfExprConseqIf visitor. * typecheck/rust-hir-type-check-expr.h (TypeCheckExpr::visit): Remove IfExprConseqIf{,Let} visitor. * backend/rust-compile-block.cc (CompileConditionalBlocks::visit): Remove IfExprConseqIf visitor. * backend/rust-compile-block.h (CompileConditionalBlocks::visit): Remove IfExprConseqIf{,Let} visitors. (CompileExprWithBlock::visit): Remove IfExprConseqIf{,Let} visitors, implement BlockExpr visitor. * backend/rust-compile-expr.cc (CompileExpr::visit): Remove IfExprConseqIf visitor. * backend/rust-compile-expr.h (CompileExpr::visit): Remove IfExprConseqIf{,Let} visitors. * checks/lints/rust-lint-marklive.h (MarkLive::visit): Remove IfExprConseqIf visitor. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/rust-const-checker.h (ConstChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/rust-unsafe-checker.h (UnsafeChecker::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Remove IfExprConseqIf{,Let} visitors. * checks/errors/privacy/rust-privacy-reporter.h (PrivacyReporter::visit): Remove IfExprConseqIf{,Let} visitors. * hir/tree/rust-hir-expr.h (class IfExprConseqElse): Make else_block ExprWithBlock. (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * hir/tree/rust-hir-full-decls.h (class IfExprConseqIf): Remove. (class IfExprConseqIfLet): Remove. * hir/tree/rust-hir.cc (IfExprConseqElse::as_string): Adjust output. (IfExprConseqIf::as_string): Remove. (IfExprConseqIfLet::as_string): Remove. (IfExprConseqIf::accept_vis): Remove. (IfExprConseqIfLet::accept_vis): Remove. * hir/tree/rust-hir-visitor.h (HIRFullVisitor::visit): Remove IfExprConseqIf{,Let} visitors. (HIRFullVisitorBase::visit): Remove IfExprConseqIf{,Let} visitors. (HIRExpressionVisitor::visit): Remove IfExprConseqIf{,Let} visitors. * hir/rust-hir-dump.cc (Dump::visit): Remove IfExprConseqIf{,Let} visitors. * hir/rust-hir-dump.h (Dump::visit): Remove IfExprConseqIf{,Let} visitors. * hir/rust-ast-lower.cc (ASTLoweringIfBlock::visit): Replace HIR::IfExprConseqIf with HIR::IfExprConseqElse. Signed-off-by: Owen Avery --- gcc/rust/backend/rust-compile-expr.cc | 37 ----------------------------------- 1 file changed, 37 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 e138e41..962135b 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -345,43 +345,6 @@ CompileExpr::visit (HIR::IfExprConseqElse &expr) } void -CompileExpr::visit (HIR::IfExprConseqIf &expr) -{ - TyTy::BaseType *if_type = nullptr; - if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), - &if_type)) - { - rust_error_at (expr.get_locus (), - "failed to lookup type of IfExprConseqElse"); - return; - } - - Bvariable *tmp = NULL; - bool needs_temp = !if_type->is_unit (); - if (needs_temp) - { - fncontext fnctx = ctx->peek_fn (); - tree enclosing_scope = ctx->peek_enclosing_scope (); - tree block_type = TyTyResolveCompile::compile (ctx, if_type); - - bool is_address_taken = false; - tree ret_var_stmt = nullptr; - tmp = ctx->get_backend ()->temporary_variable ( - fnctx.fndecl, enclosing_scope, block_type, NULL, is_address_taken, - expr.get_locus (), &ret_var_stmt); - ctx->add_statement (ret_var_stmt); - } - - auto stmt = CompileConditionalBlocks::compile (&expr, ctx, tmp); - ctx->add_statement (stmt); - - if (tmp != NULL) - { - translated = ctx->get_backend ()->var_expression (tmp, expr.get_locus ()); - } -} - -void CompileExpr::visit (HIR::BlockExpr &expr) { TyTy::BaseType *block_tyty = nullptr; -- cgit v1.1