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