clang-tools 20.0.0git
|
Base class for clang-tidy checks that want to flag declarations and/or macros for renaming based on customizable criteria. More...
#include <RenamerClangTidyCheck.h>
Classes | |
struct | DiagInfo |
Represents customized diagnostic text and how arguments should be applied. More... | |
struct | FailureInfo |
Information describing a failed check. More... | |
struct | NamingCheckFailure |
Holds an identifier name check failure, tracking the kind of the identifier, its possible fixup and the starting locations of all the identifier usages. More... | |
Public Types | |
enum class | ShouldFixStatus { ShouldFix , ConflictsWithKeyword , ConflictsWithMacroDefinition , FixInvalidIdentifier , IgnoreFailureThreshold , InsideMacro } |
This enum will be used in select of the diagnostic message. More... | |
using | NamingCheckId = std::pair< SourceLocation, StringRef > |
using | NamingCheckFailureMap = llvm::DenseMap< NamingCheckId, NamingCheckFailure > |
Public Member Functions | |
RenamerClangTidyCheck (StringRef CheckName, ClangTidyContext *Context) | |
~RenamerClangTidyCheck () | |
void | registerMatchers (ast_matchers::MatchFinder *Finder) final |
Derived classes should not implement any matching logic themselves; this class will do the matching and call the derived class' getDeclFailureInfo() and getMacroFailureInfo() for determining whether a given identifier passes or fails the check. | |
void | check (const ast_matchers::MatchFinder::MatchResult &Result) final |
ClangTidyChecks that register ASTMatchers should do the actual work in here. | |
void | registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) final |
Override this to register PPCallbacks in the preprocessor. | |
void | onEndOfTranslationUnit () final |
void | storeOptions (ClangTidyOptions::OptionMap &Opts) override |
Derived classes that override this function should call this method from the overridden method. | |
void | checkMacro (const Token &MacroNameTok, const MacroInfo *MI, const SourceManager &SourceMgr) |
Check Macros for style violations. | |
void | expandMacro (const Token &MacroNameTok, const MacroInfo *MI, const SourceManager &SourceMgr) |
Add a usage of a macro if it already has a violation. | |
void | addUsage (const NamedDecl *Decl, SourceRange Range, const SourceManager &SourceMgr) |
Public Member Functions inherited from clang::tidy::ClangTidyCheck | |
ClangTidyCheck (StringRef CheckName, ClangTidyContext *Context) | |
Initializes the check with CheckName and Context . | |
virtual bool | isLanguageVersionSupported (const LangOptions &LangOpts) const |
Override this to disable registering matchers and PP callbacks if an invalid language version is being used. | |
virtual void | registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) |
Override this to register PPCallbacks in the preprocessor. | |
virtual void | registerMatchers (ast_matchers::MatchFinder *Finder) |
Override this to register AST matchers with Finder . | |
virtual void | check (const ast_matchers::MatchFinder::MatchResult &Result) |
ClangTidyChecks that register ASTMatchers should do the actual work in here. | |
DiagnosticBuilder | diag (SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
Add a diagnostic with the check's name. | |
DiagnosticBuilder | diag (StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
Add a diagnostic with the check's name. | |
DiagnosticBuilder | configurationDiag (StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) const |
Adds a diagnostic to report errors in the check's configuration. | |
virtual void | storeOptions (ClangTidyOptions::OptionMap &Options) |
Should store all options supported by this check with their current values or default values for options that haven't been overridden. | |
Protected Member Functions | |
virtual std::optional< FailureInfo > | getDeclFailureInfo (const NamedDecl *Decl, const SourceManager &SM) const =0 |
Overridden by derived classes, returns information about if and how a Decl failed the check. | |
virtual std::optional< FailureInfo > | getMacroFailureInfo (const Token &MacroNameTok, const SourceManager &SM) const =0 |
Overridden by derived classes, returns information about if and how a macro failed the check. | |
virtual DiagInfo | getDiagInfo (const NamingCheckId &ID, const NamingCheckFailure &Failure) const =0 |
Overridden by derived classes, returns a description of the diagnostic that should be emitted for the given failure. | |
Protected Member Functions inherited from clang::tidy::ClangTidyCheck | |
StringRef | getCurrentMainFile () const |
Returns the main file name of the current translation unit. | |
const LangOptions & | getLangOpts () const |
Returns the language options from the context. | |
bool | areDiagsSelfContained () const |
Returns true when the check is run in a use case when only 1 fix will be applied at a time. | |
StringRef | getID () const override |
Additional Inherited Members | |
Protected Attributes inherited from clang::tidy::ClangTidyCheck | |
OptionsView | Options |
Base class for clang-tidy checks that want to flag declarations and/or macros for renaming based on customizable criteria.
Definition at line 28 of file RenamerClangTidyCheck.h.
using clang::tidy::RenamerClangTidyCheck::NamingCheckFailureMap = llvm::DenseMap<NamingCheckId, NamingCheckFailure> |
Definition at line 107 of file RenamerClangTidyCheck.h.
using clang::tidy::RenamerClangTidyCheck::NamingCheckId = std::pair<SourceLocation, StringRef> |
Definition at line 105 of file RenamerClangTidyCheck.h.
|
strong |
This enum will be used in select of the diagnostic message.
Each value below IgnoreFailureThreshold should have an error message.
Definition at line 49 of file RenamerClangTidyCheck.h.
clang::tidy::RenamerClangTidyCheck::RenamerClangTidyCheck | ( | StringRef | CheckName, |
ClangTidyContext * | Context | ||
) |
Definition at line 396 of file RenamerClangTidyCheck.cpp.
|
default |
void clang::tidy::RenamerClangTidyCheck::addUsage | ( | const NamedDecl * | Decl, |
SourceRange | Range, | ||
const SourceManager & | SourceMgr | ||
) |
Definition at line 454 of file RenamerClangTidyCheck.cpp.
References addUsage(), ConflictsWithKeyword, ConflictsWithMacroDefinition, Decl, FixInvalidIdentifier, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, clang::tidy::RenamerClangTidyCheck::FailureInfo::Fixup, getDeclFailureInfo(), clang::tidy::getFailureForNamedDecl(), clang::tidy::ClangTidyCheck::getLangOpts(), clang::tidy::hasNoName(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info, and clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldFix().
Referenced by addUsage(), checkMacro(), and expandMacro().
|
finalvirtual |
ClangTidyChecks
that register ASTMatchers should do the actual work in here.
Reimplemented from clang::tidy::ClangTidyCheck.
Definition at line 511 of file RenamerClangTidyCheck.cpp.
void clang::tidy::RenamerClangTidyCheck::checkMacro | ( | const Token & | MacroNameTok, |
const MacroInfo * | MI, | ||
const SourceManager & | SourceMgr | ||
) |
Check Macros for style violations.
Definition at line 523 of file RenamerClangTidyCheck.cpp.
References addUsage(), FixInvalidIdentifier, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, getMacroFailureInfo(), ID, Info, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info, Name, and Range.
void clang::tidy::RenamerClangTidyCheck::expandMacro | ( | const Token & | MacroNameTok, |
const MacroInfo * | MI, | ||
const SourceManager & | SourceMgr | ||
) |
Add a usage of a macro if it already has a violation.
Definition at line 543 of file RenamerClangTidyCheck.cpp.
References addUsage(), ID, Name, and Range.
|
protectedpure virtual |
Overridden by derived classes, returns information about if and how a Decl failed the check.
A 'std::nullopt' result means the Decl did not fail the check.
Referenced by addUsage().
|
protectedpure virtual |
Overridden by derived classes, returns a description of the diagnostic that should be emitted for the given failure.
The base class will then further customize the diagnostic by adding info about whether the fix-it can be automatically applied or not.
Referenced by onEndOfTranslationUnit().
|
protectedpure virtual |
Overridden by derived classes, returns information about if and how a macro failed the check.
A 'std::nullopt' result means the macro did not fail the check.
Referenced by checkMacro().
|
final |
Definition at line 578 of file RenamerClangTidyCheck.cpp.
References clang::tidy::RenamerClangTidyCheck::DiagInfo::ApplyArgs, Decl, clang::tidy::ClangTidyCheck::diag(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, clang::tidy::RenamerClangTidyCheck::FailureInfo::Fixup, getDiagInfo(), clang::tidy::getDiagnosticSuffix(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info, clang::tidy::RenamerClangTidyCheck::FailureInfo::KindName, Loc, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::RawUsageLocs, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldFix(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldNotify(), and clang::tidy::RenamerClangTidyCheck::DiagInfo::Text.
|
finalvirtual |
Derived classes should not implement any matching logic themselves; this class will do the matching and call the derived class' getDeclFailureInfo() and getMacroFailureInfo() for determining whether a given identifier passes or fails the check.
Reimplemented from clang::tidy::ClangTidyCheck.
Definition at line 408 of file RenamerClangTidyCheck.cpp.
|
finalvirtual |
Override this to register PPCallbacks
in the preprocessor.
This should be used for clang-tidy checks that analyze preprocessor- dependent properties, e.g. include directives and macro definitions.
This will only be executed if the function isLanguageVersionSupported returns true.
There are two Preprocessors to choose from that differ in how they handle modular #includes:
Reimplemented from clang::tidy::ClangTidyCheck.
Definition at line 412 of file RenamerClangTidyCheck.cpp.
|
overridevirtual |
Derived classes that override this function should call this method from the overridden method.
Reimplemented from clang::tidy::ClangTidyCheck.
Definition at line 403 of file RenamerClangTidyCheck.cpp.
References clang::tidy::ClangTidyCheck::Options, and clang::tidy::ClangTidyCheck::OptionsView::store().
Referenced by clang::tidy::bugprone::ReservedIdentifierCheck::storeOptions(), and clang::tidy::readability::IdentifierNamingCheck::storeOptions().