Go to the documentation of this file.
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
15 #include "clang/Basic/Diagnostic.h"
16 #include "clang/Tooling/Core/Diagnostic.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/StringSet.h"
19 #include "llvm/Support/Regex.h"
38 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
72 bool AllowEnablingAnalyzerAlphaCheckers =
false);
77 this->DiagEngine = DiagEngine;
87 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
91 DiagnosticBuilder
diag(StringRef CheckName, StringRef
Message,
118 SmallVectorImpl<tooling::Diagnostic> &NoLintErrors,
119 bool AllowIO =
true,
bool EnableNoLintBlocks =
true);
173 std::optional<ClangTidyProfiling::StorageParams>
178 CurrentBuildDirectory = std::string(BuildDirectory);
183 return CurrentBuildDirectory;
189 return AllowEnablingAnalyzerAlphaCheckers;
198 SourceLocation
Loc) {
200 static_cast<DiagnosticIDs::Level
>(
201 DiagEngine->getDiagnosticLevel(DiagnosticID,
Loc)),
203 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)));
215 DiagnosticsEngine *DiagEngine;
216 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
218 std::string CurrentFile;
221 std::unique_ptr<CachedGlobList> CheckFilter;
222 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
228 std::string CurrentBuildDirectory;
230 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
233 std::string ProfilePrefix;
237 bool SelfContainedDiags;
240 llvm::StringSet<> *OptionsCollector =
nullptr;
247 const llvm::StringMap<tooling::Replacements> *
259 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
260 bool RemoveIncompatibleErrors =
true,
261 bool GetFixesFromNotes =
false,
262 bool EnableNolintBlocks =
true);
271 std::vector<ClangTidyError>
take();
274 void finalizeLastError();
275 void removeIncompatibleErrors();
276 void removeDuplicatedDiagnosticsOfAliasCheckers();
280 llvm::Regex *getHeaderFilter();
284 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
285 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
290 DiagnosticsEngine *ExternalDiagEngine;
291 bool RemoveIncompatibleErrors;
292 bool GetFixesFromNotes;
293 bool EnableNolintBlocks;
294 std::vector<ClangTidyError> Errors;
295 std::unique_ptr<llvm::Regex> HeaderFilter;
296 bool LastErrorRelatesToUserCode;
297 bool LastErrorPassesLineFilter;
298 bool LastErrorWasIgnored;
304 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
void setCurrentBuildDirectory(StringRef BuildDirectory)
Should be called when starting to process new translation unit.
void setASTContext(ASTContext *Context)
Sets ASTContext for the current translation unit.
std::vector< ClangTidyError > take()
const ClangTidyStats & getStats() const
Returns ClangTidyStats containing issued and ignored diagnostic counters.
unsigned ErrorsIgnoredCheckFilter
ClangTidyOptions getOptionsForFile(StringRef File) const
Returns options for File.
std::pair< DiagnosticIDs::Level, std::string > DiagLevelAndFormatString
Contains displayed and ignored diagnostic counters for a ClangTidy run.
std::string getCheckName(unsigned DiagnosticID) const
Returns the name of the clang-tidy check which produced this diagnostic ID.
static const char Message[]
void setOptionsCollector(llvm::StringSet<> *Collector)
bool canEnableAnalyzerAlphaCheckers() const
If the experimental alpha checkers from the static analyzer can be enabled.
A diagnostic consumer that turns each Diagnostic into a SourceManager-independent ClangTidyError.
llvm::SourceMgr * SourceMgr
Contains options for clang-tidy.
void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine)
Sets the DiagnosticsEngine that diag() will emit diagnostics to.
void setSourceManager(SourceManager *SourceMgr)
Sets the SourceManager of the used DiagnosticsEngine.
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.
A detected error complete with information to display diagnostic and automatic fix.
DiagnosticCallback Diagnostic
unsigned ErrorsIgnoredNOLINT
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
unsigned errorsIgnored() const
void setCurrentFile(StringRef File)
Should be called when starting to process new translation unit.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
const ClangTidyGlobalOptions & getGlobalOptions() const
Returns global options.
const LangOptions & getLangOpts() const
Gets the language options from the AST context.
void setEnableProfiling(bool Profile)
Control profile collection in clang-tidy.
unsigned ErrorsIgnoredLineFilter
unsigned ErrorsIgnoredNonUserCode
const ClangTidyOptions & getOptions() const
Returns options for CurrentFile.
std::shared_ptr< SymbolCollector > Collector
void setSelfContainedDiags(bool Value)
bool isCheckEnabled(StringRef CheckName) const
Returns true if the check is enabled for the CurrentFile.
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx, DiagnosticsEngine *ExternalDiagEngine=nullptr, bool RemoveIncompatibleErrors=true, bool GetFixesFromNotes=false, bool EnableNolintBlocks=true)
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, SourceLocation Loc)
std::optional< ClangTidyProfiling::StorageParams > getProfileStorageParams() const
This class is used to locate NOLINT comments in the file being analyzed, to decide whether a diagnost...
ClangTidyContext(std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider, bool AllowEnablingAnalyzerAlphaCheckers=false)
Initializes ClangTidyContext instance.
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...
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
const std::string & getCurrentBuildDirectory() const
Returns build directory of the current translation unit.
bool getEnableProfiling() const
llvm::StringSet * getOptionsCollector() const
const llvm::StringMap< tooling::Replacements > * getFixIt(const tooling::Diagnostic &Diagnostic, bool GetFixFromNotes)
Gets the Fix attached to Diagnostic.
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc, StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors detected using this method.
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
constexpr static llvm::SourceMgr::DiagKind Warning
ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory, bool IsWarningAsError)
bool treatAsError(StringRef CheckName) const
Returns true if the check should be upgraded to error for the CurrentFile.
bool areDiagsSelfContained() const
std::vector< std::string > EnabledDiagnosticAliases
DiagnosticBuilder configurationDiag(StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors to do with reading the configuration using this method.
void setProfileStoragePrefix(StringRef ProfilePrefix)
Control storage of profile date.