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/Refactoring.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/StringMap.h"
19 #include "llvm/Support/Regex.h"
20 #include "llvm/Support/Timer.h"
25 class CompilerInstance;
26 namespace ast_matchers {
30 class CompilationDatabase;
57 Error = DiagnosticsEngine::Error
65 tooling::Replacements
Fix;
66 SmallVector<ClangTidyMessage, 1>
Notes;
95 bool contains(StringRef S,
bool Contains);
99 std::unique_ptr<GlobList> NextGlob;
138 ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider);
145 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
147 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
196 const std::vector<ClangTidyError> &
getErrors()
const {
return Errors; }
210 CurrentBuildDirectory = BuildDirectory;
215 return CurrentBuildDirectory;
225 void setDiagnosticsEngine(DiagnosticsEngine *Engine);
230 std::vector<ClangTidyError> Errors;
231 DiagnosticsEngine *DiagEngine;
232 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
234 std::string CurrentFile;
236 std::unique_ptr<GlobList> CheckFilter;
237 std::unique_ptr<GlobList> WarningAsErrorFilter;
243 std::string CurrentBuildDirectory;
245 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
263 const Diagnostic &Info)
override;
269 void finalizeLastError();
271 void removeIncompatibleErrors(SmallVectorImpl<ClangTidyError> &Errors)
const;
275 llvm::Regex *getHeaderFilter();
279 void checkFilters(SourceLocation
Location);
280 bool passesLineFilter(StringRef FileName,
unsigned LineNumber)
const;
283 std::unique_ptr<DiagnosticsEngine> Diags;
284 SmallVector<ClangTidyError, 8> Errors;
285 std::unique_ptr<llvm::Regex> HeaderFilter;
286 bool LastErrorRelatesToUserCode;
287 bool LastErrorPassesLineFilter;
293 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
SourceLocation Loc
'#' location in the include directive
ClangTidyError(StringRef CheckName, Level DiagLevel, bool IsWarningAsError, StringRef BuildDirectory)
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.
A message from a clang-tidy check.
ClangTidyMessage(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.
SmallVector< ClangTidyMessage, 1 > Notes
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.
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.
tooling::Replacements Fix
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.
std::string BuildDirectory