clang-tools 22.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 |
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 |
void | registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) final |
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) |
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. |
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.
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 388 of file RenamerClangTidyCheck.cpp.
Referenced by clang::tidy::readability::IdentifierNamingCheck::IdentifierNamingCheck(), and clang::tidy::bugprone::ReservedIdentifierCheck::ReservedIdentifierCheck().
|
default |
References storeOptions().
void clang::tidy::RenamerClangTidyCheck::addUsage | ( | const NamedDecl * | Decl, |
SourceRange | Range, | ||
const SourceManager & | SourceMgr ) |
Definition at line 450 of file RenamerClangTidyCheck.cpp.
References addUsage(), ConflictsWithKeyword, ConflictsWithMacroDefinition, FixInvalidIdentifier, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, clang::tidy::RenamerClangTidyCheck::FailureInfo::Fixup, getDeclFailureInfo(), clang::tidy::getFailureForNamedDecl(), clang::tidy::hasNoName(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info, and clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldFix().
Referenced by addUsage(), checkMacro(), and expandMacro().
|
final |
Definition at line 510 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 522 of file RenamerClangTidyCheck.cpp.
References addUsage(), FixInvalidIdentifier, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, getMacroFailureInfo(), and clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info.
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 542 of file RenamerClangTidyCheck.cpp.
References addUsage().
|
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 577 of file RenamerClangTidyCheck.cpp.
References clang::tidy::RenamerClangTidyCheck::DiagInfo::ApplyArgs, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, clang::tidy::RenamerClangTidyCheck::FailureInfo::Fixup, getDiagInfo(), clang::tidy::getDiagnosticSuffix(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info, clang::tidy::RenamerClangTidyCheck::FailureInfo::KindName, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::RawUsageLocs, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldFix(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldNotify(), and clang::tidy::RenamerClangTidyCheck::DiagInfo::Text.
|
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.
Definition at line 400 of file RenamerClangTidyCheck.cpp.
|
final |
Definition at line 404 of file RenamerClangTidyCheck.cpp.
|
override |
Derived classes that override this function should call this method from the overridden method.
Definition at line 395 of file RenamerClangTidyCheck.cpp.
Referenced by clang::tidy::bugprone::ReservedIdentifierCheck::storeOptions(), clang::tidy::readability::IdentifierNamingCheck::storeOptions(), and ~RenamerClangTidyCheck().