1010
1111namespace mlir ::query::matcher {
1212
13- Diagnostics::ArgStream Diagnostics::pushContextFrame (ContextType type,
14- SourceRange range) {
15- contextStack.emplace_back ();
16- ContextFrame &data = contextStack.back ();
17- data.type = type;
18- data.range = range;
19- return ArgStream (&data.args );
20- }
21-
22- Diagnostics::Context::Context (ConstructMatcherEnum, Diagnostics *error,
23- llvm::StringRef matcherName,
24- SourceRange matcherRange)
25- : error(error) {
26- error->pushContextFrame (ContextType::MatcherConstruct, matcherRange)
27- << matcherName;
28- }
29-
30- Diagnostics::Context::Context (MatcherArgEnum, Diagnostics *error,
31- llvm::StringRef matcherName,
32- SourceRange matcherRange, int argnumber)
33- : error(error) {
34- error->pushContextFrame (ContextType::MatcherArg, matcherRange)
35- << argnumber << matcherName;
36- }
37-
38- Diagnostics::Context::~Context () { error->contextStack .pop_back (); }
39-
40- Diagnostics::OverloadContext::OverloadContext (Diagnostics *error)
41- : error(error), beginIndex(error->errorValues.size()) {}
42-
43- Diagnostics::OverloadContext::~OverloadContext () {
44- // Merge all errors that happened while in this context.
45- if (beginIndex < error->errorValues .size ()) {
46- Diagnostics::ErrorContent &dest = error->errorValues [beginIndex];
47- for (size_t i = beginIndex + 1 , e = error->errorValues .size (); i < e; ++i) {
48- dest.messages .push_back (error->errorValues [i].messages [0 ]);
49- }
50- error->errorValues .resize (beginIndex + 1 );
51- }
52- }
53-
54- void Diagnostics::OverloadContext::revertErrors () {
55- // Revert the errors.
56- error->errorValues .resize (beginIndex);
57- }
58-
5913Diagnostics::ArgStream &
6014Diagnostics::ArgStream::operator <<(const llvm::Twine &arg) {
6115 out->push_back (arg.str ());
@@ -73,17 +27,6 @@ Diagnostics::ArgStream Diagnostics::addError(SourceRange range,
7327 return ArgStream (&last.messages .back ().args );
7428}
7529
76- llvm::StringRef
77- Diagnostics::contextTypeToFormatString (Diagnostics::ContextType type) const {
78- switch (type) {
79- case Diagnostics::ContextType::MatcherConstruct:
80- return " Error building matcher $0." ;
81- case Diagnostics::ContextType::MatcherArg:
82- return " Error parsing argument $0 for matcher $1." ;
83- }
84- llvm_unreachable (" Unknown ContextType value." );
85- }
86-
8730static llvm::StringRef errorTypeToFormatString (Diagnostics::ErrorType type) {
8831 switch (type) {
8932 case Diagnostics::ET_RegistryMatcherNotFound:
@@ -151,30 +94,24 @@ static void maybeAddLineAndColumn(SourceRange range, llvm::raw_ostream &OS) {
15194 }
15295}
15396
154- void Diagnostics::printContextFrameToStream (
155- const Diagnostics::ContextFrame &frame, llvm::raw_ostream &OS) const {
156- maybeAddLineAndColumn (frame.range , OS);
157- formatErrorString (contextTypeToFormatString (frame.type ), frame.args , OS);
158- }
159-
160- void Diagnostics::printMessageToStream (
97+ void Diagnostics::printMessage (
16198 const Diagnostics::ErrorContent::Message &message, const llvm::Twine Prefix,
16299 llvm::raw_ostream &OS) const {
163100 maybeAddLineAndColumn (message.range , OS);
164101 OS << Prefix;
165102 formatErrorString (errorTypeToFormatString (message.type ), message.args , OS);
166103}
167104
168- void Diagnostics::printErrorContentToStream (
169- const Diagnostics::ErrorContent &content, llvm::raw_ostream &OS) const {
105+ void Diagnostics::printErrorContent ( const Diagnostics::ErrorContent &content,
106+ llvm::raw_ostream &OS) const {
170107 if (content.messages .size () == 1 ) {
171- printMessageToStream (content.messages [0 ], " " , OS);
108+ printMessage (content.messages [0 ], " " , OS);
172109 } else {
173110 for (size_t i = 0 , e = content.messages .size (); i != e; ++i) {
174111 if (i != 0 )
175112 OS << " \n " ;
176- printMessageToStream (content.messages [i],
177- " Candidate " + llvm::Twine (i + 1 ) + " : " , OS);
113+ printMessage (content.messages [i],
114+ " Candidate " + llvm::Twine (i + 1 ) + " : " , OS);
178115 }
179116 }
180117}
@@ -183,19 +120,7 @@ void Diagnostics::print(llvm::raw_ostream &OS) const {
183120 for (const ErrorContent &error : errorValues) {
184121 if (&error != &errorValues.front ())
185122 OS << " \n " ;
186- printErrorContentToStream (error, OS);
187- }
188- }
189-
190- void Diagnostics::printFull (llvm::raw_ostream &OS) const {
191- for (const ErrorContent &error : errorValues) {
192- if (&error != &errorValues.front ())
193- OS << " \n " ;
194- for (const ContextFrame &frame : error.contextStack ) {
195- printContextFrameToStream (frame, OS);
196- OS << " \n " ;
197- }
198- printErrorContentToStream (error, OS);
123+ printErrorContent (error, OS);
199124 }
200125}
201126
0 commit comments