#include "clang/Frontend/VerifyDiagnosticConsumer.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TokenKinds.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/Token.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
#include <vector>
usingnamespaceclang;
Directive;
DirectiveList;
ExpectedData;
#ifndef NDEBUG
namespace {
class VerifyFileTracker : public PPCallbacks {
VerifyDiagnosticConsumer &Verify;
SourceManager &SM;
public:
VerifyFileTracker(VerifyDiagnosticConsumer &Verify, SourceManager &SM)
: Verify(Verify), SM(SM) {}
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override {
Verify.UpdateParsedFileStatus(SM, SM.getFileID(Loc),
VerifyDiagnosticConsumer::IsParsed);
}
};
}
#endif
DiagList;
const_diag_iterator;
namespace {
class StandardDirective : public Directive { … };
class RegexDirective : public Directive { … };
class ParseHelper
{ … };
struct UnattachedDirective { … };
void attachDirective(DiagnosticsEngine &Diags, const UnattachedDirective &UD,
SourceLocation ExpectedLoc,
bool MatchAnyFileAndLine = false,
bool MatchAnyLine = false) { … }
}
class VerifyDiagnosticConsumer::MarkerTracker { … };
static std::string DetailedErrorString(const DiagnosticsEngine &Diags) { … }
static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
Preprocessor *PP, SourceLocation Pos,
VerifyDiagnosticConsumer::DirectiveStatus &Status,
VerifyDiagnosticConsumer::MarkerTracker &Markers) { … }
VerifyDiagnosticConsumer::VerifyDiagnosticConsumer(DiagnosticsEngine &Diags_)
: … { … }
VerifyDiagnosticConsumer::~VerifyDiagnosticConsumer() { … }
void VerifyDiagnosticConsumer::BeginSourceFile(const LangOptions &LangOpts,
const Preprocessor *PP) { … }
void VerifyDiagnosticConsumer::EndSourceFile() { … }
void VerifyDiagnosticConsumer::HandleDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) { … }
bool VerifyDiagnosticConsumer::HandleComment(Preprocessor &PP,
SourceRange Comment) { … }
#ifndef NDEBUG
static bool findDirectives(SourceManager &SM, FileID FID,
const LangOptions &LangOpts) {
if (FID.isInvalid())
return false;
llvm::MemoryBufferRef FromFile = SM.getBufferOrFake(FID);
Lexer RawLex(FID, FromFile, SM, LangOpts);
RawLex.SetCommentRetentionState(true);
Token Tok;
Tok.setKind(tok::comment);
VerifyDiagnosticConsumer::DirectiveStatus Status =
VerifyDiagnosticConsumer::HasNoDirectives;
while (Tok.isNot(tok::eof)) {
RawLex.LexFromRawLexer(Tok);
if (!Tok.is(tok::comment)) continue;
std::string Comment = RawLex.getSpelling(Tok, SM, LangOpts);
if (Comment.empty()) continue;
VerifyDiagnosticConsumer::MarkerTracker Markers(SM.getDiagnostics());
if (ParseDirective(Comment, nullptr, SM, nullptr, Tok.getLocation(),
Status, Markers))
return true;
}
return false;
}
#endif
static unsigned PrintUnexpected(DiagnosticsEngine &Diags, SourceManager *SourceMgr,
const_diag_iterator diag_begin,
const_diag_iterator diag_end,
const char *Kind) { … }
static unsigned PrintExpected(DiagnosticsEngine &Diags,
SourceManager &SourceMgr,
std::vector<Directive *> &DL, const char *Kind) { … }
static bool IsFromSameFile(SourceManager &SM, SourceLocation DirectiveLoc,
SourceLocation DiagnosticLoc) { … }
static unsigned CheckLists(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
const char *Label,
DirectiveList &Left,
const_diag_iterator d2_begin,
const_diag_iterator d2_end,
bool IgnoreUnexpected) { … }
static unsigned CheckResults(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
const TextDiagnosticBuffer &Buffer,
ExpectedData &ED) { … }
void VerifyDiagnosticConsumer::UpdateParsedFileStatus(SourceManager &SM,
FileID FID,
ParsedStatus PS) { … }
void VerifyDiagnosticConsumer::CheckDiagnostics() { … }
std::unique_ptr<Directive> Directive::create(bool RegexKind,
SourceLocation DirectiveLoc,
SourceLocation DiagnosticLoc,
bool MatchAnyFileAndLine,
bool MatchAnyLine, StringRef Text,
unsigned Min, unsigned Max) { … }