clang-tools 24.0.0git
RenamerClangTidyCheck.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "ASTUtils.h"
11#include "clang/AST/CXXInheritance.h"
12#include "clang/AST/RecursiveASTVisitor.h"
13#include "clang/ASTMatchers/ASTMatchFinder.h"
14#include "clang/Basic/CharInfo.h"
15#include "clang/Frontend/CompilerInstance.h"
16#include "clang/Lex/PPCallbacks.h"
17#include "clang/Lex/Preprocessor.h"
18#include "llvm/ADT/DenseMapInfo.h"
19#include "llvm/ADT/PointerIntPair.h"
20#include "llvm/ADT/ScopeExit.h"
21#include <optional>
22
23#define DEBUG_TYPE "clang-tidy"
24
25using namespace clang::ast_matchers;
26
27namespace llvm {
28
29/// Specialization of DenseMapInfo to allow NamingCheckId objects in DenseMaps
30template <>
33
34 static unsigned getHashValue(NamingCheckId Val) {
35 return DenseMapInfo<clang::SourceLocation>::getHashValue(Val.first) +
36 DenseMapInfo<StringRef>::getHashValue(Val.second);
37 }
38
39 static bool isEqual(const NamingCheckId &LHS, const NamingCheckId &RHS) {
40 return LHS == RHS;
41 }
42};
43
44} // namespace llvm
45
46namespace clang::tidy {
47
48namespace {
49
50class NameLookup {
51 llvm::PointerIntPair<const NamedDecl *, 1, bool> Data;
52
53public:
54 explicit NameLookup(const NamedDecl *ND) : Data(ND, false) {}
55 explicit NameLookup(std::nullopt_t) : Data(nullptr, true) {}
56 explicit NameLookup(std::nullptr_t) : Data(nullptr, false) {}
57 NameLookup() : NameLookup(nullptr) {}
58
59 bool hasMultipleResolutions() const { return Data.getInt(); }
60 const NamedDecl *getDecl() const {
61 assert(!hasMultipleResolutions() && "Found multiple decls");
62 return Data.getPointer();
63 }
64 operator bool() const { return !hasMultipleResolutions(); }
65 const NamedDecl *operator*() const { return getDecl(); }
66};
67
68} // namespace
69
70static const NamedDecl *findDecl(const RecordDecl &RecDecl,
71 StringRef DeclName) {
72 for (const Decl *D : RecDecl.decls())
73 if (const auto *ND = dyn_cast<NamedDecl>(D);
74 ND && ND->getDeclName().isIdentifier() && ND->getName() == DeclName)
75 return ND;
76 return nullptr;
77}
78
79/// Returns the function that \p Method is overriding. If There are none or
80/// multiple overrides it returns nullptr. If the overridden function itself is
81/// overriding then it will recurse up to find the first decl of the function.
82static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
83 if (Method->size_overridden_methods() != 1)
84 return nullptr;
85
86 while (true) {
87 Method = *Method->begin_overridden_methods();
88 assert(Method && "Overridden method shouldn't be null");
89 const unsigned NumOverrides = Method->size_overridden_methods();
90 if (NumOverrides == 0)
91 return Method;
92 if (NumOverrides > 1)
93 return nullptr;
94 }
95}
96
97static bool hasNoName(const NamedDecl *Decl) {
98 return !Decl->getIdentifier() || Decl->getName().empty();
99}
100
101static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) {
102 const auto *Canonical = cast<NamedDecl>(ND->getCanonicalDecl());
103 if (Canonical != ND)
104 return Canonical;
105
106 if (const auto *Method = dyn_cast<CXXMethodDecl>(ND)) {
107 if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
108 Canonical = Overridden->getCanonicalDecl();
109 else if (const FunctionTemplateDecl *Primary = Method->getPrimaryTemplate())
110 if (const FunctionDecl *TemplatedDecl = Primary->getTemplatedDecl())
111 Canonical = TemplatedDecl->getCanonicalDecl();
112
113 if (Canonical != ND)
114 return Canonical;
115 }
116
117 return ND;
118}
119
120using RecursionProtectionSet = llvm::SmallPtrSet<const CXXRecordDecl *, 4>;
121
122/// Returns a decl matching the \p DeclName in \p Parent or one of its base
123/// classes. If \p AggressiveTemplateLookup is `true` then it will check
124/// template dependent base classes as well.
125/// If a matching decl is found in multiple base classes then it will return a
126/// flag indicating the multiple resolutions.
127static NameLookup findDeclInBases(const CXXRecordDecl &Parent,
128 StringRef DeclName,
129 bool AggressiveTemplateLookup,
130 RecursionProtectionSet &Visited) {
131 if (!Parent.hasDefinition())
132 return NameLookup(nullptr);
133
134 const auto *Definition = Parent.getDefinition();
135 if (!Visited.insert(Definition).second)
136 return NameLookup(nullptr);
137 const auto RemoveFromVisited =
138 llvm::scope_exit([&Visited, Definition] { Visited.erase(Definition); });
139
140 if (const NamedDecl *InClassRef = findDecl(Parent, DeclName))
141 return NameLookup(InClassRef);
142 const NamedDecl *Found = nullptr;
143
144 for (const CXXBaseSpecifier Base : Parent.bases()) {
145 const auto *Record = Base.getType()->getAsCXXRecordDecl();
146 if (!Record && AggressiveTemplateLookup) {
147 if (const auto *TST =
148 Base.getType()->getAs<TemplateSpecializationType>()) {
149 if (const auto *TD = dyn_cast_or_null<ClassTemplateDecl>(
150 TST->getTemplateName().getAsTemplateDecl()))
151 Record = TD->getTemplatedDecl();
152 }
153 }
154 if (!Record)
155 continue;
156 if (const auto Search = findDeclInBases(
157 *Record, DeclName, AggressiveTemplateLookup, Visited)) {
158 if (*Search) {
159 if (Found)
160 return NameLookup(
161 std::nullopt); // Multiple decls found in different base classes.
162 Found = *Search;
163 continue;
164 }
165 } else {
166 return NameLookup(std::nullopt); // Propagate multiple resolution back up.
167 }
168 }
169 return NameLookup(Found); // If nullptr, decl wasn't found.
170}
171
172namespace {
173
174/// Callback supplies macros to RenamerClangTidyCheck::checkMacro
175class RenamerClangTidyCheckPPCallbacks : public PPCallbacks {
176public:
177 RenamerClangTidyCheckPPCallbacks(const SourceManager &SM,
178 RenamerClangTidyCheck *Check)
179 : SM(SM), Check(Check) {}
180
181 /// MacroDefined calls checkMacro for macros in the main file
182 void MacroDefined(const Token &MacroNameTok,
183 const MacroDirective *MD) override {
184 const MacroInfo *Info = MD->getMacroInfo();
185 if (Info->isBuiltinMacro())
186 return;
187 if (SM.isWrittenInBuiltinFile(MacroNameTok.getLocation()))
188 return;
189 if (SM.isWrittenInCommandLineFile(MacroNameTok.getLocation()))
190 return;
191 if (SM.isInSystemHeader(MacroNameTok.getLocation()))
192 return;
193 Check->checkMacro(MacroNameTok, Info, SM);
194 }
195
196 /// MacroExpands calls expandMacro for macros in the main file
197 void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
198 SourceRange /*Range*/,
199 const MacroArgs * /*Args*/) override {
200 Check->expandMacro(MacroNameTok, MD.getMacroInfo(), SM);
201 }
202
203private:
204 const SourceManager &SM;
205 RenamerClangTidyCheck *Check;
206};
207
208class RenamerClangTidyVisitor
209 : public RecursiveASTVisitor<RenamerClangTidyVisitor> {
210public:
211 RenamerClangTidyVisitor(RenamerClangTidyCheck *Check, const SourceManager &SM,
212 bool AggressiveDependentMemberLookup)
213 : Check(Check), SM(SM),
214 AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
215
216 bool shouldVisitTemplateInstantiations() const { return true; }
217
218 bool shouldVisitImplicitCode() const { return false; }
219
220 bool VisitCXXConstructorDecl(CXXConstructorDecl *Decl) {
221 if (Decl->isImplicit())
222 return true;
223 Check->addUsage(Decl->getParent(), Decl->getNameInfo().getSourceRange(),
224 SM);
225
226 for (const auto *Init : Decl->inits()) {
227 if (!Init->isWritten() || Init->isInClassMemberInitializer())
228 continue;
229 if (const FieldDecl *FD = Init->getAnyMember())
230 Check->addUsage(FD, SourceRange(Init->getMemberLocation()), SM);
231 // Note: delegating constructors and base class initializers are handled
232 // via the "typeLoc" matcher.
233 }
234
235 return true;
236 }
237
238 bool VisitCXXDestructorDecl(CXXDestructorDecl *Decl) {
239 if (Decl->isImplicit())
240 return true;
241 SourceRange Range = Decl->getNameInfo().getSourceRange();
242 if (Range.getBegin().isInvalid())
243 return true;
244
245 // The first token that will be found is the ~ (or the equivalent trigraph),
246 // we want instead to replace the next token, that will be the identifier.
247 Range.setBegin(CharSourceRange::getTokenRange(Range).getEnd());
248 Check->addUsage(Decl->getParent(), Range, SM);
249 return true;
250 }
251
252 bool VisitUsingDecl(UsingDecl *Decl) {
253 for (const auto *Shadow : Decl->shadows())
254 Check->addUsage(Shadow->getTargetDecl(),
255 Decl->getNameInfo().getSourceRange(), SM);
256 return true;
257 }
258
259 bool VisitUsingDirectiveDecl(UsingDirectiveDecl *Decl) {
260 Check->addUsage(Decl->getNominatedNamespaceAsWritten(),
261 Decl->getIdentLocation(), SM);
262 return true;
263 }
264
265 bool VisitNamedDecl(NamedDecl *Decl) {
266 const SourceRange UsageRange =
267 DeclarationNameInfo(Decl->getDeclName(), Decl->getLocation())
268 .getSourceRange();
269 Check->addUsage(Decl, UsageRange, SM);
270 return true;
271 }
272
273 bool VisitDeclRefExpr(DeclRefExpr *DeclRef) {
274 const SourceRange Range = DeclRef->getNameInfo().getSourceRange();
275 Check->addUsage(DeclRef->getDecl(), Range, SM);
276 return true;
277 }
278
279 bool VisitSizeOfPackExpr(SizeOfPackExpr *SizeOfPack) {
280 Check->addUsage(SizeOfPack->getPack(), SizeOfPack->getPackLoc(), SM);
281 return true;
282 }
283
284 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Loc) {
285 if (const NestedNameSpecifier Spec = Loc.getNestedNameSpecifier();
286 Spec.getKind() == NestedNameSpecifier::Kind::Namespace) {
287 if (const auto *Decl =
288 dyn_cast<NamespaceDecl>(Spec.getAsNamespaceAndPrefix().Namespace))
289 Check->addUsage(Decl, Loc.getLocalSourceRange(), SM);
290 }
291
292 using Base = RecursiveASTVisitor<RenamerClangTidyVisitor>;
293 return Base::TraverseNestedNameSpecifierLoc(Loc);
294 }
295
296 bool VisitMemberExpr(MemberExpr *MemberRef) {
297 const SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange();
298 Check->addUsage(MemberRef->getMemberDecl(), Range, SM);
299 return true;
300 }
301
302 bool
303 VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *DepMemberRef) {
304 const QualType BaseType =
305 DepMemberRef->isArrow() ? DepMemberRef->getBaseType()->getPointeeType()
306 : DepMemberRef->getBaseType();
307 if (BaseType.isNull())
308 return true;
309 const CXXRecordDecl *Base = BaseType.getTypePtr()->getAsCXXRecordDecl();
310 if (!Base)
311 return true;
312 const DeclarationName DeclName =
313 DepMemberRef->getMemberNameInfo().getName();
314 if (!DeclName.isIdentifier())
315 return true;
316 const StringRef DependentName = DeclName.getAsIdentifierInfo()->getName();
317
319 if (const NameLookup Resolved = findDeclInBases(
320 *Base, DependentName, AggressiveDependentMemberLookup, Visited)) {
321 if (*Resolved)
322 Check->addUsage(*Resolved,
323 DepMemberRef->getMemberNameInfo().getSourceRange(), SM);
324 }
325
326 return true;
327 }
328
329 bool VisitTypedefTypeLoc(const TypedefTypeLoc &Loc) {
330 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
331 return true;
332 }
333
334 bool VisitTagTypeLoc(const TagTypeLoc &Loc) {
335 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
336 return true;
337 }
338
339 bool VisitUnresolvedUsingTypeLoc(const UnresolvedUsingTypeLoc &Loc) {
340 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
341 return true;
342 }
343
344 bool VisitTemplateTypeParmTypeLoc(const TemplateTypeParmTypeLoc &Loc) {
345 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
346 return true;
347 }
348
349 bool
350 VisitTemplateSpecializationTypeLoc(const TemplateSpecializationTypeLoc &Loc) {
351 const TemplateDecl *Decl =
352 Loc.getTypePtr()->getTemplateName().getAsTemplateDecl(
353 /*IgnoreDeduced=*/true);
354 if (!Decl)
355 return true;
356
357 if (const NamedDecl *TemplDecl = Decl->getTemplatedDecl())
358 Check->addUsage(TemplDecl, Loc.getTemplateNameLoc(), SM);
359
360 return true;
361 }
362
363 bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) {
364 for (const DesignatedInitExpr::Designator &D : Expr->designators()) {
365 if (!D.isFieldDesignator())
366 continue;
367 const FieldDecl *FD = D.getFieldDecl();
368 if (!FD)
369 continue;
370 const IdentifierInfo *II = FD->getIdentifier();
371 if (!II)
372 continue;
373 const SourceRange FixLocation{D.getFieldLoc(), D.getFieldLoc()};
374 Check->addUsage(FD, FixLocation, SM);
375 }
376
377 return true;
378 }
379
380private:
381 RenamerClangTidyCheck *Check;
382 const SourceManager &SM;
383 const bool AggressiveDependentMemberLookup;
384};
385
386} // namespace
387
389 ClangTidyContext *Context)
390 : ClangTidyCheck(CheckName, Context),
391 AggressiveDependentMemberLookup(
392 Options.get("AggressiveDependentMemberLookup", false)) {}
394
396 Options.store(Opts, "AggressiveDependentMemberLookup",
397 AggressiveDependentMemberLookup);
398}
399
401 Finder->addMatcher(translationUnitDecl(), this);
402}
403
405 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
406 ModuleExpanderPP->addPPCallbacks(
407 std::make_unique<RenamerClangTidyCheckPPCallbacks>(SM, this));
408}
409
410std::pair<RenamerClangTidyCheck::NamingCheckFailureMap::iterator, bool>
413 SourceRange UsageRange, const SourceManager &SourceMgr) {
414 // Do nothing if the provided range is invalid.
415 if (UsageRange.isInvalid())
416 return {NamingCheckFailures.end(), false};
417
418 // Get the spelling location for performing the fix. This is necessary because
419 // macros can map the same spelling location to different source locations,
420 // and we only want to fix the token once, before it is expanded by the macro.
421 SourceLocation FixLocation = UsageRange.getBegin();
422 FixLocation = SourceMgr.getSpellingLoc(FixLocation);
423 if (FixLocation.isInvalid())
424 return {NamingCheckFailures.end(), false};
425
426 // Skip if in system system header
427 if (SourceMgr.isInSystemHeader(FixLocation))
428 return {NamingCheckFailures.end(), false};
429
430 auto EmplaceResult = NamingCheckFailures.try_emplace(FailureId);
431 NamingCheckFailure &Failure = EmplaceResult.first->second;
432
433 // Try to insert the identifier location in the Usages map, and bail out if it
434 // is already in there
435 if (!Failure.RawUsageLocs.insert(FixLocation).second)
436 return EmplaceResult;
437
439 return EmplaceResult;
440
441 if (SourceMgr.isWrittenInScratchSpace(FixLocation))
443
444 if (!utils::rangeCanBeFixed(UsageRange, &SourceMgr))
446
447 return EmplaceResult;
448}
449
450void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl,
451 SourceRange UsageRange,
452 const SourceManager &SourceMgr) {
453 if (SourceMgr.isInSystemHeader(Decl->getLocation()))
454 return;
455
456 if (hasNoName(Decl))
457 return;
458
459 // Ignore ClassTemplateSpecializationDecl which are creating duplicate
460 // replacements with CXXRecordDecl.
461 if (isa<ClassTemplateSpecializationDecl>(Decl))
462 return;
463
464 // We don't want to create a failure for every NamedDecl we find. Ideally
465 // there is just one NamedDecl in every group of "related" NamedDecls that
466 // becomes the failure. This NamedDecl and all of its related NamedDecls
467 // become usages. E.g. Since NamedDecls are Redeclarable, only the canonical
468 // NamedDecl becomes the failure and all redeclarations become usages.
469 const NamedDecl *FailureDecl = getFailureForNamedDecl(Decl);
470
471 std::optional<FailureInfo> MaybeFailure =
472 getDeclFailureInfo(FailureDecl, SourceMgr);
473 if (!MaybeFailure)
474 return;
475
476 const NamingCheckId FailureId(FailureDecl->getLocation(),
477 FailureDecl->getName());
478
479 auto [FailureIter, NewFailure] = addUsage(FailureId, UsageRange, SourceMgr);
480
481 if (FailureIter == NamingCheckFailures.end()) {
482 // Nothing to do if the usage wasn't accepted.
483 return;
484 }
485 if (!NewFailure) {
486 // FailureInfo has already been provided.
487 return;
488 }
489
490 // Update the stored failure with info regarding the FailureDecl.
491 NamingCheckFailure &Failure = FailureIter->second;
492 Failure.Info = std::move(*MaybeFailure);
493
494 // Don't overwrite the failure status if it was already set.
495 if (!Failure.shouldFix())
496 return;
497 const IdentifierTable &Idents = FailureDecl->getASTContext().Idents;
498 const auto CheckNewIdentifier = Idents.find(Failure.Info.Fixup);
499 if (CheckNewIdentifier != Idents.end()) {
500 const IdentifierInfo *Ident = CheckNewIdentifier->second;
501 if (Ident->isKeyword(getLangOpts()))
502 Failure.FixStatus = ShouldFixStatus::ConflictsWithKeyword;
503 else if (Ident->hasMacroDefinition())
505 } else if (!isValidAsciiIdentifier(Failure.Info.Fixup)) {
506 Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
507 }
508}
509
510void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
511 if (!Result.SourceManager) {
512 // In principle SourceManager is not null but going only by the definition
513 // of MatchResult it must be handled. Cannot rename anything without a
514 // SourceManager.
515 return;
516 }
517 RenamerClangTidyVisitor Visitor(this, *Result.SourceManager,
518 AggressiveDependentMemberLookup);
519 Visitor.TraverseAST(*Result.Context);
520}
521
522void RenamerClangTidyCheck::checkMacro(const Token &MacroNameTok,
523 const MacroInfo *MI,
524 const SourceManager &SourceMgr) {
525 std::optional<FailureInfo> MaybeFailure =
526 getMacroFailureInfo(MacroNameTok, SourceMgr);
527 if (!MaybeFailure)
528 return;
529 FailureInfo &Info = *MaybeFailure;
530 const StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
531 const NamingCheckId ID(MI->getDefinitionLoc(), Name);
532 NamingCheckFailure &Failure = NamingCheckFailures[ID];
533 const SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
534
535 if (!isValidAsciiIdentifier(Info.Fixup))
536 Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
537
538 Failure.Info = std::move(Info);
539 addUsage(ID, Range, SourceMgr);
540}
541
542void RenamerClangTidyCheck::expandMacro(const Token &MacroNameTok,
543 const MacroInfo *MI,
544 const SourceManager &SourceMgr) {
545 const StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
546 const NamingCheckId ID(MI->getDefinitionLoc(), Name);
547
548 const auto Failure = NamingCheckFailures.find(ID);
549 if (Failure == NamingCheckFailures.end())
550 return;
551
552 const SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
553 addUsage(ID, Range, SourceMgr);
554}
555
556static std::string
558 const std::string &Fixup) {
559 if (Fixup.empty() ||
561 return "; cannot be fixed automatically";
563 return {};
564 if (FixStatus >=
566 return {};
568 return "; cannot be fixed because '" + Fixup +
569 "' would conflict with a keyword";
570 if (FixStatus ==
572 return "; cannot be fixed because '" + Fixup +
573 "' would conflict with a macro definition";
574 llvm_unreachable("invalid ShouldFixStatus");
575}
576
578 for (const auto &[Decl, Failure] : NamingCheckFailures) {
579 if (Failure.Info.KindName.empty())
580 continue;
581
582 if (Failure.shouldNotify()) {
583 auto DiagInfo = getDiagInfo(Decl, Failure);
584 auto Diag = diag(Decl.first,
585 DiagInfo.Text + getDiagnosticSuffix(Failure.FixStatus,
586 Failure.Info.Fixup));
587 DiagInfo.ApplyArgs(Diag);
588
589 if (Failure.shouldFix()) {
590 for (const auto &Loc : Failure.RawUsageLocs) {
591 // We assume that the identifier name is made of one token only. This
592 // is always the case as we ignore usages in macros that could build
593 // identifier names by combining multiple tokens.
594 //
595 // For destructors, we already take care of it by remembering the
596 // location of the start of the identifier and not the start of the
597 // tilde.
598 //
599 // Other multi-token identifiers, such as operators are not checked at
600 // all.
601 Diag << FixItHint::CreateReplacement(SourceRange(Loc),
602 Failure.Info.Fixup);
603 }
604 }
605 }
606 }
607}
608
609} // namespace clang::tidy
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for Markdown output.")
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) final
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) final
std::pair< SourceLocation, StringRef > NamingCheckId
virtual DiagInfo getDiagInfo(const NamingCheckId &ID, const NamingCheckFailure &Failure) const =0
Overridden by derived classes, returns a description of the diagnostic that should be emitted for the...
void expandMacro(const Token &MacroNameTok, const MacroInfo *MI, const SourceManager &SourceMgr)
Add a usage of a macro if it already has a violation.
void registerMatchers(ast_matchers::MatchFinder *Finder) final
Derived classes should not implement any matching logic themselves; this class will do the matching a...
RenamerClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
ShouldFixStatus
This enum will be used in select of the diagnostic message.
@ IgnoreFailureThreshold
Values pass this threshold will be ignored completely i.e no message, no fixup.
@ ConflictsWithMacroDefinition
The fixup will conflict with a macro definition, so we can't fix it automatically.
@ ConflictsWithKeyword
The fixup will conflict with a language keyword, so we can't fix it automatically.
@ InsideMacro
If the identifier was used or declared within a macro we won't offer a fixup for safety reasons.
@ FixInvalidIdentifier
The fixup results in an identifier that is not a valid c/c++ identifier.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Derived classes that override this function should call this method from the overridden method.
virtual std::optional< FailureInfo > getMacroFailureInfo(const Token &MacroNameTok, const SourceManager &SM) const =0
Overridden by derived classes, returns information about if and how a macro failed the check.
void addUsage(const NamedDecl *Decl, SourceRange Range, const SourceManager &SourceMgr)
virtual std::optional< FailureInfo > getDeclFailureInfo(const NamedDecl *Decl, const SourceManager &SM) const =0
Overridden by derived classes, returns information about if and how a Decl failed the check.
void checkMacro(const Token &MacroNameTok, const MacroInfo *MI, const SourceManager &SourceMgr)
Check Macros for style violations.
bool rangeCanBeFixed(SourceRange Range, const SourceManager *SM)
Definition ASTUtils.cpp:84
static std::string getDiagnosticSuffix(const RenamerClangTidyCheck::ShouldFixStatus FixStatus, const std::string &Fixup)
llvm::SmallPtrSet< const CXXRecordDecl *, 4 > RecursionProtectionSet
static const CXXMethodDecl * getOverrideMethod(const CXXMethodDecl *Method)
Returns the function that Method is overriding.
static NameLookup findDeclInBases(const CXXRecordDecl &Parent, StringRef DeclName, bool AggressiveTemplateLookup, RecursionProtectionSet &Visited)
Returns a decl matching the DeclName in Parent or one of its base classes.
static const NamedDecl * getFailureForNamedDecl(const NamedDecl *ND)
static const NamedDecl * findDecl(const RecordDecl &RecDecl, StringRef DeclName)
static bool hasNoName(const NamedDecl *Decl)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
Definition Generators.h:150
llvm::StringMap< ClangTidyValue > OptionMap
Represents customized diagnostic text and how arguments should be applied.
llvm::unique_function< void(DiagnosticBuilder &)> ApplyArgs
Information describing a failed check.
Holds an identifier name check failure, tracking the kind of the identifier, its possible fixup and t...
static bool isEqual(const NamingCheckId &LHS, const NamingCheckId &RHS)