@@ -169,14 +169,14 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks {
169
169
return ;
170
170
if (SM.isWrittenInCommandLineFile (MacroNameTok.getLocation ()))
171
171
return ;
172
- Check->checkMacro (SM, MacroNameTok, Info);
172
+ Check->checkMacro (MacroNameTok, Info, SM );
173
173
}
174
174
175
175
// / MacroExpands calls expandMacro for macros in the main file
176
176
void MacroExpands (const Token &MacroNameTok, const MacroDefinition &MD,
177
177
SourceRange /* Range*/ ,
178
178
const MacroArgs * /* Args*/ ) override {
179
- Check->expandMacro (MacroNameTok, MD.getMacroInfo ());
179
+ Check->expandMacro (MacroNameTok, MD.getMacroInfo (), SM );
180
180
}
181
181
182
182
private:
@@ -187,7 +187,7 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks {
187
187
class RenamerClangTidyVisitor
188
188
: public RecursiveASTVisitor<RenamerClangTidyVisitor> {
189
189
public:
190
- RenamerClangTidyVisitor (RenamerClangTidyCheck *Check, const SourceManager * SM,
190
+ RenamerClangTidyVisitor (RenamerClangTidyCheck *Check, const SourceManager & SM,
191
191
bool AggressiveDependentMemberLookup)
192
192
: Check(Check), SM(SM),
193
193
AggressiveDependentMemberLookup (AggressiveDependentMemberLookup) {}
@@ -258,7 +258,7 @@ class RenamerClangTidyVisitor
258
258
// Fix overridden methods
259
259
if (const auto *Method = dyn_cast<CXXMethodDecl>(Decl)) {
260
260
if (const CXXMethodDecl *Overridden = getOverrideMethod (Method)) {
261
- Check->addUsage (Overridden, Method->getLocation ());
261
+ Check->addUsage (Overridden, Method->getLocation (), SM );
262
262
return true ; // Don't try to add the actual decl as a Failure.
263
263
}
264
264
}
@@ -268,7 +268,7 @@ class RenamerClangTidyVisitor
268
268
if (isa<ClassTemplateSpecializationDecl>(Decl))
269
269
return true ;
270
270
271
- Check->checkNamedDecl (Decl, * SM);
271
+ Check->checkNamedDecl (Decl, SM);
272
272
return true ;
273
273
}
274
274
@@ -385,7 +385,7 @@ class RenamerClangTidyVisitor
385
385
386
386
private:
387
387
RenamerClangTidyCheck *Check;
388
- const SourceManager * SM;
388
+ const SourceManager & SM;
389
389
const bool AggressiveDependentMemberLookup;
390
390
};
391
391
@@ -415,7 +415,7 @@ void RenamerClangTidyCheck::registerPPCallbacks(
415
415
416
416
void RenamerClangTidyCheck::addUsage (
417
417
const RenamerClangTidyCheck::NamingCheckId &Decl, SourceRange Range,
418
- const SourceManager * SourceMgr) {
418
+ const SourceManager & SourceMgr) {
419
419
// Do nothing if the provided range is invalid.
420
420
if (Range.isInvalid ())
421
421
return ;
@@ -425,8 +425,7 @@ void RenamerClangTidyCheck::addUsage(
425
425
// spelling location to different source locations, and we only want to fix
426
426
// the token once, before it is expanded by the macro.
427
427
SourceLocation FixLocation = Range.getBegin ();
428
- if (SourceMgr)
429
- FixLocation = SourceMgr->getSpellingLoc (FixLocation);
428
+ FixLocation = SourceMgr.getSpellingLoc (FixLocation);
430
429
if (FixLocation.isInvalid ())
431
430
return ;
432
431
@@ -440,15 +439,15 @@ void RenamerClangTidyCheck::addUsage(
440
439
if (!Failure.shouldFix ())
441
440
return ;
442
441
443
- if (SourceMgr && SourceMgr-> isWrittenInScratchSpace (FixLocation))
442
+ if (SourceMgr. isWrittenInScratchSpace (FixLocation))
444
443
Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
445
444
446
- if (!utils::rangeCanBeFixed (Range, SourceMgr))
445
+ if (!utils::rangeCanBeFixed (Range, & SourceMgr))
447
446
Failure.FixStatus = RenamerClangTidyCheck::ShouldFixStatus::InsideMacro;
448
447
}
449
448
450
449
void RenamerClangTidyCheck::addUsage (const NamedDecl *Decl, SourceRange Range,
451
- const SourceManager * SourceMgr) {
450
+ const SourceManager & SourceMgr) {
452
451
// Don't keep track for non-identifier names.
453
452
auto *II = Decl->getIdentifier ();
454
453
if (!II)
@@ -489,18 +488,24 @@ void RenamerClangTidyCheck::checkNamedDecl(const NamedDecl *Decl,
489
488
}
490
489
491
490
Failure.Info = std::move (Info);
492
- addUsage (Decl, Range, & SourceMgr);
491
+ addUsage (Decl, Range, SourceMgr);
493
492
}
494
493
495
494
void RenamerClangTidyCheck::check (const MatchFinder::MatchResult &Result) {
496
- RenamerClangTidyVisitor Visitor (this , Result.SourceManager ,
495
+ if (!Result.SourceManager ) {
496
+ // In principle SourceManager is not null but going only by the definition
497
+ // of MatchResult it must be handled. Cannot rename anything without a
498
+ // SourceManager.
499
+ return ;
500
+ }
501
+ RenamerClangTidyVisitor Visitor (this , *Result.SourceManager ,
497
502
AggressiveDependentMemberLookup);
498
503
Visitor.TraverseAST (*Result.Context );
499
504
}
500
505
501
- void RenamerClangTidyCheck::checkMacro (const SourceManager &SourceMgr ,
502
- const Token &MacroNameTok ,
503
- const MacroInfo *MI ) {
506
+ void RenamerClangTidyCheck::checkMacro (const Token &MacroNameTok ,
507
+ const MacroInfo *MI ,
508
+ const SourceManager &SourceMgr ) {
504
509
std::optional<FailureInfo> MaybeFailure =
505
510
getMacroFailureInfo (MacroNameTok, SourceMgr);
506
511
if (!MaybeFailure)
@@ -515,11 +520,12 @@ void RenamerClangTidyCheck::checkMacro(const SourceManager &SourceMgr,
515
520
Failure.FixStatus = ShouldFixStatus::FixInvalidIdentifier;
516
521
517
522
Failure.Info = std::move (Info);
518
- addUsage (ID, Range);
523
+ addUsage (ID, Range, SourceMgr );
519
524
}
520
525
521
526
void RenamerClangTidyCheck::expandMacro (const Token &MacroNameTok,
522
- const MacroInfo *MI) {
527
+ const MacroInfo *MI,
528
+ const SourceManager &SourceMgr) {
523
529
StringRef Name = MacroNameTok.getIdentifierInfo ()->getName ();
524
530
NamingCheckId ID (MI->getDefinitionLoc (), Name);
525
531
@@ -528,7 +534,7 @@ void RenamerClangTidyCheck::expandMacro(const Token &MacroNameTok,
528
534
return ;
529
535
530
536
SourceRange Range (MacroNameTok.getLocation (), MacroNameTok.getEndLoc ());
531
- addUsage (ID, Range);
537
+ addUsage (ID, Range, SourceMgr );
532
538
}
533
539
534
540
static std::string
0 commit comments