From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id B51ED3858D33; Mon, 16 Jan 2023 08:17:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B51ED3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673857051; bh=ShUMbWF9dFDShIYdmK8BfJdp7QDC8L+LhMvC40KDfkw=; h=From:To:Subject:Date:From; b=xse+KeQ5UjjXdYZB06MULKopXeJlBwoSEKnKj2nlEIamvIcA5Y+AMVgj4HhX6p6oM y6f+8wELcqmB5io0YocOrE+FmL13lfCs76caUDYy5MYwV1vEliadtqmrwHahxdKqz9 hhMm2+JG/uDAz+Ow51nJ4McWiDC/23xUG0gmaLOI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Change how CompileVarDecl outputs Bvariable's X-Act-Checkin: gcc X-Git-Author: Owen Avery X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 59cbecb75d3fd270094c2008343bf86f0c3bf80d X-Git-Newrev: dc31146d6392c620a31b0f3e3625224ca4afb3cd Message-Id: <20230116081731.B51ED3858D33@sourceware.org> Date: Mon, 16 Jan 2023 08:17:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:dc31146d6392c620a31b0f3e3625224ca4afb3cd commit dc31146d6392c620a31b0f3e3625224ca4afb3cd Author: Owen Avery Date: Wed Jan 11 12:05:39 2023 -0500 Change how CompileVarDecl outputs Bvariable's This allows patterns to declare multiple/no variables Signed-off-by: Owen Avery Diff: --- gcc/rust/backend/rust-compile-base.cc | 4 +--- gcc/rust/backend/rust-compile-var-decl.h | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index a5643d2f625..5e7ab3195c3 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -457,9 +457,7 @@ HIRCompileBase::compile_locals_for_block (Context *ctx, Resolver::Rib &rib, // compile the local tree type = TyTyResolveCompile::compile (ctx, tyty); - Bvariable *compiled - = CompileVarDecl::compile (fndecl, type, pattern, ctx); - locals.push_back (compiled); + CompileVarDecl::compile (fndecl, type, pattern, locals, ctx); } return locals; } diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h index e2ee05b8163..a1dee2d770b 100644 --- a/gcc/rust/backend/rust-compile-var-decl.h +++ b/gcc/rust/backend/rust-compile-var-decl.h @@ -30,12 +30,11 @@ class CompileVarDecl : public HIRCompileBase, public HIR::HIRPatternVisitor using HIR::HIRPatternVisitor::visit; public: - static ::Bvariable *compile (tree fndecl, tree translated_type, - HIR::Pattern *pattern, Context *ctx) + static void compile (tree fndecl, tree translated_type, HIR::Pattern *pattern, + std::vector &locals, Context *ctx) { - CompileVarDecl compiler (ctx, fndecl, translated_type); + CompileVarDecl compiler (ctx, fndecl, translated_type, locals); pattern->accept_vis (compiler); - return compiler.compiled_variable; } void visit (HIR::IdentifierPattern &pattern) override @@ -43,26 +42,30 @@ public: if (!pattern.is_mut ()) translated_type = ctx->get_backend ()->immutable_type (translated_type); - compiled_variable + Bvariable *var = ctx->get_backend ()->local_variable (fndecl, pattern.get_identifier (), translated_type, NULL /*decl_var*/, pattern.get_locus ()); HirId stmt_id = pattern.get_pattern_mappings ().get_hirid (); - ctx->insert_var_decl (stmt_id, compiled_variable); + ctx->insert_var_decl (stmt_id, var); + + locals.push_back (var); } void visit (HIR::WildcardPattern &pattern) override { translated_type = ctx->get_backend ()->immutable_type (translated_type); - compiled_variable + Bvariable *var = ctx->get_backend ()->local_variable (fndecl, "_", translated_type, NULL /*decl_var*/, pattern.get_locus ()); HirId stmt_id = pattern.get_pattern_mappings ().get_hirid (); - ctx->insert_var_decl (stmt_id, compiled_variable); + ctx->insert_var_decl (stmt_id, var); + + locals.push_back (var); } // Empty visit for unused Pattern HIR nodes. @@ -78,15 +81,16 @@ public: void visit (HIR::TupleStructPattern &) override {} private: - CompileVarDecl (Context *ctx, tree fndecl, tree translated_type) + CompileVarDecl (Context *ctx, tree fndecl, tree translated_type, + std::vector &locals) : HIRCompileBase (ctx), fndecl (fndecl), translated_type (translated_type), - compiled_variable (ctx->get_backend ()->error_variable ()) + locals (locals) {} tree fndecl; tree translated_type; - Bvariable *compiled_variable; + std::vector &locals; }; } // namespace Compile