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
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Tooling/Core/Diagnostic.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/Support/Regex.h"
22 class CompilerInstance;
24 namespace ast_matchers {
28 class CompilationDatabase;
41 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
80 bool AllowEnablingAnalyzerAlphaCheckers =
false);
85 this->DiagEngine = DiagEngine;
95 DiagnosticBuilder
diag(StringRef CheckName, SourceLocation
Loc,
151 llvm::Optional<ClangTidyProfiling::StorageParams>
156 CurrentBuildDirectory = std::string(BuildDirectory);
161 return CurrentBuildDirectory;
167 return AllowEnablingAnalyzerAlphaCheckers;
172 SourceLocation
Loc) {
174 static_cast<DiagnosticIDs::Level>(
175 DiagEngine->getDiagnosticLevel(DiagnosticID,
Loc)),
177 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)));
184 DiagnosticsEngine *DiagEngine;
185 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
187 std::string CurrentFile;
190 std::unique_ptr<CachedGlobList> CheckFilter;
191 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
193 LangOptions LangOpts;
197 std::string CurrentBuildDirectory;
199 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
202 std::string ProfilePrefix;
219 bool AllowIO =
true);
229 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
230 bool RemoveIncompatibleErrors =
true);
239 std::vector<ClangTidyError>
take();
242 void finalizeLastError();
243 void removeIncompatibleErrors();
244 void removeDuplicatedDiagnosticsOfAliasCheckers();
248 llvm::Regex *getHeaderFilter();
252 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
253 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
258 DiagnosticsEngine *ExternalDiagEngine;
259 bool RemoveIncompatibleErrors;
260 std::vector<ClangTidyError> Errors;
261 std::unique_ptr<llvm::Regex> HeaderFilter;
262 bool LastErrorRelatesToUserCode;
263 bool LastErrorPassesLineFilter;
264 bool LastErrorWasIgnored;
270 #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.
bool shouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info, ClangTidyContext &Context, bool AllowIO)
Check whether a given diagnostic should be suppressed due to the presence of a "NOLINT" suppression c...
std::string getCheckName(unsigned DiagnosticID) const
Returns the name of the clang-tidy check which produced this diagnostic ID.
static const char Message[]
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.
bool isCheckEnabled(StringRef CheckName) const
Returns true if the check is enabled for the CurrentFile.
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, SourceLocation Loc)
ClangTidyContext(std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider, bool AllowEnablingAnalyzerAlphaCheckers=false)
Initializes ClangTidyContext instance.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx, DiagnosticsEngine *ExternalDiagEngine=nullptr, bool RemoveIncompatibleErrors=true)
bool getEnableProfiling() const
SourceLocation Loc
'#' location in the include directive
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc, StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Report any errors detected using this method.
const std::string & getCurrentBuildDirectory()
Returns build directory of the current translation unit.
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
constexpr static llvm::SourceMgr::DiagKind Warning
llvm::Optional< ClangTidyProfiling::StorageParams > getProfileStorageParams() const
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.
std::vector< std::string > EnabledDiagnosticAliases
void setProfileStoragePrefix(StringRef ProfilePrefix)
Control storage of profile date.