]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
lang-items: Add LangItem::IsEnumVariant
authorArthur Cohen <arthur.cohen@embecosm.com>
Mon, 23 Dec 2024 16:43:35 +0000 (16:43 +0000)
committerCohenArthur <arthur.cohen@embecosm.com>
Tue, 28 Jan 2025 17:35:37 +0000 (17:35 +0000)
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 affadf9bb1b65bc227cdd01cf32e057f0bf1f214..6b8c6e4606b242c451267482ec3efceeed7c050c 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 4836536e03ff4772fadda35abb6d55c264dc06a5..aa7efb12fcaca84b06366bad456c78dce0849a11 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