9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
16#include "clang/Basic/Diagnostic.h"
17#include "clang/Tooling/Core/Diagnostic.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/StringSet.h"
20#include "llvm/Support/Regex.h"
39 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
73 bool AllowEnablingAnalyzerAlphaCheckers =
false,
74 bool EnableModuleHeadersParsing =
false);
79 this->DiagEngine = DiagEngine;
89 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
90 StringRef Description,
91 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
93 DiagnosticBuilder
diag(StringRef CheckName, StringRef Description,
94 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
96 DiagnosticBuilder
diag(
const tooling::Diagnostic &
Error);
101 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
120 SmallVectorImpl<tooling::Diagnostic> &NoLintErrors,
121 bool AllowIO =
true,
bool EnableNoLintBlocks =
true);
166 return HeaderFileExtensions;
170 return ImplementationFileExtensions;
183 std::optional<ClangTidyProfiling::StorageParams>
188 CurrentBuildDirectory = std::string(BuildDirectory);
193 return CurrentBuildDirectory;
199 return AllowEnablingAnalyzerAlphaCheckers;
205 return EnableModuleHeadersParsing;
214 SourceLocation
Loc) {
216 static_cast<DiagnosticIDs::Level
>(
217 DiagEngine->getDiagnosticLevel(DiagnosticID,
Loc)),
219 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID))};
223 OptionsCollector = Collector;
231 DiagnosticsEngine *DiagEngine =
nullptr;
232 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
234 std::string CurrentFile;
237 std::unique_ptr<CachedGlobList> CheckFilter;
238 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
243 LangOptions LangOpts;
247 std::string CurrentBuildDirectory;
249 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
251 bool Profile =
false;
252 std::string ProfilePrefix;
257 bool SelfContainedDiags =
false;
260 llvm::StringSet<> *OptionsCollector =
nullptr;
267const llvm::StringMap<tooling::Replacements> *
279 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
280 bool RemoveIncompatibleErrors =
true,
281 bool GetFixesFromNotes =
false,
282 bool EnableNolintBlocks =
true);
291 std::vector<ClangTidyError>
take();
294 void finalizeLastError();
295 void removeIncompatibleErrors();
296 void removeDuplicatedDiagnosticsOfAliasCheckers();
300 llvm::Regex *getHeaderFilter();
304 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
305 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
310 DiagnosticsEngine *ExternalDiagEngine;
311 bool RemoveIncompatibleErrors;
312 bool GetFixesFromNotes;
313 bool EnableNolintBlocks;
314 std::vector<ClangTidyError> Errors;
315 std::unique_ptr<llvm::Regex> HeaderFilter;
316 std::unique_ptr<llvm::Regex> ExcludeHeaderFilter;
317 bool LastErrorRelatesToUserCode =
false;
318 bool LastErrorPassesLineFilter =
false;
319 bool LastErrorWasIgnored =
false;
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.
static cl::opt< bool > EnableModuleHeadersParsing("enable-module-headers-parsing", desc(R"(
Enables preprocessor-level module header parsing
for C++20 and above, empowering specific checks
to detect macro definitions within modules. This
feature may cause performance and parsing issues
and is therefore considered experimental.
)"), cl::init(false), cl::cat(ClangTidyCategory))
static constexpr llvm::SourceMgr::DiagKind Error
DiagnosticCallback Diagnostic
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
const ClangTidyStats & getStats() const
Returns ClangTidyStats containing issued and ignored diagnostic counters.
bool canEnableAnalyzerAlphaCheckers() const
If the experimental alpha checkers from the static analyzer can be enabled.
bool isCheckEnabled(StringRef CheckName) const
Returns true if the check is enabled for the CurrentFile.
std::string getCheckName(unsigned DiagnosticID) const
Returns the name of the clang-tidy check which produced this diagnostic ID.
void setSelfContainedDiags(bool Value)
void setOptionsCollector(llvm::StringSet<> *Collector)
bool areDiagsSelfContained() const
bool canEnableModuleHeadersParsing() const
const ClangTidyOptions & getOptions() const
Returns options for CurrentFile.
llvm::StringSet * getOptionsCollector() const
const std::string & getCurrentBuildDirectory() const
Returns build directory of the current translation unit.
void setCurrentBuildDirectory(StringRef BuildDirectory)
Should be called when starting to process new translation unit.
const LangOptions & getLangOpts() const
Gets the language options from the AST context.
bool getEnableProfiling() const
DiagnosticBuilder configurationDiag(StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors to do with reading the configuration using this method.
void setASTContext(ASTContext *Context)
Sets ASTContext for the current translation unit.
const FileExtensionsSet & getHeaderFileExtensions() const
void setProfileStoragePrefix(StringRef ProfilePrefix)
Control storage of profile date.
void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine)
Sets the DiagnosticsEngine that diag() will emit diagnostics to.
void setEnableProfiling(bool Profile)
Control profile collection in clang-tidy.
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, SourceLocation Loc)
std::pair< DiagnosticIDs::Level, std::string > DiagLevelAndFormatString
void setCurrentFile(StringRef File)
Should be called when starting to process new translation unit.
bool shouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info, SmallVectorImpl< tooling::Diagnostic > &NoLintErrors, bool AllowIO=true, bool EnableNoLintBlocks=true)
Check whether a given diagnostic should be suppressed due to the presence of a "NOLINT" suppression c...
bool treatAsError(StringRef CheckName) const
Returns true if the check should be upgraded to error for the CurrentFile.
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors detected using this method.
ClangTidyOptions getOptionsForFile(StringRef File) const
Returns options for File.
std::optional< ClangTidyProfiling::StorageParams > getProfileStorageParams() const
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
const ClangTidyGlobalOptions & getGlobalOptions() const
Returns global options.
void setSourceManager(SourceManager *SourceMgr)
Sets the SourceManager of the used DiagnosticsEngine.
const FileExtensionsSet & getImplementationFileExtensions() const
A diagnostic consumer that turns each Diagnostic into a SourceManager-independent ClangTidyError.
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
std::vector< ClangTidyError > take()
This class is used to locate NOLINT comments in the file being analyzed, to decide whether a diagnost...
const llvm::StringMap< tooling::Replacements > * getFixIt(const tooling::Diagnostic &Diagnostic, bool AnyFix)
Gets the Fix attached to Diagnostic.
llvm::SmallSet< llvm::StringRef, 5 > FileExtensionsSet
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
A detected error complete with information to display diagnostic and automatic fix.
std::vector< std::string > EnabledDiagnosticAliases
Contains options for clang-tidy.
Contains displayed and ignored diagnostic counters for a ClangTidy run.
unsigned ErrorsIgnoredCheckFilter
unsigned ErrorsIgnoredNonUserCode
unsigned ErrorsIgnoredLineFilter
unsigned ErrorsIgnoredNOLINT
unsigned errorsIgnored() const