aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2023-03-18 01:41:01 -0400
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:34:08 +0100
commit197962cb062edb41538af9f5e9b4c02f090c4ba8 (patch)
tree536c925e94418bf49faf12e7518d2acd0f7048f5 /gcc/rust/resolve
parent694063d84e47f57c99d4558e789932c31a7bf6dd (diff)
downloadgcc-197962cb062edb41538af9f5e9b4c02f090c4ba8.zip
gcc-197962cb062edb41538af9f5e9b4c02f090c4ba8.tar.gz
gcc-197962cb062edb41538af9f5e9b4c02f090c4ba8.tar.bz2
gccrs: Add lowering for if-let expressions
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add implementation for IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.h: (TypeCheckExpr::visit): Remove stub implementation for IfLetExprConseqElse. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower IfLetExpr{,ConseqElse}. * hir/rust-ast-lower-expr.h: (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse. (ASTLoweringExprWithBlock::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse. * hir/tree/rust-hir-expr.h (IfLetExprConseqElse::IfLetExprConseqElse): Make constructor more general. (IfLetExprConseqElse::vis_else_block): Add. (IfLetExprConseqElse::get_else_block): Add. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add IfLetExprConseqElse visitor. * resolve/rust-ast-resolve-expr.h (ResolveExpr::visit): Add IfLetExprConseqElse visitor. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Increase test coverage. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.cc31
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index 339fd8a..41ce9c9 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -217,6 +217,37 @@ ResolveExpr::visit (AST::IfLetExpr &expr)
}
void
+ResolveExpr::visit (AST::IfLetExprConseqElse &expr)
+{
+ ResolveExpr::go (expr.get_value_expr ().get (), prefix, canonical_prefix);
+
+ NodeId scope_node_id = expr.get_node_id ();
+ resolver->get_name_scope ().push (scope_node_id);
+ resolver->get_type_scope ().push (scope_node_id);
+ resolver->get_label_scope ().push (scope_node_id);
+ resolver->push_new_name_rib (resolver->get_name_scope ().peek ());
+ resolver->push_new_type_rib (resolver->get_type_scope ().peek ());
+ resolver->push_new_label_rib (resolver->get_type_scope ().peek ());
+
+ // We know expr.get_patterns () has one pattern at most
+ // so there's no reason to handle it like an AltPattern.
+ std::vector<PatternBinding> bindings
+ = {PatternBinding (PatternBoundCtx::Product, std::set<Identifier> ())};
+
+ for (auto &pattern : expr.get_patterns ())
+ {
+ PatternDeclaration::go (pattern.get (), Rib::ItemType::Var, bindings);
+ }
+
+ ResolveExpr::go (expr.get_if_block ().get (), prefix, canonical_prefix);
+ ResolveExpr::go (expr.get_else_block ().get (), prefix, canonical_prefix);
+
+ resolver->get_name_scope ().pop ();
+ resolver->get_type_scope ().pop ();
+ resolver->get_label_scope ().pop ();
+}
+
+void
ResolveExpr::visit (AST::BlockExpr &expr)
{
NodeId scope_node_id = expr.get_node_id ();
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h
index 7b0beaf..896617cc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.h
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.h
@@ -51,6 +51,7 @@ public:
void visit (AST::IfExpr &expr) override;
void visit (AST::IfExprConseqElse &expr) override;
void visit (AST::IfLetExpr &expr) override;
+ void visit (AST::IfLetExprConseqElse &expr) override;
void visit (AST::BlockExpr &expr) override;
void visit (AST::UnsafeBlockExpr &expr) override;
void visit (AST::ArrayElemsValues &elems) override;