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 TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc Loc) {
280 if (const NestedNameSpecifier Spec = Loc.getNestedNameSpecifier();
281 Spec.getKind() == NestedNameSpecifier::Kind::Namespace) {
282 if (const auto *Decl =
283 dyn_cast<NamespaceDecl>(Spec.getAsNamespaceAndPrefix().Namespace))
284 Check->addUsage(Decl, Loc.getLocalSourceRange(), SM);
285 }
286
287 using Base = RecursiveASTVisitor<RenamerClangTidyVisitor>;
288 return Base::TraverseNestedNameSpecifierLoc(Loc);
289 }
290
291 bool VisitMemberExpr(MemberExpr *MemberRef) {
292 const SourceRange Range = MemberRef->getMemberNameInfo().getSourceRange();
293 Check->addUsage(MemberRef->getMemberDecl(), Range, SM);
294 return true;
295 }
296
297 bool
298 VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *DepMemberRef) {
299 const QualType BaseType =
300 DepMemberRef->isArrow() ? DepMemberRef->getBaseType()->getPointeeType()
301 : DepMemberRef->getBaseType();
302 if (BaseType.isNull())
303 return true;
304 const CXXRecordDecl *Base = BaseType.getTypePtr()->getAsCXXRecordDecl();
305 if (!Base)
306 return true;
307 const DeclarationName DeclName =
308 DepMemberRef->getMemberNameInfo().getName();
309 if (!DeclName.isIdentifier())
310 return true;
311 const StringRef DependentName = DeclName.getAsIdentifierInfo()->getName();
312
314 if (const NameLookup Resolved = findDeclInBases(
315 *Base, DependentName, AggressiveDependentMemberLookup, Visited)) {
316 if (*Resolved)
317 Check->addUsage(*Resolved,
318 DepMemberRef->getMemberNameInfo().getSourceRange(), SM);
319 }
320
321 return true;
322 }
323
324 bool VisitTypedefTypeLoc(const TypedefTypeLoc &Loc) {
325 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
326 return true;
327 }
328
329 bool VisitTagTypeLoc(const TagTypeLoc &Loc) {
330 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
331 return true;
332 }
333
334 bool VisitUnresolvedUsingTypeLoc(const UnresolvedUsingTypeLoc &Loc) {
335 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
336 return true;
337 }
338
339 bool VisitTemplateTypeParmTypeLoc(const TemplateTypeParmTypeLoc &Loc) {
340 Check->addUsage(Loc.getDecl(), Loc.getNameLoc(), SM);
341 return true;
342 }
343
344 bool
345 VisitTemplateSpecializationTypeLoc(const TemplateSpecializationTypeLoc &Loc) {
346 const TemplateDecl *Decl =
347 Loc.getTypePtr()->getTemplateName().getAsTemplateDecl(
348 /*IgnoreDeduced=*/true);
349 if (!Decl)
350 return true;
351
352 if (const NamedDecl *TemplDecl = Decl->getTemplatedDecl())
353 Check->addUsage(TemplDecl, Loc.getTemplateNameLoc(), SM);
354
355 return true;
356 }
357
358 bool VisitDesignatedInitExpr(DesignatedInitExpr *Expr) {
359 for (const DesignatedInitExpr::Designator &D : Expr->designators()) {
360 if (!D.isFieldDesignator())
361 continue;
362 const FieldDecl *FD = D.getFieldDecl();
363 if (!FD)
364 continue;
365 const IdentifierInfo *II = FD->getIdentifier();
366 if (!II)
367 continue;
368 const SourceRange FixLocation{D.getFieldLoc(), D.getFieldLoc()};
369 Check->addUsage(FD, FixLocation, SM);
370 }
371
372 return true;
373 }
374
375private:
376 RenamerClangTidyCheck *Check;
377 const SourceManager &SM;
378 const bool AggressiveDependentMemberLookup;
379};
380
381} // namespace
382
384 ClangTidyContext *Context)
385 : ClangTidyCheck(CheckName, Context),
386 AggressiveDependentMemberLookup(
387 Options.get("AggressiveDependentMemberLookup", false)) {}
389
391 Options.store(Opts, "AggressiveDependentMemberLookup",
392 AggressiveDependentMemberLookup);
393}
394
396 Finder->addMatcher(translationUnitDecl(), this);
397}
398
400 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
401 ModuleExpanderPP->addPPCallbacks(
402 std::make_unique<RenamerClangTidyCheckPPCallbacks>(SM, this));
403}
404
405std::pair<RenamerClangTidyCheck::NamingCheckFailureMap::iterator, bool>
408 SourceRange UsageRange, const SourceManager &SourceMgr) {
409 // Do nothing if the provided range is invalid.
410 if (UsageRange.isInvalid())
411 return {NamingCheckFailures.end(), false};
412
413 // Get the spelling location for performing the fix. This is necessary because
414 // macros can map the same spelling location to different source locations,
415 // and we only want to fix the token once, before it is expanded by the macro.
416 SourceLocation FixLocation = UsageRange.getBegin();
417 FixLocation = SourceMgr.getSpellingLoc(FixLocation);
418 if (FixLocation.isInvalid())
419 return {NamingCheckFailures.end(), false};
420
421 // Skip if in system system header
422 if (SourceMgr.isInSystemHeader(FixLocation))
423 return {NamingCheckFailures.end(), false};
424
425 auto EmplaceResult = NamingCheckFailures.try_emplace(FailureId);
426 NamingCheckFailure &Failure = EmplaceResult.first->second;
427
428 // Try to insert the identifier location in the Usages map, and bail out if it
429 // is already in there
430 if (!Failure.RawUsageLocs.insert(FixLocation).second)
431 return EmplaceResult;
432
434 return EmplaceResult;
435
436 if (SourceMgr.isWrittenInScratchSpace(FixLocation))
438
439 if (!utils::rangeCanBeFixed(UsageRange, &SourceMgr))
441
442 return EmplaceResult;
443}
444
445void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl,
446 SourceRange UsageRange,
447 const SourceManager &SourceMgr) {
448 if (SourceMgr.isInSystemHeader(Decl->getLocation()))
449 return;
450
451 if (hasNoName(Decl))
452 return;
453
454 // Ignore ClassTemplateSpecializationDecl which are creating duplicate
455 // replacements with CXXRecordDecl.
456 if (isa<ClassTemplateSpecializationDecl>(Decl))
457 return;
458
459 // We don't want to create a failure for every NamedDecl we find. Ideally
460 // there is just one NamedDecl in every group of "related" NamedDecls that
461 // becomes the failure. This NamedDecl and all of its related NamedDecls
462 // become usages. E.g. Since NamedDecls are Redeclarable, only the canonical
463 // NamedDecl becomes the failure and all redeclarations become usages.
464 const NamedDecl *FailureDecl = getFailureForNamedDecl(Decl);
465
466 std::optional<FailureInfo> MaybeFailure =
467 getDeclFailureInfo(FailureDecl, SourceMgr);
468 if (!MaybeFailure)
469 return;
470
471 const NamingCheckId FailureId(FailureDecl->getLocation(),
472 FailureDecl->getName());
473
474 auto [FailureIter, NewFailure] = addUsage(FailureId, UsageRange, SourceMgr);
475
476 if (FailureIter == NamingCheckFailures.end()) {
477 // Nothing to do if the usage wasn't accepted.
478 return;
479 }
480 if (!NewFailure) {
481 // FailureInfo has already been provided.
482 return;
483 }
484
485 // Update the stored failure with info regarding the FailureDecl.
486 NamingCheckFailure &Failure = FailureIter->second;
487 Failure.Info = std::move(*MaybeFailure);
488
489 // Don't overwrite the failure status if it was already set.
490 if (!Failure.shouldFix())
491 return;
492 const IdentifierTable &Idents = FailureDecl->getASTContext().Idents;
493 const auto CheckNewIdentifier = Idents.find(Failure.Info.Fixup);
494 if (CheckNewIdentifier != Idents.end()) {
495 const IdentifierInfo *Ident = CheckNewIdentifier->second;
496 if (Ident->isKeyword(getLangOpts()))
497 Failure.FixStatus = ShouldFixStatus::ConflictsWithKeyword;
498 else if (Ident->hasMacroDefinition())
500 } else if (!isValidAsciiIdentifier(Failure.Info.Fixup)) {
501 Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
502 }
503}
504
505void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
506 if (!Result.SourceManager) {
507 // In principle SourceManager is not null but going only by the definition
508 // of MatchResult it must be handled. Cannot rename anything without a
509 // SourceManager.
510 return;
511 }
512 RenamerClangTidyVisitor Visitor(this, *Result.SourceManager,
513 AggressiveDependentMemberLookup);
514 Visitor.TraverseAST(*Result.Context);
515}
516
517void RenamerClangTidyCheck::checkMacro(const Token &MacroNameTok,
518 const MacroInfo *MI,
519 const SourceManager &SourceMgr) {
520 std::optional<FailureInfo> MaybeFailure =
521 getMacroFailureInfo(MacroNameTok, SourceMgr);
522 if (!MaybeFailure)
523 return;
524 FailureInfo &Info = *MaybeFailure;
525 const StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
526 const NamingCheckId ID(MI->getDefinitionLoc(), Name);
527 NamingCheckFailure &Failure = NamingCheckFailures[ID];
528 const SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
529
530 if (!isValidAsciiIdentifier(Info.Fixup))
531 Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
532
533 Failure.Info = std::move(Info);
534 addUsage(ID, Range, SourceMgr);
535}
536
537void RenamerClangTidyCheck::expandMacro(const Token &MacroNameTok,
538 const MacroInfo *MI,
539 const SourceManager &SourceMgr) {
540 const StringRef Name = MacroNameTok.getIdentifierInfo()->getName();
541 const NamingCheckId ID(MI->getDefinitionLoc(), Name);
542
543 const auto Failure = NamingCheckFailures.find(ID);
544 if (Failure == NamingCheckFailures.end())
545 return;
546
547 const SourceRange Range(MacroNameTok.getLocation(), MacroNameTok.getEndLoc());
548 addUsage(ID, Range, SourceMgr);
549}
550
551static std::string
553 const std::string &Fixup) {
554 if (Fixup.empty() ||
556 return "; cannot be fixed automatically";
558 return {};
559 if (FixStatus >=
561 return {};
563 return "; cannot be fixed because '" + Fixup +
564 "' would conflict with a keyword";
565 if (FixStatus ==
567 return "; cannot be fixed because '" + Fixup +
568 "' would conflict with a macro definition";
569 llvm_unreachable("invalid ShouldFixStatus");
570}
571
573 for (const auto &[Decl, Failure] : NamingCheckFailures) {
574 if (Failure.Info.KindName.empty())
575 continue;
576
577 if (Failure.shouldNotify()) {
578 auto DiagInfo = getDiagInfo(Decl, Failure);
579 auto Diag = diag(Decl.first,
580 DiagInfo.Text + getDiagnosticSuffix(Failure.FixStatus,
581 Failure.Info.Fixup));
582 DiagInfo.ApplyArgs(Diag);
583
584 if (Failure.shouldFix()) {
585 for (const auto &Loc : Failure.RawUsageLocs) {
586 // We assume that the identifier name is made of one token only. This
587 // is always the case as we ignore usages in macros that could build
588 // identifier names by combining multiple tokens.
589 //
590 // For destructors, we already take care of it by remembering the
591 // location of the start of the identifier and not the start of the
592 // tilde.
593 //
594 // Other multi-token identifiers, such as operators are not checked at
595 // all.
596 Diag << FixItHint::CreateReplacement(SourceRange(Loc),
597 Failure.Info.Fixup);
598 }
599 }
600 }
601 }
602}
603
604} // 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)