@@ -24,18 +24,19 @@ namespace mlir {
24
24
namespace query {
25
25
namespace matcher {
26
26
27
+ // Represents the line and column numbers in a source file.
27
28
struct SourceLocation {
28
- SourceLocation () : line(), column() {}
29
- unsigned line;
30
- unsigned column;
29
+ unsigned line{};
30
+ unsigned column{};
31
31
};
32
32
33
+ // Represents a range in a source file, defined by its start and end locations.
33
34
struct SourceRange {
34
- SourceLocation start;
35
- SourceLocation end;
35
+ SourceLocation start{} ;
36
+ SourceLocation end{} ;
36
37
};
37
38
38
- // Helper class to manage error messages.
39
+ // Diagnostics class to manage error messages.
39
40
class Diagnostics {
40
41
public:
41
42
// Parser context types.
@@ -62,7 +63,7 @@ class Diagnostics {
62
63
ET_ParserFailedToBuildMatcher
63
64
};
64
65
65
- // Helper stream class.
66
+ // Helper stream class for constructing error messages .
66
67
class ArgStream {
67
68
public:
68
69
ArgStream (std::vector<std::string> *out) : out(out) {}
@@ -76,13 +77,8 @@ class Diagnostics {
76
77
std::vector<std::string> *out;
77
78
};
78
79
79
- // Class defining a parser context.
80
- // Used by the parser to specify (possibly recursive) contexts where the
81
- // parsing/construction can fail. Any error triggered within a context will
82
- // keep information about the context chain.
83
- // This class should be used as a RAII instance in the stack.
80
+ // Context for constructing a matcher or parsing its argument.
84
81
struct Context {
85
- public:
86
82
// About to call the constructor for a matcher.
87
83
enum ConstructMatcherEnum { ConstructMatcher };
88
84
Context (ConstructMatcherEnum, Diagnostics *error,
@@ -97,26 +93,22 @@ class Diagnostics {
97
93
Diagnostics *const error;
98
94
};
99
95
100
- // Context for overloaded matcher construction.
101
- // This context will take care of merging all errors that happen within it
102
- // as "candidate" overloads for the same matcher.
96
+ // Context for managing overloaded matcher construction.
103
97
struct OverloadContext {
104
- public:
98
+ // Construct an overload context with the given error.
105
99
OverloadContext (Diagnostics *error);
106
100
~OverloadContext ();
107
-
108
- // Revert all errors that happened within this context.
101
+ // Revert all errors that occurred within this context.
109
102
void revertErrors ();
110
103
111
104
private:
112
105
Diagnostics *const error;
113
- unsigned beginIndex;
106
+ unsigned beginIndex{} ;
114
107
};
115
108
116
- // Add an error to the diagnostics.
117
- // All the context information will be kept on the error message.
118
- // Returns a helper class to allow the caller to pass the arguments for the
119
- // error message, using the << operator.
109
+ // Add an error message with the specified range and error type.
110
+ // Returns an ArgStream object to allow constructing the error message using
111
+ // the << operator.
120
112
ArgStream addError (SourceRange range, ErrorType error);
121
113
122
114
// Information stored for one frame of the context.
@@ -136,20 +128,25 @@ class Diagnostics {
136
128
};
137
129
std::vector<Message> messages;
138
130
};
131
+
132
+ // Get an array reference to the error contents.
139
133
llvm::ArrayRef<ErrorContent> errors () const { return errorValues; }
140
134
141
- // Returns a simple string representation of each error.
142
- // Each error only shows the error message without any context.
135
+ // Print all error messages to the specified output stream.
143
136
void printToStream (llvm::raw_ostream &OS) const ;
137
+ // Get a string representation of all error messages.
144
138
std::string toString () const ;
145
139
146
- // Returns the full string representation of each error.
147
- // Each error message contains the full context .
140
+ // Print the full error messages, including the context information, to the
141
+ // specified output stream .
148
142
void printToStreamFull (llvm::raw_ostream &OS) const ;
143
+ // Get the full string representation of all error messages, including the
144
+ // context information.
149
145
std::string toStringFull () const ;
150
146
151
147
private:
152
- // Helper function used by the constructors of ContextFrame.
148
+ // Push a new context frame onto the context stack with the specified type and
149
+ // range.
153
150
ArgStream pushContextFrame (ContextType type, SourceRange range);
154
151
155
152
std::vector<ContextFrame> contextStack;
@@ -160,4 +157,4 @@ class Diagnostics {
160
157
} // namespace query
161
158
} // namespace mlir
162
159
163
- #endif // MLIR_TOOLS_MLIRQUERY_MATCHERDIAGNOSTICS_H
160
+ #endif // MLIR_TOOLS_MLIRQUERY_MATCHERDIAGNOSTICS_H
0 commit comments