11 #include "../utils/ASTUtils.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/AST/CXXInheritance.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);
212 return "Camel_Snake_Case";
214 return "camel_Snake_Back";
217 llvm_unreachable(
"Unknown Case Type");
220 for (
size_t i = 0; i <
SK_Count; ++i) {
221 if (NamingStyles[i]) {
222 if (NamingStyles[i]->Case) {
227 NamingStyles[i]->Prefix);
229 NamingStyles[i]->Suffix);
233 Options.
store(Opts,
"IgnoreFailedSplit", IgnoreFailedSplit);
237 Finder->addMatcher(namedDecl().bind(
"decl"),
this);
238 Finder->addMatcher(usingDecl().bind(
"using"),
this);
239 Finder->addMatcher(declRefExpr().bind(
"declRef"),
this);
240 Finder->addMatcher(cxxConstructorDecl(unless(isImplicit())).bind(
"classRef"),
242 Finder->addMatcher(cxxDestructorDecl(unless(isImplicit())).bind(
"classRef"),
244 Finder->addMatcher(typeLoc().bind(
"typeLoc"),
this);
245 Finder->addMatcher(nestedNameSpecifierLoc().bind(
"nestedNameLoc"),
this);
247 functionDecl(unless(cxxMethodDecl(isImplicit())),
248 hasBody(forEachDescendant(memberExpr().bind(
"memberExpr")))),
252 unless(isImplicit()),
253 forEachConstructorInitializer(
254 allOf(isWritten(), withInitializer(forEachDescendant(
255 memberExpr().bind(
"memberExpr")))))),
257 Finder->addMatcher(fieldDecl(hasInClassInitializer(
258 forEachDescendant(memberExpr().bind(
"memberExpr")))),
263 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
264 ModuleExpanderPP->addPPCallbacks(
265 std::make_unique<IdentifierNamingCheckPPCallbacks>(ModuleExpanderPP,
271 static llvm::Regex Matchers[] = {
273 llvm::Regex(
"^[a-z][a-z0-9_]*$"),
274 llvm::Regex(
"^[a-z][a-zA-Z0-9]*$"),
275 llvm::Regex(
"^[A-Z][A-Z0-9_]*$"),
276 llvm::Regex(
"^[A-Z][a-zA-Z0-9]*$"),
277 llvm::Regex(
"^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
278 llvm::Regex(
"^[a-z]([a-z0-9]*(_[A-Z])?)*"),
281 if (Name.startswith(Style.
Prefix))
282 Name = Name.drop_front(Style.
Prefix.size());
286 if (Name.endswith(Style.
Suffix))
287 Name = Name.drop_back(Style.
Suffix.size());
293 if (Name.startswith(
"_") || Name.endswith(
"_"))
296 if (Style.
Case && !Matchers[static_cast<size_t>(*Style.
Case)].match(Name))
304 static llvm::Regex Splitter(
305 "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
307 SmallVector<StringRef, 8> Substrs;
308 Name.split(Substrs,
"_", -1,
false);
310 SmallVector<StringRef, 8> Words;
311 for (
auto Substr : Substrs) {
312 while (!Substr.empty()) {
313 SmallVector<StringRef, 8> Groups;
314 if (!Splitter.match(Substr, &Groups))
317 if (Groups[2].size() > 0) {
318 Words.push_back(Groups[1]);
319 Substr = Substr.substr(Groups[0].size());
320 }
else if (Groups[3].size() > 0) {
321 Words.push_back(Groups[3]);
322 Substr = Substr.substr(Groups[0].size() - Groups[4].size());
323 }
else if (Groups[5].size() > 0) {
324 Words.push_back(Groups[5]);
325 Substr = Substr.substr(Groups[0].size() - Groups[6].size());
340 for (
auto const &
Word : Words) {
341 if (&
Word != &Words.front())
343 Fixup +=
Word.lower();
348 for (
auto const &
Word : Words) {
349 if (&
Word != &Words.front())
351 Fixup +=
Word.upper();
356 for (
auto const &
Word : Words) {
357 Fixup +=
Word.substr(0, 1).upper();
358 Fixup +=
Word.substr(1).lower();
363 for (
auto const &
Word : Words) {
364 if (&
Word == &Words.front()) {
365 Fixup +=
Word.lower();
367 Fixup +=
Word.substr(0, 1).upper();
368 Fixup +=
Word.substr(1).lower();
374 for (
auto const &
Word : Words) {
375 if (&
Word != &Words.front())
377 Fixup +=
Word.substr(0, 1).upper();
378 Fixup +=
Word.substr(1).lower();
383 for (
auto const &
Word : Words) {
384 if (&
Word != &Words.front()) {
386 Fixup +=
Word.substr(0, 1).upper();
388 Fixup +=
Word.substr(0, 1).lower();
390 Fixup +=
Word.substr(1).lower();
402 Name, Style.
Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
403 StringRef Mid = StringRef(Fixed).trim(
"_");
411 const std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>>
413 assert(D && D->getIdentifier() && !D->getName().empty() && !D->isImplicit() &&
414 "Decl must be an explicit identifier with a name.");
416 if (isa<ObjCIvarDecl>(D) && NamingStyles[SK_ObjcIvar])
419 if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef])
422 if (isa<TypeAliasDecl>(D) && NamingStyles[SK_TypeAlias])
425 if (
const auto *
Decl = dyn_cast<NamespaceDecl>(D)) {
426 if (
Decl->isAnonymousNamespace())
429 if (
Decl->isInline() && NamingStyles[SK_InlineNamespace])
430 return SK_InlineNamespace;
432 if (NamingStyles[SK_Namespace])
436 if (isa<EnumDecl>(D) && NamingStyles[SK_Enum])
439 if (isa<EnumConstantDecl>(D)) {
440 if (NamingStyles[SK_EnumConstant])
441 return SK_EnumConstant;
443 if (NamingStyles[SK_Constant])
449 if (
const auto *
Decl = dyn_cast<CXXRecordDecl>(D)) {
450 if (
Decl->isAnonymousStructOrUnion())
453 if (!
Decl->getCanonicalDecl()->isThisDeclarationADefinition())
456 if (
Decl->hasDefinition() &&
Decl->isAbstract() &&
457 NamingStyles[SK_AbstractClass])
458 return SK_AbstractClass;
460 if (
Decl->isStruct() && NamingStyles[SK_Struct])
463 if (
Decl->isStruct() && NamingStyles[SK_Class])
466 if (
Decl->isClass() && NamingStyles[SK_Class])
469 if (
Decl->isClass() && NamingStyles[SK_Struct])
472 if (
Decl->isUnion() && NamingStyles[SK_Union])
475 if (
Decl->isEnum() && NamingStyles[SK_Enum])
481 if (
const auto *
Decl = dyn_cast<FieldDecl>(D)) {
484 if (!Type.isNull() && Type.isConstQualified()) {
485 if (NamingStyles[SK_ConstantMember])
486 return SK_ConstantMember;
488 if (NamingStyles[SK_Constant])
492 if (
Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
493 return SK_PrivateMember;
495 if (
Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMember])
496 return SK_ProtectedMember;
498 if (
Decl->getAccess() == AS_public && NamingStyles[SK_PublicMember])
499 return SK_PublicMember;
501 if (NamingStyles[SK_Member])
507 if (
const auto *
Decl = dyn_cast<ParmVarDecl>(D)) {
510 if (
Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
511 return SK_ConstexprVariable;
513 if (!Type.isNull() && Type.isConstQualified()) {
514 if (Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_ConstantPointerParameter])
515 return SK_ConstantPointerParameter;
517 if (NamingStyles[SK_ConstantParameter])
518 return SK_ConstantParameter;
520 if (NamingStyles[SK_Constant])
524 if (
Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
525 return SK_ParameterPack;
527 if (!Type.isNull() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_PointerParameter])
528 return SK_PointerParameter;
530 if (NamingStyles[SK_Parameter])
536 if (
const auto *
Decl = dyn_cast<VarDecl>(D)) {
539 if (
Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
540 return SK_ConstexprVariable;
542 if (!Type.isNull() && Type.isConstQualified()) {
543 if (
Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
544 return SK_ClassConstant;
546 if (
Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_GlobalConstantPointer])
547 return SK_GlobalConstantPointer;
549 if (
Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
550 return SK_GlobalConstant;
552 if (
Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
553 return SK_StaticConstant;
555 if (
Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalConstantPointer])
556 return SK_LocalConstantPointer;
558 if (
Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
559 return SK_LocalConstant;
561 if (
Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
562 return SK_LocalConstant;
564 if (NamingStyles[SK_Constant])
568 if (
Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
569 return SK_ClassMember;
571 if (
Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_GlobalPointer])
572 return SK_GlobalPointer;
574 if (
Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable])
575 return SK_GlobalVariable;
577 if (
Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
578 return SK_StaticVariable;
580 if (
Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() && NamingStyles[SK_LocalPointer])
581 return SK_LocalPointer;
583 if (
Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable])
584 return SK_LocalVariable;
586 if (
Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalVariable])
587 return SK_LocalVariable;
589 if (NamingStyles[SK_Variable])
595 if (
const auto *
Decl = dyn_cast<CXXMethodDecl>(D)) {
596 if (
Decl->isMain() || !
Decl->isUserProvided() ||
597 Decl->size_overridden_methods() > 0)
602 auto FindHidden = [&](
const CXXBaseSpecifier *S, clang::CXXBasePath &P) {
603 return CXXRecordDecl::FindOrdinaryMember(S, P,
Decl->getDeclName());
605 CXXBasePaths UnusedPaths;
606 if (
Decl->getParent()->lookupInBases(FindHidden, UnusedPaths))
609 if (
Decl->isConstexpr() && NamingStyles[SK_ConstexprMethod])
610 return SK_ConstexprMethod;
612 if (
Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction])
613 return SK_ConstexprFunction;
615 if (
Decl->isStatic() && NamingStyles[SK_ClassMethod])
616 return SK_ClassMethod;
618 if (
Decl->isVirtual() && NamingStyles[SK_VirtualMethod])
619 return SK_VirtualMethod;
621 if (
Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMethod])
622 return SK_PrivateMethod;
624 if (
Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMethod])
625 return SK_ProtectedMethod;
627 if (
Decl->getAccess() == AS_public && NamingStyles[SK_PublicMethod])
628 return SK_PublicMethod;
630 if (NamingStyles[SK_Method])
633 if (NamingStyles[SK_Function])
639 if (
const auto *
Decl = dyn_cast<FunctionDecl>(D)) {
643 if (
Decl->isConstexpr() && NamingStyles[SK_ConstexprFunction])
644 return SK_ConstexprFunction;
646 if (
Decl->isGlobal() && NamingStyles[SK_GlobalFunction])
647 return SK_GlobalFunction;
649 if (NamingStyles[SK_Function])
653 if (isa<TemplateTypeParmDecl>(D)) {
654 if (NamingStyles[SK_TypeTemplateParameter])
655 return SK_TypeTemplateParameter;
657 if (NamingStyles[SK_TemplateParameter])
658 return SK_TemplateParameter;
663 if (isa<NonTypeTemplateParmDecl>(D)) {
664 if (NamingStyles[SK_ValueTemplateParameter])
665 return SK_ValueTemplateParameter;
667 if (NamingStyles[SK_TemplateParameter])
668 return SK_TemplateParameter;
673 if (isa<TemplateTemplateParmDecl>(D)) {
674 if (NamingStyles[SK_TemplateTemplateParameter])
675 return SK_TemplateTemplateParameter;
677 if (NamingStyles[SK_TemplateParameter])
678 return SK_TemplateParameter;
688 SourceRange
Range, SourceManager *SourceMgr =
nullptr) {
690 if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
697 SourceLocation FixLocation = Range.getBegin();
699 FixLocation = SourceMgr->getSpellingLoc(FixLocation);
700 if (FixLocation.isInvalid())
705 auto &Failure = Failures[
Decl];
706 if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
709 if (!Failure.ShouldFix())
718 const NamedDecl *
Decl, SourceRange
Range,
719 SourceManager *SourceMgr =
nullptr) {
722 Decl->getNameAsString()),
727 if (
const auto *
Decl =
728 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"classRef")) {
731 Decl->getNameInfo().getSourceRange());
733 for (
const auto *Init :
Decl->inits()) {
734 if (!Init->isWritten() || Init->isInClassMemberInitializer())
736 if (
const auto *FD = Init->getAnyMember())
738 SourceRange(Init->getMemberLocation()));
745 if (
const auto *
Decl =
746 Result.Nodes.getNodeAs<CXXDestructorDecl>(
"classRef")) {
748 SourceRange
Range =
Decl->getNameInfo().getSourceRange();
749 if (Range.getBegin().isInvalid())
759 if (
const auto *
Loc = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc")) {
760 NamedDecl *
Decl =
nullptr;
761 if (
const auto &Ref =
Loc->getAs<TagTypeLoc>()) {
762 Decl = Ref.getDecl();
763 }
else if (
const auto &Ref =
Loc->getAs<InjectedClassNameTypeLoc>()) {
764 Decl = Ref.getDecl();
765 }
else if (
const auto &Ref =
Loc->getAs<UnresolvedUsingTypeLoc>()) {
766 Decl = Ref.getDecl();
767 }
else if (
const auto &Ref =
Loc->getAs<TemplateTypeParmTypeLoc>()) {
768 Decl = Ref.getDecl();
772 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
776 if (
const auto &Ref =
Loc->getAs<TemplateSpecializationTypeLoc>()) {
778 Ref.getTypePtr()->getTemplateName().getAsTemplateDecl();
780 SourceRange
Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
781 if (
const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
782 if (
const auto *TemplDecl = ClassDecl->getTemplatedDecl())
788 if (
const auto &Ref =
789 Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
790 if (
const auto *Decl = Ref.getTypePtr()->getAsTagDecl())
791 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
796 if (
const auto *
Loc =
797 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>(
"nestedNameLoc")) {
798 if (NestedNameSpecifier *Spec =
Loc->getNestedNameSpecifier()) {
799 if (NamespaceDecl *
Decl = Spec->getAsNamespace()) {
806 if (
const auto *
Decl = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
807 for (
const auto *Shadow :
Decl->shadows()) {
808 addUsage(NamingCheckFailures, Shadow->getTargetDecl(),
809 Decl->getNameInfo().getSourceRange());
814 if (
const auto *
DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declRef")) {
815 SourceRange
Range =
DeclRef->getNameInfo().getSourceRange();
817 Result.SourceManager);
821 if (
const auto *MemberRef =
822 Result.Nodes.getNodeAs<MemberExpr>(
"memberExpr")) {
823 SourceRange
Range = MemberRef->getMemberNameInfo().getSourceRange();
824 addUsage(NamingCheckFailures, MemberRef->getMemberDecl(),
Range,
825 Result.SourceManager);
829 if (
const auto *
Decl = Result.Nodes.getNodeAs<NamedDecl>(
"decl")) {
830 if (!
Decl->getIdentifier() ||
Decl->getName().empty() ||
Decl->isImplicit())
834 if (
const auto *Value = Result.Nodes.getNodeAs<ValueDecl>(
"decl")) {
835 if (
const auto *TypePtr = Value->getType().getTypePtrOrNull()) {
836 if (
const auto *Typedef = TypePtr->getAs<TypedefType>()) {
837 addUsage(NamingCheckFailures, Typedef->getDecl(),
838 Value->getSourceRange());
844 if (
const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>(
"decl")) {
845 if (
const auto *Typedef =
846 Value->getReturnType().getTypePtr()->getAs<TypedefType>()) {
847 addUsage(NamingCheckFailures, Typedef->getDecl(),
848 Value->getSourceRange());
850 for (
unsigned i = 0; i < Value->getNumParams(); ++i) {
851 if (
const auto *Typedef = Value->parameters()[i]
854 ->getAs<TypedefType>()) {
855 addUsage(NamingCheckFailures, Typedef->getDecl(),
856 Value->getSourceRange());
863 if (isa<ClassTemplateSpecializationDecl>(
Decl))
870 if (!NamingStyles[SK])
879 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
882 if (StringRef(Fixup).equals(Name)) {
883 if (!IgnoreFailedSplit) {
884 LLVM_DEBUG(llvm::dbgs()
885 <<
Decl->getBeginLoc().printToString(*Result.SourceManager)
886 << llvm::format(
": unable to split words for %s '%s'\n",
887 KindName.c_str(), Name.str().c_str()));
891 Decl->getLocation(),
Decl->getNameAsString())];
893 DeclarationNameInfo(
Decl->getDeclName(),
Decl->getLocation())
896 const IdentifierTable &Idents =
Decl->getASTContext().Idents;
897 auto CheckNewIdentifier = Idents.find(Fixup);
898 if (CheckNewIdentifier != Idents.end()) {
899 const IdentifierInfo *Ident = CheckNewIdentifier->second;
902 else if (Ident->hasMacroDefinition())
906 Failure.
Fixup = std::move(Fixup);
907 Failure.
KindName = std::move(KindName);
914 const Token &MacroNameTok,
915 const MacroInfo *MI) {
916 if (!NamingStyles[SK_MacroDefinition])
919 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
920 const NamingStyle &Style = *NamingStyles[SK_MacroDefinition];
924 std::string KindName =
926 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
929 if (StringRef(Fixup).equals(Name)) {
930 if (!IgnoreFailedSplit) {
931 LLVM_DEBUG(llvm::dbgs()
932 << MacroNameTok.getLocation().printToString(SourceMgr)
933 << llvm::format(
": unable to split words for %s '%s'\n",
934 KindName.c_str(), Name.str().c_str()));
939 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
941 Failure.Fixup = std::move(Fixup);
942 Failure.KindName = std::move(KindName);
948 const MacroInfo *MI) {
949 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
952 auto Failure = NamingCheckFailures.find(ID);
953 if (Failure == NamingCheckFailures.end())
956 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
961 for (
const auto &Pair : NamingCheckFailures) {
971 "invalid case style for %0 '%1'%select{|" 975 "; cannot be fixed because '%3' would conflict with a keyword|" 976 "; cannot be fixed because '%3' would conflict with a macro " 993 Diag << FixItHint::CreateReplacement(
994 SourceRange(SourceLocation::getFromRawEncoding(
Loc)),
static unsigned getHashValue(NamingCheckId Val)
SourceLocation Loc
'#' location in the include directive
const FunctionDecl * Decl
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)
Holds an identifier name check failure, tracking the kind of the identifier, its possible fixup and t...
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
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.
bool ShouldFix() const
Whether the failure should be fixed or not.
llvm::Optional< CaseType > Case
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
static NamingCheckId getEmptyKey()
Base class for all clang-tidy checks.
const LangOptions & getLangOpts() const
Returns the language options from the context.
static std::string replace(llvm::StringRef Haystack, llvm::StringRef Needle, llvm::StringRef Repl)
static bool isEqual(const NamingCheckId &LHS, const NamingCheckId &RHS)
clang::tidy::readability::IdentifierNamingCheck::NamingCheckId NamingCheckId
bool ShouldNotify() const
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
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.
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< Range > getTokenRange(const SourceManager &SM, const LangOptions &LangOpts, SourceLocation TokLoc)
Returns the taken range at TokLoc.
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)
The fixup will conflict with a language keyword, so we can't fix it automatically.
void checkMacro(SourceManager &sourceMgr, const Token &MacroNameTok, const MacroInfo *MI)
Check Macros for style violations.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
ShouldFixStatus FixStatus
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.
std::string get(StringRef LocalName, StringRef Default) const
Read a named option from the Context.
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.