2011-09-26 08:38:03 +08:00
|
|
|
//===---- VerifyDiagnosticConsumer.cpp - Verifying Diagnostic Client ------===//
|
2009-11-14 11:23:19 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is a concrete diagnostic client, which buffers the diagnostic messages.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
#include "clang/Frontend/VerifyDiagnosticConsumer.h"
|
2013-02-09 06:30:41 +08:00
|
|
|
#include "clang/Basic/CharInfo.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/FileManager.h"
|
2009-11-14 11:23:19 +08:00
|
|
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
|
|
|
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
2012-08-10 09:06:16 +08:00
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
2009-11-14 11:23:19 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
2010-04-29 04:02:30 +08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2009-11-14 11:23:19 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-12-15 10:58:00 +08:00
|
|
|
|
2009-11-14 11:23:19 +08:00
|
|
|
using namespace clang;
|
2012-07-10 10:56:15 +08:00
|
|
|
typedef VerifyDiagnosticConsumer::Directive Directive;
|
|
|
|
typedef VerifyDiagnosticConsumer::DirectiveList DirectiveList;
|
|
|
|
typedef VerifyDiagnosticConsumer::ExpectedData ExpectedData;
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
VerifyDiagnosticConsumer::VerifyDiagnosticConsumer(DiagnosticsEngine &_Diags)
|
2012-08-10 09:06:16 +08:00
|
|
|
: Diags(_Diags),
|
|
|
|
PrimaryClient(Diags.getClient()), OwnsPrimaryClient(Diags.ownsClient()),
|
|
|
|
Buffer(new TextDiagnosticBuffer()), CurrentPreprocessor(0),
|
2012-10-19 20:49:32 +08:00
|
|
|
LangOpts(0), SrcManager(0), ActiveSourceFiles(0), Status(HasNoDirectives)
|
2011-09-13 09:26:44 +08:00
|
|
|
{
|
|
|
|
Diags.takeClient();
|
2012-08-19 00:58:52 +08:00
|
|
|
if (Diags.hasSourceManager())
|
|
|
|
setSourceManager(Diags.getSourceManager());
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
VerifyDiagnosticConsumer::~VerifyDiagnosticConsumer() {
|
2012-08-10 09:06:16 +08:00
|
|
|
assert(!ActiveSourceFiles && "Incomplete parsing of source files!");
|
|
|
|
assert(!CurrentPreprocessor && "CurrentPreprocessor should be invalid!");
|
2012-08-19 00:58:52 +08:00
|
|
|
SrcManager = 0;
|
2011-09-13 09:26:44 +08:00
|
|
|
CheckDiagnostics();
|
|
|
|
Diags.takeClient();
|
|
|
|
if (OwnsPrimaryClient)
|
|
|
|
delete PrimaryClient;
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
namespace {
|
|
|
|
class VerifyFileTracker : public PPCallbacks {
|
2012-08-19 00:58:52 +08:00
|
|
|
VerifyDiagnosticConsumer &Verify;
|
2012-08-10 09:06:16 +08:00
|
|
|
SourceManager &SM;
|
|
|
|
|
|
|
|
public:
|
2012-08-19 00:58:52 +08:00
|
|
|
VerifyFileTracker(VerifyDiagnosticConsumer &Verify, SourceManager &SM)
|
|
|
|
: Verify(Verify), SM(SM) { }
|
2012-08-10 09:06:16 +08:00
|
|
|
|
|
|
|
/// \brief Hook into the preprocessor and update the list of parsed
|
|
|
|
/// files when the preprocessor indicates a new file is entered.
|
|
|
|
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
|
|
|
|
SrcMgr::CharacteristicKind FileType,
|
|
|
|
FileID PrevFID) {
|
2012-08-19 00:58:52 +08:00
|
|
|
Verify.UpdateParsedFileStatus(SM, SM.getFileID(Loc),
|
|
|
|
VerifyDiagnosticConsumer::IsParsed);
|
2012-08-10 09:06:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // End anonymous namespace.
|
|
|
|
#endif
|
|
|
|
|
2011-09-26 07:39:51 +08:00
|
|
|
// DiagnosticConsumer interface.
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
void VerifyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts,
|
2012-01-21 00:28:04 +08:00
|
|
|
const Preprocessor *PP) {
|
2012-08-10 09:06:16 +08:00
|
|
|
// Attach comment handler on first invocation.
|
|
|
|
if (++ActiveSourceFiles == 1) {
|
|
|
|
if (PP) {
|
|
|
|
CurrentPreprocessor = PP;
|
2012-08-19 00:58:52 +08:00
|
|
|
this->LangOpts = &LangOpts;
|
|
|
|
setSourceManager(PP->getSourceManager());
|
2012-08-10 09:06:16 +08:00
|
|
|
const_cast<Preprocessor*>(PP)->addCommentHandler(this);
|
|
|
|
#ifndef NDEBUG
|
2012-08-19 00:58:52 +08:00
|
|
|
// Debug build tracks parsed files.
|
|
|
|
VerifyFileTracker *V = new VerifyFileTracker(*this, *SrcManager);
|
2012-08-10 09:06:16 +08:00
|
|
|
const_cast<Preprocessor*>(PP)->addPPCallbacks(V);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
assert((!PP || CurrentPreprocessor == PP) && "Preprocessor changed!");
|
2009-11-14 11:23:19 +08:00
|
|
|
PrimaryClient->BeginSourceFile(LangOpts, PP);
|
|
|
|
}
|
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
void VerifyDiagnosticConsumer::EndSourceFile() {
|
2012-08-10 09:06:16 +08:00
|
|
|
assert(ActiveSourceFiles && "No active source files!");
|
2009-11-14 11:23:19 +08:00
|
|
|
PrimaryClient->EndSourceFile();
|
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
// Detach comment handler once last active source file completed.
|
|
|
|
if (--ActiveSourceFiles == 0) {
|
|
|
|
if (CurrentPreprocessor)
|
|
|
|
const_cast<Preprocessor*>(CurrentPreprocessor)->removeCommentHandler(this);
|
|
|
|
|
|
|
|
// Check diagnostics once last file completed.
|
|
|
|
CheckDiagnostics();
|
|
|
|
CurrentPreprocessor = 0;
|
2012-08-19 00:58:52 +08:00
|
|
|
LangOpts = 0;
|
2012-08-10 09:06:16 +08:00
|
|
|
}
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
2009-11-14 15:53:24 +08:00
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
void VerifyDiagnosticConsumer::HandleDiagnostic(
|
2011-09-26 09:18:08 +08:00
|
|
|
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) {
|
2012-08-19 00:58:52 +08:00
|
|
|
if (Info.hasSourceManager())
|
|
|
|
setSourceManager(Info.getSourceManager());
|
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
#ifndef NDEBUG
|
2012-08-19 00:58:52 +08:00
|
|
|
// Debug build tracks unparsed files for possible
|
|
|
|
// unparsed expected-* directives.
|
|
|
|
if (SrcManager) {
|
|
|
|
SourceLocation Loc = Info.getLocation();
|
|
|
|
if (Loc.isValid()) {
|
|
|
|
ParsedStatus PS = IsUnparsed;
|
|
|
|
|
|
|
|
Loc = SrcManager->getExpansionLoc(Loc);
|
|
|
|
FileID FID = SrcManager->getFileID(Loc);
|
|
|
|
|
|
|
|
const FileEntry *FE = SrcManager->getFileEntryForID(FID);
|
|
|
|
if (FE && CurrentPreprocessor && SrcManager->isLoadedFileID(FID)) {
|
|
|
|
// If the file is a modules header file it shall not be parsed
|
|
|
|
// for expected-* directives.
|
|
|
|
HeaderSearch &HS = CurrentPreprocessor->getHeaderSearchInfo();
|
|
|
|
if (HS.findModuleForHeader(FE))
|
|
|
|
PS = IsUnparsedNoDirectives;
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateParsedFileStatus(*SrcManager, FID, PS);
|
|
|
|
}
|
2011-07-26 03:18:12 +08:00
|
|
|
}
|
2012-08-10 09:06:16 +08:00
|
|
|
#endif
|
2012-08-19 00:58:52 +08:00
|
|
|
|
2009-11-14 11:23:19 +08:00
|
|
|
// Send the diagnostic to the buffer, we will check it once we reach the end
|
|
|
|
// of the source file (or are destructed).
|
|
|
|
Buffer->HandleDiagnostic(DiagLevel, Info);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Checking diagnostics implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef TextDiagnosticBuffer::DiagList DiagList;
|
|
|
|
typedef TextDiagnosticBuffer::const_iterator const_diag_iterator;
|
|
|
|
|
2010-04-29 04:02:30 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// StandardDirective - Directive with string matching.
|
|
|
|
///
|
|
|
|
class StandardDirective : public Directive {
|
|
|
|
public:
|
2012-07-10 10:57:03 +08:00
|
|
|
StandardDirective(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc,
|
2012-07-10 10:57:26 +08:00
|
|
|
StringRef Text, unsigned Min, unsigned Max)
|
|
|
|
: Directive(DirectiveLoc, DiagnosticLoc, Text, Min, Max) { }
|
2010-04-29 04:02:30 +08:00
|
|
|
|
|
|
|
virtual bool isValid(std::string &Error) {
|
|
|
|
// all strings are considered valid; even empty ones
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-10 10:56:15 +08:00
|
|
|
virtual bool match(StringRef S) {
|
|
|
|
return S.find(Text) != StringRef::npos;
|
2010-04-29 04:02:30 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// RegexDirective - Directive with regular-expression matching.
|
|
|
|
///
|
|
|
|
class RegexDirective : public Directive {
|
|
|
|
public:
|
2012-07-10 10:57:03 +08:00
|
|
|
RegexDirective(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc,
|
2012-07-10 10:57:26 +08:00
|
|
|
StringRef Text, unsigned Min, unsigned Max)
|
|
|
|
: Directive(DirectiveLoc, DiagnosticLoc, Text, Min, Max), Regex(Text) { }
|
2010-04-29 04:02:30 +08:00
|
|
|
|
|
|
|
virtual bool isValid(std::string &Error) {
|
|
|
|
if (Regex.isValid(Error))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-10 10:56:15 +08:00
|
|
|
virtual bool match(StringRef S) {
|
2010-04-29 04:02:30 +08:00
|
|
|
return Regex.match(S);
|
|
|
|
}
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2010-04-29 04:02:30 +08:00
|
|
|
private:
|
|
|
|
llvm::Regex Regex;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParseHelper
|
|
|
|
{
|
|
|
|
public:
|
2012-07-12 03:58:23 +08:00
|
|
|
ParseHelper(StringRef S)
|
|
|
|
: Begin(S.begin()), End(S.end()), C(Begin), P(Begin), PEnd(NULL) { }
|
2010-04-29 04:02:30 +08:00
|
|
|
|
|
|
|
// Return true if string literal is next.
|
2011-07-23 18:55:15 +08:00
|
|
|
bool Next(StringRef S) {
|
2010-04-29 04:02:30 +08:00
|
|
|
P = C;
|
2010-09-02 01:28:48 +08:00
|
|
|
PEnd = C + S.size();
|
2010-04-29 04:02:30 +08:00
|
|
|
if (PEnd > End)
|
|
|
|
return false;
|
2010-09-02 01:28:48 +08:00
|
|
|
return !memcmp(P, S.data(), S.size());
|
2010-04-29 04:02:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if number is next.
|
|
|
|
// Output N only if number is next.
|
|
|
|
bool Next(unsigned &N) {
|
|
|
|
unsigned TMP = 0;
|
|
|
|
P = C;
|
|
|
|
for (; P < End && P[0] >= '0' && P[0] <= '9'; ++P) {
|
|
|
|
TMP *= 10;
|
|
|
|
TMP += P[0] - '0';
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
2010-04-29 04:02:30 +08:00
|
|
|
if (P == C)
|
|
|
|
return false;
|
|
|
|
PEnd = P;
|
|
|
|
N = TMP;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if string literal is found.
|
|
|
|
// When true, P marks begin-position of S in content.
|
2012-10-19 20:36:49 +08:00
|
|
|
bool Search(StringRef S, bool EnsureStartOfWord = false) {
|
|
|
|
do {
|
|
|
|
P = std::search(C, End, S.begin(), S.end());
|
|
|
|
PEnd = P + S.size();
|
|
|
|
if (P == End)
|
|
|
|
break;
|
|
|
|
if (!EnsureStartOfWord
|
|
|
|
// Check if string literal starts a new word.
|
2013-02-09 06:30:41 +08:00
|
|
|
|| P == Begin || isWhitespace(P[-1])
|
2012-10-19 20:36:49 +08:00
|
|
|
// Or it could be preceeded by the start of a comment.
|
|
|
|
|| (P > (Begin + 1) && (P[-1] == '/' || P[-1] == '*')
|
|
|
|
&& P[-2] == '/'))
|
|
|
|
return true;
|
|
|
|
// Otherwise, skip and search again.
|
|
|
|
} while (Advance());
|
|
|
|
return false;
|
2010-04-29 04:02:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advance 1-past previous next/search.
|
|
|
|
// Behavior is undefined if previous next/search failed.
|
|
|
|
bool Advance() {
|
|
|
|
C = PEnd;
|
|
|
|
return C < End;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip zero or more whitespace.
|
|
|
|
void SkipWhitespace() {
|
2013-02-09 06:30:41 +08:00
|
|
|
for (; C < End && isWhitespace(*C); ++C)
|
2010-04-29 04:02:30 +08:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if EOF reached.
|
|
|
|
bool Done() {
|
|
|
|
return !(C < End);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * const Begin; // beginning of expected content
|
|
|
|
const char * const End; // end of expected content (1-past)
|
|
|
|
const char *C; // position of next char in content
|
|
|
|
const char *P;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *PEnd; // previous next/search subject end (1-past)
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace anonymous
|
|
|
|
|
|
|
|
/// ParseDirective - Go through the comment and see if it indicates expected
|
|
|
|
/// diagnostics. If so, then put them in the appropriate directive list.
|
|
|
|
///
|
2012-07-12 03:58:23 +08:00
|
|
|
/// Returns true if any valid directives were found.
|
2012-08-10 09:06:16 +08:00
|
|
|
static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
|
2012-10-19 20:49:32 +08:00
|
|
|
SourceLocation Pos, DiagnosticsEngine &Diags,
|
|
|
|
VerifyDiagnosticConsumer::DirectiveStatus &Status) {
|
2010-04-29 04:02:30 +08:00
|
|
|
// A single comment may contain multiple directives.
|
2012-07-12 03:58:23 +08:00
|
|
|
bool FoundDirective = false;
|
|
|
|
for (ParseHelper PH(S); !PH.Done();) {
|
2012-07-10 10:57:03 +08:00
|
|
|
// Search for token: expected
|
2012-10-19 20:36:49 +08:00
|
|
|
if (!PH.Search("expected", true))
|
2010-04-29 04:02:30 +08:00
|
|
|
break;
|
|
|
|
PH.Advance();
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Next token: -
|
2010-04-29 04:02:30 +08:00
|
|
|
if (!PH.Next("-"))
|
|
|
|
continue;
|
|
|
|
PH.Advance();
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Next token: { error | warning | note }
|
2010-04-29 04:02:30 +08:00
|
|
|
DirectiveList* DL = NULL;
|
|
|
|
if (PH.Next("error"))
|
2012-08-10 09:06:16 +08:00
|
|
|
DL = ED ? &ED->Errors : NULL;
|
2010-04-29 04:02:30 +08:00
|
|
|
else if (PH.Next("warning"))
|
2012-08-10 09:06:16 +08:00
|
|
|
DL = ED ? &ED->Warnings : NULL;
|
2010-04-29 04:02:30 +08:00
|
|
|
else if (PH.Next("note"))
|
2012-08-10 09:06:16 +08:00
|
|
|
DL = ED ? &ED->Notes : NULL;
|
2012-10-19 20:49:32 +08:00
|
|
|
else if (PH.Next("no-diagnostics")) {
|
|
|
|
if (Status == VerifyDiagnosticConsumer::HasOtherExpectedDirectives)
|
|
|
|
Diags.Report(Pos, diag::err_verify_invalid_no_diags)
|
|
|
|
<< /*IsExpectedNoDiagnostics=*/true;
|
|
|
|
else
|
|
|
|
Status = VerifyDiagnosticConsumer::HasExpectedNoDiagnostics;
|
|
|
|
continue;
|
|
|
|
} else
|
2010-04-29 04:02:30 +08:00
|
|
|
continue;
|
|
|
|
PH.Advance();
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-10-19 20:49:32 +08:00
|
|
|
if (Status == VerifyDiagnosticConsumer::HasExpectedNoDiagnostics) {
|
|
|
|
Diags.Report(Pos, diag::err_verify_invalid_no_diags)
|
|
|
|
<< /*IsExpectedNoDiagnostics=*/false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Status = VerifyDiagnosticConsumer::HasOtherExpectedDirectives;
|
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
// If a directive has been found but we're not interested
|
|
|
|
// in storing the directive information, return now.
|
|
|
|
if (!DL)
|
|
|
|
return true;
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Default directive kind.
|
2010-04-29 04:02:30 +08:00
|
|
|
bool RegexKind = false;
|
|
|
|
const char* KindStr = "string";
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Next optional token: -
|
2010-04-29 04:02:30 +08:00
|
|
|
if (PH.Next("-re")) {
|
|
|
|
PH.Advance();
|
|
|
|
RegexKind = true;
|
|
|
|
KindStr = "regex";
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Next optional token: @
|
|
|
|
SourceLocation ExpectedLoc;
|
|
|
|
if (!PH.Next("@")) {
|
|
|
|
ExpectedLoc = Pos;
|
|
|
|
} else {
|
|
|
|
PH.Advance();
|
|
|
|
unsigned Line = 0;
|
|
|
|
bool FoundPlus = PH.Next("+");
|
|
|
|
if (FoundPlus || PH.Next("-")) {
|
|
|
|
// Relative to current line.
|
|
|
|
PH.Advance();
|
|
|
|
bool Invalid = false;
|
|
|
|
unsigned ExpectedLine = SM.getSpellingLineNumber(Pos, &Invalid);
|
|
|
|
if (!Invalid && PH.Next(Line) && (FoundPlus || Line < ExpectedLine)) {
|
|
|
|
if (FoundPlus) ExpectedLine += Line;
|
|
|
|
else ExpectedLine -= Line;
|
|
|
|
ExpectedLoc = SM.translateLineCol(SM.getFileID(Pos), ExpectedLine, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Absolute line number.
|
|
|
|
if (PH.Next(Line) && Line > 0)
|
|
|
|
ExpectedLoc = SM.translateLineCol(SM.getFileID(Pos), Line, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ExpectedLoc.isInvalid()) {
|
|
|
|
Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin),
|
|
|
|
diag::err_verify_missing_line) << KindStr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PH.Advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip optional whitespace.
|
2010-04-29 04:02:30 +08:00
|
|
|
PH.SkipWhitespace();
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Next optional token: positive integer or a '+'.
|
2012-07-10 10:57:26 +08:00
|
|
|
unsigned Min = 1;
|
|
|
|
unsigned Max = 1;
|
|
|
|
if (PH.Next(Min)) {
|
2010-04-29 04:02:30 +08:00
|
|
|
PH.Advance();
|
2012-07-10 10:57:26 +08:00
|
|
|
// A positive integer can be followed by a '+' meaning min
|
|
|
|
// or more, or by a '-' meaning a range from min to max.
|
|
|
|
if (PH.Next("+")) {
|
|
|
|
Max = Directive::MaxCount;
|
|
|
|
PH.Advance();
|
|
|
|
} else if (PH.Next("-")) {
|
|
|
|
PH.Advance();
|
|
|
|
if (!PH.Next(Max) || Max < Min) {
|
|
|
|
Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin),
|
|
|
|
diag::err_verify_invalid_range) << KindStr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PH.Advance();
|
|
|
|
} else {
|
|
|
|
Max = Min;
|
|
|
|
}
|
|
|
|
} else if (PH.Next("+")) {
|
|
|
|
// '+' on its own means "1 or more".
|
|
|
|
Max = Directive::MaxCount;
|
2011-12-15 10:28:16 +08:00
|
|
|
PH.Advance();
|
|
|
|
}
|
2010-04-29 04:02:30 +08:00
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Skip optional whitespace.
|
2010-04-29 04:02:30 +08:00
|
|
|
PH.SkipWhitespace();
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Next token: {{
|
2010-04-29 04:02:30 +08:00
|
|
|
if (!PH.Next("{{")) {
|
2012-07-10 10:56:15 +08:00
|
|
|
Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin),
|
|
|
|
diag::err_verify_missing_start) << KindStr;
|
2010-04-29 04:02:30 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PH.Advance();
|
|
|
|
const char* const ContentBegin = PH.C; // mark content begin
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Search for token: }}
|
2010-04-29 04:02:30 +08:00
|
|
|
if (!PH.Search("}}")) {
|
2012-07-10 10:56:15 +08:00
|
|
|
Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin),
|
|
|
|
diag::err_verify_missing_end) << KindStr;
|
2010-04-29 04:02:30 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const char* const ContentEnd = PH.P; // mark content end
|
|
|
|
PH.Advance();
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Build directive text; convert \n to newlines.
|
2010-04-29 04:02:30 +08:00
|
|
|
std::string Text;
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef NewlineStr = "\\n";
|
|
|
|
StringRef Content(ContentBegin, ContentEnd-ContentBegin);
|
2010-04-29 04:02:30 +08:00
|
|
|
size_t CPos = 0;
|
|
|
|
size_t FPos;
|
2011-07-23 18:55:15 +08:00
|
|
|
while ((FPos = Content.find(NewlineStr, CPos)) != StringRef::npos) {
|
2010-04-29 04:02:30 +08:00
|
|
|
Text += Content.substr(CPos, FPos-CPos);
|
|
|
|
Text += '\n';
|
|
|
|
CPos = FPos + NewlineStr.size();
|
|
|
|
}
|
|
|
|
if (Text.empty())
|
|
|
|
Text.assign(ContentBegin, ContentEnd);
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
// Construct new directive.
|
2012-07-10 10:57:26 +08:00
|
|
|
Directive *D = Directive::create(RegexKind, Pos, ExpectedLoc, Text,
|
|
|
|
Min, Max);
|
2010-04-29 04:02:30 +08:00
|
|
|
std::string Error;
|
2012-07-12 03:58:23 +08:00
|
|
|
if (D->isValid(Error)) {
|
2010-04-29 04:02:30 +08:00
|
|
|
DL->push_back(D);
|
2012-07-12 03:58:23 +08:00
|
|
|
FoundDirective = true;
|
|
|
|
} else {
|
2012-07-10 10:56:15 +08:00
|
|
|
Diags.Report(Pos.getLocWithOffset(ContentBegin-PH.Begin),
|
|
|
|
diag::err_verify_invalid_content)
|
2010-04-29 04:02:30 +08:00
|
|
|
<< KindStr << Error;
|
|
|
|
}
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
2012-07-12 03:58:23 +08:00
|
|
|
|
|
|
|
return FoundDirective;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// HandleComment - Hook into the preprocessor and extract comments containing
|
|
|
|
/// expected errors and warnings.
|
|
|
|
bool VerifyDiagnosticConsumer::HandleComment(Preprocessor &PP,
|
|
|
|
SourceRange Comment) {
|
|
|
|
SourceManager &SM = PP.getSourceManager();
|
|
|
|
SourceLocation CommentBegin = Comment.getBegin();
|
|
|
|
|
|
|
|
const char *CommentRaw = SM.getCharacterData(CommentBegin);
|
|
|
|
StringRef C(CommentRaw, SM.getCharacterData(Comment.getEnd()) - CommentRaw);
|
|
|
|
|
|
|
|
if (C.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Fold any "\<EOL>" sequences
|
|
|
|
size_t loc = C.find('\\');
|
|
|
|
if (loc == StringRef::npos) {
|
2012-10-19 20:49:32 +08:00
|
|
|
ParseDirective(C, &ED, SM, CommentBegin, PP.getDiagnostics(), Status);
|
2012-07-12 03:58:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string C2;
|
|
|
|
C2.reserve(C.size());
|
|
|
|
|
|
|
|
for (size_t last = 0;; loc = C.find('\\', last)) {
|
|
|
|
if (loc == StringRef::npos || loc == C.size()) {
|
|
|
|
C2 += C.substr(last);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
C2 += C.substr(last, loc-last);
|
|
|
|
last = loc + 1;
|
|
|
|
|
|
|
|
if (C[last] == '\n' || C[last] == '\r') {
|
|
|
|
++last;
|
|
|
|
|
|
|
|
// Escape \r\n or \n\r, but not \n\n.
|
|
|
|
if (last < C.size())
|
|
|
|
if (C[last] == '\n' || C[last] == '\r')
|
|
|
|
if (C[last] != C[last-1])
|
|
|
|
++last;
|
|
|
|
} else {
|
|
|
|
// This was just a normal backslash.
|
|
|
|
C2 += '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!C2.empty())
|
2012-10-19 20:49:32 +08:00
|
|
|
ParseDirective(C2, &ED, SM, CommentBegin, PP.getDiagnostics(), Status);
|
2012-07-12 03:58:23 +08:00
|
|
|
return false;
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
/// \brief Lex the specified source file to determine whether it contains
|
|
|
|
/// any expected-* directives. As a Lexer is used rather than a full-blown
|
|
|
|
/// Preprocessor, directives inside skipped #if blocks will still be found.
|
|
|
|
///
|
|
|
|
/// \return true if any directives were found.
|
2012-08-19 00:58:52 +08:00
|
|
|
static bool findDirectives(SourceManager &SM, FileID FID,
|
|
|
|
const LangOptions &LangOpts) {
|
2011-07-26 03:18:12 +08:00
|
|
|
// Create a raw lexer to pull all the comments out of FID.
|
|
|
|
if (FID.isInvalid())
|
2012-08-10 09:06:16 +08:00
|
|
|
return false;
|
2009-11-14 11:23:19 +08:00
|
|
|
|
|
|
|
// Create a lexer to lex all the tokens of the main file in raw mode.
|
2009-11-30 12:18:44 +08:00
|
|
|
const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID);
|
2012-08-19 00:58:52 +08:00
|
|
|
Lexer RawLex(FID, FromFile, SM, LangOpts);
|
2009-11-14 11:23:19 +08:00
|
|
|
|
|
|
|
// Return comments as tokens, this is how we find expected diagnostics.
|
|
|
|
RawLex.SetCommentRetentionState(true);
|
|
|
|
|
|
|
|
Token Tok;
|
|
|
|
Tok.setKind(tok::comment);
|
2012-10-19 20:49:32 +08:00
|
|
|
VerifyDiagnosticConsumer::DirectiveStatus Status =
|
|
|
|
VerifyDiagnosticConsumer::HasNoDirectives;
|
2009-11-14 11:23:19 +08:00
|
|
|
while (Tok.isNot(tok::eof)) {
|
|
|
|
RawLex.Lex(Tok);
|
|
|
|
if (!Tok.is(tok::comment)) continue;
|
|
|
|
|
2012-08-19 00:58:52 +08:00
|
|
|
std::string Comment = RawLex.getSpelling(Tok, SM, LangOpts);
|
2009-11-14 11:23:19 +08:00
|
|
|
if (Comment.empty()) continue;
|
|
|
|
|
2012-08-19 00:58:52 +08:00
|
|
|
// Find first directive.
|
|
|
|
if (ParseDirective(Comment, 0, SM, Tok.getLocation(),
|
2012-10-19 20:49:32 +08:00
|
|
|
SM.getDiagnostics(), Status))
|
2012-08-19 00:58:52 +08:00
|
|
|
return true;
|
2012-08-10 09:06:16 +08:00
|
|
|
}
|
2012-08-19 00:58:52 +08:00
|
|
|
return false;
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
2012-08-10 09:06:16 +08:00
|
|
|
#endif // !NDEBUG
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
/// \brief Takes a list of diagnostics that have been generated but not matched
|
|
|
|
/// by an expected-* directive and produces a diagnostic to the user from this.
|
|
|
|
static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceMgr,
|
|
|
|
const_diag_iterator diag_begin,
|
|
|
|
const_diag_iterator diag_end,
|
|
|
|
const char *Kind) {
|
2009-11-14 11:23:19 +08:00
|
|
|
if (diag_begin == diag_end) return 0;
|
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> Fmt;
|
2009-11-14 11:23:19 +08:00
|
|
|
llvm::raw_svector_ostream OS(Fmt);
|
|
|
|
for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) {
|
2009-11-14 15:53:24 +08:00
|
|
|
if (I->first.isInvalid() || !SourceMgr)
|
2009-11-14 11:23:19 +08:00
|
|
|
OS << "\n (frontend)";
|
|
|
|
else
|
2011-02-23 08:47:48 +08:00
|
|
|
OS << "\n Line " << SourceMgr->getPresumedLineNumber(I->first);
|
2009-11-14 11:23:19 +08:00
|
|
|
OS << ": " << I->second;
|
|
|
|
}
|
|
|
|
|
2012-07-12 00:50:36 +08:00
|
|
|
Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
|
2012-07-10 10:57:03 +08:00
|
|
|
<< Kind << /*Unexpected=*/true << OS.str();
|
2009-11-14 11:23:19 +08:00
|
|
|
return std::distance(diag_begin, diag_end);
|
|
|
|
}
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
/// \brief Takes a list of diagnostics that were expected to have been generated
|
|
|
|
/// but were not and produces a diagnostic to the user from this.
|
|
|
|
static unsigned PrintExpected(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
|
|
|
|
DirectiveList &DL, const char *Kind) {
|
2010-04-29 04:02:30 +08:00
|
|
|
if (DL.empty())
|
|
|
|
return 0;
|
|
|
|
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> Fmt;
|
2010-04-29 04:02:30 +08:00
|
|
|
llvm::raw_svector_ostream OS(Fmt);
|
|
|
|
for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) {
|
2012-07-10 10:57:03 +08:00
|
|
|
Directive &D = **I;
|
|
|
|
OS << "\n Line " << SourceMgr.getPresumedLineNumber(D.DiagnosticLoc);
|
|
|
|
if (D.DirectiveLoc != D.DiagnosticLoc)
|
|
|
|
OS << " (directive at "
|
|
|
|
<< SourceMgr.getFilename(D.DirectiveLoc) << ":"
|
|
|
|
<< SourceMgr.getPresumedLineNumber(D.DirectiveLoc) << ")";
|
2010-04-29 04:02:30 +08:00
|
|
|
OS << ": " << D.Text;
|
|
|
|
}
|
|
|
|
|
2012-07-12 00:50:36 +08:00
|
|
|
Diags.Report(diag::err_verify_inconsistent_diags).setForceEmit()
|
2012-07-10 10:57:03 +08:00
|
|
|
<< Kind << /*Unexpected=*/false << OS.str();
|
2010-04-29 04:02:30 +08:00
|
|
|
return DL.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckLists - Compare expected to seen diagnostic lists and return the
|
|
|
|
/// the difference between them.
|
2009-11-14 11:23:19 +08:00
|
|
|
///
|
2011-09-26 07:23:43 +08:00
|
|
|
static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
|
2010-04-29 04:02:30 +08:00
|
|
|
const char *Label,
|
|
|
|
DirectiveList &Left,
|
|
|
|
const_diag_iterator d2_begin,
|
|
|
|
const_diag_iterator d2_end) {
|
|
|
|
DirectiveList LeftOnly;
|
2009-11-14 11:23:19 +08:00
|
|
|
DiagList Right(d2_begin, d2_end);
|
|
|
|
|
2010-04-29 04:02:30 +08:00
|
|
|
for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) {
|
|
|
|
Directive& D = **I;
|
2012-07-10 10:57:03 +08:00
|
|
|
unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.DiagnosticLoc);
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-07-10 10:57:26 +08:00
|
|
|
for (unsigned i = 0; i < D.Max; ++i) {
|
2010-04-29 04:02:30 +08:00
|
|
|
DiagList::iterator II, IE;
|
|
|
|
for (II = Right.begin(), IE = Right.end(); II != IE; ++II) {
|
2011-02-23 08:47:48 +08:00
|
|
|
unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first);
|
2010-04-29 04:02:30 +08:00
|
|
|
if (LineNo1 != LineNo2)
|
|
|
|
continue;
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2010-04-29 04:02:30 +08:00
|
|
|
const std::string &RightText = II->second;
|
2012-07-10 10:56:15 +08:00
|
|
|
if (D.match(RightText))
|
2010-04-29 04:02:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (II == IE) {
|
|
|
|
// Not found.
|
2012-07-10 10:57:26 +08:00
|
|
|
if (i >= D.Min) break;
|
2010-04-29 04:02:30 +08:00
|
|
|
LeftOnly.push_back(*I);
|
|
|
|
} else {
|
|
|
|
// Found. The same cannot be found twice.
|
|
|
|
Right.erase(II);
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now all that's left in Right are those that were not matched.
|
2012-07-10 10:57:03 +08:00
|
|
|
unsigned num = PrintExpected(Diags, SourceMgr, LeftOnly, Label);
|
|
|
|
num += PrintUnexpected(Diags, &SourceMgr, Right.begin(), Right.end(), Label);
|
2011-12-17 21:00:31 +08:00
|
|
|
return num;
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckResults - This compares the expected results to those that
|
|
|
|
/// were actually reported. It emits any discrepencies. Return "true" if there
|
|
|
|
/// were problems. Return "false" otherwise.
|
|
|
|
///
|
2011-09-26 07:23:43 +08:00
|
|
|
static unsigned CheckResults(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
|
2009-11-14 11:23:19 +08:00
|
|
|
const TextDiagnosticBuffer &Buffer,
|
2010-04-29 04:02:30 +08:00
|
|
|
ExpectedData &ED) {
|
2009-11-14 11:23:19 +08:00
|
|
|
// We want to capture the delta between what was expected and what was
|
|
|
|
// seen.
|
|
|
|
//
|
|
|
|
// Expected \ Seen - set expected but not seen
|
|
|
|
// Seen \ Expected - set seen but not expected
|
|
|
|
unsigned NumProblems = 0;
|
|
|
|
|
|
|
|
// See if there are error mismatches.
|
2010-04-29 04:02:30 +08:00
|
|
|
NumProblems += CheckLists(Diags, SourceMgr, "error", ED.Errors,
|
|
|
|
Buffer.err_begin(), Buffer.err_end());
|
2009-11-14 15:53:24 +08:00
|
|
|
|
2009-11-14 11:23:19 +08:00
|
|
|
// See if there are warning mismatches.
|
2010-04-29 04:02:30 +08:00
|
|
|
NumProblems += CheckLists(Diags, SourceMgr, "warning", ED.Warnings,
|
|
|
|
Buffer.warn_begin(), Buffer.warn_end());
|
2009-11-14 11:23:19 +08:00
|
|
|
|
|
|
|
// See if there are note mismatches.
|
2010-04-29 04:02:30 +08:00
|
|
|
NumProblems += CheckLists(Diags, SourceMgr, "note", ED.Notes,
|
|
|
|
Buffer.note_begin(), Buffer.note_end());
|
2009-11-14 11:23:19 +08:00
|
|
|
|
|
|
|
return NumProblems;
|
|
|
|
}
|
|
|
|
|
2012-08-19 00:58:52 +08:00
|
|
|
void VerifyDiagnosticConsumer::UpdateParsedFileStatus(SourceManager &SM,
|
|
|
|
FileID FID,
|
|
|
|
ParsedStatus PS) {
|
|
|
|
// Check SourceManager hasn't changed.
|
|
|
|
setSourceManager(SM);
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (FID.isInvalid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const FileEntry *FE = SM.getFileEntryForID(FID);
|
|
|
|
|
|
|
|
if (PS == IsParsed) {
|
|
|
|
// Move the FileID from the unparsed set to the parsed set.
|
|
|
|
UnparsedFiles.erase(FID);
|
|
|
|
ParsedFiles.insert(std::make_pair(FID, FE));
|
|
|
|
} else if (!ParsedFiles.count(FID) && !UnparsedFiles.count(FID)) {
|
|
|
|
// Add the FileID to the unparsed set if we haven't seen it before.
|
|
|
|
|
|
|
|
// Check for directives.
|
|
|
|
bool FoundDirectives;
|
|
|
|
if (PS == IsUnparsedNoDirectives)
|
|
|
|
FoundDirectives = false;
|
|
|
|
else
|
|
|
|
FoundDirectives = !LangOpts || findDirectives(SM, FID, *LangOpts);
|
|
|
|
|
|
|
|
// Add the FileID to the unparsed set.
|
|
|
|
UnparsedFiles.insert(std::make_pair(FID,
|
|
|
|
UnparsedFileStatus(FE, FoundDirectives)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-26 08:38:03 +08:00
|
|
|
void VerifyDiagnosticConsumer::CheckDiagnostics() {
|
2009-11-14 11:23:19 +08:00
|
|
|
// Ensure any diagnostics go to the primary client.
|
2011-09-13 09:26:44 +08:00
|
|
|
bool OwnsCurClient = Diags.ownsClient();
|
2011-09-26 07:39:51 +08:00
|
|
|
DiagnosticConsumer *CurClient = Diags.takeClient();
|
2011-09-13 09:26:44 +08:00
|
|
|
Diags.setClient(PrimaryClient, false);
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-08-10 09:06:16 +08:00
|
|
|
#ifndef NDEBUG
|
2012-08-19 00:58:52 +08:00
|
|
|
// In a debug build, scan through any files that may have been missed
|
|
|
|
// during parsing and issue a fatal error if directives are contained
|
|
|
|
// within these files. If a fatal error occurs, this suggests that
|
|
|
|
// this file is being parsed separately from the main file, in which
|
|
|
|
// case consider moving the directives to the correct place, if this
|
|
|
|
// is applicable.
|
|
|
|
if (UnparsedFiles.size() > 0) {
|
|
|
|
// Generate a cache of parsed FileEntry pointers for alias lookups.
|
|
|
|
llvm::SmallPtrSet<const FileEntry *, 8> ParsedFileCache;
|
|
|
|
for (ParsedFilesMap::iterator I = ParsedFiles.begin(),
|
|
|
|
End = ParsedFiles.end(); I != End; ++I) {
|
|
|
|
if (const FileEntry *FE = I->second)
|
|
|
|
ParsedFileCache.insert(FE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through list of unparsed files.
|
|
|
|
for (UnparsedFilesMap::iterator I = UnparsedFiles.begin(),
|
|
|
|
End = UnparsedFiles.end(); I != End; ++I) {
|
|
|
|
const UnparsedFileStatus &Status = I->second;
|
|
|
|
const FileEntry *FE = Status.getFile();
|
|
|
|
|
|
|
|
// Skip files that have been parsed via an alias.
|
|
|
|
if (FE && ParsedFileCache.count(FE))
|
2012-08-10 09:06:16 +08:00
|
|
|
continue;
|
|
|
|
|
2012-08-19 00:58:52 +08:00
|
|
|
// Report a fatal error if this file contained directives.
|
|
|
|
if (Status.foundDirectives()) {
|
2012-08-10 09:06:16 +08:00
|
|
|
llvm::report_fatal_error(Twine("-verify directives found after rather"
|
|
|
|
" than during normal parsing of ",
|
2012-08-19 00:58:52 +08:00
|
|
|
StringRef(FE ? FE->getName() : "(unknown)")));
|
|
|
|
}
|
2011-08-24 21:36:19 +08:00
|
|
|
}
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2012-08-19 00:58:52 +08:00
|
|
|
// UnparsedFiles has been processed now, so clear it.
|
|
|
|
UnparsedFiles.clear();
|
|
|
|
}
|
|
|
|
#endif // !NDEBUG
|
|
|
|
|
|
|
|
if (SrcManager) {
|
2012-10-19 20:49:32 +08:00
|
|
|
// Produce an error if no expected-* directives could be found in the
|
|
|
|
// source file(s) processed.
|
|
|
|
if (Status == HasNoDirectives) {
|
|
|
|
Diags.Report(diag::err_verify_no_directives).setForceEmit();
|
|
|
|
++NumErrors;
|
|
|
|
Status = HasNoDirectivesReported;
|
|
|
|
}
|
|
|
|
|
2009-11-14 15:53:24 +08:00
|
|
|
// Check that the expected diagnostics occurred.
|
2012-08-19 00:58:52 +08:00
|
|
|
NumErrors += CheckResults(Diags, *SrcManager, *Buffer, ED);
|
2009-11-14 15:53:24 +08:00
|
|
|
} else {
|
2012-07-10 10:57:03 +08:00
|
|
|
NumErrors += (PrintUnexpected(Diags, 0, Buffer->err_begin(),
|
|
|
|
Buffer->err_end(), "error") +
|
|
|
|
PrintUnexpected(Diags, 0, Buffer->warn_begin(),
|
|
|
|
Buffer->warn_end(), "warn") +
|
|
|
|
PrintUnexpected(Diags, 0, Buffer->note_begin(),
|
|
|
|
Buffer->note_end(), "note"));
|
2009-11-14 15:53:24 +08:00
|
|
|
}
|
2009-11-14 11:23:19 +08:00
|
|
|
|
2010-08-19 06:29:43 +08:00
|
|
|
Diags.takeClient();
|
2011-09-13 09:26:44 +08:00
|
|
|
Diags.setClient(CurClient, OwnsCurClient);
|
2009-11-14 11:23:19 +08:00
|
|
|
|
|
|
|
// Reset the buffer, we have processed all the diagnostics in it.
|
|
|
|
Buffer.reset(new TextDiagnosticBuffer());
|
2012-07-11 00:24:07 +08:00
|
|
|
ED.Errors.clear();
|
|
|
|
ED.Warnings.clear();
|
|
|
|
ED.Notes.clear();
|
2009-11-14 11:23:19 +08:00
|
|
|
}
|
2010-04-29 04:02:30 +08:00
|
|
|
|
2011-09-29 08:38:00 +08:00
|
|
|
DiagnosticConsumer *
|
|
|
|
VerifyDiagnosticConsumer::clone(DiagnosticsEngine &Diags) const {
|
|
|
|
if (!Diags.getClient())
|
|
|
|
Diags.setClient(PrimaryClient->clone(Diags));
|
|
|
|
|
|
|
|
return new VerifyDiagnosticConsumer(Diags);
|
|
|
|
}
|
|
|
|
|
2012-07-10 10:57:03 +08:00
|
|
|
Directive *Directive::create(bool RegexKind, SourceLocation DirectiveLoc,
|
|
|
|
SourceLocation DiagnosticLoc, StringRef Text,
|
2012-07-10 10:57:26 +08:00
|
|
|
unsigned Min, unsigned Max) {
|
2010-04-29 04:02:30 +08:00
|
|
|
if (RegexKind)
|
2012-07-10 10:57:26 +08:00
|
|
|
return new RegexDirective(DirectiveLoc, DiagnosticLoc, Text, Min, Max);
|
|
|
|
return new StandardDirective(DirectiveLoc, DiagnosticLoc, Text, Min, Max);
|
2010-04-29 04:02:30 +08:00
|
|
|
}
|