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);
78 this->DiagEngine = DiagEngine;
88 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
90 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
92 DiagnosticBuilder
diag(StringRef CheckName, StringRef Message,
93 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
95 DiagnosticBuilder
diag(
const tooling::Diagnostic &
Error);
100 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
119 SmallVectorImpl<tooling::Diagnostic> &NoLintErrors,
120 bool AllowIO =
true,
bool EnableNoLintBlocks =
true);
165 return HeaderFileExtensions;
169 return ImplementationFileExtensions;
182 std::optional<ClangTidyProfiling::StorageParams>
187 CurrentBuildDirectory = std::string(BuildDirectory);
192 return CurrentBuildDirectory;
198 return AllowEnablingAnalyzerAlphaCheckers;
207 SourceLocation
Loc) {
209 static_cast<DiagnosticIDs::Level
>(
210 DiagEngine->getDiagnosticLevel(DiagnosticID,
Loc)),
212 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)));
216 OptionsCollector = Collector;
224 DiagnosticsEngine *DiagEngine;
225 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
227 std::string CurrentFile;
230 std::unique_ptr<CachedGlobList> CheckFilter;
231 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
236 LangOptions LangOpts;
240 std::string CurrentBuildDirectory;
242 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
245 std::string ProfilePrefix;
249 bool SelfContainedDiags;
252 llvm::StringSet<> *OptionsCollector =
nullptr;
259const llvm::StringMap<tooling::Replacements> *
271 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
272 bool RemoveIncompatibleErrors =
true,
273 bool GetFixesFromNotes =
false,
274 bool EnableNolintBlocks =
true);
283 std::vector<ClangTidyError>
take();
286 void finalizeLastError();
287 void removeIncompatibleErrors();
288 void removeDuplicatedDiagnosticsOfAliasCheckers();
292 llvm::Regex *getHeaderFilter();
296 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
297 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
302 DiagnosticsEngine *ExternalDiagEngine;
303 bool RemoveIncompatibleErrors;
304 bool GetFixesFromNotes;
305 bool EnableNolintBlocks;
306 std::vector<ClangTidyError> Errors;
307 std::unique_ptr<llvm::Regex> HeaderFilter;
308 bool LastErrorRelatesToUserCode;
309 bool LastErrorPassesLineFilter;
310 bool LastErrorWasIgnored;
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 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
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.
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.
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc, StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors detected using this method.
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 GetFixFromNotes)
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