12 #include "../utils/ASTUtils.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.h" 14 #include "clang/Frontend/CompilerInstance.h" 15 #include "clang/Lex/PPCallbacks.h" 16 #include "clang/Lex/Preprocessor.h" 17 #include "llvm/ADT/DenseMapInfo.h" 18 #include "llvm/Support/Debug.h" 19 #include "llvm/Support/Format.h" 21 #define DEBUG_TYPE "clang-tidy" 35 clang::SourceLocation::getFromRawEncoding(static_cast<unsigned>(-1)),
41 clang::SourceLocation::getFromRawEncoding(static_cast<unsigned>(-2)),
46 assert(Val != getEmptyKey() &&
"Cannot hash the empty key!");
47 assert(Val != getTombstoneKey() &&
"Cannot hash the tombstone key!");
49 std::hash<NamingCheckId::second_type> SecondHash;
50 return Val.first.getRawEncoding() + SecondHash(Val.second);
53 static bool isEqual(
const NamingCheckId &LHS,
const NamingCheckId &RHS) {
54 if (RHS == getEmptyKey())
55 return LHS == getEmptyKey();
56 if (RHS == getTombstoneKey())
57 return LHS == getTombstoneKey();
65 namespace readability {
68 #define NAMING_KEYS(m) \ 72 m(ConstexprVariable) \ 81 m(GlobalConstantPointer) \ 85 m(LocalConstantPointer) \ 92 m(ConstantParameter) \ 96 m(ConstantPointerParameter) \ 103 m(ConstexprFunction) \ 113 m(TypeTemplateParameter) \ 114 m(ValueTemplateParameter) \ 115 m(TemplateTemplateParameter) \ 116 m(TemplateParameter) \ 122 #define ENUMERATE(v) SK_ ## v, 130 #define STRINGIZE(v) #v, 140 class IdentifierNamingCheckPPCallbacks :
public PPCallbacks {
142 IdentifierNamingCheckPPCallbacks(Preprocessor *PP,
144 : PP(PP), Check(Check) {}
147 void MacroDefined(
const Token &MacroNameTok,
148 const MacroDirective *
MD)
override {
149 Check->
checkMacro(PP->getSourceManager(), MacroNameTok, MD->getMacroInfo());
153 void MacroExpands(
const Token &MacroNameTok,
const MacroDefinition &MD,
155 const MacroArgs * )
override {
156 Check->
expandMacro(MacroNameTok, MD.getMacroInfo());
165 IdentifierNamingCheck::IdentifierNamingCheck(StringRef
Name,
168 auto const fromString = [](StringRef Str) {
169 return llvm::StringSwitch<llvm::Optional<CaseType>>(Str)
177 .Default(llvm::None);
180 for (
auto const &Name : StyleNames) {
181 auto const caseOptional =
182 fromString(
Options.
get((Name +
"Case").str(),
""));
183 auto prefix =
Options.
get((Name +
"Prefix").str(),
"");
184 auto postfix =
Options.
get((Name +
"Suffix").str(),
"");
186 if (caseOptional || !prefix.empty() || !postfix.empty()) {
187 NamingStyles.push_back(
NamingStyle(caseOptional, prefix, postfix));
189 NamingStyles.push_back(llvm::None);
193 IgnoreFailedSplit =
Options.
get(
"IgnoreFailedSplit", 0);
210 return "Camel_Snake_Case";
212 return "camel_Snake_Back";
215 llvm_unreachable(
"Unknown Case Type");
218 for (
size_t i = 0; i <
SK_Count; ++i) {
219 if (NamingStyles[i]) {
220 if (NamingStyles[i]->Case) {
225 NamingStyles[i]->Prefix);
227 NamingStyles[i]->Suffix);
231 Options.
store(Opts,
"IgnoreFailedSplit", IgnoreFailedSplit);
235 Finder->addMatcher(namedDecl().bind(
"decl"),
this);
236 Finder->addMatcher(usingDecl().bind(
"using"),
this);
237 Finder->addMatcher(declRefExpr().bind(
"declRef"),
this);
238 Finder->addMatcher(cxxConstructorDecl().bind(
"classRef"),
this);
239 Finder->addMatcher(cxxDestructorDecl().bind(
"classRef"),
this);
240 Finder->addMatcher(typeLoc().bind(
"typeLoc"),
this);
241 Finder->addMatcher(nestedNameSpecifierLoc().bind(
"nestedNameLoc"),
this);
245 Compiler.getPreprocessor().addPPCallbacks(
246 llvm::make_unique<IdentifierNamingCheckPPCallbacks>(
247 &Compiler.getPreprocessor(),
this));
252 static llvm::Regex Matchers[] = {
254 llvm::Regex(
"^[a-z][a-z0-9_]*$"),
255 llvm::Regex(
"^[a-z][a-zA-Z0-9]*$"),
256 llvm::Regex(
"^[A-Z][A-Z0-9_]*$"),
257 llvm::Regex(
"^[A-Z][a-zA-Z0-9]*$"),
258 llvm::Regex(
"^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
259 llvm::Regex(
"^[a-z]([a-z0-9]*(_[A-Z])?)*"),
263 if (Name.startswith(Style.
Prefix))
264 Name = Name.drop_front(Style.
Prefix.size());
268 if (Name.endswith(Style.
Suffix))
269 Name = Name.drop_back(Style.
Suffix.size());
275 if (Name.startswith(
"_") || Name.endswith(
"_"))
278 if (Style.
Case && !Matchers[static_cast<size_t>(*Style.
Case)].match(Name))
286 static llvm::Regex Splitter(
287 "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
289 SmallVector<StringRef, 8> Substrs;
290 Name.split(Substrs,
"_", -1,
false);
292 SmallVector<StringRef, 8> Words;
293 for (
auto Substr : Substrs) {
294 while (!Substr.empty()) {
295 SmallVector<StringRef, 8> Groups;
296 if (!Splitter.match(Substr, &Groups))
299 if (Groups[2].size() > 0) {
300 Words.push_back(Groups[1]);
301 Substr = Substr.substr(Groups[0].size());
302 }
else if (Groups[3].size() > 0) {
303 Words.push_back(Groups[3]);
304 Substr = Substr.substr(Groups[0].size() - Groups[4].size());
305 }
else if (Groups[5].size() > 0) {
306 Words.push_back(Groups[5]);
307 Substr = Substr.substr(Groups[0].size() - Groups[6].size());
322 for (
auto const &Word : Words) {
323 if (&Word != &Words.front())
325 Fixup += Word.lower();
330 for (
auto const &Word : Words) {
331 if (&Word != &Words.front())
333 Fixup += Word.upper();
338 for (
auto const &Word : Words) {
339 Fixup += Word.substr(0, 1).upper();
340 Fixup += Word.substr(1).lower();
345 for (
auto const &Word : Words) {
346 if (&Word == &Words.front()) {
347 Fixup += Word.lower();
349 Fixup += Word.substr(0, 1).upper();
350 Fixup += Word.substr(1).lower();
356 for (
auto const &Word : Words) {
357 if (&Word != &Words.front())
359 Fixup += Word.substr(0, 1).upper();
360 Fixup += Word.substr(1).lower();
365 for (
auto const &Word : Words) {
366 if (&Word != &Words.front()) {
368 Fixup += Word.substr(0, 1).upper();
370 Fixup += Word.substr(0, 1).lower();
372 Fixup += Word.substr(1).lower();
384 Name, Style.
Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
385 StringRef Mid = StringRef(Fixed).trim(
"_");
393 const std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>>
395 assert(D && D->getIdentifier() && !D->getName().empty() && !D->isImplicit() &&
396 "Decl must be an explicit identifier with a name.");
398 if (isa<ObjCIvarDecl>(D) && NamingStyles[SK_ObjcIvar])
401 if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef])
404 if (isa<TypeAliasDecl>(D) && NamingStyles[SK_TypeAlias])
407 if (
const auto *Decl = dyn_cast<NamespaceDecl>(D)) {
408 if (Decl->isAnonymousNamespace())
411 if (Decl->isInline() && NamingStyles[SK_InlineNamespace])
412 return SK_InlineNamespace;
414 if (NamingStyles[SK_Namespace])
418 if (isa<EnumDecl>(D) && NamingStyles[SK_Enum])
421 if (isa<EnumConstantDecl>(D)) {
422 if (NamingStyles[SK_EnumConstant])
423 return SK_EnumConstant;
425 if (NamingStyles[SK_Constant])
431 if (
const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
432 if (Decl->isAnonymousStructOrUnion())
435 if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
438 if (Decl->hasDefinition() && Decl->isAbstract() &&
439 NamingStyles[SK_AbstractClass])
440 return SK_AbstractClass;
442 if (Decl->isStruct() && NamingStyles[SK_Struct])
445 if (Decl->isStruct() && NamingStyles[SK_Class])
448 if (Decl->isClass() && NamingStyles[SK_Class])
451 if (Decl->isClass() && NamingStyles[SK_Struct])
454 if (Decl->isUnion() && NamingStyles[SK_Union])
457 if (Decl->isEnum() && NamingStyles[SK_Enum])
463 if (
const auto *Decl = dyn_cast<FieldDecl>(D)) {
464 QualType Type = Decl->getType();
466 if (!Type.isNull() && Type.isConstQualified()) {
467 if (NamingStyles[SK_ConstantMember])
468 return SK_ConstantMember;
470 if (NamingStyles[SK_Constant])
474 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
475 return SK_PrivateMember;
477 if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMember])
478 return SK_ProtectedMember;
480 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMember])
481 return SK_PublicMember;
483 if (NamingStyles[SK_Member])
489 if (
const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
490 QualType Type = Decl->getType();
492 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
493 return SK_ConstexprVariable;
495 if (!Type.isNull() && Type.isConstQualified()) {
496 if (Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_ConstantPointerParameter])
497 return SK_ConstantPointerParameter;
499 if (NamingStyles[SK_ConstantParameter])
500 return SK_ConstantParameter;
502 if (NamingStyles[SK_Constant])
506 if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
507 return SK_ParameterPack;
509 if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_PointerParameter])
510 return SK_PointerParameter;
512 if (NamingStyles[SK_Parameter])
518 if (
const auto *Decl = dyn_cast<VarDecl>(D)) {
519 QualType Type = Decl->getType();
521 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
522 return SK_ConstexprVariable;
524 if (!Type.isNull() && Type.isConstQualified()) {
525 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
526 return SK_ClassConstant;
528 if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_GlobalConstantPointer])
529 return SK_GlobalConstantPointer;
531 if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
532 return SK_GlobalConstant;
534 if (Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
535 return SK_StaticConstant;
537 if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalConstantPointer])
538 return SK_LocalConstantPointer;
540 if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
541 return SK_LocalConstant;
543 if (Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
544 return SK_LocalConstant;
546 if (NamingStyles[SK_Constant])
550 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
551 return SK_ClassMember;
553 if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_GlobalPointer])
554 return SK_GlobalPointer;
556 if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable])
557 return SK_GlobalVariable;
559 if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
560 return SK_StaticVariable;
562 if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalPointer])
563 return SK_LocalPointer;
565 if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable])
566 return SK_LocalVariable;
568 if (Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalVariable])
569 return SK_LocalVariable;
571 if (NamingStyles[SK_Variable])
577 if (
const auto *Decl = dyn_cast<CXXMethodDecl>(D)) {
578 if (Decl->isMain() || !Decl->isUserProvided() ||
579 Decl->size_overridden_methods() > 0)
582 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod])
583 return SK_ConstexprMethod;
585 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction])
586 return SK_ConstexprFunction;
588 if (Decl->isStatic() && NamingStyles[SK_ClassMethod])
589 return SK_ClassMethod;
591 if (Decl->isVirtual() && NamingStyles[SK_VirtualMethod])
592 return SK_VirtualMethod;
594 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMethod])
595 return SK_PrivateMethod;
597 if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMethod])
598 return SK_ProtectedMethod;
600 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMethod])
601 return SK_PublicMethod;
603 if (NamingStyles[SK_Method])
606 if (NamingStyles[SK_Function])
612 if (
const auto *Decl = dyn_cast<FunctionDecl>(D)) {
616 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction])
617 return SK_ConstexprFunction;
619 if (Decl->isGlobal() && NamingStyles[SK_GlobalFunction])
620 return SK_GlobalFunction;
622 if (NamingStyles[SK_Function])
626 if (isa<TemplateTypeParmDecl>(D)) {
627 if (NamingStyles[SK_TypeTemplateParameter])
628 return SK_TypeTemplateParameter;
630 if (NamingStyles[SK_TemplateParameter])
631 return SK_TemplateParameter;
636 if (isa<NonTypeTemplateParmDecl>(D)) {
637 if (NamingStyles[SK_ValueTemplateParameter])
638 return SK_ValueTemplateParameter;
640 if (NamingStyles[SK_TemplateParameter])
641 return SK_TemplateParameter;
646 if (isa<TemplateTemplateParmDecl>(D)) {
647 if (NamingStyles[SK_TemplateTemplateParameter])
648 return SK_TemplateTemplateParameter;
650 if (NamingStyles[SK_TemplateParameter])
651 return SK_TemplateParameter;
661 SourceRange
Range, SourceManager *SourceMgr =
nullptr) {
663 if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
670 SourceLocation FixLocation = Range.getBegin();
672 FixLocation = SourceMgr->getSpellingLoc(FixLocation);
673 if (FixLocation.isInvalid())
678 auto &Failure = Failures[Decl];
679 if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
682 if (!Failure.ShouldFix)
690 const NamedDecl *Decl, SourceRange
Range,
691 SourceManager *SourceMgr =
nullptr) {
694 Decl->getNameAsString()),
699 if (
const auto *Decl =
700 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"classRef")) {
701 if (Decl->isImplicit())
704 addUsage(NamingCheckFailures, Decl->getParent(),
705 Decl->getNameInfo().getSourceRange());
707 for (
const auto *Init : Decl->inits()) {
708 if (!Init->isWritten() || Init->isInClassMemberInitializer())
710 if (
const auto *FD = Init->getAnyMember())
712 SourceRange(Init->getMemberLocation()));
719 if (
const auto *Decl =
720 Result.Nodes.getNodeAs<CXXDestructorDecl>(
"classRef")) {
721 if (Decl->isImplicit())
724 SourceRange
Range = Decl->getNameInfo().getSourceRange();
725 if (Range.getBegin().isInvalid())
729 Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
735 if (
const auto *
Loc = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc")) {
736 NamedDecl *Decl =
nullptr;
737 if (
const auto &Ref =
Loc->getAs<TagTypeLoc>()) {
738 Decl = Ref.getDecl();
739 }
else if (
const auto &Ref =
Loc->getAs<InjectedClassNameTypeLoc>()) {
740 Decl = Ref.getDecl();
741 }
else if (
const auto &Ref =
Loc->getAs<UnresolvedUsingTypeLoc>()) {
742 Decl = Ref.getDecl();
743 }
else if (
const auto &Ref =
Loc->getAs<TemplateTypeParmTypeLoc>()) {
744 Decl = Ref.getDecl();
748 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
752 if (
const auto &Ref =
Loc->getAs<TemplateSpecializationTypeLoc>()) {
754 Ref.getTypePtr()->getTemplateName().getAsTemplateDecl();
756 SourceRange
Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
757 if (
const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
758 if (
const auto *TemplDecl = ClassDecl->getTemplatedDecl())
764 if (
const auto &Ref =
765 Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
766 if (
const auto *Decl = Ref.getTypePtr()->getAsTagDecl())
767 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
772 if (
const auto *
Loc =
773 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>(
"nestedNameLoc")) {
774 if (NestedNameSpecifier *Spec =
Loc->getNestedNameSpecifier()) {
775 if (NamespaceDecl *Decl = Spec->getAsNamespace()) {
776 addUsage(NamingCheckFailures, Decl,
Loc->getLocalSourceRange());
782 if (
const auto *Decl = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
783 for (
const auto &Shadow : Decl->shadows()) {
784 addUsage(NamingCheckFailures, Shadow->getTargetDecl(),
785 Decl->getNameInfo().getSourceRange());
790 if (
const auto *
DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declRef")) {
791 SourceRange
Range =
DeclRef->getNameInfo().getSourceRange();
793 Result.SourceManager);
797 if (
const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>(
"decl")) {
798 if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
802 if (
const auto *Value = Result.Nodes.getNodeAs<ValueDecl>(
"decl")) {
803 if (
const auto *Typedef =
804 Value->getType().getTypePtr()->getAs<TypedefType>()) {
805 addUsage(NamingCheckFailures, Typedef->getDecl(),
806 Value->getSourceRange());
811 if (
const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>(
"decl")) {
812 if (
const auto *Typedef =
813 Value->getReturnType().getTypePtr()->getAs<TypedefType>()) {
814 addUsage(NamingCheckFailures, Typedef->getDecl(),
815 Value->getSourceRange());
817 for (
unsigned i = 0; i < Value->getNumParams(); ++i) {
818 if (
const auto *Typedef = Value->parameters()[i]
821 ->getAs<TypedefType>()) {
822 addUsage(NamingCheckFailures, Typedef->getDecl(),
823 Value->getSourceRange());
830 if (isa<ClassTemplateSpecializationDecl>(Decl))
837 if (!NamingStyles[SK])
841 StringRef
Name = Decl->getName();
846 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
849 if (StringRef(Fixup).equals(Name)) {
850 if (!IgnoreFailedSplit) {
851 LLVM_DEBUG(llvm::dbgs()
852 << Decl->getBeginLoc().printToString(*Result.SourceManager)
853 << llvm::format(
": unable to split words for %s '%s'\n",
854 KindName.c_str(), Name.str().c_str()));
858 Decl->getLocation(), Decl->getNameAsString())];
860 DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
863 Failure.
Fixup = std::move(Fixup);
864 Failure.
KindName = std::move(KindName);
865 addUsage(NamingCheckFailures, Decl, Range);
871 const Token &MacroNameTok,
872 const MacroInfo *MI) {
873 if (!NamingStyles[SK_MacroDefinition])
876 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
877 const NamingStyle &Style = *NamingStyles[SK_MacroDefinition];
881 std::string KindName =
883 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
886 if (StringRef(Fixup).equals(Name)) {
887 if (!IgnoreFailedSplit) {
888 LLVM_DEBUG(llvm::dbgs()
889 << MacroNameTok.getLocation().printToString(SourceMgr)
890 << llvm::format(
": unable to split words for %s '%s'\n",
891 KindName.c_str(), Name.str().c_str()));
896 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
898 Failure.Fixup = std::move(Fixup);
899 Failure.KindName = std::move(KindName);
905 const MacroInfo *MI) {
906 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
909 auto Failure = NamingCheckFailures.find(ID);
910 if (Failure == NamingCheckFailures.end())
913 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
918 for (
const auto &Pair : NamingCheckFailures) {
926 auto Diag =
diag(Decl.first,
"invalid case style for %0 '%1'")
940 Diag << FixItHint::CreateReplacement(
941 SourceRange(SourceLocation::getFromRawEncoding(
Loc)),
static unsigned getHashValue(NamingCheckId Val)
SourceLocation Loc
'#' location in the include directive
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 registerPPCallbacks(CompilerInstance &Compiler) override
Override this to register PPCallbacks with Compiler.
Some operations such as code completion produce a set of candidates.
static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures, const IdentifierNamingCheck::NamingCheckId &Decl, SourceRange Range, SourceManager *SourceMgr=nullptr)
std::string get(StringRef LocalName, StringRef Default) const
Read a named option from the Context.
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
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 registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
static constexpr llvm::StringLiteral Name
std::map< std::string, std::string > OptionMap
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
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.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle &Style)
llvm::DenseMap< NamingCheckId, NamingCheckFailure > NamingCheckFailureMap
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
static StyleKind findStyleKind(const NamedDecl *D, const std::vector< llvm::Optional< IdentifierNamingCheck::NamingStyle >> &NamingStyles)
CharSourceRange Range
SourceRange for the file name.
bool rangeCanBeFixed(SourceRange Range, const SourceManager *SM)
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.
Checks for identifiers naming style mismatch.
bool ShouldFix
Whether the failure should be fixed or not.