clang-tools  12.0.0git
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
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:
Inheritance graph
[legend]
Collaboration diagram for clang::tidy::RenamerClangTidyCheck:
Collaboration graph
[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  ShouldFixStatus {
  ShouldFixStatus::ShouldFix, ShouldFixStatus::ConflictsWithKeyword, ShouldFixStatus::ConflictsWithMacroDefinition, 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...
 
- Public Member Functions inherited from clang::tidy::ClangTidyCheck
 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...
 

Protected Member Functions

virtual llvm::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. More...
 
virtual llvm::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. 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...
 
- Protected Member Functions inherited from clang::tidy::ClangTidyCheck
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...
 

Additional Inherited Members

- Protected Attributes inherited from clang::tidy::ClangTidyCheck
OptionsView Options
 

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

Definition at line 107 of file RenamerClangTidyCheck.h.

◆ NamingCheckId

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

Definition at line 104 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.

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 50 of file RenamerClangTidyCheck.h.

Constructor & Destructor Documentation

◆ RenamerClangTidyCheck()

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

Definition at line 101 of file RenamerClangTidyCheck.cpp.

◆ ~RenamerClangTidyCheck()

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

Member Function Documentation

◆ addUsage() [1/2]

void clang::tidy::RenamerClangTidyCheck::addUsage ( const RenamerClangTidyCheck::NamingCheckId Decl,
SourceRange  Range,
SourceManager *  SourceMgr = nullptr 
)

◆ addUsage() [2/2]

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 172 of file RenamerClangTidyCheck.cpp.

References addUsage().

◆ check()

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

ClangTidyChecks that register ASTMatchers should do the actual work in here.

Reimplemented from clang::tidy::ClangTidyCheck.

Definition at line 250 of file RenamerClangTidyCheck.cpp.

◆ checkMacro()

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

Check Macros for style violations.

Definition at line 445 of file RenamerClangTidyCheck.cpp.

References GetMacroFailureInfo(), Info, and Name.

◆ expandMacro()

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 462 of file RenamerClangTidyCheck.cpp.

References Name.

◆ GetDeclFailureInfo()

virtual llvm::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 'None' result means the Decl did not fail the check.

◆ 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 llvm::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 'None' result means the macro did not fail the check.

Referenced by checkMacro().

◆ onEndOfTranslationUnit()

void clang::tidy::RenamerClangTidyCheck::onEndOfTranslationUnit ( )
finaloverride

◆ registerMatchers()

void clang::tidy::RenamerClangTidyCheck::registerMatchers ( ast_matchers::MatchFinder *  Finder)
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.

◆ registerPPCallbacks()

void clang::tidy::RenamerClangTidyCheck::registerPPCallbacks ( const SourceManager &  SM,
Preprocessor *  PP,
Preprocessor *  ModuleExpanderPP 
)
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:

  • PP is the real Preprocessor. It doesn't walk into modular #includes and thus doesn't generate PPCallbacks for their contents.
  • ModuleExpanderPP preprocesses the whole translation unit in the non-modular mode, which allows it to generate PPCallbacks not only for the main file and textual headers, but also for all transitively included modular headers when the analysis runs with modules enabled. When modules are not enabled ModuleExpanderPP just points to the real preprocessor.

Reimplemented from clang::tidy::ClangTidyCheck.

Definition at line 131 of file RenamerClangTidyCheck.cpp.

◆ storeOptions()

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


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