[llvm] [AsmParser][NFCI] Restructure DiagnosticPredicate (PR #126653)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 10:32:48 PST 2025
================
@@ -198,21 +192,36 @@ enum class DiagnosticPredicateTy {
// This is a light-weight alternative to the 'NearMissInfo' approach
// below which collects *all* possible diagnostics. This alternative
// is optional and fully backward compatible with existing
-// PredicateMethods that return a 'bool' (match or no match).
-struct DiagnosticPredicate {
- DiagnosticPredicateTy Type;
-
- explicit DiagnosticPredicate(bool Match)
- : Type(Match ? DiagnosticPredicateTy::Match
- : DiagnosticPredicateTy::NearMatch) {}
- DiagnosticPredicate(DiagnosticPredicateTy T) : Type(T) {}
- DiagnosticPredicate(const DiagnosticPredicate &) = default;
+// PredicateMethods that return a 'bool' (match or near match).
+class DiagnosticPredicate {
+ enum class PredicateTy {
+ Match, // Matches
+ NearMatch, // Close Match: use Specific Diagnostic
+ NoMatch, // No Match: use `InvalidOperand`
+ } Predicate;
+
+public:
+#if __cplusplus >= 202002L
+ using enum PredicateTy;
+#else
+ static constexpr PredicateTy Match = PredicateTy::Match;
+ static constexpr PredicateTy NearMatch = PredicateTy::NearMatch;
+ static constexpr PredicateTy NoMatch = PredicateTy::NoMatch;
+#endif
----------------
s-barannikov wrote:
That `enum class` helped me a lot to find implicit conversions to/from `bool` / `enum OperandMatchResultTy` during migration. Now it stays for additional type safety.
The `using` / `constexpr` shorten `ParseStatus::StatusTy::Success` to `ParseStatus::Success`.
It is private because it isn't supposed to be used directly.
https://github.com/llvm/llvm-project/pull/126653
More information about the llvm-commits
mailing list