10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H 11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H 15 #include "clang/Basic/Diagnostic.h" 16 #include "clang/Basic/SourceManager.h" 17 #include "clang/Tooling/Core/Diagnostic.h" 18 #include "clang/Tooling/Refactoring.h" 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/StringMap.h" 21 #include "llvm/Support/Regex.h" 22 #include "llvm/Support/Timer.h" 27 class CompilerInstance;
28 namespace ast_matchers {
32 class CompilationDatabase;
45 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
46 bool IsWarningAsError);
65 bool contains(StringRef S,
bool Contains);
69 std::unique_ptr<GlobList> NextGlob;
76 : ErrorsDisplayed(0), ErrorsIgnoredCheckFilter(0), ErrorsIgnoredNOLINT(0),
77 ErrorsIgnoredNonUserCode(0), ErrorsIgnoredLineFilter(0) {}
86 return ErrorsIgnoredNOLINT + ErrorsIgnoredCheckFilter +
87 ErrorsIgnoredNonUserCode + ErrorsIgnoredLineFilter;
113 DiagnosticBuilder diag(StringRef CheckName, SourceLocation
Loc,
115 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
120 void setSourceManager(SourceManager *SourceMgr);
123 void setCurrentFile(StringRef
File);
129 void setASTContext(ASTContext *Context);
136 StringRef getCheckName(
unsigned DiagnosticID)
const;
141 bool isCheckEnabled(StringRef CheckName)
const;
145 bool treatAsError(StringRef CheckName)
const;
164 ArrayRef<ClangTidyError>
getErrors()
const {
return Errors; }
170 void setEnableProfiling(
bool Profile);
174 void setProfileStoragePrefix(StringRef ProfilePrefix);
175 llvm::Optional<ClangTidyProfiling::StorageParams>
176 getProfileStorageParams()
const;
180 CurrentBuildDirectory = BuildDirectory;
185 return CurrentBuildDirectory;
201 void setDiagnosticsEngine(DiagnosticsEngine *Engine);
206 std::vector<ClangTidyError> Errors;
207 DiagnosticsEngine *DiagEngine;
208 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
210 std::string CurrentFile;
213 std::unique_ptr<CachedGlobList> CheckFilter;
214 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
216 LangOptions LangOpts;
220 std::string CurrentBuildDirectory;
222 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
225 std::string ProfilePrefix;
238 bool RemoveIncompatibleErrors =
true);
243 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
244 const Diagnostic &
Info)
override;
247 void finish()
override;
250 void finalizeLastError();
252 void removeIncompatibleErrors(SmallVectorImpl<ClangTidyError> &Errors)
const;
256 llvm::Regex *getHeaderFilter();
260 void checkFilters(SourceLocation
Location);
261 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
264 bool RemoveIncompatibleErrors;
265 std::unique_ptr<DiagnosticsEngine> Diags;
266 SmallVector<ClangTidyError, 8> Errors;
268 bool LastErrorRelatesToUserCode;
269 bool LastErrorPassesLineFilter;
270 bool LastErrorWasIgnored;
276 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
SourceLocation Loc
'#' location in the include directive
bool canEnableAnalyzerAlphaCheckers() const
If the experimental alpha checkers from the static analyzer can be enabled.
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.
bool getEnableProfiling() const
static const StringRef Message
Contains options for clang-tidy.
unsigned ErrorsIgnoredCheckFilter
unsigned ErrorsIgnoredNOLINT
static cl::opt< bool > AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers", cl::init(false), cl::Hidden, cl::cat(ClangTidyCategory))
This option allows enabling the experimental alpha checkers from the static analyzer.
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.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
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.
tooling::ExecutionContext * Ctx
The core clang tidy plugin action.
void setCurrentBuildDirectory(StringRef BuildDirectory)
Should be called when starting to process new translation unit.
const std::string & getCurrentBuildDirectory()
Returns build directory of the current translation unit.