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,
45 bool IsWarningAsError);
64 bool contains(StringRef S,
bool Contains);
68 std::unique_ptr<GlobList> NextGlob;
75 : ErrorsDisplayed(0), ErrorsIgnoredCheckFilter(0), ErrorsIgnoredNOLINT(0),
76 ErrorsIgnoredNonUserCode(0), ErrorsIgnoredLineFilter(0) {}
85 return ErrorsIgnoredNOLINT + ErrorsIgnoredCheckFilter +
86 ErrorsIgnoredNonUserCode + ErrorsIgnoredLineFilter;
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);
123 void setSourceManager(SourceManager *SourceMgr);
126 void setCurrentFile(StringRef
File);
132 void setASTContext(ASTContext *Context);
139 StringRef getCheckName(
unsigned DiagnosticID)
const;
144 bool isCheckEnabled(StringRef CheckName)
const;
148 bool treatAsError(StringRef CheckName)
const;
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;
211 LangOptions LangOpts;
215 std::string CurrentBuildDirectory;
217 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
230 bool RemoveIncompatibleErrors =
true);
235 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
236 const Diagnostic &
Info)
override;
239 void finish()
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;
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.
static cl::opt< std::string > HeaderFilter("header-filter", cl::desc(R"(
Regular expression matching the names of the
headers to output diagnostics from. Diagnostics
from the main file of each translation unit are
always displayed.
Can be used together with -line-filter.
This option overrides the 'HeaderFilter' option
in .clang-tidy file, if any.
)"), cl::init(""), cl::cat(ClangTidyCategory))
bool contains(StringRef S)
Returns true if the pattern matches S.
static const StringRef Message
Contains options for clang-tidy.
unsigned ErrorsIgnoredCheckFilter
llvm::StringMap< llvm::TimeRecord > Records
unsigned ErrorsIgnoredNOLINT
unsigned errorsIgnored() const
unsigned ErrorsIgnoredNonUserCode
const LangOptions & getLangOpts() const
Gets the language options from the AST context.
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
A diagnostic consumer that turns each Diagnostic into a SourceManager-independent ClangTidyError...
unsigned ErrorsIgnoredLineFilter
ArrayRef< ClangTidyError > getErrors() const
Returns all collected errors.
void clearErrors()
Clears collected errors.
A detected error complete with information to display diagnostic and automatic fix.
Contains displayed and ignored diagnostic counters for a ClangTidy run.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
const ClangTidyStats & getStats() const
Returns ClangTidyStats containing issued and ignored diagnostic counters.
ProfileData * getCheckProfileData() const
The core clang tidy plugin action.
void setCurrentBuildDirectory(StringRef BuildDirectory)
Should be called when starting to process new translation unit.
Container for clang-tidy profiling data.
const std::string & getCurrentBuildDirectory()
Returns build directory of the current translation unit.