aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/rust-ast-lower-pattern.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-07 11:29:06 +0000
committerGitHub <noreply@github.com>2022-01-07 11:29:06 +0000
commitbc27d113167ec6c6cc96b01c8559fc9b9219417c (patch)
tree0fa63b2f89ed49d1b8b4a6c6c2ee20af30dd70c3 /gcc/rust/hir/rust-ast-lower-pattern.cc
parente082b6cfd0362b3bd8eacd65359812a0d34aa563 (diff)
parent6d0892636e9642e75a858c40c45acd1df79c63e1 (diff)
downloadgcc-bc27d113167ec6c6cc96b01c8559fc9b9219417c.zip
gcc-bc27d113167ec6c6cc96b01c8559fc9b9219417c.tar.gz
gcc-bc27d113167ec6c6cc96b01c8559fc9b9219417c.tar.bz2
Merge #866
866: Add support for wildcard patterns within MatchExprs r=philberty a=philberty GCC CASE_LABEL_EXPR's contain operand 0 and 1, operand 0 is used for the low value of a case label and operand 1 for a high value. So with this CASE_LABEL_EXPR is is possible to support a range of values from low->high if set apropriately, but for the wildcard case this is effectively a default case which means we set both operand 0 and 1 to NULL_TREE. Fixes #853 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/hir/rust-ast-lower-pattern.cc')
-rw-r--r--gcc/rust/hir/rust-ast-lower-pattern.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc
index 156f023..4bf3c51 100644
--- a/gcc/rust/hir/rust-ast-lower-pattern.cc
+++ b/gcc/rust/hir/rust-ast-lower-pattern.cc
@@ -23,6 +23,23 @@ namespace Rust {
namespace HIR {
void
+ASTLoweringPattern::visit (AST::IdentifierPattern &pattern)
+{
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ std::unique_ptr<Pattern> to_bind;
+ translated
+ = new HIR::IdentifierPattern (mapping, pattern.get_ident (),
+ pattern.get_locus (), pattern.get_is_ref (),
+ pattern.get_is_mut () ? Mutability::Mut
+ : Mutability::Imm,
+ std::move (to_bind));
+}
+
+void
ASTLoweringPattern::visit (AST::PathInExpression &pattern)
{
translated = ASTLowerPathInExpression::translate (&pattern);
@@ -135,5 +152,16 @@ ASTLoweringPattern::visit (AST::StructPattern &pattern)
translated = new HIR::StructPattern (mapping, *path, std::move (elems));
}
+void
+ASTLoweringPattern::visit (AST::WildcardPattern &pattern)
+{
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
+
+ translated = new HIR::WildcardPattern (mapping, pattern.get_locus ());
+}
+
} // namespace HIR
} // namespace Rust