[llvm] [AsmParser][NFCI] Restructure DiagnosticPredicate (PR #126653)
Sam Elliott via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 22:57: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
+
+ constexpr DiagnosticPredicate(PredicateTy T) : Predicate(T) {}
+
DiagnosticPredicate& operator=(const DiagnosticPredicate &) = default;
+ DiagnosticPredicate(const DiagnosticPredicate &) = default;
+
+ explicit constexpr DiagnosticPredicate(bool Matches)
+ : Predicate(Matches ? Match : NearMatch) {}
+
+ operator bool() const { return Predicate == Match; }
----------------
lenary wrote:
(I put that change in a separate commit on the PR so we can back it out if we don't like it)
https://github.com/llvm/llvm-project/pull/126653
More information about the llvm-commits
mailing list