[NFC][clang-tidy] use hasOperands in place of hasEitherOperand
authorNathan James <n.james93@hotmail.co.uk>
Mon, 18 May 2020 09:11:22 +0000 (10:11 +0100)
committerNathan James <n.james93@hotmail.co.uk>
Mon, 18 May 2020 09:11:22 +0000 (10:11 +0100)
clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp

index 513714e..9539e28 100644 (file)
@@ -52,8 +52,8 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {
       // Match [=!]= with a zero on one side and a string.find on the other.
       binaryOperator(
           hasAnyOperatorName("==", "!="),
-          hasEitherOperand(ignoringParenImpCasts(ZeroLiteral)),
-          hasEitherOperand(ignoringParenImpCasts(StringFind.bind("findexpr"))))
+          hasOperands(ignoringParenImpCasts(ZeroLiteral),
+                      ignoringParenImpCasts(StringFind.bind("findexpr"))))
           .bind("expr"),
       this);
 }
index ecaee65..39526da 100644 (file)
@@ -163,10 +163,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
   if (WarnOnSizeOfCompareToConstant) {
     Finder->addMatcher(
         binaryOperator(matchers::isRelationalOperator(),
-                       hasEitherOperand(ignoringParenImpCasts(SizeOfExpr)),
-                       hasEitherOperand(ignoringParenImpCasts(
-                           anyOf(integerLiteral(equals(0)),
-                                 integerLiteral(isBiggerThan(0x80000))))))
+                       hasOperands(ignoringParenImpCasts(SizeOfExpr),
+                                   ignoringParenImpCasts(anyOf(
+                                       integerLiteral(equals(0)),
+                                       integerLiteral(isBiggerThan(0x80000))))))
             .bind("sizeof-compare-constant"),
         this);
   }
@@ -205,10 +205,11 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
 
   Finder->addMatcher(
       binaryOperator(hasOperatorName("*"),
-                     hasEitherOperand(ignoringParenImpCasts(SizeOfExpr)),
-                     hasEitherOperand(ignoringParenImpCasts(binaryOperator(
-                         hasOperatorName("*"),
-                         hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))))
+                     hasOperands(ignoringParenImpCasts(SizeOfExpr),
+                                 ignoringParenImpCasts(binaryOperator(
+                                     hasOperatorName("*"),
+                                     hasEitherOperand(
+                                         ignoringParenImpCasts(SizeOfExpr))))))
           .bind("sizeof-multiply-sizeof"),
       this);
 
@@ -232,12 +233,12 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       binaryOperator(
           hasAnyOperatorName("==", "!=", "<", "<=", ">", ">=", "+", "-"),
-          hasEitherOperand(expr(anyOf(
-              ignoringParenImpCasts(SizeOfExpr),
-              ignoringParenImpCasts(binaryOperator(
-                  hasOperatorName("*"),
-                  hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))))),
-          hasEitherOperand(ignoringParenImpCasts(PtrDiffExpr)))
+          hasOperands(expr(anyOf(ignoringParenImpCasts(SizeOfExpr),
+                                 ignoringParenImpCasts(binaryOperator(
+                                     hasOperatorName("*"),
+                                     hasEitherOperand(
+                                         ignoringParenImpCasts(SizeOfExpr)))))),
+                      ignoringParenImpCasts(PtrDiffExpr)))
           .bind("sizeof-in-ptr-arithmetic-mul"),
       this);
 
index 337c369..cc59601 100644 (file)
@@ -139,10 +139,10 @@ void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) {
       this);
 
   Finder->addMatcher(
-      binaryOperator(hasAnyOperatorName("+", "|"),
-                     hasEitherOperand(
-                         expr(hasType(isInteger()), unless(enumExpr("", "")))),
-                     hasEitherOperand(enumExpr("enumExpr", "enumDecl"))),
+      binaryOperator(
+          hasAnyOperatorName("+", "|"),
+          hasOperands(expr(hasType(isInteger()), unless(enumExpr("", ""))),
+                      enumExpr("enumExpr", "enumDecl"))),
       this);
 
   Finder->addMatcher(binaryOperator(hasAnyOperatorName("|=", "+="),
index 028e88e..ee4850e 100644 (file)
@@ -156,11 +156,11 @@ void SuspiciousStringCompareCheck::registerMatchers(MatchFinder *Finder) {
                 has(ignoringParenImpCasts(integerLiteral(unless(equals(0)))))),
             characterLiteral(), cxxBoolLiteral()));
 
