this));
}
-static void addUsage(RenamerClangTidyCheck::NamingCheckFailureMap &Failures,
- const RenamerClangTidyCheck::NamingCheckId &Decl,
- SourceRange Range, SourceManager *SourceMgr = nullptr) {
+void RenamerClangTidyCheck::addUsage(
+ const RenamerClangTidyCheck::NamingCheckId &Decl, SourceRange Range,
+ SourceManager *SourceMgr) {
// Do nothing if the provided range is invalid.
if (Range.isInvalid())
return;
// Try to insert the identifier location in the Usages map, and bail out if it
// is already in there
- RenamerClangTidyCheck::NamingCheckFailure &Failure = Failures[Decl];
+ RenamerClangTidyCheck::NamingCheckFailure &Failure =
+ NamingCheckFailures[Decl];
if (!Failure.RawUsageLocs.insert(FixLocation.getRawEncoding()).second)
return;
Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
}
-/// Convenience method when the usage to be added is a NamedDecl
-static void addUsage(RenamerClangTidyCheck::NamingCheckFailureMap &Failures,
- const NamedDecl *Decl, SourceRange Range,
- SourceManager *SourceMgr = nullptr) {
- return addUsage(Failures,
- RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
+void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl, SourceRange Range,
+ SourceManager *SourceMgr) {
+
+ return addUsage(RenamerClangTidyCheck::NamingCheckId(Decl->getLocation(),
Decl->getNameAsString()),
Range, SourceMgr);
}
if (const auto *Decl =
Result.Nodes.getNodeAs<CXXConstructorDecl>("classRef")) {
- addUsage(NamingCheckFailures, Decl->getParent(),
- Decl->getNameInfo().getSourceRange());
+ addUsage(Decl->getParent(), Decl->getNameInfo().getSourceRange());
for (const auto *Init : Decl->inits()) {
if (!Init->isWritten() || Init->isInClassMemberInitializer())
continue;
if (const FieldDecl *FD = Init->getAnyMember())
- addUsage(NamingCheckFailures, FD,
- SourceRange(Init->getMemberLocation()));
+ addUsage(FD, SourceRange(Init->getMemberLocation()));
// Note: delegating constructors and base class initializers are handled
// via the "typeLoc" matcher.
}
// we want instead to replace the next token, that will be the identifier.
Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
- addUsage(NamingCheckFailures, Decl->getParent(), Range);
+ addUsage(Decl->getParent(), Range);
return;
}
// further TypeLocs handled below
if (Decl) {
- addUsage(NamingCheckFailures, Decl, Loc->getSourceRange());
+ addUsage(Decl, Loc->getSourceRange());
return;
}
SourceRange Range(Ref.getTemplateNameLoc(), Ref.getTemplateNameLoc());
if (const auto *ClassDecl = dyn_cast<TemplateDecl>(Decl)) {
if (const NamedDecl *TemplDecl = ClassDecl->getTemplatedDecl())
- addUsage(NamingCheckFailures, TemplDecl, Range);
+ addUsage(TemplDecl, Range);
return;
}
}
if (const auto &Ref =
Loc->getAs<DependentTemplateSpecializationTypeLoc>()) {
if (const TagDecl *Decl = Ref.getTypePtr()->getAsTagDecl())
- addUsage(NamingCheckFailures, Decl, Loc->getSourceRange());
+ addUsage(Decl, Loc->getSourceRange());
return;
}
}
Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("nestedNameLoc")) {
if (const NestedNameSpecifier *Spec = Loc->getNestedNameSpecifier()) {
if (const NamespaceDecl *Decl = Spec->getAsNamespace()) {
- addUsage(NamingCheckFailures, Decl, Loc->getLocalSourceRange());
+ addUsage(Decl, Loc->getLocalSourceRange());
return;
}
}
if (const auto *Decl = Result.Nodes.getNodeAs<UsingDecl>("using")) {
for (const auto *Shadow : Decl->shadows())
- addUsage(NamingCheckFailures, Shadow->getTargetDecl(),
- Decl->getNameInfo().getSourceRange());
+ addUsage(Shadow->getTargetDecl(), Decl->getNameInfo().getSourceRange());
return;
}
if (const auto *DeclRef = Result.Nodes.getNodeAs<DeclRefExpr>("declRef")) {
SourceRange Range = DeclRef->getNameInfo().getSourceRange();
- addUsage(NamingCheckFailures, DeclRef->getDecl(), Range,
- Result.SourceManager);
+ addUsage(DeclRef->getDecl(), Range, Result.SourceManager);
return;
}
if (const auto *MemberRef =
Result.Nodes.getNodeAs<MemberExpr>("memberExpr")) {
SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange();
- addUsage(NamingCheckFailures, MemberRef->getMemberDecl(), Range,
- Result.SourceManager);
+ addUsage(MemberRef->getMemberDecl(), Range, Result.SourceManager);
return;
}
if (NameLookup Resolved = findDeclInBases(
*Base, DependentName, AggressiveDependentMemberLookup)) {
if (*Resolved)
- addUsage(NamingCheckFailures, *Resolved,
- DepMemberRef->getMemberNameInfo().getSourceRange(),
+ addUsage(*Resolved, DepMemberRef->getMemberNameInfo().getSourceRange(),
Result.SourceManager);
}
return;
if (const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl")) {
// Fix using namespace declarations.
if (const auto *UsingNS = dyn_cast<UsingDirectiveDecl>(Decl))
- addUsage(NamingCheckFailures, UsingNS->getNominatedNamespaceAsWritten(),
+ addUsage(UsingNS->getNominatedNamespaceAsWritten(),
UsingNS->getIdentLocation());
if (!Decl->getIdentifier() || Decl->getName().empty() || Decl->isImplicit())
if (const auto *Value = Result.Nodes.getNodeAs<ValueDecl>("decl")) {
if (const Type *TypePtr = Value->getType().getTypePtrOrNull()) {
if (const auto *Typedef = TypePtr->getAs<TypedefType>())
- addUsage(NamingCheckFailures, Typedef->getDecl(),
- Value->getSourceRange());
+ addUsage(Typedef->getDecl(), Value->getSourceRange());
}
}
if (const auto *Value = Result.Nodes.getNodeAs<FunctionDecl>("decl")) {
if (const auto *Typedef =
Value->getReturnType().getTypePtr()->getAs<TypedefType>())
- addUsage(NamingCheckFailures, Typedef->getDecl(),
- Value->getSourceRange());
+ addUsage(Typedef->getDecl(), Value->getSourceRange());
for (const ParmVarDecl *Param : Value->parameters()) {
if (const TypedefType *Typedef =
Param->getType().getTypePtr()->getAs<TypedefType>())
- addUsage(NamingCheckFailures, Typedef->getDecl(),
- Value->getSourceRange());
+ addUsage(Typedef->getDecl(), Value->getSourceRange());
}
}
}
Failure.Info = std::move(Info);
- addUsage(NamingCheckFailures, Decl, Range);
+ addUsage(Decl, Range);
}
}
SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
Failure.Info = std::move(Info);
- addUsage(NamingCheckFailures, ID, Range);
+ addUsage(ID, Range);
}
void RenamerClangTidyCheck::expandMacro(const Token &MacroNameTok,
return;
SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
- addUsage(NamingCheckFailures, ID, Range);
+ addUsage(ID, Range);
}
static std::string