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);
116 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
118 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
167 ArrayRef<ClangTidyError>
getErrors()
const {
return Errors; }
181 CurrentBuildDirectory = BuildDirectory;
186 return CurrentBuildDirectory;
196 void setDiagnosticsEngine(DiagnosticsEngine *Engine);
201 std::vector<ClangTidyError> Errors;
202 DiagnosticsEngine *DiagEngine;
203 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
205 std::string CurrentFile;
208 std::unique_ptr<CachedGlobList> CheckFilter;
209 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
215 std::string CurrentBuildDirectory;
217 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
230 bool RemoveIncompatibleErrors =
true);
236 const Diagnostic &Info)
override;
242 void finalizeLastError();
244 void removeIncompatibleErrors(SmallVectorImpl<ClangTidyError> &Errors)
const;
248 llvm::Regex *getHeaderFilter();
252 void checkFilters(SourceLocation
Location);
253 bool passesLineFilter(StringRef FileName,
unsigned LineNumber)
const;
256 bool RemoveIncompatibleErrors;
257 std::unique_ptr<DiagnosticsEngine> Diags;
258 SmallVector<ClangTidyError, 8> Errors;
259 std::unique_ptr<llvm::Regex> HeaderFilter;
260 bool LastErrorRelatesToUserCode;
261 bool LastErrorPassesLineFilter;
262 bool LastErrorWasIgnored;
268 #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
ProfileData * getCheckProfileData() const
llvm::StringMap< llvm::TimeRecord > Records
unsigned ErrorsIgnoredNOLINT
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
ArrayRef< 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
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.
bool treatAsError(StringRef CheckName) const
Returns true if the check should be upgraded to error for the CurrentFile.
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
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx, bool RemoveIncompatibleErrors=true)
bool isCheckEnabled(StringRef CheckName) const
Returns true if the check is enabled for the CurrentFile.
Container for clang-tidy profiling data.
const std::string & getCurrentBuildDirectory()
Returns build directory of the current translation unit.