blob: 69eb887843cb67fd5d70036427b131d0e66312e1 [file] [log] [blame]
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +00001//===--- VerifyDiagnosticsClient.cpp - Verifying Diagnostic Client --------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is a concrete diagnostic client, which buffers the diagnostic messages.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Frontend/VerifyDiagnosticsClient.h"
15#include "clang/Frontend/FrontendDiagnostic.h"
16#include "clang/Frontend/TextDiagnosticBuffer.h"
17#include "clang/Lex/Preprocessor.h"
18#include "llvm/ADT/SmallString.h"
Chris Lattner60909e12010-04-28 20:02:30 +000019#include "llvm/Support/Regex.h"
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000020#include "llvm/Support/raw_ostream.h"
21using namespace clang;
22
Douglas Gregor78243652011-09-13 01:26:44 +000023VerifyDiagnosticsClient::VerifyDiagnosticsClient(Diagnostic &_Diags)
24 : Diags(_Diags), PrimaryClient(Diags.getClient()),
25 OwnsPrimaryClient(Diags.ownsClient()),
26 Buffer(new TextDiagnosticBuffer()), CurrentPreprocessor(0)
27{
28 Diags.takeClient();
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000029}
30
31VerifyDiagnosticsClient::~VerifyDiagnosticsClient() {
Douglas Gregor78243652011-09-13 01:26:44 +000032 CheckDiagnostics();
33 Diags.takeClient();
34 if (OwnsPrimaryClient)
35 delete PrimaryClient;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000036}
37
38// DiagnosticClient interface.
39
40void VerifyDiagnosticsClient::BeginSourceFile(const LangOptions &LangOpts,
41 const Preprocessor *PP) {
42 // FIXME: Const hack, we screw up the preprocessor but in practice its ok
43 // because it doesn't get reused. It would be better if we could make a copy
44 // though.
45 CurrentPreprocessor = const_cast<Preprocessor*>(PP);
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000046
47 PrimaryClient->BeginSourceFile(LangOpts, PP);
48}
49
50void VerifyDiagnosticsClient::EndSourceFile() {
51 CheckDiagnostics();
52
53 PrimaryClient->EndSourceFile();
54
55 CurrentPreprocessor = 0;
56}
Daniel Dunbar221c7212009-11-14 07:53:24 +000057
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000058void VerifyDiagnosticsClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
59 const DiagnosticInfo &Info) {
Axel Naumann01231612011-07-25 19:18:12 +000060 if (FirstErrorFID.isInvalid() && Info.hasSourceManager()) {
61 const SourceManager &SM = Info.getSourceManager();
62 FirstErrorFID = SM.getFileID(Info.getLocation());
63 }
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000064 // Send the diagnostic to the buffer, we will check it once we reach the end
65 // of the source file (or are destructed).
66 Buffer->HandleDiagnostic(DiagLevel, Info);
67}
68
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000069//===----------------------------------------------------------------------===//
70// Checking diagnostics implementation.
71//===----------------------------------------------------------------------===//
72
73typedef TextDiagnosticBuffer::DiagList DiagList;
74typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
75
Chris Lattner60909e12010-04-28 20:02:30 +000076namespace {
77
78/// Directive - Abstract class representing a parsed verify directive.
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000079///
Chris Lattner60909e12010-04-28 20:02:30 +000080class Directive {
81public:
82 static Directive* Create(bool RegexKind, const SourceLocation &Location,
83 const std::string &Text, unsigned Count);
84public:
85 SourceLocation Location;
86 const std::string Text;
87 unsigned Count;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000088
Chris Lattner60909e12010-04-28 20:02:30 +000089 virtual ~Directive() { }
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +000090
Chris Lattner60909e12010-04-28 20:02:30 +000091 // Returns true if directive text is valid.
92 // Otherwise returns false and populates E.
93 virtual bool isValid(std::string &Error) = 0;
94
95 // Returns true on match.
96 virtual bool Match(const std::string &S) = 0;
97
98protected:
99 Directive(const SourceLocation &Location, const std::string &Text,
100 unsigned Count)
101 : Location(Location), Text(Text), Count(Count) { }
102
103private:
Argyrios Kyrtzidisc83d2d72010-08-15 10:17:39 +0000104 Directive(const Directive&); // DO NOT IMPLEMENT
105 void operator=(const Directive&); // DO NOT IMPLEMENT
Chris Lattner60909e12010-04-28 20:02:30 +0000106};
107
108/// StandardDirective - Directive with string matching.
109///
110class StandardDirective : public Directive {
111public:
112 StandardDirective(const SourceLocation &Location, const std::string &Text,
113 unsigned Count)
114 : Directive(Location, Text, Count) { }
115
116 virtual bool isValid(std::string &Error) {
117 // all strings are considered valid; even empty ones
118 return true;
119 }
120
121 virtual bool Match(const std::string &S) {
122 return S.find(Text) != std::string::npos ||
123 Text.find(S) != std::string::npos;
124 }
125};
126
127/// RegexDirective - Directive with regular-expression matching.
128///
129class RegexDirective : public Directive {
130public:
131 RegexDirective(const SourceLocation &Location, const std::string &Text,
132 unsigned Count)
133 : Directive(Location, Text, Count), Regex(Text) { }
134
135 virtual bool isValid(std::string &Error) {
136 if (Regex.isValid(Error))
137 return true;
138 return false;
139 }
140
141 virtual bool Match(const std::string &S) {
142 return Regex.match(S);
143 }
144
145private:
146 llvm::Regex Regex;
147};
148
149typedef std::vector<Directive*> DirectiveList;
150
151/// ExpectedData - owns directive objects and deletes on destructor.
152///
153struct ExpectedData {
154 DirectiveList Errors;
155 DirectiveList Warnings;
156 DirectiveList Notes;
157
158 ~ExpectedData() {
159 DirectiveList* Lists[] = { &Errors, &Warnings, &Notes, 0 };
160 for (DirectiveList **PL = Lists; *PL; ++PL) {
161 DirectiveList * const L = *PL;
162 for (DirectiveList::iterator I = L->begin(), E = L->end(); I != E; ++I)
163 delete *I;
164 }
165 }
166};
167
168class ParseHelper
169{
170public:
171 ParseHelper(const char *Begin, const char *End)
172 : Begin(Begin), End(End), C(Begin), P(Begin), PEnd(NULL) { }
173
174 // Return true if string literal is next.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000175 bool Next(StringRef S) {
Chris Lattner60909e12010-04-28 20:02:30 +0000176 P = C;
Benjamin Kramer0080f0c2010-09-01 17:28:48 +0000177 PEnd = C + S.size();
Chris Lattner60909e12010-04-28 20:02:30 +0000178 if (PEnd > End)
179 return false;
Benjamin Kramer0080f0c2010-09-01 17:28:48 +0000180 return !memcmp(P, S.data(), S.size());
Chris Lattner60909e12010-04-28 20:02:30 +0000181 }
182
183 // Return true if number is next.
184 // Output N only if number is next.
185 bool Next(unsigned &N) {
186 unsigned TMP = 0;
187 P = C;
188 for (; P < End && P[0] >= '0' && P[0] <= '9'; ++P) {
189 TMP *= 10;
190 TMP += P[0] - '0';
191 }
192 if (P == C)
193 return false;
194 PEnd = P;
195 N = TMP;
196 return true;
197 }
198
199 // Return true if string literal is found.
200 // When true, P marks begin-position of S in content.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000201 bool Search(StringRef S) {
Chris Lattner60909e12010-04-28 20:02:30 +0000202 P = std::search(C, End, S.begin(), S.end());
Benjamin Kramer0080f0c2010-09-01 17:28:48 +0000203 PEnd = P + S.size();
Chris Lattner60909e12010-04-28 20:02:30 +0000204 return P != End;
205 }
206
207 // Advance 1-past previous next/search.
208 // Behavior is undefined if previous next/search failed.
209 bool Advance() {
210 C = PEnd;
211 return C < End;
212 }
213
214 // Skip zero or more whitespace.
215 void SkipWhitespace() {
216 for (; C < End && isspace(*C); ++C)
217 ;
218 }
219
220 // Return true if EOF reached.
221 bool Done() {
222 return !(C < End);
223 }
224
225 const char * const Begin; // beginning of expected content
226 const char * const End; // end of expected content (1-past)
227 const char *C; // position of next char in content
228 const char *P;
229
230private:
231 const char *PEnd; // previous next/search subject end (1-past)
232};
233
234} // namespace anonymous
235
236/// ParseDirective - Go through the comment and see if it indicates expected
237/// diagnostics. If so, then put them in the appropriate directive list.
238///
239static void ParseDirective(const char *CommentStart, unsigned CommentLen,
240 ExpectedData &ED, Preprocessor &PP,
241 SourceLocation Pos) {
242 // A single comment may contain multiple directives.
243 for (ParseHelper PH(CommentStart, CommentStart+CommentLen); !PH.Done();) {
244 // search for token: expected
245 if (!PH.Search("expected"))
246 break;
247 PH.Advance();
248
249 // next token: -
250 if (!PH.Next("-"))
251 continue;
252 PH.Advance();
253
254 // next token: { error | warning | note }
255 DirectiveList* DL = NULL;
256 if (PH.Next("error"))
257 DL = &ED.Errors;
258 else if (PH.Next("warning"))
259 DL = &ED.Warnings;
260 else if (PH.Next("note"))
261 DL = &ED.Notes;
262 else
263 continue;
264 PH.Advance();
265
266 // default directive kind
267 bool RegexKind = false;
268 const char* KindStr = "string";
269
270 // next optional token: -
271 if (PH.Next("-re")) {
272 PH.Advance();
273 RegexKind = true;
274 KindStr = "regex";
275 }
276
277 // skip optional whitespace
278 PH.SkipWhitespace();
279
280 // next optional token: positive integer
281 unsigned Count = 1;
282 if (PH.Next(Count))
283 PH.Advance();
284
285 // skip optional whitespace
286 PH.SkipWhitespace();
287
288 // next token: {{
289 if (!PH.Next("{{")) {
Argyrios Kyrtzidisa64ccef2011-09-19 20:40:19 +0000290 PP.Diag(Pos.getLocWithOffset(PH.C-PH.Begin),
Chris Lattner60909e12010-04-28 20:02:30 +0000291 diag::err_verify_missing_start) << KindStr;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000292 continue;
293 }
Chris Lattner60909e12010-04-28 20:02:30 +0000294 PH.Advance();
295 const char* const ContentBegin = PH.C; // mark content begin
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000296
Chris Lattner60909e12010-04-28 20:02:30 +0000297 // search for token: }}
298 if (!PH.Search("}}")) {
Argyrios Kyrtzidisa64ccef2011-09-19 20:40:19 +0000299 PP.Diag(Pos.getLocWithOffset(PH.C-PH.Begin),
Chris Lattner60909e12010-04-28 20:02:30 +0000300 diag::err_verify_missing_end) << KindStr;
301 continue;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000302 }
Chris Lattner60909e12010-04-28 20:02:30 +0000303 const char* const ContentEnd = PH.P; // mark content end
304 PH.Advance();
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000305
Chris Lattner60909e12010-04-28 20:02:30 +0000306 // build directive text; convert \n to newlines
307 std::string Text;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000308 StringRef NewlineStr = "\\n";
309 StringRef Content(ContentBegin, ContentEnd-ContentBegin);
Chris Lattner60909e12010-04-28 20:02:30 +0000310 size_t CPos = 0;
311 size_t FPos;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000312 while ((FPos = Content.find(NewlineStr, CPos)) != StringRef::npos) {
Chris Lattner60909e12010-04-28 20:02:30 +0000313 Text += Content.substr(CPos, FPos-CPos);
314 Text += '\n';
315 CPos = FPos + NewlineStr.size();
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000316 }
Chris Lattner60909e12010-04-28 20:02:30 +0000317 if (Text.empty())
318 Text.assign(ContentBegin, ContentEnd);
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000319
Chris Lattner60909e12010-04-28 20:02:30 +0000320 // construct new directive
321 Directive *D = Directive::Create(RegexKind, Pos, Text, Count);
322 std::string Error;
323 if (D->isValid(Error))
324 DL->push_back(D);
325 else {
Argyrios Kyrtzidisa64ccef2011-09-19 20:40:19 +0000326 PP.Diag(Pos.getLocWithOffset(ContentBegin-PH.Begin),
Chris Lattner60909e12010-04-28 20:02:30 +0000327 diag::err_verify_invalid_content)
328 << KindStr << Error;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000329 }
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000330 }
331}
332
333/// FindExpectedDiags - Lex the main source file to find all of the
334// expected errors and warnings.
Axel Naumann01231612011-07-25 19:18:12 +0000335static void FindExpectedDiags(Preprocessor &PP, ExpectedData &ED, FileID FID) {
336 // Create a raw lexer to pull all the comments out of FID.
337 if (FID.isInvalid())
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000338 return;
339
Axel Naumann01231612011-07-25 19:18:12 +0000340 SourceManager& SM = PP.getSourceManager();
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000341 // Create a lexer to lex all the tokens of the main file in raw mode.
Chris Lattner6e290142009-11-30 04:18:44 +0000342 const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
343 Lexer RawLex(FID, FromFile, SM, PP.getLangOptions());
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000344
345 // Return comments as tokens, this is how we find expected diagnostics.
346 RawLex.SetCommentRetentionState(true);
347
348 Token Tok;
349 Tok.setKind(tok::comment);
350 while (Tok.isNot(tok::eof)) {
351 RawLex.Lex(Tok);
352 if (!Tok.is(tok::comment)) continue;
353
354 std::string Comment = PP.getSpelling(Tok);
355 if (Comment.empty()) continue;
356
Chris Lattner60909e12010-04-28 20:02:30 +0000357 // Find all expected errors/warnings/notes.
358 ParseDirective(&Comment[0], Comment.size(), ED, PP, Tok.getLocation());
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000359 };
360}
361
362/// PrintProblem - This takes a diagnostic map of the delta between expected and
363/// seen diagnostics. If there's anything in it, then something unexpected
364/// happened. Print the map out in a nice format and return "true". If the map
365/// is empty and we're not going to print things, then return "false".
366///
Daniel Dunbar221c7212009-11-14 07:53:24 +0000367static unsigned PrintProblem(Diagnostic &Diags, SourceManager *SourceMgr,
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000368 const_diag_iterator diag_begin,
369 const_diag_iterator diag_end,
370 const char *Kind, bool Expected) {
371 if (diag_begin == diag_end) return 0;
372
373 llvm::SmallString<256> Fmt;
374 llvm::raw_svector_ostream OS(Fmt);
375 for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) {
Daniel Dunbar221c7212009-11-14 07:53:24 +0000376 if (I->first.isInvalid() || !SourceMgr)
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000377 OS << "\n (frontend)";
378 else
Chandler Carruth5ef04ee2011-02-23 00:47:48 +0000379 OS << "\n Line " << SourceMgr->getPresumedLineNumber(I->first);
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000380 OS << ": " << I->second;
381 }
382
383 Diags.Report(diag::err_verify_inconsistent_diags)
Daniel Dunbar221c7212009-11-14 07:53:24 +0000384 << Kind << !Expected << OS.str();
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000385 return std::distance(diag_begin, diag_end);
386}
387
Chris Lattner60909e12010-04-28 20:02:30 +0000388static unsigned PrintProblem(Diagnostic &Diags, SourceManager *SourceMgr,
389 DirectiveList &DL, const char *Kind,
390 bool Expected) {
391 if (DL.empty())
392 return 0;
393
394 llvm::SmallString<256> Fmt;
395 llvm::raw_svector_ostream OS(Fmt);
396 for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) {
397 Directive& D = **I;
398 if (D.Location.isInvalid() || !SourceMgr)
399 OS << "\n (frontend)";
400 else
Chandler Carruth5ef04ee2011-02-23 00:47:48 +0000401 OS << "\n Line " << SourceMgr->getPresumedLineNumber(D.Location);
Chris Lattner60909e12010-04-28 20:02:30 +0000402 OS << ": " << D.Text;
403 }
404
405 Diags.Report(diag::err_verify_inconsistent_diags)
406 << Kind << !Expected << OS.str();
407 return DL.size();
408}
409
410/// CheckLists - Compare expected to seen diagnostic lists and return the
411/// the difference between them.
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000412///
Chris Lattner60909e12010-04-28 20:02:30 +0000413static unsigned CheckLists(Diagnostic &Diags, SourceManager &SourceMgr,
414 const char *Label,
415 DirectiveList &Left,
416 const_diag_iterator d2_begin,
417 const_diag_iterator d2_end) {
418 DirectiveList LeftOnly;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000419 DiagList Right(d2_begin, d2_end);
420
Chris Lattner60909e12010-04-28 20:02:30 +0000421 for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) {
422 Directive& D = **I;
Chandler Carruth5ef04ee2011-02-23 00:47:48 +0000423 unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.Location);
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000424
Chris Lattner60909e12010-04-28 20:02:30 +0000425 for (unsigned i = 0; i < D.Count; ++i) {
426 DiagList::iterator II, IE;
427 for (II = Right.begin(), IE = Right.end(); II != IE; ++II) {
Chandler Carruth5ef04ee2011-02-23 00:47:48 +0000428 unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first);
Chris Lattner60909e12010-04-28 20:02:30 +0000429 if (LineNo1 != LineNo2)
430 continue;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000431
Chris Lattner60909e12010-04-28 20:02:30 +0000432 const std::string &RightText = II->second;
433 if (D.Match(RightText))
434 break;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000435 }
Chris Lattner60909e12010-04-28 20:02:30 +0000436 if (II == IE) {
437 // Not found.
438 LeftOnly.push_back(*I);
439 } else {
440 // Found. The same cannot be found twice.
441 Right.erase(II);
442 }
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000443 }
444 }
445 // Now all that's left in Right are those that were not matched.
446
Chris Lattner60909e12010-04-28 20:02:30 +0000447 return (PrintProblem(Diags, &SourceMgr, LeftOnly, Label, true) +
448 PrintProblem(Diags, &SourceMgr, Right.begin(), Right.end(),
449 Label, false));
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000450}
451
452/// CheckResults - This compares the expected results to those that
453/// were actually reported. It emits any discrepencies. Return "true" if there
454/// were problems. Return "false" otherwise.
455///
456static unsigned CheckResults(Diagnostic &Diags, SourceManager &SourceMgr,
457 const TextDiagnosticBuffer &Buffer,
Chris Lattner60909e12010-04-28 20:02:30 +0000458 ExpectedData &ED) {
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000459 // We want to capture the delta between what was expected and what was
460 // seen.
461 //
462 // Expected \ Seen - set expected but not seen
463 // Seen \ Expected - set seen but not expected
464 unsigned NumProblems = 0;
465
466 // See if there are error mismatches.
Chris Lattner60909e12010-04-28 20:02:30 +0000467 NumProblems += CheckLists(Diags, SourceMgr, "error", ED.Errors,
468 Buffer.err_begin(), Buffer.err_end());
Daniel Dunbar221c7212009-11-14 07:53:24 +0000469
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000470 // See if there are warning mismatches.
Chris Lattner60909e12010-04-28 20:02:30 +0000471 NumProblems += CheckLists(Diags, SourceMgr, "warning", ED.Warnings,
472 Buffer.warn_begin(), Buffer.warn_end());
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000473
474 // See if there are note mismatches.
Chris Lattner60909e12010-04-28 20:02:30 +0000475 NumProblems += CheckLists(Diags, SourceMgr, "note", ED.Notes,
476 Buffer.note_begin(), Buffer.note_end());
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000477
478 return NumProblems;
479}
480
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000481void VerifyDiagnosticsClient::CheckDiagnostics() {
Chris Lattner60909e12010-04-28 20:02:30 +0000482 ExpectedData ED;
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000483
484 // Ensure any diagnostics go to the primary client.
Douglas Gregor78243652011-09-13 01:26:44 +0000485 bool OwnsCurClient = Diags.ownsClient();
Douglas Gregorbdbb0042010-08-18 22:29:43 +0000486 DiagnosticClient *CurClient = Diags.takeClient();
Douglas Gregor78243652011-09-13 01:26:44 +0000487 Diags.setClient(PrimaryClient, false);
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000488
489 // If we have a preprocessor, scan the source for expected diagnostic
490 // markers. If not then any diagnostics are unexpected.
491 if (CurrentPreprocessor) {
Axel Naumann01231612011-07-25 19:18:12 +0000492 SourceManager &SM = CurrentPreprocessor->getSourceManager();
493 // Extract expected-error strings from main file.
494 FindExpectedDiags(*CurrentPreprocessor, ED, SM.getMainFileID());
495 // Only check for expectations in other diagnostic locations
496 // if they are not the main file (via ID or FileEntry) - the main
497 // file has already been looked at, and its expectations must not
498 // be added twice.
499 if (!FirstErrorFID.isInvalid() && FirstErrorFID != SM.getMainFileID()
500 && (!SM.getFileEntryForID(FirstErrorFID)
501 || (SM.getFileEntryForID(FirstErrorFID) !=
Axel Naumann84c05e32011-08-24 13:36:19 +0000502 SM.getFileEntryForID(SM.getMainFileID())))) {
Axel Naumann01231612011-07-25 19:18:12 +0000503 FindExpectedDiags(*CurrentPreprocessor, ED, FirstErrorFID);
Axel Naumann84c05e32011-08-24 13:36:19 +0000504 FirstErrorFID = FileID();
505 }
Daniel Dunbar221c7212009-11-14 07:53:24 +0000506
507 // Check that the expected diagnostics occurred.
Axel Naumann01231612011-07-25 19:18:12 +0000508 NumErrors += CheckResults(Diags, SM, *Buffer, ED);
Daniel Dunbar221c7212009-11-14 07:53:24 +0000509 } else {
510 NumErrors += (PrintProblem(Diags, 0,
511 Buffer->err_begin(), Buffer->err_end(),
512 "error", false) +
513 PrintProblem(Diags, 0,
514 Buffer->warn_begin(), Buffer->warn_end(),
515 "warn", false) +
516 PrintProblem(Diags, 0,
517 Buffer->note_begin(), Buffer->note_end(),
518 "note", false));
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000519 }
520
Douglas Gregorbdbb0042010-08-18 22:29:43 +0000521 Diags.takeClient();
Douglas Gregor78243652011-09-13 01:26:44 +0000522 Diags.setClient(CurClient, OwnsCurClient);
Daniel Dunbar81f5a1e2009-11-14 03:23:19 +0000523
524 // Reset the buffer, we have processed all the diagnostics in it.
525 Buffer.reset(new TextDiagnosticBuffer());
526}
Chris Lattner60909e12010-04-28 20:02:30 +0000527
528Directive* Directive::Create(bool RegexKind, const SourceLocation &Location,
529 const std::string &Text, unsigned Count) {
530 if (RegexKind)
531 return new RegexDirective(Location, Text, Count);
532 return new StandardDirective(Location, Text, Count);
533}