clang-tools 22.0.0git
clang::tidy::RenamerClangTidyCheck Class Referenceabstract

Base class for clang-tidy checks that want to flag declarations and/or macros for renaming based on customizable criteria. More...

#include <RenamerClangTidyCheck.h>

Inheritance diagram for clang::tidy::RenamerClangTidyCheck:
[legend]

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< FailureInfogetDeclFailureInfo (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< FailureInfogetMacroFailureInfo (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.

Detailed Description

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.

Member Typedef Documentation

◆ NamingCheckFailureMap

Initial value:
llvm::DenseMap<NamingCheckId, NamingCheckFailure>

Definition at line 107 of file RenamerClangTidyCheck.h.

◆ NamingCheckId

using clang::tidy::RenamerClangTidyCheck::NamingCheckId = std::pair<SourceLocation, StringRef>

Definition at line 105 of file RenamerClangTidyCheck.h.

Member Enumeration Documentation

◆ ShouldFixStatus

This enum will be used in select of the diagnostic message.

Each value below IgnoreFailureThreshold should have an error message.

Enumerator
ShouldFix 
ConflictsWithKeyword 

The fixup will conflict with a language keyword, so we can't fix it automatically.

ConflictsWithMacroDefinition 

The fixup will conflict with a macro definition, so we can't fix it automatically.

FixInvalidIdentifier 

The fixup results in an identifier that is not a valid c/c++ identifier.

IgnoreFailureThreshold 

Values pass this threshold will be ignored completely i.e no message, no fixup.

InsideMacro 

If the identifier was used or declared within a macro we won't offer a fixup for safety reasons.

Definition at line 49 of file RenamerClangTidyCheck.h.

Constructor & Destructor Documentation

◆ RenamerClangTidyCheck()

clang::tidy::RenamerClangTidyCheck::RenamerClangTidyCheck ( StringRef CheckName,
ClangTidyContext * Context )

◆ ~RenamerClangTidyCheck()

clang::tidy::RenamerClangTidyCheck::~RenamerClangTidyCheck ( )
default

References storeOptions().

Member Function Documentation

◆ addUsage()

◆ check()

void clang::tidy::RenamerClangTidyCheck::check ( const ast_matchers::MatchFinder::MatchResult & Result)
final

Definition at line 510 of file RenamerClangTidyCheck.cpp.

◆ checkMacro()

void clang::tidy::RenamerClangTidyCheck::checkMacro ( const Token & MacroNameTok,
const MacroInfo * MI,
const SourceManager & SourceMgr )

◆ expandMacro()

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().

◆ getDeclFailureInfo()

virtual std::optional< FailureInfo > clang::tidy::RenamerClangTidyCheck::getDeclFailureInfo ( const NamedDecl * Decl,
const SourceManager & SM ) const
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().

◆ getDiagInfo()

virtual DiagInfo clang::tidy::RenamerClangTidyCheck::getDiagInfo ( const NamingCheckId & ID,
const NamingCheckFailure & Failure ) const
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().

◆ getMacroFailureInfo()

virtual std::optional< FailureInfo > clang::tidy::RenamerClangTidyCheck::getMacroFailureInfo ( const Token & MacroNameTok,
const SourceManager & SM ) const
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().

◆ onEndOfTranslationUnit()

◆ registerMatchers()

void clang::tidy::RenamerClangTidyCheck::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.

Definition at line 400 of file RenamerClangTidyCheck.cpp.

◆ registerPPCallbacks()

void clang::tidy::RenamerClangTidyCheck::registerPPCallbacks ( const SourceManager & SM,
Preprocessor * PP,
Preprocessor * ModuleExpanderPP )
final

Definition at line 404 of file RenamerClangTidyCheck.cpp.

◆ storeOptions()

void clang::tidy::RenamerClangTidyCheck::storeOptions ( ClangTidyOptions::OptionMap & Opts)
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().


The documentation for this class was generated from the following files: