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" 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);
52 static bool isEqual(
const NamingCheckId &LHS,
const NamingCheckId &RHS) {
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) \ 115 #define ENUMERATE(v) SK_ ## v, 123 #define STRINGIZE(v) #v, 133 class IdentifierNamingCheckPPCallbacks :
public PPCallbacks {
135 IdentifierNamingCheckPPCallbacks(Preprocessor *PP,
137 : PP(PP), Check(Check) {}
140 void MacroDefined(
const Token &MacroNameTok,
141 const MacroDirective *MD)
override {
142 Check->
checkMacro(PP->getSourceManager(), MacroNameTok, MD->getMacroInfo());
146 void MacroExpands(
const Token &MacroNameTok,
const MacroDefinition &MD,
148 const MacroArgs * )
override {
149 Check->
expandMacro(MacroNameTok, MD.getMacroInfo());
158 IdentifierNamingCheck::IdentifierNamingCheck(StringRef
Name,
161 auto const fromString = [](StringRef Str) {
162 return llvm::StringSwitch<llvm::Optional<CaseType>>(Str)
170 .Default(llvm::None);
173 for (
auto const &Name : StyleNames) {
174 auto const caseOptional =
175 fromString(
Options.
get((Name +
"Case").str(),
""));
176 auto prefix =
Options.
get((Name +
"Prefix").str(),
"");
177 auto postfix =
Options.
get((Name +
"Suffix").str(),
"");
179 if (caseOptional || !prefix.empty() || !postfix.empty()) {
180 NamingStyles.push_back(
NamingStyle(caseOptional, prefix, postfix));
182 NamingStyles.push_back(llvm::None);
186 IgnoreFailedSplit =
Options.
get(
"IgnoreFailedSplit", 0);
203 return "Camel_Snake_Case";
205 return "camel_Snake_Back";
208 llvm_unreachable(
"Unknown Case Type");
211 for (
size_t i = 0; i <
SK_Count; ++i) {
212 if (NamingStyles[i]) {
213 if (NamingStyles[i]->Case) {
218 NamingStyles[i]->Prefix);
220 NamingStyles[i]->Suffix);
224 Options.
store(Opts,
"IgnoreFailedSplit", IgnoreFailedSplit);
228 Finder->addMatcher(namedDecl().bind(
"decl"),
this);
229 Finder->addMatcher(usingDecl().bind(
"using"),
this);
230 Finder->addMatcher(declRefExpr().bind(
"declRef"),
this);
231 Finder->addMatcher(cxxConstructorDecl().bind(
"classRef"),
this);
232 Finder->addMatcher(cxxDestructorDecl().bind(
"classRef"),
this);
233 Finder->addMatcher(typeLoc().bind(
"typeLoc"),
this);
234 Finder->addMatcher(nestedNameSpecifierLoc().bind(
"nestedNameLoc"),
this);
238 Compiler.getPreprocessor().addPPCallbacks(
239 llvm::make_unique<IdentifierNamingCheckPPCallbacks>(
240 &Compiler.getPreprocessor(),
this));
245 static llvm::Regex Matchers[] = {
247 llvm::Regex(
"^[a-z][a-z0-9_]*$"),
248 llvm::Regex(
"^[a-z][a-zA-Z0-9]*$"),
249 llvm::Regex(
"^[A-Z][A-Z0-9_]*$"),
250 llvm::Regex(
"^[A-Z][a-zA-Z0-9]*$"),
251 llvm::Regex(
"^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
252 llvm::Regex(
"^[a-z]([a-z0-9]*(_[A-Z])?)*"),
256 if (Name.startswith(Style.
Prefix))
257 Name = Name.drop_front(Style.
Prefix.size());
261 if (Name.endswith(Style.
Suffix))
262 Name = Name.drop_back(Style.
Suffix.size());
268 if (Name.startswith(
"_") || Name.endswith(
"_"))
271 if (Style.
Case && !Matchers[static_cast<size_t>(*Style.
Case)].match(Name))
279 static llvm::Regex Splitter(
280 "([a-z0-9A-Z]*)(_+)|([A-Z]?[a-z0-9]+)([A-Z]|$)|([A-Z]+)([A-Z]|$)");
282 SmallVector<StringRef, 8> Substrs;
283 Name.split(Substrs,
"_", -1,
false);
285 SmallVector<StringRef, 8> Words;
286 for (
auto Substr : Substrs) {
287 while (!Substr.empty()) {
288 SmallVector<StringRef, 8> Groups;
289 if (!Splitter.match(Substr, &Groups))
292 if (Groups[2].size() > 0) {
293 Words.push_back(Groups[1]);
294 Substr = Substr.substr(Groups[0].size());
295 }
else if (Groups[3].size() > 0) {
296 Words.push_back(Groups[3]);
297 Substr = Substr.substr(Groups[0].size() - Groups[4].size());
298 }
else if (Groups[5].size() > 0) {
299 Words.push_back(Groups[5]);
300 Substr = Substr.substr(Groups[0].size() - Groups[6].size());
315 for (
auto const &Word : Words) {
316 if (&Word != &Words.front())
318 Fixup += Word.lower();
323 for (
auto const &Word : Words) {
324 if (&Word != &Words.front())
326 Fixup += Word.upper();
331 for (
auto const &Word : Words) {
332 Fixup += Word.substr(0, 1).upper();
333 Fixup += Word.substr(1).lower();
338 for (
auto const &Word : Words) {
339 if (&Word == &Words.front()) {
340 Fixup += Word.lower();
342 Fixup += Word.substr(0, 1).upper();
343 Fixup += Word.substr(1).lower();
349 for (
auto const &Word : Words) {
350 if (&Word != &Words.front())
352 Fixup += Word.substr(0, 1).upper();
353 Fixup += Word.substr(1).lower();
358 for (
auto const &Word : Words) {
359 if (&Word != &Words.front()) {
361 Fixup += Word.substr(0, 1).upper();
363 Fixup += Word.substr(0, 1).lower();
365 Fixup += Word.substr(1).lower();
377 Name, Style.
Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
378 StringRef Mid = StringRef(Fixed).trim(
"_");
386 const std::vector<llvm::Optional<IdentifierNamingCheck::NamingStyle>>
388 if (isa<ObjCIvarDecl>(D) && NamingStyles[SK_ObjcIvar])
391 if (isa<TypedefDecl>(D) && NamingStyles[SK_Typedef])
394 if (isa<TypeAliasDecl>(D) && NamingStyles[SK_TypeAlias])
397 if (
const auto *Decl = dyn_cast<NamespaceDecl>(D)) {
398 if (Decl->isAnonymousNamespace())
401 if (Decl->isInline() && NamingStyles[SK_InlineNamespace])
402 return SK_InlineNamespace;
404 if (NamingStyles[SK_Namespace])
408 if (isa<EnumDecl>(D) && NamingStyles[SK_Enum])
411 if (isa<EnumConstantDecl>(D)) {
412 if (NamingStyles[SK_EnumConstant])
413 return SK_EnumConstant;
415 if (NamingStyles[SK_Constant])
421 if (
const auto *Decl = dyn_cast<CXXRecordDecl>(D)) {
422 if (Decl->isAnonymousStructOrUnion())
425 if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
428 if (Decl->hasDefinition() && Decl->isAbstract() &&
429 NamingStyles[SK_AbstractClass])
430 return SK_AbstractClass;
432 if (Decl->isStruct() && NamingStyles[SK_Struct])
435 if (Decl->isStruct() && NamingStyles[SK_Class])
438 if (Decl->isClass() && NamingStyles[SK_Class])
441 if (Decl->isClass() && NamingStyles[SK_Struct])
444 if (Decl->isUnion() && NamingStyles[SK_Union])
447 if (Decl->isEnum() && NamingStyles[SK_Enum])
453 if (
const auto *Decl = dyn_cast<FieldDecl>(D)) {
454 QualType Type = Decl->getType();
456 if (!Type.isNull() && Type.isConstQualified()) {
457 if (NamingStyles[SK_ConstantMember])
458 return SK_ConstantMember;
460 if (NamingStyles[SK_Constant])
464 if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
465 return SK_PrivateMember;
467 if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMember])
468 return SK_ProtectedMember;
470 if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMember])
471 return SK_PublicMember;
473 if (NamingStyles[SK_Member])
479 if (
const auto *Decl = dyn_cast<ParmVarDecl>(D)) {
480 QualType Type = Decl->getType();
482 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
483 return SK_ConstexprVariable;
485 if (!Type.isNull() && Type.isConstQualified()) {
486 if (NamingStyles[SK_ConstantParameter])
487 return SK_ConstantParameter;
489 if (NamingStyles[SK_Constant])
493 if (Decl->isParameterPack() && NamingStyles[SK_ParameterPack])
494 return SK_ParameterPack;
496 if (NamingStyles[SK_Parameter])
502 if (
const auto *Decl = dyn_cast<VarDecl>(D)) {
503 QualType Type = Decl->getType();
505 if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
506 return SK_ConstexprVariable;
508 if (!Type.isNull() && Type.isConstQualified()) {
509 if (Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
510 return SK_ClassConstant;
512 if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
513 return SK_GlobalConstant;
515 if (Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
516 return SK_StaticConstant;
518 if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
519 return SK_LocalConstant;
521 if (Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
522 return SK_LocalConstant;
524 if (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;
635 SourceRange
Range, SourceManager *SourceMgr =
nullptr) {
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,
683 SourceManager *SourceMgr =
nullptr) {
686 Decl->getNameAsString()),
691 if (
const auto *Decl =
692 Result.Nodes.getNodeAs<CXXConstructorDecl>(
"classRef")) {
693 if (Decl->isImplicit())
696 addUsage(NamingCheckFailures, Decl->getParent(),
697 Decl->getNameInfo().getSourceRange());
699 for (
const auto *Init : Decl->inits()) {
700 if (!Init->isWritten() || Init->isInClassMemberInitializer())
702 if (
const auto *FD = Init->getAnyMember())
704 SourceRange(Init->getMemberLocation()));
711 if (
const auto *Decl =
712 Result.Nodes.getNodeAs<CXXDestructorDecl>(
"classRef")) {
713 if (Decl->isImplicit())
716 SourceRange
Range = Decl->getNameInfo().getSourceRange();
717 if (Range.getBegin().isInvalid())
721 Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
727 if (
const auto *
Loc = Result.Nodes.getNodeAs<TypeLoc>(
"typeLoc")) {
728 NamedDecl *Decl =
nullptr;
729 if (
const auto &Ref =
Loc->getAs<TagTypeLoc>()) {
730 Decl = Ref.getDecl();
731 }
else if (
const auto &Ref =
Loc->getAs<InjectedClassNameTypeLoc>()) {
732 Decl = Ref.getDecl();
733 }
else if (
const auto &Ref =
Loc->getAs<UnresolvedUsingTypeLoc>()) {
734 Decl = Ref.getDecl();
735 }
else if (
const auto &Ref =
Loc->getAs<TemplateTypeParmTypeLoc>()) {
736 Decl = Ref.getDecl();
740 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
744 if (
const auto &Ref =
Loc->getAs<TemplateSpecializationTypeLoc>()) {
746 Ref.getTypePtr()->getTemplateName().getAsTemplateDecl();
748 SourceRange
Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
749 if (
const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
750 if (
const auto *TemplDecl = ClassDecl->getTemplatedDecl())
756 if (
const auto &Ref =
757 Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
758 if (
const auto *Decl = Ref.getTypePtr()->getAsTagDecl())
759 addUsage(NamingCheckFailures, Decl,
Loc->getSourceRange());
764 if (
const auto *
Loc =
765 Result.Nodes.getNodeAs<NestedNameSpecifierLoc>(
"nestedNameLoc")) {
766 if (NestedNameSpecifier *Spec =
Loc->getNestedNameSpecifier()) {
767 if (NamespaceDecl *Decl = Spec->getAsNamespace()) {
768 addUsage(NamingCheckFailures, Decl,
Loc->getLocalSourceRange());
774 if (
const auto *Decl = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
775 for (
const auto &Shadow : Decl->shadows()) {
776 addUsage(NamingCheckFailures, Shadow->getTargetDecl(),
777 Decl->getNameInfo().getSourceRange());
782 if (
const auto *
DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>(
"declRef")) {
783 SourceRange
Range =
DeclRef->getNameInfo().getSourceRange();
785 Result.SourceManager);
789 if (
const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>(
"decl")) {
790 if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
794 if (
const auto *Value = Result.Nodes.getNodeAs<ValueDecl>(
"decl")) {
795 if (
const auto *Typedef =
796 Value->getType().getTypePtr()->getAs<TypedefType>()) {
797 addUsage(NamingCheckFailures, Typedef->getDecl(),
798 Value->getSourceRange());
803 if (
const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>(
"decl")) {
804 if (
const auto *Typedef =
805 Value->getReturnType().getTypePtr()->getAs<TypedefType>()) {
806 addUsage(NamingCheckFailures, Typedef->getDecl(),
807 Value->getSourceRange());
809 for (
unsigned i = 0; i < Value->getNumParams(); ++i) {
810 if (
const auto *Typedef = Value->parameters()[i]
813 ->getAs<TypedefType>()) {
814 addUsage(NamingCheckFailures, Typedef->getDecl(),
815 Value->getSourceRange());
822 if (isa<ClassTemplateSpecializationDecl>(Decl))
829 if (!NamingStyles[SK])
833 StringRef
Name = Decl->getName();
838 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
841 if (StringRef(Fixup).equals(Name)) {
842 if (!IgnoreFailedSplit) {
843 LLVM_DEBUG(llvm::dbgs()
844 << Decl->getLocStart().printToString(*Result.SourceManager)
845 << llvm::format(
": unable to split words for %s '%s'\n",
846 KindName.c_str(), Name.str().c_str()));
850 Decl->getLocation(), Decl->getNameAsString())];
852 DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
855 Failure.
Fixup = std::move(Fixup);
856 Failure.
KindName = std::move(KindName);
857 addUsage(NamingCheckFailures, Decl, Range);
863 const Token &MacroNameTok,
864 const MacroInfo *MI) {
865 if (!NamingStyles[SK_MacroDefinition])
868 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
869 const NamingStyle &Style = *NamingStyles[SK_MacroDefinition];
873 std::string KindName =
875 std::replace(KindName.begin(), KindName.end(),
'_',
' ');
878 if (StringRef(Fixup).equals(Name)) {
879 if (!IgnoreFailedSplit) {
880 LLVM_DEBUG(llvm::dbgs()
881 << MacroNameTok.getLocation().printToString(SourceMgr)
882 << llvm::format(
": unable to split words for %s '%s'\n",
883 KindName.c_str(), Name.str().c_str()));
888 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
890 Failure.Fixup = std::move(Fixup);
891 Failure.KindName = std::move(KindName);
897 const MacroInfo *MI) {
898 StringRef
Name = MacroNameTok.getIdentifierInfo()->getName();
901 auto Failure = NamingCheckFailures.find(ID);
902 if (Failure == NamingCheckFailures.end())
905 SourceRange
Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
910 for (
const auto &Pair : NamingCheckFailures) {
918 auto Diag =
diag(Decl.first,
"invalid case style for %0 '%1'")
932 Diag << FixItHint::CreateReplacement(
933 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.
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.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
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.
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.