public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Marklive: support match expr
@ 2022-06-08 12:48 Thomas Schwinge
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Schwinge @ 2022-06-08 12:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:75c9f9f61cb2d69f39d490c47a3b42810c31c1ff

commit 75c9f9f61cb2d69f39d490c47a3b42810c31c1ff
Author: Thomas Young <wenzhang5800@gmail.com>
Date:   Sat May 21 21:23:55 2022 +0800

    Marklive: support match expr

Diff:
---
 gcc/rust/hir/tree/rust-hir-expr.h    |  6 ++++++
 gcc/rust/lint/rust-lint-marklive.h   | 15 +++++++++++++++
 gcc/testsuite/rust/compile/match6.rs | 21 +++++++++++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index e585dd2a331..f6f035e2134 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3842,6 +3842,12 @@ public:
     return match_arm_patterns;
   }
 
+  std::unique_ptr<Expr> &get_guard_expr ()
+  {
+    rust_assert (has_match_arm_guard ());
+    return guard_expr;
+  }
+
   Location get_locus () const { return locus; }
 };
 
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index aeecda5f73c..89a6d7e94f1 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -204,6 +204,21 @@ public:
     expr.get_else_block ()->accept_vis (*this);
   }
 
+  void visit (HIR::MatchExpr &expr) override
+  {
+    expr.get_scrutinee_expr ()->accept_vis (*this);
+    std::vector<HIR::MatchCase> &cases = expr.get_match_cases ();
+    for (auto &&caz : cases)
+      {
+	auto case_arm = caz.get_arm ();
+	if (case_arm.has_match_arm_guard ())
+	  {
+	    case_arm.get_guard_expr ()->accept_vis (*this);
+	  }
+	caz.get_expr ()->accept_vis (*this);
+      }
+  }
+
   void visit (HIR::IfExprConseqIf &expr) override
   {
     expr.get_if_condition ()->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/match6.rs b/gcc/testsuite/rust/compile/match6.rs
new file mode 100644
index 00000000000..eec775ba94b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match6.rs
@@ -0,0 +1,21 @@
+fn foo() -> bool {
+    true
+}
+
+fn int32() -> i32 {
+    1
+}
+
+fn bar() -> i32 {
+    match foo() {
+        true => int32(),
+        false => 0
+    }
+}
+
+fn main() -> () {
+    bar();
+}
+
+
+


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc/devel/rust/master] Marklive: support match expr
@ 2022-06-08 12:48 Thomas Schwinge
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Schwinge @ 2022-06-08 12:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dccb3f8121e416009dae6e5b8f675603d2a0503d

commit dccb3f8121e416009dae6e5b8f675603d2a0503d
Author: Thomas Young <wenzhang5800@gmail.com>
Date:   Sun May 22 12:11:21 2022 +0800

    Marklive: support match expr

Diff:
---
 gcc/rust/hir/tree/rust-hir-expr.h    |  6 ++++++
 gcc/rust/lint/rust-lint-marklive.h   | 13 +++++++++++++
 gcc/testsuite/rust/compile/match6.rs | 18 ++++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index e585dd2a331..f6f035e2134 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -3842,6 +3842,12 @@ public:
     return match_arm_patterns;
   }
 
+  std::unique_ptr<Expr> &get_guard_expr ()
+  {
+    rust_assert (has_match_arm_guard ());
+    return guard_expr;
+  }
+
   Location get_locus () const { return locus; }
 };
 
diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h
index aeecda5f73c..529afa63c2b 100644
--- a/gcc/rust/lint/rust-lint-marklive.h
+++ b/gcc/rust/lint/rust-lint-marklive.h
@@ -204,6 +204,19 @@ public:
     expr.get_else_block ()->accept_vis (*this);
   }
 
+  void visit (HIR::MatchExpr &expr) override
+  {
+    expr.get_scrutinee_expr ()->accept_vis (*this);
+    std::vector<HIR::MatchCase> &cases = expr.get_match_cases ();
+    for (auto &&caz : cases)
+      {
+	auto case_arm = caz.get_arm ();
+	if (case_arm.has_match_arm_guard ())
+	  case_arm.get_guard_expr ()->accept_vis (*this);
+	caz.get_expr ()->accept_vis (*this);
+      }
+  }
+
   void visit (HIR::IfExprConseqIf &expr) override
   {
     expr.get_if_condition ()->accept_vis (*this);
diff --git a/gcc/testsuite/rust/compile/match6.rs b/gcc/testsuite/rust/compile/match6.rs
new file mode 100644
index 00000000000..8fe06f7c116
--- /dev/null
+++ b/gcc/testsuite/rust/compile/match6.rs
@@ -0,0 +1,18 @@
+fn foo() -> bool {
+    true
+}
+
+fn int32() -> i32 {
+    1
+}
+
+fn bar() -> i32 {
+    match foo() {
+        true => int32(),
+        false => 0
+    }
+}
+
+fn main() -> () {
+    bar();
+}
\ No newline at end of file


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-08 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:48 [gcc/devel/rust/master] Marklive: support match expr Thomas Schwinge
2022-06-08 12:48 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).