]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: lang-items: Add LangItem::IsEnumVariant
authorArthur Cohen <arthur.cohen@embecosm.com>
Mon, 23 Dec 2024 16:43:35 +0000 (16:43 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:06:54 +0000 (13:06 +0100)
gcc/rust/ChangeLog:

* util/rust-lang-item.cc (LangItem::IsEnumVariant): New function.
* util/rust-lang-item.h: Declare it.

gcc/rust/util/rust-lang-item.cc
gcc/rust/util/rust-lang-item.h

index ac90f979e834db2fbe5f4dc348d4d749b266bb36..b37a237c24e6901dea220e3af995ff0dd0e935e0 100644 (file)
@@ -248,4 +248,13 @@ LangItem::NegationOperatorToLangItem (NegationOperator op)
   rust_unreachable ();
 }
 
+bool
+LangItem::IsEnumVariant (LangItem::Kind type)
+{
+  const static std::set<LangItem::Kind> enum_variants
+    = {Kind::OPTION_NONE, Kind::OPTION_SOME, Kind::RESULT_OK, Kind::RESULT_ERR};
+
+  return enum_variants.find (type) != enum_variants.end ();
+}
+
 } // namespace Rust
index ad081a7d3fb7bcc47f8617f8214da0e07a0d35eb..851909d409c0b39ddffc545b8c8e9c9831e43fa0 100644 (file)
@@ -146,15 +146,18 @@ public:
   static const BiMap<std::string, Kind> lang_items;
 
   static tl::optional<Kind> Parse (const std::string &item);
+
   static std::string ToString (Kind type);
   static std::string PrettyString (Kind type);
+
   static Kind OperatorToLangItem (ArithmeticOrLogicalOperator op);
   static Kind
   CompoundAssignmentOperatorToLangItem (ArithmeticOrLogicalOperator op);
   static Kind NegationOperatorToLangItem (NegationOperator op);
   static Kind ComparisonToLangItem (ComparisonOperator op);
-
   static std::string ComparisonToSegment (ComparisonOperator op);
+
+  static bool IsEnumVariant (Kind type);
 };
 
 } // namespace Rust