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<llvm::Optional<CaseType>>(Str)
169 .Default(llvm::None);
173 auto const caseOptional =
174 fromString(
Options.
get((Name +
"Case").str(),
""));
175 auto prefix =
Options.
get((Name +
"Prefix").str(),
"");
176 auto postfix =
Options.
get((Name +
"Suffix").str(),
"");
178 if (caseOptional || !prefix.empty() || !postfix.empty()) {
179 NamingStyles.push_back(
NamingStyle(caseOptional, prefix, postfix));
181 NamingStyles.push_back(llvm::None);
185 IgnoreFailedSplit =
Options.
get(
"IgnoreFailedSplit", 0);
202 return "Camel_Snake_Case";
204 return "camel_Snake_Back";
207 llvm_unreachable(
"Unknown Case Type");
210 for (
size_t i = 0; i <
SK_Count; ++i) {
211 if (NamingStyles[i]) {
212 if (NamingStyles[i]->Case) {
217 NamingStyles[i]->Prefix);
219 NamingStyles[i]->Suffix);
223 Options.
store(Opts,
"IgnoreFailedSplit", IgnoreFailedSplit);
227 Finder->addMatcher(namedDecl().bind(
"decl"),
this);
228 Finder->addMatcher(usingDecl().bind(
"using"),
this);
229 Finder->addMatcher(declRefExpr().bind(
"declRef"),
this);
230 Finder->addMatcher(cxxConstructorDecl().bind(
"classRef"),
this);
231 Finder->addMatcher(cxxDestructorDecl().bind(
"classRef"),
this);
232 Finder->addMatcher(typeLoc().bind(
"typeLoc"),
this);
233 Finder->addMatcher(nestedNameSpecifierLoc().bind(
"nestedNameLoc"),
this);
237 Compiler.getPreprocessor().addPPCallbacks(
238 llvm::make_unique<IdentifierNamingCheckPPCallbacks>(
239 &Compiler.getPreprocessor(),
this));
244 static llvm::Regex Matchers[] = {
246 llvm::Regex(
"^[a-z][a-z0-9_]*$"),
247 llvm::Regex(
"^[a-z][a-zA-Z0-9]*$"),
248 llvm::Regex(
"^[A-Z][A-Z0-9_]*$"),
249 llvm::Regex(
"^[A-Z][a-zA-Z0-9]*$"),
250 llvm::Regex(
"^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
251 llvm::Regex(
"^[a-z]([a-z0-9]*(_[A-Z])?)*"),
255 if (Name.startswith(Style.
Prefix))
256 Name = Name.drop_front(Style.
Prefix.size());
260 if (Name.endswith(Style.
Suffix))
261 Name = Name.drop_back(Style.
Suffix.size());
267 if (Name.startswith(
"_") || Name.endswith(
"_"))
270 if (Style.
Case && !Matchers[static_cast<size_t>(*Style.
Case)].match(Name))
278 static llvm::Regex Splitter(
279 "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
281 SmallVector<StringRef, 8> Substrs;
282 Name.split(Substrs,
"_", -1,
false);
284 SmallVector<StringRef, 8> Words;
285 for (
auto Substr : Substrs) {
286 while (!Substr.empty()) {
287 SmallVector<StringRef, 8> Groups;
288 if (!Splitter.match(Substr, &Groups))
291 if (Groups[2].size() > 0) {
292 Words.push_back(Groups[1]);
293 Substr = Substr.substr(Groups[0].size());
294 }
else if (Groups[3].size() > 0) {
295 Words.push_back(Groups[3]);
296 Substr = Substr.substr(Groups[0].size() - Groups[4].size());
297 }
else if (Groups[5].size() > 0) {
298 Words.push_back(Groups[5]);
299 Substr = Substr.substr(Groups[0].size() - Groups[6].size());
314 for (
auto const &Word : Words) {
315 if (&Word != &Words.front())
317 Fixup += Word.lower();
322 for (
auto const &Word : Words) {
323 if (&Word != &Words.front())
325 Fixup += Word.upper();
330 for (
auto const &Word : Words) {
331 Fixup += Word.substr(0, 1).upper();
332 Fixup += Word.substr(1).lower();
337 for (
auto const &Word : Words) {
338 if (&Word == &Words.front()) {
339 Fixup += Word.lower();
341 Fixup += Word.substr(0, 1).upper();
342 Fixup += Word.substr(1).lower();
348 for (
auto const &Word : Words) {
349 if (&Word != &Words.front())
351 Fixup += Word.substr(0, 1).upper();
352 Fixup += Word.substr(1).lower();
357 for (
auto const &Word : Words) {
358 if (&Word != &Words.front()) {
360 Fixup += Word.substr(0, 1).upper();
362 Fixup += Word.substr(0, 1).lower();
364 Fixup += Word.substr(1).lower();
376 Name, Style.
Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
377 StringRef Mid = StringRef(Fixed).trim(
"_");
385 const std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>>
387 if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef])
390 if (isa<TypeAliasDecl>(D) && NamingStyles[SK_TypeAlias])
393 if (
const auto *Decl = dyn_cast<NamespaceDecl>(D)) {
394 if (Decl->isAnonymousNamespace())
397 if (Decl->isInline() && NamingStyles[SK_InlineNamespace])
398 return SK_InlineNamespace;
400 if (NamingStyles[SK_Namespace])
404 if (isa<EnumDecl>(D) && NamingStyles[SK_Enum])
407 if (isa<EnumConstantDecl>(D)) {
408 if (NamingStyles[SK_EnumConstant])
409 return SK_EnumConstant;
411 if (NamingStyles[SK_Constant])
417 if (
const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
418 if (Decl->isAnonymousStructOrUnion())
421 if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
424 if (Decl->hasDefinition() && Decl->isAbstract() &&
425 NamingStyles[SK_AbstractClass])
426 return SK_AbstractClass;
428 if (Decl->isStruct() && NamingStyles[SK_Struct])
431 if (Decl->isStruct() && NamingStyles[SK_Class])
434 if (Decl->isClass() && NamingStyles[SK_Class])
437 if (Decl->isClass() && NamingStyles[SK_Struct])
440 if (Decl->isUnion() && NamingStyles[SK_Union])
443 if (Decl->isEnum() && NamingStyles[SK_Enum])
449 if (
const auto *Decl = dyn_cast<FieldDecl>(D)) {
450 QualType Type = Decl->getType();
452 if (!Type.isNull() && Type.isLocalConstQualified() &&
453 NamingStyles[SK_ConstantMember])
454 return SK_ConstantMember;
456 if (!Type.isNull() && Type.isLocalConstQualified() &&
457 NamingStyles[SK_Constant])
460 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
461 return SK_PrivateMember;
463 if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMember])
464 return SK_ProtectedMember;
466 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMember])
467 return SK_PublicMember;
469 if (NamingStyles[SK_Member])
475 if (
const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
476 QualType Type = Decl->getType();
478 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
479 return SK_ConstexprVariable;
481 if (!Type.isNull() && Type.isLocalConstQualified() &&
482 NamingStyles[SK_ConstantParameter])
483 return SK_ConstantParameter;
485 if (!Type.isNull() && Type.isLocalConstQualified() &&
486 NamingStyles[SK_Constant])
489 if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
490 return SK_ParameterPack;
492 if (NamingStyles[SK_Parameter])
498 if (
const auto *Decl = dyn_cast<VarDecl>(D)) {
499 QualType Type = Decl->getType();
501 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
502 return SK_ConstexprVariable;
504 if (!Type.isNull() && Type.isLocalConstQualified() &&
505 Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
506 return SK_ClassConstant;
508 if (!Type.isNull() && Type.isLocalConstQualified() &&
509 Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
510 return SK_GlobalConstant;
512 if (!Type.isNull() && Type.isLocalConstQualified() &&
513 Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
514 return SK_StaticConstant;
516 if (!Type.isNull() && Type.isLocalConstQualified() &&
517 Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
518 return SK_LocalConstant;
520 if (!Type.isNull() && Type.isLocalConstQualified() &&
521 Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
522 return SK_LocalConstant;
524 if (!Type.isNull() && Type.isLocalConstQualified() &&
525 NamingStyles[SK_Constant])
528 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
529 return SK_ClassMember;
531 if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable])
532 return SK_GlobalVariable;
534 if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
535 return SK_StaticVariable;
537 if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable])
538 return SK_LocalVariable;
540 if (Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalVariable])
541 return SK_LocalVariable;
543 if (NamingStyles[SK_Variable])
549 if (
const auto *Decl = dyn_cast<CXXMethodDecl>(D)) {
550 if (Decl->isMain() || !Decl->isUserProvided() ||
551 Decl->isUsualDeallocationFunction() ||
552 Decl->isCopyAssignmentOperator() || Decl->isMoveAssignmentOperator() ||
553 Decl->size_overridden_methods() > 0)
556 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod])
557 return SK_ConstexprMethod;
559 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction])
560 return SK_ConstexprFunction;
562 if (Decl->isStatic() && NamingStyles[SK_ClassMethod])
563 return SK_ClassMethod;
565 if (Decl->isVirtual() && NamingStyles[SK_VirtualMethod])
566 return SK_VirtualMethod;
568 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMethod])
569 return SK_PrivateMethod;
571 if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMethod])
572 return SK_ProtectedMethod;
574 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMethod])
575 return SK_PublicMethod;
577 if (NamingStyles[SK_Method])
580 if (NamingStyles[SK_Function])
586 if (
const auto *Decl = dyn_cast<FunctionDecl>(D)) {
590 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction])
591 return SK_ConstexprFunction;
593 if (Decl->isGlobal() && NamingStyles[SK_GlobalFunction])
594 return SK_GlobalFunction;
596 if (NamingStyles[SK_Function])
600 if (isa<TemplateTypeParmDecl>(D)) {
601 if (NamingStyles[SK_TypeTemplateParameter])
602 return SK_TypeTemplateParameter;
604 if (NamingStyles[SK_TemplateParameter])
605 return SK_TemplateParameter;
610 if (isa<NonTypeTemplateParmDecl>(D)) {
611 if (NamingStyles[SK_ValueTemplateParameter])
612 return SK_ValueTemplateParameter;
614 if (NamingStyles[SK_TemplateParameter])
615 return SK_TemplateParameter;
620 if (isa<TemplateTemplateParmDecl>(D)) {
621 if (NamingStyles[SK_TemplateTemplateParameter])
622 return SK_TemplateTemplateParameter;
624 if (NamingStyles[SK_TemplateParameter])
625 return SK_TemplateParameter;
637 if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
644 SourceLocation FixLocation = Range.getBegin();
646 FixLocation =
SourceMgr->getSpellingLoc(FixLocation);
647 if (FixLocation.isInvalid())
652 auto &Failure = Failures[Decl];
653 if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
656 if (!Failure.ShouldFix)
660 SourceLocation MacroArgExpansionStartForRangeBegin;
661 SourceLocation MacroArgExpansionStartForRangeEnd;
662 bool RangeIsEntirelyWithinMacroArgument =
664 SourceMgr->isMacroArgExpansion(Range.getBegin(),
665 &MacroArgExpansionStartForRangeBegin) &&
666 SourceMgr->isMacroArgExpansion(Range.getEnd(),
667 &MacroArgExpansionStartForRangeEnd) &&
668 MacroArgExpansionStartForRangeBegin == MacroArgExpansionStartForRangeEnd;
671 bool RangeContainsMacroExpansion = RangeIsEntirelyWithinMacroArgument ||
672 Range.getBegin().isMacroID() ||
673 Range.getEnd().isMacroID();
675 bool RangeCanBeFixed =
676 RangeIsEntirelyWithinMacroArgument || !RangeContainsMacroExpansion;
677 Failure.ShouldFix = RangeCanBeFixed;
682 const NamedDecl *Decl, SourceRange
Range,
685 Decl->getLocation(), Decl->getNameAsString()),
690 if (
const auto *Decl =
691 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"classRef")) {
692 if (Decl->isImplicit())
695 addUsage(NamingCheckFailures, Decl->getParent(),
696 Decl->getNameInfo().getSourceRange());
698 for (
const auto *Init : Decl->inits()) {
699 if (!Init->isWritten() || Init->isInClassMemberInitializer())
701 if (
const auto *FD = Init->getAnyMember())
702 addUsage(NamingCheckFailures, FD, SourceRange(Init->getMemberLocation()));
709 if (
const auto *Decl =
710 Result.Nodes.getNodeAs<CXXDestructorDecl>(
"classRef")) {
711 if (Decl->isImplicit())
714 SourceRange
Range = Decl->getNameInfo().getSourceRange();
715 if (Range.getBegin().isInvalid())
719 Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
725 if (
const auto *
Loc = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc")) {
726 NamedDecl *Decl =
nullptr;
727 if (
const auto &Ref =
Loc->getAs<TagTypeLoc>()) {
728 Decl = Ref.getDecl();
729 }
else if (
const auto &Ref =
Loc->getAs<InjectedClassNameTypeLoc>()) {
730 Decl = Ref.getDecl();
731 }
else if (
const auto &Ref =
Loc->getAs<UnresolvedUsingTypeLoc>()) {
732 Decl = Ref.getDecl();
733 }
else if (
const auto &Ref =
Loc->getAs<TemplateTypeParmTypeLoc>()) {
734 Decl = Ref.getDecl();
738 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
742 if (
const auto &Ref =
Loc->getAs<TemplateSpecializationTypeLoc>()) {
744 Ref.getTypePtr()->getTemplateName().getAsTemplateDecl();
746 SourceRange
Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
747 if (
const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
748 if (
const auto *TemplDecl = ClassDecl->getTemplatedDecl())
754 if (
const auto &Ref =
755 Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
756 if (
const auto *Decl = Ref.getTypePtr()->getAsTagDecl())
757 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
762 if (
const auto *
Loc =
763 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>(
"nestedNameLoc")) {
764 if (NestedNameSpecifier *Spec =
Loc->getNestedNameSpecifier()) {
765 if (NamespaceDecl *Decl = Spec->getAsNamespace()) {
766 addUsage(NamingCheckFailures, Decl,
Loc->getLocalSourceRange());
772 if (
const auto *Decl = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
773 for (
const auto &Shadow : Decl->shadows()) {
774 addUsage(NamingCheckFailures, Shadow->getTargetDecl(),
775 Decl->getNameInfo().getSourceRange());
780 if (
const auto *
DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declRef")) {
781 SourceRange
Range =
DeclRef->getNameInfo().getSourceRange();
783 Result.SourceManager);
787 if (
const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>(
"decl")) {
788 if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
792 if (
const auto *Value = Result.Nodes.getNodeAs<ValueDecl>(
"decl")) {
793 if (
const auto *Typedef =
794 Value->getType().getTypePtr()->getAs<TypedefType>()) {
795 addUsage(NamingCheckFailures, Typedef->getDecl(),
796 Value->getSourceRange());
801 if (
const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>(
"decl")) {
802 if (
const auto *Typedef =
803 Value->getReturnType().getTypePtr()->getAs<TypedefType>()) {
804 addUsage(NamingCheckFailures, Typedef->getDecl(),
805 Value->getSourceRange());
807 for (
unsigned i = 0; i < Value->getNumParams(); ++i) {
808 if (
const auto *Typedef = Value->parameters()[i]
811 ->getAs<TypedefType>()) {
812 addUsage(NamingCheckFailures, Typedef->getDecl(),
813 Value->getSourceRange());
820 if (isa<ClassTemplateSpecializationDecl>(Decl))
827 if (!NamingStyles[SK])
831 StringRef
Name = Decl->getName();
836 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
839 if (StringRef(Fixup).equals(Name)) {
840 if (!IgnoreFailedSplit) {
842 << Decl->getLocStart().printToString(*Result.SourceManager)
843 << llvm::format(
": unable to split words for %s '%s'\n",
844 KindName.c_str(), Name.str().c_str()));
848 Decl->getLocation(), Decl->getNameAsString())];
850 DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
853 Failure.
Fixup = std::move(Fixup);
854 Failure.
KindName = std::move(KindName);
855 addUsage(NamingCheckFailures, Decl, Range);
861 const Token &MacroNameTok,
862 const MacroInfo *MI) {
863 if (!NamingStyles[SK_MacroDefinition])
866 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
867 const NamingStyle &Style = *NamingStyles[SK_MacroDefinition];
871 std::string KindName =
873 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
876 if (StringRef(Fixup).equals(Name)) {
877 if (!IgnoreFailedSplit) {
879 llvm::dbgs() << MacroNameTok.getLocation().printToString(SourceMgr)
880 << llvm::format(
": unable to split words for %s '%s'\n",
881 KindName.c_str(), Name.str().c_str()));
886 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
888 Failure.Fixup = std::move(Fixup);
889 Failure.KindName = std::move(KindName);
895 const MacroInfo *MI) {
896 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
899 auto Failure = NamingCheckFailures.find(ID);
900 if (Failure == NamingCheckFailures.end())
903 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
908 for (
const auto &Pair : NamingCheckFailures) {
916 auto Diag =
diag(Decl.first,
"invalid case style for %0 '%1'")
930 Diag << FixItHint::CreateReplacement(
931 SourceRange(SourceLocation::getFromRawEncoding(
Loc)),
static unsigned getHashValue(NamingCheckId Val)
SourceLocation Loc
'#' location in the include directive
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.
llvm::Optional< CaseType > Case
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
static NamingCheckId getEmptyKey()
Base class for all clang-tidy checks.
static bool isEqual(const NamingCheckId &LHS, const NamingCheckId &RHS)
clang::tidy::readability::IdentifierNamingCheck::NamingCheckId NamingCheckId
IdentifierNamingCheck * Check
std::string get(StringRef LocalName, StringRef Default) const
Read a named option from the Context.
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.
static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle &Style)
llvm::DenseMap< NamingCheckId, NamingCheckFailure > NamingCheckFailureMap
static StyleKind findStyleKind(const NamedDecl *D, const std::vector< llvm::Optional< IdentifierNamingCheck::NamingStyle >> &NamingStyles)
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.
bool ShouldFix
Whether the failure should be fixed or not.