Skip to content

Commit 9218906

Browse files
committed
Unexpose diagnostics functions
1 parent da170ac commit 9218906

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

mlir/include/mlir/Query/Matcher/Diagnostics.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ struct SourceRange {
3838
// Diagnostics class to manage error messages.
3939
class Diagnostics {
4040
public:
41-
// Parser context types.
42-
enum ContextType { CT_MatcherArg, CT_MatcherConstruct };
43-
4441
// All errors from the system.
4542
enum ErrorType {
4643
ET_None,
@@ -92,6 +89,22 @@ class Diagnostics {
9289
Diagnostics *const error;
9390
};
9491

92+
// Add an error message with the specified range and error type.
93+
// Returns an ArgStream object to allow constructing the error message using
94+
// the << operator.
95+
ArgStream addError(SourceRange range, ErrorType error);
96+
97+
// Print all error messages to the specified output stream.
98+
void print(llvm::raw_ostream &OS) const;
99+
100+
// Print the full error messages, including the context information, to the
101+
// specified output stream.
102+
void printFull(llvm::raw_ostream &OS) const;
103+
104+
private:
105+
// Parser context types.
106+
enum ContextType { CT_MatcherArg, CT_MatcherConstruct };
107+
95108
// Context for managing overloaded matcher construction.
96109
struct OverloadContext {
97110
// Construct an overload context with the given error.
@@ -105,11 +118,6 @@ class Diagnostics {
105118
unsigned beginIndex{};
106119
};
107120

108-
// Add an error message with the specified range and error type.
109-
// Returns an ArgStream object to allow constructing the error message using
110-
// the << operator.
111-
ArgStream addError(SourceRange range, ErrorType error);
112-
113121
// Information stored for one frame of the context.
114122
struct ContextFrame {
115123
ContextType type;
@@ -131,14 +139,18 @@ class Diagnostics {
131139
// Get an array reference to the error contents.
132140
llvm::ArrayRef<ErrorContent> errors() const { return errorValues; }
133141

134-
// Print all error messages to the specified output stream.
135-
void print(llvm::raw_ostream &OS) const;
142+
llvm::StringRef contextTypeToFormatString(ContextType type) const;
136143

137-
// Print the full error messages, including the context information, to the
138-
// specified output stream.
139-
void printFull(llvm::raw_ostream &OS) const;
144+
void printContextFrameToStream(const ContextFrame &frame,
145+
llvm::raw_ostream &OS) const;
146+
147+
void printMessageToStream(const ErrorContent::Message &message,
148+
const llvm::Twine Prefix,
149+
llvm::raw_ostream &OS) const;
150+
151+
void printErrorContentToStream(const ErrorContent &content,
152+
llvm::raw_ostream &OS) const;
140153

141-
private:
142154
// Push a new context frame onto the context stack with the specified type and
143155
// range.
144156
ArgStream pushContextFrame(ContextType type, SourceRange range);

mlir/include/mlir/Query/Matcher/MatchFinder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ class MatchFinder {
3939

4040
} // namespace mlir::query::matcher
4141

42-
#endif // MLIR_TOOLS_MLIRQUERY_MATCHER_MATCHERFINDER_H
42+
#endif // MLIR_TOOLS_MLIRQUERY_MATCHER_MATCHERFINDER_H

mlir/lib/Query/Matcher/Diagnostics.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Diagnostics::ArgStream Diagnostics::addError(SourceRange range,
7272
return ArgStream(&last.messages.back().args);
7373
}
7474

75-
static llvm::StringRef
76-
contextTypeToFormatString(Diagnostics::ContextType type) {
75+
llvm::StringRef
76+
Diagnostics::contextTypeToFormatString(Diagnostics::ContextType type) const {
7777
switch (type) {
7878
case Diagnostics::CT_MatcherConstruct:
7979
return "Error building matcher $0.";
@@ -150,22 +150,22 @@ static void maybeAddLineAndColumn(SourceRange range, llvm::raw_ostream &OS) {
150150
}
151151
}
152152

153-
static void printContextFrameToStream(const Diagnostics::ContextFrame &frame,
154-
llvm::raw_ostream &OS) {
153+
void Diagnostics::printContextFrameToStream(
154+
const Diagnostics::ContextFrame &frame, llvm::raw_ostream &OS) const {
155155
maybeAddLineAndColumn(frame.range, OS);
156156
formatErrorString(contextTypeToFormatString(frame.type), frame.args, OS);
157157
}
158158

159-
static void
160-
printMessageToStream(const Diagnostics::ErrorContent::Message &message,
161-
const llvm::Twine Prefix, llvm::raw_ostream &OS) {
159+
void Diagnostics::printMessageToStream(
160+
const Diagnostics::ErrorContent::Message &message, const llvm::Twine Prefix,
161+
llvm::raw_ostream &OS) const {
162162
maybeAddLineAndColumn(message.range, OS);
163163
OS << Prefix;
164164
formatErrorString(errorTypeToFormatString(message.type), message.args, OS);
165165
}
166166

167-
static void printErrorContentToStream(const Diagnostics::ErrorContent &content,
168-
llvm::raw_ostream &OS) {
167+
void Diagnostics::printErrorContentToStream(
168+
const Diagnostics::ErrorContent &content, llvm::raw_ostream &OS) const {
169169
if (content.messages.size() == 1) {
170170
printMessageToStream(content.messages[0], "", OS);
171171
} else {

0 commit comments

Comments
 (0)