xref: /llvm-project/mlir/include/mlir/Query/Matcher/ErrorBuilder.h (revision 58b44c8102afb0e76d1cb70d4a5d089f70d2f657)
1 //===--- ErrorBuilder.h - Helper for building error messages ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // ErrorBuilder to manage error messages.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHER_ERRORBUILDER_H
14 #define MLIR_TOOLS_MLIRQUERY_MATCHER_ERRORBUILDER_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/Twine.h"
18 #include <initializer_list>
19 
20 namespace mlir::query::matcher::internal {
21 class Diagnostics;
22 
23 // Represents the line and column numbers in a source query.
24 struct SourceLocation {
25   unsigned line{};
26   unsigned column{};
27 };
28 
29 // Represents a range in a source query, defined by its start and end locations.
30 struct SourceRange {
31   SourceLocation start{};
32   SourceLocation end{};
33 };
34 
35 // All errors from the system.
36 enum class ErrorType {
37   None,
38 
39   // Parser Errors
40   ParserChainedExprInvalidArg,
41   ParserChainedExprNoCloseParen,
42   ParserChainedExprNoOpenParen,
43   ParserFailedToBuildMatcher,
44   ParserInvalidToken,
45   ParserMalformedChainedExpr,
46   ParserNoCloseParen,
47   ParserNoCode,
48   ParserNoComma,
49   ParserNoOpenParen,
50   ParserNotAMatcher,
51   ParserOverloadedType,
52   ParserStringError,
53   ParserTrailingCode,
54 
55   // Registry Errors
56   RegistryMatcherNotFound,
57   RegistryNotBindable,
58   RegistryValueNotFound,
59   RegistryWrongArgCount,
60   RegistryWrongArgType,
61 };
62 
63 void addError(Diagnostics *error, SourceRange range, ErrorType errorType,
64               std::initializer_list<llvm::Twine> errorTexts);
65 
66 } // namespace mlir::query::matcher::internal
67 
68 #endif // MLIR_TOOLS_MLIRQUERY_MATCHER_ERRORBUILDER_H
69