Skip to content

Commit 7ac2a3e

Browse files
committed
[NFC] Avoid some duplications
1 parent 73231c8 commit 7ac2a3e

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ UseStructuredBindingCheck::UseStructuredBindingCheck(StringRef Name,
202202
;
203203
}
204204

205-
static auto getVarInitWithMemberMatcher(StringRef PairName,
206-
StringRef MemberName,
207-
StringRef TypeName,
208-
StringRef BindingName) {
205+
static auto getVarInitWithMemberMatcher(
206+
StringRef PairName, StringRef MemberName, StringRef TypeName,
207+
StringRef BindingName,
208+
ast_matchers::internal::Matcher<VarDecl> ExtraMatcher) {
209209
return varDecl(
210-
unless(hasAnySpecifiersShouldBeIgnored()), unless(isInMarco()),
210+
ExtraMatcher,
211211
hasInitializer(
212212
ignoringImpCasts(ignoringCopyCtorAndImplicitCast(memberExpr(
213213
hasObjectExpression(ignoringImpCasts(declRefExpr(
@@ -223,10 +223,20 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
223223
hasUnqualifiedDesugaredType(recordType(
224224
hasDeclaration(cxxRecordDecl(hasAnyName(PairTypes))))));
225225

226-
auto VarInitWithFirstMember = getVarInitWithMemberMatcher(
227-
PairDeclName, "first", FirstTypeName, FirstVarDeclName);
228-
auto VarInitWithSecondMember = getVarInitWithMemberMatcher(
229-
PairDeclName, "second", SecondTypeName, SecondVarDeclName);
226+
auto UnlessShouldBeIgnored =
227+
unless(anyOf(hasAnySpecifiersShouldBeIgnored(), isInMarco()));
228+
229+
auto VarInitWithFirstMember =
230+
getVarInitWithMemberMatcher(PairDeclName, "first", FirstTypeName,
231+
FirstVarDeclName, UnlessShouldBeIgnored);
232+
auto VarInitWithSecondMember =
233+
getVarInitWithMemberMatcher(PairDeclName, "second", SecondTypeName,
234+
SecondVarDeclName, UnlessShouldBeIgnored);
235+
236+
auto RefToBindName = [&UnlessShouldBeIgnored](const llvm::StringLiteral &Name)
237+
-> ast_matchers::internal::BindableMatcher<Stmt> {
238+
return declRefExpr(to(varDecl(UnlessShouldBeIgnored).bind(Name)));
239+
};
230240

231241
// X x;
232242
// Y y;
@@ -237,23 +247,10 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
237247
has(cxxOperatorCallExpr(
238248
hasOverloadedOperatorName("="),
239249
hasLHS(ignoringImplicit(
240-
callExpr(
241-
callee(
242-
functionDecl(isInStdNamespace(), hasName("tie"))),
243-
hasArgument(
244-
0,
245-
declRefExpr(to(
246-
varDecl(
247-
unless(hasAnySpecifiersShouldBeIgnored()),
248-
unless(isInMarco()))
249-
.bind(FirstVarDeclName)))),
250-
hasArgument(
251-
1,
252-
declRefExpr(to(
253-
varDecl(
254-
unless(hasAnySpecifiersShouldBeIgnored()),
255-
unless(isInMarco()))
256-
.bind(SecondVarDeclName)))))
250+
callExpr(callee(functionDecl(isInStdNamespace(),
251+
hasName("tie"))),
252+
hasArgument(0, RefToBindName(FirstVarDeclName)),
253+
hasArgument(1, RefToBindName(SecondVarDeclName)))
257254
.bind(StdTieExprName))),
258255
hasRHS(expr(hasType(PairType))))
259256
.bind(StdTieAssignStmtName)),
@@ -269,7 +266,7 @@ void UseStructuredBindingCheck::registerMatchers(MatchFinder *Finder) {
269266
declStmt(
270267
unless(isInMarco()),
271268
hasSingleDecl(
272-
varDecl(unless(hasAnySpecifiersShouldBeIgnored()),
269+
varDecl(UnlessShouldBeIgnored,
273270
hasType(qualType(anyOf(PairType, lValueReferenceType(
274271
pointee(PairType))))
275272
.bind(PairVarTypeName)),

0 commit comments

Comments
 (0)