12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/Frontend/CompilerInstance.h"
14 #include "clang/Lex/PPCallbacks.h"
15 #include "clang/Lex/Preprocessor.h"
16 #include "llvm/ADT/DenseMapInfo.h"
17 #include "llvm/Support/Debug.h"
18 #include "llvm/Support/Format.h"
20 #define DEBUG_TYPE "clang-tidy"
22 using namespace clang::ast_matchers;
34 clang::SourceLocation::getFromRawEncoding(static_cast<unsigned>(-1)),
40 clang::SourceLocation::getFromRawEncoding(static_cast<unsigned>(-2)),
45 assert(Val != getEmptyKey() &&
"Cannot hash the empty key!");
46 assert(Val != getTombstoneKey() &&
"Cannot hash the tombstone key!");
48 std::hash<NamingCheckId::second_type> SecondHash;
49 return Val.first.getRawEncoding() + SecondHash(Val.second);
53 if (RHS == getEmptyKey())
54 return LHS == getEmptyKey();
55 if (RHS == getTombstoneKey())
56 return LHS == getTombstoneKey();
64 namespace readability {
67 #define NAMING_KEYS(m) \
71 m(ConstexprVariable) \
87 m(ConstantParameter) \
96 m(ConstexprFunction) \
106 m(TypeTemplateParameter) \
107 m(ValueTemplateParameter) \
108 m(TemplateTemplateParameter) \
109 m(TemplateParameter) \
114 #define ENUMERATE(v) SK_ ## v,
122 #define STRINGIZE(v) #v,
132 class IdentifierNamingCheckPPCallbacks :
public PPCallbacks {
134 IdentifierNamingCheckPPCallbacks(Preprocessor *
PP,
135 IdentifierNamingCheck *
Check)
136 : PP(PP), Check(Check) {}
139 void MacroDefined(
const Token &MacroNameTok,
140 const MacroDirective *MD)
override {
141 Check->checkMacro(
PP->getSourceManager(), MacroNameTok, MD->getMacroInfo());
145 void MacroExpands(
const Token &MacroNameTok,
const MacroDefinition &MD,
147 const MacroArgs * )
override {
148 Check->expandMacro(MacroNameTok, MD.getMacroInfo());
157 IdentifierNamingCheck::IdentifierNamingCheck(StringRef
Name,
160 auto const fromString = [](StringRef Str) {
161 return llvm::StringSwitch<CaseType>(Str)
172 NamingStyles.push_back(
178 IgnoreFailedSplit =
Options.
get(
"IgnoreFailedSplit", 0);
195 return "Camel_Snake_Case";
197 return "camel_Snake_Back";
200 llvm_unreachable(
"Unknown Case Type");
203 for (
size_t i = 0; i <
SK_Count; ++i) {
207 NamingStyles[i].Prefix);
209 NamingStyles[i].Suffix);
212 Options.
store(Opts,
"IgnoreFailedSplit", IgnoreFailedSplit);
216 Finder->addMatcher(namedDecl().bind(
"decl"),
this);
217 Finder->addMatcher(usingDecl().bind(
"using"),
this);
218 Finder->addMatcher(declRefExpr().bind(
"declRef"),
this);
219 Finder->addMatcher(cxxConstructorDecl().bind(
"classRef"),
this);
220 Finder->addMatcher(cxxDestructorDecl().bind(
"classRef"),
this);
221 Finder->addMatcher(typeLoc().bind(
"typeLoc"),
this);
222 Finder->addMatcher(nestedNameSpecifierLoc().bind(
"nestedNameLoc"),
this);
226 Compiler.getPreprocessor().addPPCallbacks(
227 llvm::make_unique<IdentifierNamingCheckPPCallbacks>(
228 &Compiler.getPreprocessor(),
this));
233 static llvm::Regex Matchers[] = {
235 llvm::Regex(
"^[a-z][a-z0-9_]*$"),
236 llvm::Regex(
"^[a-z][a-zA-Z0-9]*$"),
237 llvm::Regex(
"^[A-Z][A-Z0-9_]*$"),
238 llvm::Regex(
"^[A-Z][a-zA-Z0-9]*$"),
239 llvm::Regex(
"^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
240 llvm::Regex(
"^[a-z]([a-z0-9]*(_[A-Z])?)*"),
244 if (Name.startswith(Style.
Prefix))
245 Name = Name.drop_front(Style.
Prefix.size());
249 if (Name.endswith(Style.
Suffix))
250 Name = Name.drop_back(Style.
Suffix.size());
254 if (!Matchers[static_cast<size_t>(Style.
Case)].match(Name))
262 static llvm::Regex Splitter(
263 "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
265 SmallVector<StringRef, 8> Substrs;
266 Name.split(Substrs,
"_", -1,
false);
268 SmallVector<StringRef, 8> Words;
269 for (
auto Substr : Substrs) {
270 while (!Substr.empty()) {
271 SmallVector<StringRef, 8> Groups;
272 if (!Splitter.match(Substr, &Groups))
275 if (Groups[2].size() > 0) {
276 Words.push_back(Groups[1]);
277 Substr = Substr.substr(Groups[0].size());
278 }
else if (Groups[3].size() > 0) {
279 Words.push_back(Groups[3]);
280 Substr = Substr.substr(Groups[0].size() - Groups[4].size());
281 }
else if (Groups[5].size() > 0) {
282 Words.push_back(Groups[5]);
283 Substr = Substr.substr(Groups[0].size() - Groups[6].size());
298 for (
auto const &Word : Words) {
299 if (&Word != &Words.front())
301 Fixup += Word.lower();
306 for (
auto const &Word : Words) {
307 if (&Word != &Words.front())
309 Fixup += Word.upper();
314 for (
auto const &Word : Words) {
315 Fixup += Word.substr(0, 1).upper();
316 Fixup += Word.substr(1).lower();
321 for (
auto const &Word : Words) {
322 if (&Word == &Words.front()) {
323 Fixup += Word.lower();
325 Fixup += Word.substr(0, 1).upper();
326 Fixup += Word.substr(1).lower();
332 for (
auto const &Word : Words) {
333 if (&Word != &Words.front())
335 Fixup += Word.substr(0, 1).upper();
336 Fixup += Word.substr(1).lower();
341 for (
auto const &Word : Words) {
342 if (&Word != &Words.front()) {
344 Fixup += Word.substr(0, 1).upper();
346 Fixup += Word.substr(0, 1).lower();
348 Fixup += Word.substr(1).lower();
363 const std::vector<IdentifierNamingCheck::NamingStyle> &NamingStyles) {
364 if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef].isSet())
367 if (isa<TypeAliasDecl>(D) && NamingStyles[SK_TypeAlias].isSet())
370 if (
const auto *Decl = dyn_cast<NamespaceDecl>(D)) {
371 if (Decl->isAnonymousNamespace())
374 if (Decl->isInline() && NamingStyles[SK_InlineNamespace].isSet())
375 return SK_InlineNamespace;
377 if (NamingStyles[SK_Namespace].isSet())
381 if (isa<EnumDecl>(D) && NamingStyles[SK_Enum].isSet())
384 if (isa<EnumConstantDecl>(D)) {
385 if (NamingStyles[SK_EnumConstant].isSet())
386 return SK_EnumConstant;
388 if (NamingStyles[SK_Constant].isSet())
394 if (
const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
395 if (Decl->isAnonymousStructOrUnion())
398 if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
401 if (Decl->hasDefinition() && Decl->isAbstract() &&
402 NamingStyles[SK_AbstractClass].isSet())
403 return SK_AbstractClass;
405 if (Decl->isStruct() && NamingStyles[SK_Struct].isSet())
408 if (Decl->isStruct() && NamingStyles[SK_Class].isSet())
411 if (Decl->isClass() && NamingStyles[SK_Class].isSet())
414 if (Decl->isClass() && NamingStyles[SK_Struct].isSet())
417 if (Decl->isUnion() && NamingStyles[SK_Union].isSet())
420 if (Decl->isEnum() && NamingStyles[SK_Enum].isSet())
426 if (
const auto *Decl = dyn_cast<FieldDecl>(D)) {
427 QualType Type = Decl->getType();
429 if (!Type.isNull() && Type.isLocalConstQualified() &&
430 NamingStyles[SK_ConstantMember].isSet())
431 return SK_ConstantMember;
433 if (!Type.isNull() && Type.isLocalConstQualified() &&
434 NamingStyles[SK_Constant].isSet())
437 if (Decl->getAccess() == AS_private &&
438 NamingStyles[SK_PrivateMember].isSet())
439 return SK_PrivateMember;
441 if (Decl->getAccess() == AS_protected &&
442 NamingStyles[SK_ProtectedMember].isSet())
443 return SK_ProtectedMember;
445 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMember].isSet())
446 return SK_PublicMember;
448 if (NamingStyles[SK_Member].isSet())
454 if (
const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
455 QualType Type = Decl->getType();
457 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable].isSet())
458 return SK_ConstexprVariable;
460 if (!Type.isNull() && Type.isLocalConstQualified() &&
461 NamingStyles[SK_ConstantParameter].isSet())
462 return SK_ConstantParameter;
464 if (!Type.isNull() && Type.isLocalConstQualified() &&
465 NamingStyles[SK_Constant].isSet())
468 if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack].isSet())
469 return SK_ParameterPack;
471 if (NamingStyles[SK_Parameter].isSet())
477 if (
const auto *Decl = dyn_cast<VarDecl>(D)) {
478 QualType Type = Decl->getType();
480 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable].isSet())
481 return SK_ConstexprVariable;
483 if (!Type.isNull() && Type.isLocalConstQualified() &&
484 Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant].isSet())
485 return SK_ClassConstant;
487 if (!Type.isNull() && Type.isLocalConstQualified() &&
488 Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant].isSet())
489 return SK_GlobalConstant;
491 if (!Type.isNull() && Type.isLocalConstQualified() &&
492 Decl->isStaticLocal() && NamingStyles[SK_StaticConstant].isSet())
493 return SK_StaticConstant;
495 if (!Type.isNull() && Type.isLocalConstQualified() &&
496 Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant].isSet())
497 return SK_LocalConstant;
499 if (!Type.isNull() && Type.isLocalConstQualified() &&
500 Decl->isFunctionOrMethodVarDecl() &&
501 NamingStyles[SK_LocalConstant].isSet())
502 return SK_LocalConstant;
504 if (!Type.isNull() && Type.isLocalConstQualified() &&
505 NamingStyles[SK_Constant].isSet())
508 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember].isSet())
509 return SK_ClassMember;
511 if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable].isSet())
512 return SK_GlobalVariable;
514 if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable].isSet())
515 return SK_StaticVariable;
517 if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable].isSet())
518 return SK_LocalVariable;
520 if (Decl->isFunctionOrMethodVarDecl() &&
521 NamingStyles[SK_LocalVariable].isSet())
522 return SK_LocalVariable;
524 if (NamingStyles[SK_Variable].isSet())
530 if (
const auto *Decl = dyn_cast<CXXMethodDecl>(D)) {
531 if (Decl->isMain() || !Decl->isUserProvided() ||
532 Decl->isUsualDeallocationFunction() ||
533 Decl->isCopyAssignmentOperator() || Decl->isMoveAssignmentOperator() ||
534 Decl->size_overridden_methods() > 0)
537 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod].isSet())
538 return SK_ConstexprMethod;
540 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction].isSet())
541 return SK_ConstexprFunction;
543 if (Decl->isStatic() && NamingStyles[SK_ClassMethod].isSet())
544 return SK_ClassMethod;
546 if (Decl->isVirtual() && NamingStyles[SK_VirtualMethod].isSet())
547 return SK_VirtualMethod;
549 if (Decl->getAccess() == AS_private &&
550 NamingStyles[SK_PrivateMethod].isSet())
551 return SK_PrivateMethod;
553 if (Decl->getAccess() == AS_protected &&
554 NamingStyles[SK_ProtectedMethod].isSet())
555 return SK_ProtectedMethod;
557 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMethod].isSet())
558 return SK_PublicMethod;
560 if (NamingStyles[SK_Method].isSet())
563 if (NamingStyles[SK_Function].isSet())
569 if (
const auto *Decl = dyn_cast<FunctionDecl>(D)) {
573 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction].isSet())
574 return SK_ConstexprFunction;
576 if (Decl->isGlobal() && NamingStyles[SK_GlobalFunction].isSet())
577 return SK_GlobalFunction;
579 if (NamingStyles[SK_Function].isSet())
583 if (isa<TemplateTypeParmDecl>(D)) {
584 if (NamingStyles[SK_TypeTemplateParameter].isSet())
585 return SK_TypeTemplateParameter;
587 if (NamingStyles[SK_TemplateParameter].isSet())
588 return SK_TemplateParameter;
593 if (isa<NonTypeTemplateParmDecl>(D)) {
594 if (NamingStyles[SK_ValueTemplateParameter].isSet())
595 return SK_ValueTemplateParameter;
597 if (NamingStyles[SK_TemplateParameter].isSet())
598 return SK_TemplateParameter;
603 if (isa<TemplateTemplateParmDecl>(D)) {
604 if (NamingStyles[SK_TemplateTemplateParameter].isSet())
605 return SK_TemplateTemplateParameter;
607 if (NamingStyles[SK_TemplateParameter].isSet())
608 return SK_TemplateParameter;
620 if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
627 SourceLocation FixLocation = Range.getBegin();
629 FixLocation =
SourceMgr->getSpellingLoc(FixLocation);
630 if (FixLocation.isInvalid())
635 auto &Failure = Failures[Decl];
636 if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
639 if (!Failure.ShouldFix)
643 SourceLocation MacroArgExpansionStartForRangeBegin;
644 SourceLocation MacroArgExpansionStartForRangeEnd;
645 bool RangeIsEntirelyWithinMacroArgument =
647 SourceMgr->isMacroArgExpansion(Range.getBegin(),
648 &MacroArgExpansionStartForRangeBegin) &&
649 SourceMgr->isMacroArgExpansion(Range.getEnd(),
650 &MacroArgExpansionStartForRangeEnd) &&
651 MacroArgExpansionStartForRangeBegin == MacroArgExpansionStartForRangeEnd;
654 bool RangeContainsMacroExpansion = RangeIsEntirelyWithinMacroArgument ||
655 Range.getBegin().isMacroID() ||
656 Range.getEnd().isMacroID();
658 bool RangeCanBeFixed =
659 RangeIsEntirelyWithinMacroArgument || !RangeContainsMacroExpansion;
660 Failure.ShouldFix = RangeCanBeFixed;
665 const NamedDecl *Decl, SourceRange
Range,
668 Decl->getLocation(), Decl->getNameAsString()),
673 if (
const auto *Decl =
674 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"classRef")) {
675 if (Decl->isImplicit())
678 addUsage(NamingCheckFailures, Decl->getParent(),
679 Decl->getNameInfo().getSourceRange());
681 for (
const auto *Init : Decl->inits()) {
682 if (!Init->isWritten() || Init->isInClassMemberInitializer())
684 if (
const auto *FD = Init->getAnyMember())
685 addUsage(NamingCheckFailures, FD, SourceRange(Init->getMemberLocation()));
692 if (
const auto *Decl =
693 Result.Nodes.getNodeAs<CXXDestructorDecl>(
"classRef")) {
694 if (Decl->isImplicit())
697 SourceRange
Range = Decl->getNameInfo().getSourceRange();
698 if (Range.getBegin().isInvalid())
702 Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
708 if (
const auto *
Loc = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc")) {
709 NamedDecl *Decl =
nullptr;
710 if (
const auto &Ref =
Loc->getAs<TagTypeLoc>()) {
711 Decl = Ref.getDecl();
712 }
else if (
const auto &Ref =
Loc->getAs<InjectedClassNameTypeLoc>()) {
713 Decl = Ref.getDecl();
714 }
else if (
const auto &Ref =
Loc->getAs<UnresolvedUsingTypeLoc>()) {
715 Decl = Ref.getDecl();
716 }
else if (
const auto &Ref =
Loc->getAs<TemplateTypeParmTypeLoc>()) {
717 Decl = Ref.getDecl();
721 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
725 if (
const auto &Ref =
Loc->getAs<TemplateSpecializationTypeLoc>()) {
727 Ref.getTypePtr()->getTemplateName().getAsTemplateDecl();
729 SourceRange
Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
730 if (
const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
731 if (
const auto *TemplDecl = ClassDecl->getTemplatedDecl())
737 if (
const auto &Ref =
738 Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
739 if (
const auto *Decl = Ref.getTypePtr()->getAsTagDecl())
740 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
745 if (
const auto *
Loc =
746 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>(
"nestedNameLoc")) {
747 if (NestedNameSpecifier *Spec =
Loc->getNestedNameSpecifier()) {
748 if (NamespaceDecl *Decl = Spec->getAsNamespace()) {
749 addUsage(NamingCheckFailures, Decl,
Loc->getLocalSourceRange());
755 if (
const auto *Decl = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
756 for (
const auto &Shadow : Decl->shadows()) {
757 addUsage(NamingCheckFailures, Shadow->getTargetDecl(),
758 Decl->getNameInfo().getSourceRange());
763 if (
const auto *
DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declRef")) {
764 SourceRange
Range =
DeclRef->getNameInfo().getSourceRange();
766 Result.SourceManager);
770 if (
const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>(
"decl")) {
771 if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
775 if (
const auto *Value = Result.Nodes.getNodeAs<ValueDecl>(
"decl")) {
776 if (
const auto *Typedef =
777 Value->getType().getTypePtr()->getAs<TypedefType>()) {
778 addUsage(NamingCheckFailures, Typedef->getDecl(),
779 Value->getSourceRange());
784 if (
const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>(
"decl")) {
785 if (
const auto *Typedef =
786 Value->getReturnType().getTypePtr()->getAs<TypedefType>()) {
787 addUsage(NamingCheckFailures, Typedef->getDecl(),
788 Value->getSourceRange());
790 for (
unsigned i = 0; i < Value->getNumParams(); ++i) {
791 if (
const auto *Typedef = Value->parameters()[i]
794 ->getAs<TypedefType>()) {
795 addUsage(NamingCheckFailures, Typedef->getDecl(),
796 Value->getSourceRange());
803 if (isa<ClassTemplateSpecializationDecl>(Decl))
811 StringRef
Name = Decl->getName();
816 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
819 if (StringRef(Fixup).equals(Name)) {
820 if (!IgnoreFailedSplit) {
822 << Decl->getLocStart().printToString(*Result.SourceManager)
823 << llvm::format(
": unable to split words for %s '%s'\n",
824 KindName.c_str(), Name.str().c_str()));
828 Decl->getLocation(), Decl->getNameAsString())];
830 DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
833 Failure.
Fixup = std::move(Fixup);
834 Failure.
KindName = std::move(KindName);
835 addUsage(NamingCheckFailures, Decl, Range);
841 const Token &MacroNameTok,
842 const MacroInfo *MI) {
843 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
844 NamingStyle Style = NamingStyles[SK_MacroDefinition];
848 std::string KindName =
850 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
853 if (StringRef(Fixup).equals(Name)) {
854 if (!IgnoreFailedSplit) {
856 llvm::dbgs() << MacroNameTok.getLocation().printToString(SourceMgr)
857 << llvm::format(
": unable to split words for %s '%s'\n",
858 KindName.c_str(), Name.str().c_str()));
863 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
865 Failure.Fixup = std::move(Fixup);
866 Failure.KindName = std::move(KindName);
872 const MacroInfo *MI) {
873 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
876 auto Failure = NamingCheckFailures.find(ID);
877 if (Failure == NamingCheckFailures.end())
880 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
885 for (
const auto &Pair : NamingCheckFailures) {
893 auto Diag =
diag(Decl.first,
"invalid case style for %0 '%1'")
907 Diag << FixItHint::CreateReplacement(
908 SourceRange(SourceLocation::getFromRawEncoding(
Loc)),
static unsigned getHashValue(NamingCheckId Val)
SourceLocation Loc
'#' location in the include directive
static StyleKind findStyleKind(const NamedDecl *D, const std::vector< IdentifierNamingCheck::NamingStyle > &NamingStyles)
void registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures, const IdentifierNamingCheck::NamingCheckId &Decl, SourceRange Range, SourceManager *SourceMgr=nullptr)
std::unique_ptr< ast_matchers::MatchFinder > Finder
Holds an identifier name check failure, tracking the kind of the identifer, its possible fixup and th...
static bool matchesStyle(StringRef Name, IdentifierNamingCheck::NamingStyle Style)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
static NamingCheckId getEmptyKey()
Base class for all clang-tidy checks.
clang::tidy::readability::IdentifierNamingCheck::NamingCheckId NamingCheckId
IdentifierNamingCheck * Check
std::string get(StringRef LocalName, StringRef Default) const
Read a named option from the Context.
static std::string fixupWithStyle(StringRef Name, IdentifierNamingCheck::NamingStyle Style)
void expandMacro(const Token &MacroNameTok, const MacroInfo *MI)
Add a usage of a macro if it already has a violation.
std::pair< SourceLocation, std::string > NamingCheckId
static NamingCheckId getTombstoneKey()
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
std::map< std::string, std::string > OptionMap
void onEndOfTranslationUnit() override
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
static std::string fixupWithCase(StringRef Name, IdentifierNamingCheck::CaseType Case)
void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok, const MacroInfo *MI)
Check Macros for style violations.
llvm::DenseMap< NamingCheckId, NamingCheckFailure > NamingCheckFailureMap
CharSourceRange Range
SourceRange for the file name.
ClangTidyContext & Context
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
static StringRef const StyleNames[]
llvm::DenseSet< unsigned > RawUsageLocs
A set of all the identifier usages starting SourceLocation, in their encoded form.
const DeclRefExpr * DeclRef
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
static bool isEqual(NamingCheckId LHS, NamingCheckId RHS)
bool ShouldFix
Whether the failure should be fixed or not.