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;
92 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
93 StringRef Description,
94 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
96 DiagnosticBuilder
diag(StringRef CheckName, StringRef Description,
97 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
99 DiagnosticBuilder
diag(
const tooling::Diagnostic &
Error);
104 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
123 SmallVectorImpl<tooling::Diagnostic> &NoLintErrors,
124 bool AllowIO =
true,
bool EnableNoLintBlocks =
true);
169 return HeaderFileExtensions;
173 return ImplementationFileExtensions;
186 std::optional<ClangTidyProfiling::StorageParams>
191 CurrentBuildDirectory = std::string(BuildDirectory);
196 return CurrentBuildDirectory;
202 return AllowEnablingAnalyzerAlphaCheckers;
208 return EnableModuleHeadersParsing;
217 SourceLocation
Loc) {
219 static_cast<DiagnosticIDs::Level
>(
220 DiagEngine->getDiagnosticLevel(DiagnosticID,
Loc)),
222 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID))};
226 OptionsCollector = Collector;
234 DiagnosticsEngine *DiagEngine =
nullptr;
235 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
237 std::string CurrentFile;
240 std::unique_ptr<CachedGlobList> CheckFilter;
241 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
246 LangOptions LangOpts;
250 std::string CurrentBuildDirectory;
252 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
254 bool Profile =
false;
255 std::string ProfilePrefix;
260 bool SelfContainedDiags =
false;
263 llvm::StringSet<> *OptionsCollector =
nullptr;
270const llvm::StringMap<tooling::Replacements> *
282 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
283 bool RemoveIncompatibleErrors =
true,
284 bool GetFixesFromNotes =
false,
285 bool EnableNolintBlocks =
true);
294 std::vector<ClangTidyError>
take();
297 void finalizeLastError();
298 void removeIncompatibleErrors();
299 void removeDuplicatedDiagnosticsOfAliasCheckers();
303 llvm::Regex *getHeaderFilter();
307 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
308 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
313 DiagnosticsEngine *ExternalDiagEngine;
314 bool RemoveIncompatibleErrors;
315 bool GetFixesFromNotes;
316 bool EnableNolintBlocks;
317 std::vector<ClangTidyError> Errors;
318 std::unique_ptr<llvm::Regex> HeaderFilter;
319 std::unique_ptr<llvm::Regex> ExcludeHeaderFilter;
320 bool LastErrorRelatesToUserCode =
false;
321 bool LastErrorPassesLineFilter =
false;
322 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.
ClangTidyContext(const ClangTidyContext &)=delete
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.
ClangTidyContext & operator=(const ClangTidyContext &)=delete
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