diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-01-30 23:46:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-30 23:46:48 +0000 |
commit | d0dad09f5de7ddcb52b825b5d3cd4f1aee16f982 (patch) | |
tree | 131d1a073723e60be8c01be2a017338cc4fc04fd /gcc/rust/backend/rust-compile-pattern.cc | |
parent | 026e20b1dcc4765f17d593031fe8c1114e4bfaa5 (diff) | |
parent | a731476b50301c0f551ec7964d08e669a2b13e66 (diff) | |
download | gcc-d0dad09f5de7ddcb52b825b5d3cd4f1aee16f982.zip gcc-d0dad09f5de7ddcb52b825b5d3cd4f1aee16f982.tar.gz gcc-d0dad09f5de7ddcb52b825b5d3cd4f1aee16f982.tar.bz2 |
Merge #1775
1775: Create and use CompilePatternLet visitor for compiling let statments r=philberty a=powerboat9
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Implements and utilizes CompilePatternLet to compile let statements
Co-authored-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-pattern.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-pattern.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index b837f73..ba8374a 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -341,5 +341,63 @@ CompilePatternBindings::visit (HIR::GroupedPattern &pattern) pattern.get_item ()->accept_vis (*this); } +void +CompilePatternLet::visit (HIR::IdentifierPattern &pattern) +{ + Bvariable *var = nullptr; + rust_assert ( + ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var)); + + auto fnctx = ctx->peek_fn (); + if (ty->is_unit ()) + { + ctx->add_statement (init_expr); + + tree stmt_type = TyTyResolveCompile::compile (ctx, ty); + + auto unit_type_init_expr + = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1, + rval_locus); + auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, + unit_type_init_expr); + ctx->add_statement (s); + } + else + { + auto s + = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr); + ctx->add_statement (s); + } +} + +void +CompilePatternLet::visit (HIR::WildcardPattern &pattern) +{ + Bvariable *var = nullptr; + rust_assert ( + ctx->lookup_var_decl (pattern.get_pattern_mappings ().get_hirid (), &var)); + + auto fnctx = ctx->peek_fn (); + if (ty->is_unit ()) + { + ctx->add_statement (init_expr); + + tree stmt_type = TyTyResolveCompile::compile (ctx, ty); + + auto unit_type_init_expr + = ctx->get_backend ()->constructor_expression (stmt_type, false, {}, -1, + rval_locus); + auto s = ctx->get_backend ()->init_statement (fnctx.fndecl, var, + unit_type_init_expr); + ctx->add_statement (s); + } + else + { + auto s + = ctx->get_backend ()->init_statement (fnctx.fndecl, var, init_expr); + ctx->add_statement (s); + } +} + } // namespace Compile } // namespace Rust |