From dd9e4c1e0ca0b14388a3cd43f18a4e1a7aebe6e5 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 21 Apr 2022 14:32:21 +0100 Subject: Add name and type resolution for TuplePatterns This adds the relevant pattern resolution steps to match up the TuplePattern. This patch leaves out type resolution on TupleRange Patterns for now. Some thought is needed to figure out how do have a canonical algorithm for code-generation here so splitting this up makes sense for now. This patch extracts the type-resolution handling for HIR::LiteralExpr to have a generic function to resolve the HIR::Literal which is used within HIR::LiteralExpr and HIR::LiteralPattern. Addresses #1081 --- gcc/rust/resolve/rust-ast-resolve-pattern.cc | 30 ++++++++++++++++++++++++++++ gcc/rust/resolve/rust-ast-resolve-pattern.h | 2 ++ 2 files changed, 32 insertions(+) (limited to 'gcc/rust/resolve') diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.cc b/gcc/rust/resolve/rust-ast-resolve-pattern.cc index 0c7c8f3..24cd171 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.cc +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.cc @@ -100,5 +100,35 @@ PatternDeclaration::visit (AST::StructPattern &pattern) rust_assert (!struct_pattern_elems.has_etc ()); } +void +PatternDeclaration::visit (AST::TuplePattern &pattern) +{ + std::unique_ptr &items = pattern.get_items (); + switch (items->get_pattern_type ()) + { + case AST::TuplePatternItems::TuplePatternItemType::MULTIPLE: { + AST::TuplePatternItemsMultiple &ref + = *static_cast ( + pattern.get_items ().get ()); + + for (auto &p : ref.get_patterns ()) + p->accept_vis (*this); + } + break; + + case AST::TuplePatternItems::TuplePatternItemType::RANGED: { + AST::TuplePatternItemsRanged &ref + = *static_cast ( + pattern.get_items ().get ()); + + for (auto &p : ref.get_lower_patterns ()) + p->accept_vis (*this); + for (auto &p : ref.get_upper_patterns ()) + p->accept_vis (*this); + } + break; + } +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h b/gcc/rust/resolve/rust-ast-resolve-pattern.h index dca8258..464e362 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.h +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h @@ -101,6 +101,8 @@ public: void visit (AST::TupleStructPattern &pattern) override; + void visit (AST::TuplePattern &pattern) override; + private: PatternDeclaration (NodeId parent) : ResolverBase (parent) {} }; -- cgit v1.1