-  Finder->addMatcher(binaryOperator(isComparisonOperator(),
-                                    hasEitherOperand(StringCompareCallExpr),
-                                    hasEitherOperand(InvalidLiteral))
-                         .bind("invalid-comparison"),
-                     this);
+  Finder->addMatcher(
+      binaryOperator(isComparisonOperator(),
+                     hasOperands(StringCompareCallExpr, InvalidLiteral))
+          .bind("invalid-comparison"),
+      this);
 }
 
 void SuspiciousStringCompareCheck::check(
index 066ba70..4d54489 100644 (file)
@@ -533,8 +533,8 @@ static ast_matchers::internal::Matcher<Expr>
 matchBinOpIntegerConstantExpr(StringRef Id) {
   const auto BinOpCstExpr =
       expr(anyOf(binaryOperator(hasAnyOperatorName("+", "|", "&"),
-                                hasEitherOperand(matchSymbolicExpr(Id)),
-                                hasEitherOperand(matchIntegerConstantExpr(Id))),
+                                hasOperands(matchSymbolicExpr(Id),
+                                            matchIntegerConstantExpr(Id))),
                  binaryOperator(hasOperatorName("-"),
                                 hasLHS(matchSymbolicExpr(Id)),
                                 hasRHS(matchIntegerConstantExpr(Id)))))
@@ -900,13 +900,14 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
 
   // Match expressions like: (X << 8) & 0xFF
   Finder->addMatcher(
-      binaryOperator(hasOperatorName("&"),
-                     hasEitherOperand(ignoringParenImpCasts(binaryOperator(
-                         hasOperatorName("<<"),
-                         hasRHS(ignoringParenImpCasts(
-                             integerLiteral().bind("shift-const")))))),
-                     hasEitherOperand(ignoringParenImpCasts(
-                         integerLiteral().bind("and-const"))))
+      binaryOperator(
+          hasOperatorName("&"),
+          hasOperands(
+              ignoringParenImpCasts(
+                  binaryOperator(hasOperatorName("<<"),
+                                 hasRHS(ignoringParenImpCasts(
+                                     integerLiteral().bind("shift-const"))))),
+              ignoringParenImpCasts(integerLiteral().bind("and-const"))))
           .bind("left-right-shift-confusion"),
       this);
 
@@ -923,8 +924,7 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
 
   // Match expressions like: x <op> 0xFF == 0xF00.
   Finder->addMatcher(binaryOperator(isComparisonOperator(),
-                                    hasEitherOperand(BinOpCstLeft),
-                                    hasEitherOperand(CstRight))
+                                    hasOperands(BinOpCstLeft, CstRight))
                          .bind("binop-const-compare-to-const"),
                      this);
 
index 303833d..18a775e 100644 (file)
@@ -35,9 +35,8 @@ void DeleteNullPointerCheck::registerMatchers(MatchFinder *Finder) {
 
   const auto PointerCondition = castExpr(hasCastKind(CK_PointerToBoolean),
                                          hasSourceExpression(PointerExpr));
-  const auto BinaryPointerCheckCondition =
-      binaryOperator(hasEitherOperand(castExpr(hasCastKind(CK_NullToPointer))),
-                     hasEitherOperand(PointerExpr));
+  const auto BinaryPointerCheckCondition = binaryOperator(
+      hasOperands(castExpr(hasCastKind(CK_NullToPointer)), PointerExpr));
 
   Finder->addMatcher(
       ifStmt(hasCondition(anyOf(PointerCondition, BinaryPointerCheckCondition)),
index 9949ab2..bf78acd 100644 (file)
@@ -82,10 +82,10 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
   // Matches against nullptr.
   Finder->addMatcher(
       binaryOperator(hasAnyOperatorName("==", "!="),
-                     hasEitherOperand(ignoringImpCasts(
-                         anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(),
-                               integerLiteral(equals(0))))),
-                     hasEitherOperand(callToGet(knownSmartptr()))),
+                     hasOperands(ignoringImpCasts(anyOf(
+                                     cxxNullPtrLiteralExpr(), gnuNullExpr(),
+                                     integerLiteral(equals(0)))),
+                                 callToGet(knownSmartptr()))),
       Callback);
 
   // FIXME: Match and fix if (l.get() == r.get()).
index fcf5820..e823245 100644 (file)
@@ -39,8 +39,8 @@ void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
   // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0.
   Finder->addMatcher(
       binaryOperator(hasAnyOperatorName("==", "!="),
-                     hasEitherOperand(StrCompare.bind("compare")),
-                     hasEitherOperand(integerLiteral(equals(0)).bind("zero")))
+                     hasOperands(StrCompare.bind("compare"),
+                                 integerLiteral(equals(0)).bind("zero")))
           .bind("match2"),
       this);
 }