10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/SourceManager.h"
16 #include "clang/Tooling/Core/Diagnostic.h"
17 #include "clang/Tooling/Refactoring.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/Support/Regex.h"
21 #include "llvm/Support/Timer.h"
26 class CompilerInstance;
27 namespace ast_matchers {
31 class CompilationDatabase;
44 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
64 bool contains(StringRef S,
bool Contains);
68 std::unique_ptr<GlobList> NextGlob;
92 llvm::StringMap<llvm::TimeRecord>
Records;
107 ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider);
114 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
116 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
165 const std::vector<ClangTidyError> &
getErrors()
const {
return Errors; }
179 CurrentBuildDirectory = BuildDirectory;
184 return CurrentBuildDirectory;
194 void setDiagnosticsEngine(DiagnosticsEngine *Engine);
199 std::vector<ClangTidyError> Errors;
200 DiagnosticsEngine *DiagEngine;
201 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
203 std::string CurrentFile;
205 std::unique_ptr<GlobList> CheckFilter;
206 std::unique_ptr<GlobList> WarningAsErrorFilter;
212 std::string CurrentBuildDirectory;
214 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
232 const Diagnostic &Info)
override;
238 void finalizeLastError();
240 void removeIncompatibleErrors(SmallVectorImpl<ClangTidyError> &Errors)
const;
244 llvm::Regex *getHeaderFilter();
248 void checkFilters(SourceLocation
Location);
249 bool passesLineFilter(StringRef FileName,
unsigned LineNumber)
const;
252 std::unique_ptr<DiagnosticsEngine> Diags;
253 SmallVector<ClangTidyError, 8> Errors;
254 std::unique_ptr<llvm::Regex> HeaderFilter;
255 bool LastErrorRelatesToUserCode;
256 bool LastErrorPassesLineFilter;
257 bool LastErrorWasIgnored;
263 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
SourceLocation Loc
'#' location in the include directive
Read-only set of strings represented as a list of positive and negative globs.
GlobList(StringRef Globs)
GlobList is a comma-separated list of globs (only '*' metacharacter is supported) with optional '-' p...
void finish() override
Flushes the internal diagnostics buffer to the ClangTidyContext.
bool contains(StringRef S)
Returns true if the pattern matches S.
static const StringRef Message
Contains options for clang-tidy.
unsigned ErrorsIgnoredCheckFilter
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx)
ProfileData * getCheckProfileData() const
llvm::StringMap< llvm::TimeRecord > Records
unsigned ErrorsIgnoredNOLINT
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
const std::vector< ClangTidyError > & getErrors() const
Returns all collected errors.
ClangTidyOptions getOptionsForFile(StringRef File) const
Returns options for File.
void setCurrentFile(StringRef File)
Should be called when starting to process new translation unit.
const ClangTidyOptions & getOptions() const
Returns options for CurrentFile.
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc, StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors detected using this method.
unsigned ErrorsIgnoredNonUserCode
void setCheckProfileData(ProfileData *Profile)
Set the output struct for profile data.
ClangTidyContext(std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider)
Initializes ClangTidyContext instance.
ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory, bool IsWarningAsError)
void setASTContext(ASTContext *Context)
Sets ASTContext for the current translation unit.
A diagnostic consumer that turns each Diagnostic into a SourceManager-independent ClangTidyError...
unsigned ErrorsIgnoredLineFilter
GlobList & getWarningAsErrorFilter()
Returns check filter for the CurrentFile which selects checks for upgrade to error.
const ClangTidyGlobalOptions & getGlobalOptions() const
Returns global options.
const LangOptions & getLangOpts() const
Gets the language options from the AST context.
void setSourceManager(SourceManager *SourceMgr)
Sets the SourceManager of the used DiagnosticsEngine.
void clearErrors()
Clears collected errors.
const ClangTidyStats & getStats() const
Returns ClangTidyStats containing issued and ignored diagnostic counters.
unsigned errorsIgnored() const
StringRef getCheckName(unsigned DiagnosticID) const
Returns the name of the clang-tidy check which produced this diagnostic ID.
A detected error complete with information to display diagnostic and automatic fix.
Contains displayed and ignored diagnostic counters for a ClangTidy run.
ClangTidyContext & Context
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
The core clang tidy plugin action.
void setCurrentBuildDirectory(StringRef BuildDirectory)
Should be called when starting to process new translation unit.
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
GlobList & getChecksFilter()
Returns check filter for the CurrentFile.
Container for clang-tidy profiling data.
const std::string & getCurrentBuildDirectory()
Returns build directory of the current translation unit.