public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Compile literal patterns for match expressions
@ 2022-06-08 12:42 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:42 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ca75e756e802ccfff445f7efb4f3b530c6f3891f
commit ca75e756e802ccfff445f7efb4f3b530c6f3891f
Author: David Faust <david.faust@oracle.com>
Date: Tue May 3 12:55:08 2022 -0700
Compile literal patterns for match expressions
Diff:
---
gcc/rust/backend/rust-compile-pattern.cc | 14 ++++++++++++++
gcc/rust/backend/rust-compile-pattern.h | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index 393fbd5d517..e8f1c51a1d4 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -80,6 +80,20 @@ CompilePatternCaseLabelExpr::visit (HIR::WildcardPattern &pattern)
= build_case_label (NULL_TREE, NULL_TREE, associated_case_label);
}
+void
+CompilePatternCaseLabelExpr::visit (HIR::LiteralPattern &pattern)
+{
+ // Compile the literal
+ HIR::LiteralExpr *litexpr
+ = new HIR::LiteralExpr (pattern.get_pattern_mappings (),
+ pattern.get_literal (), pattern.get_locus (),
+ std::vector<AST::Attribute> ());
+
+ tree lit = CompileExpr::Compile (litexpr, ctx);
+
+ case_label_expr = build_case_label (lit, NULL_TREE, associated_case_label);
+}
+
// setup the bindings
void
diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h
index 5bff317fe98..1b6e80fb88d 100644
--- a/gcc/rust/backend/rust-compile-pattern.h
+++ b/gcc/rust/backend/rust-compile-pattern.h
@@ -41,7 +41,7 @@ public:
// Empty visit for unused Pattern HIR nodes.
void visit (HIR::GroupedPattern &) override {}
void visit (HIR::IdentifierPattern &) override {}
- void visit (HIR::LiteralPattern &) override {}
+ void visit (HIR::LiteralPattern &) override;
void visit (HIR::QualifiedPathInExpression &) override {}
void visit (HIR::RangePattern &) override {}
void visit (HIR::ReferencePattern &) override {}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:42 [gcc/devel/rust/master] Compile literal patterns for match expressions Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).