[clang-tools-extra] 4f0cc10 - [NFC][clang-tidy] use hasOperands in place of hasEitherOperand

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Mon May 18 02:11:33 PDT 2020


Author: Nathan James
Date: 2020-05-18T10:11:22+01:00
New Revision: 4f0cc10bf5d0009a9d00565fedb34933c2adf8f6

URL: https://github.com/llvm/llvm-project/commit/4f0cc10bf5d0009a9d00565fedb34933c2adf8f6
DIFF: https://github.com/llvm/llvm-project/commit/4f0cc10bf5d0009a9d00565fedb34933c2adf8f6.diff

LOG: [NFC][clang-tidy] use hasOperands in place of hasEitherOperand

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
index 513714e99cb8..9539e28cd790 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
@@ -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);
 }

diff  --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index ecaee65b2ea6..39526dab79ae 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -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);
 

diff  --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index 337c3691be05..cc59601066ed 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -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("|=", "+="),

diff  --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
index 028e88e04617..ee4850e9dce2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringCompareCheck.cpp
@@ -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(

diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index 066ba708f265..4d54489e71b6 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -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);
 

diff  --git a/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp b/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
index 303833d73ec1..18a775e87e3d 100644
--- a/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -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)),

diff  --git a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 9949ab2c4fce..bf78acdc5f68 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -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()).

diff  --git a/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp b/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
index fcf582071e52..e82324578711 100644
--- a/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
@@ -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);
 }


        


More information about the cfe-commits mailing list