Skip to content

Commit ded9e5e

Browse files
committed
create SM local var
1 parent d722beb commit ded9e5e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../utils/LexerUtils.h"
1111
#include "clang/AST/DeclGroup.h"
1212
#include "clang/Basic/SourceLocation.h"
13+
#include "clang/Basic/SourceManager.h"
1314
#include "clang/Basic/TokenKinds.h"
1415
#include "clang/Lex/Lexer.h"
1516
#include <string>
@@ -86,6 +87,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
8687
if (!ParentDecl)
8788
return;
8889

90+
const SourceManager &SM = *Result.SourceManager;
91+
8992
// Match CXXRecordDecl only to store the range of the last non-implicit full
9093
// declaration, to later check whether it's within the typdef itself.
9194
const auto *MatchedTagDecl = Result.Nodes.getNodeAs<TagDecl>(TagDeclName);
@@ -124,8 +127,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
124127

125128
const TypeLoc TL = MatchedDecl->getTypeSourceInfo()->getTypeLoc();
126129

127-
auto [Type, QualifierStr] = [MatchedDecl, &Result, this,
128-
&TL]() -> std::pair<std::string, std::string> {
130+
auto [Type, QualifierStr] = [MatchedDecl, this, &TL,
131+
&SM]() -> std::pair<std::string, std::string> {
129132
SourceRange TypeRange = TL.getSourceRange();
130133

131134
// Function pointer case, get the left and right side of the identifier
@@ -134,15 +137,12 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
134137
const auto RangeLeftOfIdentifier = CharSourceRange::getCharRange(
135138
TypeRange.getBegin(), MatchedDecl->getLocation());
136139
const auto RangeRightOfIdentifier = CharSourceRange::getCharRange(
137-
Lexer::getLocForEndOfToken(MatchedDecl->getLocation(), 0,
138-
*Result.SourceManager, getLangOpts()),
139-
Lexer::getLocForEndOfToken(TypeRange.getEnd(), 0,
140-
*Result.SourceManager, getLangOpts()));
140+
Lexer::getLocForEndOfToken(MatchedDecl->getLocation(), 0, SM,
141+
getLangOpts()),
142+
Lexer::getLocForEndOfToken(TypeRange.getEnd(), 0, SM, getLangOpts()));
141143
const std::string VerbatimType =
142-
(Lexer::getSourceText(RangeLeftOfIdentifier, *Result.SourceManager,
143-
getLangOpts()) +
144-
Lexer::getSourceText(RangeRightOfIdentifier, *Result.SourceManager,
145-
getLangOpts()))
144+
(Lexer::getSourceText(RangeLeftOfIdentifier, SM, getLangOpts()) +
145+
Lexer::getSourceText(RangeRightOfIdentifier, SM, getLangOpts()))
146146
.str();
147147
return {VerbatimType, ""};
148148
}
@@ -153,21 +153,21 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
153153
// pointer type seperately, so we need to sigure out if the new using-decl
154154
// needs to be to a reference or pointer as well.
155155
const SourceLocation Tok = utils::lexer::findPreviousAnyTokenKind(
156-
MatchedDecl->getLocation(), *Result.SourceManager, getLangOpts(),
157-
tok::TokenKind::star, tok::TokenKind::amp, tok::TokenKind::comma,
156+
MatchedDecl->getLocation(), SM, getLangOpts(), tok::TokenKind::star,
157+
tok::TokenKind::amp, tok::TokenKind::comma,
158158
tok::TokenKind::kw_typedef);
159159

160160
ExtraReference = Lexer::getSourceText(
161-
CharSourceRange::getCharRange(Tok, Tok.getLocWithOffset(1)),
162-
*Result.SourceManager, getLangOpts());
161+
CharSourceRange::getCharRange(Tok, Tok.getLocWithOffset(1)), SM,
162+
getLangOpts());
163163

164164
if (ExtraReference != "*" && ExtraReference != "&")
165165
ExtraReference = "";
166166

167167
TypeRange.setEnd(MainTypeEndLoc);
168168
}
169-
return {Lexer::getSourceText(CharSourceRange::getTokenRange(TypeRange),
170-
*Result.SourceManager, getLangOpts())
169+
return {Lexer::getSourceText(CharSourceRange::getTokenRange(TypeRange), SM,
170+
getLangOpts())
171171
.str(),
172172
ExtraReference.str()};
173173
}();
@@ -217,8 +217,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
217217
LastTagDeclRange->second.isValid() &&
218218
ReplaceRange.fullyContains(LastTagDeclRange->second)) {
219219
Type = std::string(Lexer::getSourceText(
220-
CharSourceRange::getTokenRange(LastTagDeclRange->second),
221-
*Result.SourceManager, getLangOpts()));
220+
CharSourceRange::getTokenRange(LastTagDeclRange->second), SM,
221+
getLangOpts()));
222222
if (Type.empty())
223223
return;
224224
}

0 commit comments

Comments
 (0)