|
clang-tools 22.0.0git
|
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
More...
#include <ClangTidyDiagnosticConsumer.h>
Public Types | |
| using | DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string> |
Public Member Functions | |
| ClangTidyContext (std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider) | |
| ClangTidyContext (std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider, bool AllowEnablingAnalyzerAlphaCheckers, bool EnableModuleHeadersParsing, bool ExperimentalCustomChecks) | |
Initializes ClangTidyContext instance. | |
| void | setDiagnosticsEngine (std::unique_ptr< DiagnosticOptions > DiagOpts, DiagnosticsEngine *DiagEngine) |
| Sets the DiagnosticsEngine that diag() will emit diagnostics to. | |
| ~ClangTidyContext () | |
| ClangTidyContext (const ClangTidyContext &)=delete | |
| ClangTidyContext & | operator= (const ClangTidyContext &)=delete |
| DiagnosticBuilder | diag (StringRef CheckName, SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
| Report any errors detected using this method. | |
| DiagnosticBuilder | diag (StringRef CheckName, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
| DiagnosticBuilder | diag (const tooling::Diagnostic &Error) |
| DiagnosticBuilder | configurationDiag (StringRef Message, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
| Report any errors to do with reading the configuration using this method. | |
| 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 comment. | |
| void | setSourceManager (SourceManager *SourceMgr) |
Sets the SourceManager of the used DiagnosticsEngine. | |
| void | setCurrentFile (StringRef File) |
| Should be called when starting to process new translation unit. | |
| StringRef | getCurrentFile () const |
| Returns the main file name of the current translation unit. | |
| void | setASTContext (ASTContext *Context) |
| Sets ASTContext for the current translation unit. | |
| const LangOptions & | getLangOpts () const |
| Gets the language options from the AST context. | |
| std::string | getCheckName (unsigned DiagnosticID) const |
| Returns the name of the clang-tidy check which produced this diagnostic ID. | |
| bool | isCheckEnabled (StringRef CheckName) const |
Returns true if the check is enabled for the CurrentFile. | |
| bool | treatAsError (StringRef CheckName) const |
Returns true if the check should be upgraded to error for the CurrentFile. | |
| const ClangTidyGlobalOptions & | getGlobalOptions () const |
| Returns global options. | |
| const ClangTidyOptions & | getOptions () const |
Returns options for CurrentFile. | |
| ClangTidyOptions | getOptionsForFile (StringRef File) const |
Returns options for File. | |
| const FileExtensionsSet & | getHeaderFileExtensions () const |
| const FileExtensionsSet & | getImplementationFileExtensions () const |
| const ClangTidyStats & | getStats () const |
Returns ClangTidyStats containing issued and ignored diagnostic counters. | |
| void | setEnableProfiling (bool Profile) |
| Control profile collection in clang-tidy. | |
| bool | getEnableProfiling () const |
| void | setProfileStoragePrefix (StringRef ProfilePrefix) |
| Control storage of profile date. | |
| std::optional< ClangTidyProfiling::StorageParams > | getProfileStorageParams () const |
| void | setCurrentBuildDirectory (StringRef BuildDirectory) |
| Should be called when starting to process new translation unit. | |
| const std::string & | getCurrentBuildDirectory () const |
| Returns build directory of the current translation unit. | |
| bool | canEnableAnalyzerAlphaCheckers () const |
| If the experimental alpha checkers from the static analyzer can be enabled. | |
| bool | canEnableModuleHeadersParsing () const |
| bool | canExperimentalCustomChecks () const |
| void | setSelfContainedDiags (bool Value) |
| bool | areDiagsSelfContained () const |
| DiagLevelAndFormatString | getDiagLevelAndFormatString (unsigned DiagnosticID, SourceLocation Loc) |
| void | setOptionsCollector (llvm::StringSet<> *Collector) |
| llvm::StringSet * | getOptionsCollector () const |
Friends | |
| class | ClangTidyDiagnosticConsumer |
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
A ClangTidyCheck always has access to the active context to report warnings like:
Definition at line 70 of file ClangTidyDiagnosticConsumer.h.
| using clang::tidy::ClangTidyContext::DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string> |
Definition at line 225 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Definition at line 72 of file ClangTidyDiagnosticConsumer.h.
References ClangTidyContext().
Referenced by ClangTidyContext(), ClangTidyContext(), and operator=().
| ClangTidyContext::ClangTidyContext | ( | std::unique_ptr< ClangTidyOptionsProvider > | OptionsProvider, |
| bool | AllowEnablingAnalyzerAlphaCheckers, | ||
| bool | EnableModuleHeadersParsing, | ||
| bool | ExperimentalCustomChecks ) |
Initializes ClangTidyContext instance.
Definition at line 161 of file ClangTidyDiagnosticConsumer.cpp.
References setCurrentFile().
|
default |
|
delete |
References ClangTidyContext().
|
inline |
Definition at line 223 of file ClangTidyDiagnosticConsumer.h.
|
inline |
If the experimental alpha checkers from the static analyzer can be enabled.
Definition at line 207 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Definition at line 213 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Definition at line 219 of file ClangTidyDiagnosticConsumer.h.
| DiagnosticBuilder ClangTidyContext::configurationDiag | ( | StringRef | Message, |
| DiagnosticIDs::Level | Level = DiagnosticIDs::Warning ) |
Report any errors to do with reading the configuration using this method.
Definition at line 208 of file ClangTidyDiagnosticConsumer.cpp.
References diag().
Referenced by clang::tidy::custom::emitConfigurationDiag(), clang::tidy::bugprone::parseCheckedFunctions(), and setCurrentFile().
| DiagnosticBuilder ClangTidyContext::diag | ( | const tooling::Diagnostic & | Error | ) |
Definition at line 195 of file ClangTidyDiagnosticConsumer.cpp.
References diag().
| DiagnosticBuilder ClangTidyContext::diag | ( | StringRef | CheckName, |
| SourceLocation | Loc, | ||
| StringRef | Description, | ||
| DiagnosticIDs::Level | Level = DiagnosticIDs::Warning ) |
Report any errors detected using this method.
This is still under heavy development and will likely change towards using tablegen'd diagnostic IDs. FIXME: Figure out a way to manage ID spaces.
Definition at line 176 of file ClangTidyDiagnosticConsumer.cpp.
Referenced by configurationDiag(), and diag().
| DiagnosticBuilder ClangTidyContext::diag | ( | StringRef | CheckName, |
| StringRef | Description, | ||
| DiagnosticIDs::Level | Level = DiagnosticIDs::Warning ) |
Definition at line 186 of file ClangTidyDiagnosticConsumer.cpp.
| std::string ClangTidyContext::getCheckName | ( | unsigned | DiagnosticID | ) | const |
Returns the name of the clang-tidy check which produced this diagnostic ID.
Definition at line 297 of file ClangTidyDiagnosticConsumer.cpp.
Referenced by shouldSuppressDiagnostic(), and clang::clangd::StoreDiags::take().
|
inline |
Returns build directory of the current translation unit.
Definition at line 201 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Returns the main file name of the current translation unit.
Definition at line 141 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Definition at line 226 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Definition at line 188 of file ClangTidyDiagnosticConsumer.h.
| const ClangTidyGlobalOptions & ClangTidyContext::getGlobalOptions | ( | ) | const |
Returns global options.
Definition at line 258 of file ClangTidyDiagnosticConsumer.cpp.
|
inline |
Definition at line 174 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Definition at line 178 of file ClangTidyDiagnosticConsumer.h.
|
inline |
Gets the language options from the AST context.
Definition at line 147 of file ClangTidyDiagnosticConsumer.h.
Referenced by clang::tidy::ClangTidyCheckFactories::createChecksForLanguage().
| const ClangTidyOptions & ClangTidyContext::getOptions | ( | ) | const |
Returns options for CurrentFile.
The CurrentFile can be changed using setCurrentFile.
Definition at line 262 of file ClangTidyDiagnosticConsumer.cpp.
Referenced by clang::tidy::getAllChecksAndOptions(), and setCurrentFile().
|
inline |
Definition at line 237 of file ClangTidyDiagnosticConsumer.h.
Referenced by clang::tidy::findPriorityOption().
| ClangTidyOptions ClangTidyContext::getOptionsForFile | ( | StringRef | File | ) | const |
Returns options for File.
Does not change or depend on CurrentFile.
Definition at line 266 of file ClangTidyDiagnosticConsumer.cpp.
References clang::tidy::ClangTidyOptions::getDefaults(), and clang::tidy::ClangTidyOptions::merge().
Referenced by clang::tidy::runClangTidy(), and setCurrentFile().
| std::optional< ClangTidyProfiling::StorageParams > ClangTidyContext::getProfileStorageParams | ( | ) | const |
Definition at line 280 of file ClangTidyDiagnosticConsumer.cpp.
|
inline |
Returns ClangTidyStats containing issued and ignored diagnostic counters.
Definition at line 184 of file ClangTidyDiagnosticConsumer.h.
| bool ClangTidyContext::isCheckEnabled | ( | StringRef | CheckName | ) | const |
Returns true if the check is enabled for the CurrentFile.
The CurrentFile can be changed using setCurrentFile.
Definition at line 287 of file ClangTidyDiagnosticConsumer.cpp.
Referenced by clang::tidy::ClangTidyCheckFactories::createChecks(), and clang::tidy::ClangTidyCheckFactories::createChecksForLanguage().
|
delete |
References ClangTidyContext().
| void ClangTidyContext::setASTContext | ( | ASTContext * | Context | ) |
Sets ASTContext for the current translation unit.
Definition at line 253 of file ClangTidyDiagnosticConsumer.cpp.
|
inline |
Should be called when starting to process new translation unit.
Definition at line 196 of file ClangTidyDiagnosticConsumer.h.
| void ClangTidyContext::setCurrentFile | ( | StringRef | File | ) |
Should be called when starting to process new translation unit.
Definition at line 239 of file ClangTidyDiagnosticConsumer.cpp.
References Checks(), configurationDiag(), getOptions(), getOptionsForFile(), parseFileExtensions(), and WarningsAsErrors().
Referenced by ClangTidyContext().
|
inline |
Sets the DiagnosticsEngine that diag() will emit diagnostics to.
Definition at line 82 of file ClangTidyDiagnosticConsumer.h.
Referenced by clang::tidy::getCheckOptions(), and clang::tidy::runClangTidy().
| void ClangTidyContext::setEnableProfiling | ( | bool | Profile | ) |
Control profile collection in clang-tidy.
Definition at line 273 of file ClangTidyDiagnosticConsumer.cpp.
Referenced by clang::tidy::runClangTidy().
|
inline |
Definition at line 234 of file ClangTidyDiagnosticConsumer.h.
Referenced by clang::tidy::getAllChecksAndOptions().
| void ClangTidyContext::setProfileStoragePrefix | ( | StringRef | ProfilePrefix | ) |
Control storage of profile date.
Definition at line 275 of file ClangTidyDiagnosticConsumer.cpp.
Referenced by clang::tidy::runClangTidy().
|
inline |
Definition at line 221 of file ClangTidyDiagnosticConsumer.h.
| void ClangTidyContext::setSourceManager | ( | SourceManager * | SourceMgr | ) |
Sets the SourceManager of the used DiagnosticsEngine.
This is called from the ClangTidyCheck base class.
Definition at line 223 of file ClangTidyDiagnosticConsumer.cpp.
| bool ClangTidyContext::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 comment.
This is exposed so that other tools that present clang-tidy diagnostics (such as clangd) can respect the same suppression rules as clang-tidy. This does not handle suppression of notes following a suppressed diagnostic; that is left to the caller as it requires maintaining state in between calls to this function. If any NOLINT is malformed, e.g. a BEGIN without a subsequent END, output
| NoLintErrors | will return an error about it. If |
| AllowIO | is false, the function does not attempt to read source files from disk which are not already mapped into memory; such files are treated as not containing a suppression comment. |
| EnableNoLintBlocks | controls whether to honor NOLINTBEGIN/NOLINTEND blocks; if false, only considers line-level disabling. |
Definition at line 214 of file ClangTidyDiagnosticConsumer.cpp.
References getCheckName().
| bool ClangTidyContext::treatAsError | ( | StringRef | CheckName | ) | const |
Returns true if the check should be upgraded to error for the CurrentFile.
Definition at line 292 of file ClangTidyDiagnosticConsumer.cpp.
|
friend |
Definition at line 241 of file ClangTidyDiagnosticConsumer.h.
References ClangTidyDiagnosticConsumer.
Referenced by ClangTidyDiagnosticConsumer.