clang-tools
15.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 | ShouldFixStatus { ShouldFixStatus::ShouldFix, ShouldFixStatus::ConflictsWithKeyword, ShouldFixStatus::ConflictsWithMacroDefinition, ShouldFixStatus::FixInvalidIdentifier, ShouldFixStatus::IgnoreFailureThreshold, ShouldFixStatus::InsideMacro } |
This enum will be used in select of the diagnostic message. More... | |
using | NamingCheckId = std::pair< SourceLocation, std::string > |
using | NamingCheckFailureMap = llvm::DenseMap< NamingCheckId, NamingCheckFailure > |
Public Member Functions | |
RenamerClangTidyCheck (StringRef CheckName, ClangTidyContext *Context) | |
~RenamerClangTidyCheck () | |
void | registerMatchers (ast_matchers::MatchFinder *Finder) override 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. More... | |
void | check (const ast_matchers::MatchFinder::MatchResult &Result) override final |
ClangTidyChecks that register ASTMatchers should do the actual work in here. More... | |
void | registerPPCallbacks (const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override final |
Override this to register PPCallbacks in the preprocessor. More... | |
void | onEndOfTranslationUnit () override final |
void | storeOptions (ClangTidyOptions::OptionMap &Opts) override |
Derived classes that override this function should call this method from the overridden method. More... | |
void | checkMacro (SourceManager &SourceMgr, const Token &MacroNameTok, const MacroInfo *MI) |
Check Macros for style violations. More... | |
void | expandMacro (const Token &MacroNameTok, const MacroInfo *MI) |
Add a usage of a macro if it already has a violation. More... | |
void | addUsage (const RenamerClangTidyCheck::NamingCheckId &Decl, SourceRange Range, SourceManager *SourceMgr=nullptr) |
void | addUsage (const NamedDecl *Decl, SourceRange Range, SourceManager *SourceMgr=nullptr) |
Convenience method when the usage to be added is a NamedDecl. More... | |
![]() | |
ClangTidyCheck (StringRef CheckName, ClangTidyContext *Context) | |
Initializes the check with CheckName and Context . More... | |
virtual bool | isLanguageVersionSupported (const LangOptions &LangOpts) const |
Override this to disable registering matchers and PP callbacks if an invalid language version is being used. More... | |
DiagnosticBuilder | diag (SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
Add a diagnostic with the check's name. More... | |
DiagnosticBuilder | diag (StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) |
Add a diagnostic with the check's name. More... | |
DiagnosticBuilder | configurationDiag (StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) const |
Adds a diagnostic to report errors in the check's configuration. More... | |
Protected Member Functions | |
virtual llvm::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. More... | |
virtual llvm::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. More... | |
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. More... | |
![]() | |
StringRef | getCurrentMainFile () const |
Returns the main file name of the current translation unit. More... | |
const LangOptions & | getLangOpts () const |
Returns the language options from the context. More... | |
bool | areDiagsSelfContained () const |
Returns true when the check is run in a use case when only 1 fix will be applied at a time. More... | |
Additional Inherited Members | |
![]() | |
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 109 of file RenamerClangTidyCheck.h.
using clang::tidy::RenamerClangTidyCheck::NamingCheckId = std::pair<SourceLocation, std::string> |
Definition at line 106 of file RenamerClangTidyCheck.h.
This enum will be used in select of the diagnostic message.
Each value below IgnoreFailureThreshold should have an error message.
Definition at line 50 of file RenamerClangTidyCheck.h.
clang::tidy::RenamerClangTidyCheck::RenamerClangTidyCheck | ( | StringRef | CheckName, |
ClangTidyContext * | Context | ||
) |
Definition at line 101 of file RenamerClangTidyCheck.cpp.
|
default |
void clang::tidy::RenamerClangTidyCheck::addUsage | ( | const NamedDecl * | Decl, |
SourceRange | Range, | ||
SourceManager * | SourceMgr = nullptr |
||
) |
Convenience method when the usage to be added is a NamedDecl.
Definition at line 189 of file RenamerClangTidyCheck.cpp.
References addUsage(), Decl, clang::tidy::getOverrideMethod(), Range, and SourceMgr.
void clang::tidy::RenamerClangTidyCheck::addUsage | ( | const RenamerClangTidyCheck::NamingCheckId & | Decl, |
SourceRange | Range, | ||
SourceManager * | SourceMgr = nullptr |
||
) |
Definition at line 155 of file RenamerClangTidyCheck.cpp.
References Decl, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, InsideMacro, Range, clang::tidy::utils::rangeCanBeFixed(), clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::RawUsageLocs, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::shouldFix(), and SourceMgr.
Referenced by addUsage(), checkMacro(), and expandMacro().
|
finaloverridevirtual |
ClangTidyChecks
that register ASTMatchers should do the actual work in here.
Reimplemented from clang::tidy::ClangTidyCheck.
Definition at line 271 of file RenamerClangTidyCheck.cpp.
void clang::tidy::RenamerClangTidyCheck::checkMacro | ( | SourceManager & | SourceMgr, |
const Token & | MacroNameTok, | ||
const MacroInfo * | MI | ||
) |
Check Macros for style violations.
Definition at line 476 of file RenamerClangTidyCheck.cpp.
References addUsage(), FixInvalidIdentifier, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::FixStatus, getMacroFailureInfo(), ID, clang::tidy::RenamerClangTidyCheck::NamingCheckFailure::Info, Info, Name, Range, and SourceMgr.
void clang::tidy::RenamerClangTidyCheck::expandMacro | ( | const Token & | MacroNameTok, |
const MacroInfo * | MI | ||
) |
Add a usage of a macro if it already has a violation.
Definition at line 496 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 'None' result means the Decl did not fail the check.
|
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 'None' result means the macro did not fail the check.
Referenced by checkMacro().
|
finaloverride |
Definition at line 530 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.
|
finaloverridevirtual |
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 113 of file RenamerClangTidyCheck.cpp.
|
finaloverridevirtual |
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 131 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 108 of file RenamerClangTidyCheck.cpp.