From 61bf08cac6860dfd33287ee756dcb7453f14a4e4 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 17 Sep 2015 13:31:25 +0000 Subject: [PATCH] Refactors AST matching code to use the new AST matcher names. This patch correlates to r247885 which performs the AST matcher rename in Clang. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@247886 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../AddOverride/AddOverrideMatchers.cpp | 4 +- clang-modernize/LoopConvert/LoopMatchers.cpp | 33 +++++++------ .../PassByValue/PassByValueMatchers.cpp | 10 ++-- .../ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp | 6 +-- clang-modernize/UseAuto/UseAutoMatchers.cpp | 2 +- .../google/ExplicitConstructorCheck.cpp | 4 +- clang-tidy/google/OverloadedUnaryAndCheck.cpp | 9 ++-- clang-tidy/misc/ArgumentCommentCheck.cpp | 4 +- .../misc/AssignOperatorSignatureCheck.cpp | 19 ++++---- .../BoolPointerImplicitConversionCheck.cpp | 2 +- clang-tidy/misc/InaccurateEraseCheck.cpp | 12 ++--- clang-tidy/misc/InefficientAlgorithmCheck.cpp | 8 ++-- clang-tidy/misc/MoveConstructorInitCheck.cpp | 18 +++---- .../misc/NoexceptMoveConstructorCheck.cpp | 4 +- clang-tidy/misc/SizeofContainerCheck.cpp | 11 +++-- clang-tidy/misc/StaticAssertCheck.cpp | 4 +- clang-tidy/misc/UndelegatedConstructor.cpp | 7 +-- .../misc/UniqueptrResetReleaseCheck.cpp | 17 +++---- clang-tidy/misc/UnusedRAIICheck.cpp | 6 +-- clang-tidy/modernize/LoopConvertCheck.cpp | 35 +++++++------- clang-tidy/modernize/PassByValueCheck.cpp | 10 ++-- clang-tidy/modernize/ReplaceAutoPtrCheck.cpp | 11 +++-- clang-tidy/modernize/ShrinkToFitCheck.cpp | 12 ++--- clang-tidy/modernize/UseAutoCheck.cpp | 27 ++++++----- clang-tidy/modernize/UseOverrideCheck.cpp | 2 +- .../BracesAroundStatementsCheck.cpp | 2 +- .../readability/ContainerSizeEmptyCheck.cpp | 5 +- clang-tidy/readability/FunctionSizeCheck.cpp | 2 +- .../readability/RedundantSmartptrGetCheck.cpp | 31 ++++++------ .../readability/RedundantStringCStrCheck.cpp | 30 ++++++------ .../readability/SimplifyBooleanExprCheck.cpp | 47 ++++++++++--------- 31 files changed, 207 insertions(+), 187 deletions(-) diff --git a/clang-modernize/AddOverride/AddOverrideMatchers.cpp b/clang-modernize/AddOverride/AddOverrideMatchers.cpp index e323b5d..41985a5 100644 --- a/clang-modernize/AddOverride/AddOverrideMatchers.cpp +++ b/clang-modernize/AddOverride/AddOverrideMatchers.cpp @@ -22,8 +22,8 @@ using namespace clang; const char *MethodId = "method"; DeclarationMatcher makeCandidateForOverrideAttrMatcher() { - return methodDecl(hasParent(recordDecl()), + return cxxMethodDecl(hasParent(recordDecl()), isOverride(), - unless(destructorDecl())).bind(MethodId); + unless(cxxDestructorDecl())).bind(MethodId); } diff --git a/clang-modernize/LoopConvert/LoopMatchers.cpp b/clang-modernize/LoopConvert/LoopMatchers.cpp index 807937f..d6652f3 100644 --- a/clang-modernize/LoopConvert/LoopMatchers.cpp +++ b/clang-modernize/LoopConvert/LoopMatchers.cpp @@ -112,10 +112,10 @@ StatementMatcher makeArrayLoopMatcher() { /// - If the end iterator variable 'g' is defined, it is the same as 'f' StatementMatcher makeIteratorLoopMatcher() { StatementMatcher BeginCallMatcher = - memberCallExpr( + cxxMemberCallExpr( argumentCountIs(0), callee( - methodDecl(hasName("begin")) + cxxMethodDecl(hasName("begin")) ) ).bind(BeginCallName); @@ -133,8 +133,8 @@ StatementMatcher makeIteratorLoopMatcher() { DeclarationMatcher EndDeclMatcher = varDecl(hasInitializer(anything())).bind(EndVarName); - StatementMatcher EndCallMatcher = - memberCallExpr(argumentCountIs(0), callee(methodDecl(hasName("end")))); + StatementMatcher EndCallMatcher = cxxMemberCallExpr( + argumentCountIs(0), callee(cxxMethodDecl(hasName("end")))); StatementMatcher IteratorBoundMatcher = expr(anyOf(ignoringParenImpCasts(declRefExpr(to( @@ -148,7 +148,7 @@ StatementMatcher makeIteratorLoopMatcher() { expr(ignoringParenImpCasts(declRefExpr(to( varDecl().bind(ConditionVarName))))); - StatementMatcher OverloadedNEQMatcher = operatorCallExpr( + StatementMatcher OverloadedNEQMatcher = cxxOperatorCallExpr( hasOverloadedOperatorName("!="), argumentCountIs(2), hasArgument(0, IteratorComparisonMatcher), @@ -159,7 +159,7 @@ StatementMatcher makeIteratorLoopMatcher() { // reference then the return type is tagged with DerefByValueResultName. internal::Matcher TestDerefReturnsByValue = hasType( - recordDecl( + cxxRecordDecl( hasMethod( allOf( hasOverloadedOperatorName("*"), @@ -218,7 +218,7 @@ StatementMatcher makeIteratorLoopMatcher() { )) ) ), - operatorCallExpr( + cxxOperatorCallExpr( hasOverloadedOperatorName("++"), hasArgument(0, declRefExpr(to( @@ -276,15 +276,15 @@ StatementMatcher makePseudoArrayLoopMatcher() { qualType( isConstQualified(), hasDeclaration( - recordDecl( + cxxRecordDecl( hasMethod( - methodDecl( + cxxMethodDecl( hasName("begin"), isConst() ) ), hasMethod( - methodDecl( + cxxMethodDecl( hasName("end"), isConst() ) @@ -295,7 +295,7 @@ StatementMatcher makePseudoArrayLoopMatcher() { qualType( unless(isConstQualified()), hasDeclaration( - recordDecl( + cxxRecordDecl( hasMethod(hasName("begin")), hasMethod(hasName("end")) ) @@ -304,12 +304,11 @@ StatementMatcher makePseudoArrayLoopMatcher() { ) ); - StatementMatcher SizeCallMatcher = - memberCallExpr(argumentCountIs(0), - callee(methodDecl(anyOf(hasName("size"), - hasName("length")))), - on(anyOf(hasType(pointsTo(RecordWithBeginEnd)), - hasType(RecordWithBeginEnd)))); + StatementMatcher SizeCallMatcher = cxxMemberCallExpr( + argumentCountIs(0), + callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), + on(anyOf(hasType(pointsTo(RecordWithBeginEnd)), + hasType(RecordWithBeginEnd)))); StatementMatcher EndInitMatcher = expr(anyOf( diff --git a/clang-modernize/PassByValue/PassByValueMatchers.cpp b/clang-modernize/PassByValue/PassByValueMatchers.cpp index c6ee6a8..484e8d3 100644 --- a/clang-modernize/PassByValue/PassByValueMatchers.cpp +++ b/clang-modernize/PassByValue/PassByValueMatchers.cpp @@ -59,13 +59,13 @@ static TypeMatcher nonConstValueType() { } DeclarationMatcher makePassByValueCtorParamMatcher() { - return constructorDecl( - forEachConstructorInitializer(ctorInitializer( + return cxxConstructorDecl( + forEachConstructorInitializer(cxxCtorInitializer( // Clang builds a CXXConstructExpr only when it knowns which // constructor will be called. In dependent contexts a ParenListExpr // is generated instead of a CXXConstructExpr, filtering out templates // automatically for us. - withInitializer(constructExpr( + withInitializer(cxxConstructExpr( has(declRefExpr(to( parmVarDecl(hasType(qualType( // match only const-ref or a non-const value @@ -73,9 +73,9 @@ DeclarationMatcher makePassByValueCtorParamMatcher() { // shouldn't be modified. anyOf(constRefType(), nonConstValueType())))) .bind(PassByValueParamId)))), - hasDeclaration(constructorDecl( + hasDeclaration(cxxConstructorDecl( isCopyConstructor(), unless(isDeleted()), - hasDeclContext(recordDecl(isMoveConstructible()))))))) + hasDeclContext(cxxRecordDecl(isMoveConstructible()))))))) .bind(PassByValueInitializerId))) .bind(PassByValueCtorId); } diff --git a/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp b/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp index e03a2c3..64976f5 100644 --- a/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp +++ b/clang-modernize/ReplaceAutoPtr/ReplaceAutoPtrMatchers.cpp @@ -67,13 +67,13 @@ DeclarationMatcher makeAutoPtrUsingDeclMatcher() { StatementMatcher makeTransferOwnershipExprMatcher() { StatementMatcher assignOperator = - operatorCallExpr(allOf( + cxxOperatorCallExpr(allOf( hasOverloadedOperatorName("="), - callee(methodDecl(ofClass(AutoPtrDecl))), + callee(cxxMethodDecl(ofClass(AutoPtrDecl))), hasArgument(1, MovableArgumentMatcher))); StatementMatcher copyCtor = - constructExpr(allOf(hasType(AutoPtrType), + cxxConstructExpr(allOf(hasType(AutoPtrType), argumentCountIs(1), hasArgument(0, MovableArgumentMatcher))); diff --git a/clang-modernize/UseAuto/UseAutoMatchers.cpp b/clang-modernize/UseAuto/UseAutoMatchers.cpp index 4f314ad..72eec8d 100644 --- a/clang-modernize/UseAuto/UseAutoMatchers.cpp +++ b/clang-modernize/UseAuto/UseAutoMatchers.cpp @@ -258,7 +258,7 @@ StatementMatcher makeDeclWithNewMatcher() { unless(has(varDecl( anyOf( unless(hasInitializer( - ignoringParenImpCasts(newExpr()) + ignoringParenImpCasts(cxxNewExpr()) )), // FIXME: TypeLoc information is not reliable where CV qualifiers are // concerned so these types can't be handled for now. diff --git a/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tidy/google/ExplicitConstructorCheck.cpp index 22e2139..68baf70 100644 --- a/clang-tidy/google/ExplicitConstructorCheck.cpp +++ b/clang-tidy/google/ExplicitConstructorCheck.cpp @@ -23,8 +23,8 @@ void ExplicitConstructorCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++; the functionality currently does not // provide any benefit to other languages, despite being benign. if (getLangOpts().CPlusPlus) - Finder->addMatcher(constructorDecl(unless(isInstantiated())).bind("ctor"), - this); + Finder->addMatcher( + cxxConstructorDecl(unless(isInstantiated())).bind("ctor"), this); } // Looks for the token matching the predicate and returns the range of the found diff --git a/clang-tidy/google/OverloadedUnaryAndCheck.cpp b/clang-tidy/google/OverloadedUnaryAndCheck.cpp index 5dad36f..6fb1ca9 100644 --- a/clang-tidy/google/OverloadedUnaryAndCheck.cpp +++ b/clang-tidy/google/OverloadedUnaryAndCheck.cpp @@ -27,14 +27,15 @@ OverloadedUnaryAndCheck::registerMatchers(ast_matchers::MatchFinder *Finder) { return; // Match unary methods that overload operator&. - Finder->addMatcher(methodDecl(parameterCountIs(0), hasOverloadedOperatorName( - "&")).bind("overload"), - this); + Finder->addMatcher( + cxxMethodDecl(parameterCountIs(0), hasOverloadedOperatorName("&")) + .bind("overload"), + this); // Also match freestanding unary operator& overloads. Be careful not to match // binary methods. Finder->addMatcher( functionDecl( - allOf(unless(methodDecl()), + allOf(unless(cxxMethodDecl()), functionDecl(parameterCountIs(1), hasOverloadedOperatorName("&")).bind("overload"))), this); diff --git a/clang-tidy/misc/ArgumentCommentCheck.cpp b/clang-tidy/misc/ArgumentCommentCheck.cpp index 100998d..a69aaec 100644 --- a/clang-tidy/misc/ArgumentCommentCheck.cpp +++ b/clang-tidy/misc/ArgumentCommentCheck.cpp @@ -26,7 +26,7 @@ ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name, void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( - callExpr(unless(operatorCallExpr()), + callExpr(unless(cxxOperatorCallExpr()), // NewCallback's arguments relate to the pointed function, don't // check them against NewCallback's parameter names. // FIXME: Make this configurable. @@ -34,7 +34,7 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) { hasName("NewCallback"), hasName("NewPermanentCallback")))))) .bind("expr"), this); - Finder->addMatcher(constructExpr().bind("expr"), this); + Finder->addMatcher(cxxConstructExpr().bind("expr"), this); } std::vector> diff --git a/clang-tidy/misc/AssignOperatorSignatureCheck.cpp b/clang-tidy/misc/AssignOperatorSignatureCheck.cpp index 7488d98..a1ecfbd 100644 --- a/clang-tidy/misc/AssignOperatorSignatureCheck.cpp +++ b/clang-tidy/misc/AssignOperatorSignatureCheck.cpp @@ -24,20 +24,21 @@ void AssignOperatorSignatureCheck::registerMatchers( if (!getLangOpts().CPlusPlus) return; - const auto HasGoodReturnType = methodDecl(returns(lValueReferenceType(pointee( - unless(isConstQualified()), hasDeclaration(equalsBoundNode("class")))))); + const auto HasGoodReturnType = cxxMethodDecl(returns( + lValueReferenceType(pointee(unless(isConstQualified()), + hasDeclaration(equalsBoundNode("class")))))); const auto IsSelf = qualType( anyOf(hasDeclaration(equalsBoundNode("class")), referenceType(pointee(hasDeclaration(equalsBoundNode("class")))))); const auto IsSelfAssign = - methodDecl(unless(anyOf(isDeleted(), isPrivate(), isImplicit())), - hasName("operator="), ofClass(recordDecl().bind("class")), - hasParameter(0, parmVarDecl(hasType(IsSelf)))) + cxxMethodDecl(unless(anyOf(isDeleted(), isPrivate(), isImplicit())), + hasName("operator="), ofClass(recordDecl().bind("class")), + hasParameter(0, parmVarDecl(hasType(IsSelf)))) .bind("method"); Finder->addMatcher( - methodDecl(IsSelfAssign, unless(HasGoodReturnType)).bind("ReturnType"), + cxxMethodDecl(IsSelfAssign, unless(HasGoodReturnType)).bind("ReturnType"), this); const auto BadSelf = referenceType( @@ -45,11 +46,13 @@ void AssignOperatorSignatureCheck::registerMatchers( rValueReferenceType(pointee(isConstQualified())))); Finder->addMatcher( - methodDecl(IsSelfAssign, hasParameter(0, parmVarDecl(hasType(BadSelf)))) + cxxMethodDecl(IsSelfAssign, + hasParameter(0, parmVarDecl(hasType(BadSelf)))) .bind("ArgumentType"), this); - Finder->addMatcher(methodDecl(IsSelfAssign, isConst()).bind("Const"), this); + Finder->addMatcher(cxxMethodDecl(IsSelfAssign, isConst()).bind("Const"), + this); } diff --git a/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp b/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp index 95f1a68..ec13e63 100644 --- a/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp +++ b/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp @@ -63,7 +63,7 @@ void BoolPointerImplicitConversionCheck::check( // bool. !match(findAll(callExpr(hasAnyArgument(DeclRef))), *If, *Result.Context) .empty() || - !match(findAll(deleteExpr(has(expr(DeclRef)))), *If, *Result.Context) + !match(findAll(cxxDeleteExpr(has(expr(DeclRef)))), *If, *Result.Context) .empty()) return; diff --git a/clang-tidy/misc/InaccurateEraseCheck.cpp b/clang-tidy/misc/InaccurateEraseCheck.cpp index ffccc31..6e69f2a 100644 --- a/clang-tidy/misc/InaccurateEraseCheck.cpp +++ b/clang-tidy/misc/InaccurateEraseCheck.cpp @@ -25,15 +25,15 @@ void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) { return; const auto CheckForEndCall = hasArgument( - 1, - anyOf(constructExpr(has(memberCallExpr(callee(methodDecl(hasName("end")))) - .bind("InaccEndCall"))), - anything())); + 1, anyOf(cxxConstructExpr( + has(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end")))) + .bind("InaccEndCall"))), + anything())); Finder->addMatcher( - memberCallExpr( + cxxMemberCallExpr( on(hasType(namedDecl(matchesName("^::std::")))), - callee(methodDecl(hasName("erase"))), argumentCountIs(1), + callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1), hasArgument(0, has(callExpr(callee(functionDecl(matchesName( "^::std::(remove(_if)?|unique)$"))), CheckForEndCall) diff --git a/clang-tidy/misc/InefficientAlgorithmCheck.cpp b/clang-tidy/misc/InefficientAlgorithmCheck.cpp index a9a1a09..94e3785 100644 --- a/clang-tidy/misc/InefficientAlgorithmCheck.cpp +++ b/clang-tidy/misc/InefficientAlgorithmCheck.cpp @@ -41,16 +41,16 @@ void InefficientAlgorithmCheck::registerMatchers(MatchFinder *Finder) { callExpr( callee(functionDecl(matchesName(Algorithms))), hasArgument( - 0, constructExpr(has(memberCallExpr( - callee(methodDecl(hasName("begin"))), + 0, cxxConstructExpr(has(cxxMemberCallExpr( + callee(cxxMethodDecl(hasName("begin"))), on(declRefExpr( hasDeclaration(decl().bind("IneffContObj")), anyOf(hasType(ContainerMatcher.bind("IneffCont")), hasType(pointsTo( ContainerMatcher.bind("IneffContPtr"))))) .bind("IneffContExpr")))))), - hasArgument(1, constructExpr(has(memberCallExpr( - callee(methodDecl(hasName("end"))), + hasArgument(1, cxxConstructExpr(has(cxxMemberCallExpr( + callee(cxxMethodDecl(hasName("end"))), on(declRefExpr(hasDeclaration( equalsBoundNode("IneffContObj")))))))), hasArgument(2, expr().bind("AlgParam")), diff --git a/clang-tidy/misc/MoveConstructorInitCheck.cpp b/clang-tidy/misc/MoveConstructorInitCheck.cpp index 5e513d8..0ba0f16 100644 --- a/clang-tidy/misc/MoveConstructorInitCheck.cpp +++ b/clang-tidy/misc/MoveConstructorInitCheck.cpp @@ -23,14 +23,16 @@ void MoveConstructorInitCheck::registerMatchers(MatchFinder *Finder) { return; Finder->addMatcher( - constructorDecl(unless(isImplicit()), allOf( - isMoveConstructor(), - hasAnyConstructorInitializer( - ctorInitializer(withInitializer(constructExpr(hasDeclaration( - constructorDecl(isCopyConstructor()).bind("ctor") - )))).bind("init") - ) - )), this); + cxxConstructorDecl( + unless(isImplicit()), + allOf(isMoveConstructor(), + hasAnyConstructorInitializer( + cxxCtorInitializer( + withInitializer(cxxConstructExpr(hasDeclaration( + cxxConstructorDecl(isCopyConstructor()) + .bind("ctor"))))) + .bind("init")))), + this); } void MoveConstructorInitCheck::check(const MatchFinder::MatchResult &Result) { diff --git a/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp b/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp index ff6ba0c..1a22e17 100644 --- a/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp +++ b/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp @@ -23,8 +23,8 @@ void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) { return; Finder->addMatcher( - methodDecl(anyOf(constructorDecl(), hasOverloadedOperatorName("=")), - unless(isImplicit()), unless(isDeleted())) + cxxMethodDecl(anyOf(cxxConstructorDecl(), hasOverloadedOperatorName("=")), + unless(isImplicit()), unless(isDeleted())) .bind("decl"), this); } diff --git a/clang-tidy/misc/SizeofContainerCheck.cpp b/clang-tidy/misc/SizeofContainerCheck.cpp index 5bd9f75..cd26426 100644 --- a/clang-tidy/misc/SizeofContainerCheck.cpp +++ b/clang-tidy/misc/SizeofContainerCheck.cpp @@ -19,11 +19,12 @@ namespace tidy { void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( expr(unless(isInTemplateInstantiation()), - expr(sizeOfExpr(has(expr(hasType(hasCanonicalType(hasDeclaration( - recordDecl(matchesName("^(::std::|::string)"), - unless(matchesName("^::std::(bitset|array)$")), - hasMethod(methodDecl(hasName("size"), isPublic(), - isConst())))))))))) + expr(sizeOfExpr(has( + expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl( + matchesName("^(::std::|::string)"), + unless(matchesName("^::std::(bitset|array)$")), + hasMethod(cxxMethodDecl(hasName("size"), isPublic(), + isConst())))))))))) .bind("sizeof"), // Ignore ARRAYSIZE() pattern. unless(hasAncestor(binaryOperator( diff --git a/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tidy/misc/StaticAssertCheck.cpp index 7b596cd..c9793bc 100644 --- a/clang-tidy/misc/StaticAssertCheck.cpp +++ b/clang-tidy/misc/StaticAssertCheck.cpp @@ -33,8 +33,8 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) { return; auto IsAlwaysFalse = expr(ignoringParenImpCasts( - expr(anyOf(boolLiteral(equals(false)), integerLiteral(equals(0)), - nullPtrLiteralExpr(), gnuNullExpr())) + expr(anyOf(cxxBoolLiteral(equals(false)), integerLiteral(equals(0)), + cxxNullPtrLiteralExpr(), gnuNullExpr())) .bind("isAlwaysFalse"))); auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf( IsAlwaysFalse, cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr"))); diff --git a/clang-tidy/misc/UndelegatedConstructor.cpp b/clang-tidy/misc/UndelegatedConstructor.cpp index d684049..90135e3 100644 --- a/clang-tidy/misc/UndelegatedConstructor.cpp +++ b/clang-tidy/misc/UndelegatedConstructor.cpp @@ -63,10 +63,11 @@ void UndelegatedConstructorCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( compoundStmt( - hasParent(constructorDecl(ofClass(recordDecl().bind("parent")))), + hasParent( + cxxConstructorDecl(ofClass(cxxRecordDecl().bind("parent")))), forEach(ignoringTemporaryExpr( - constructExpr(hasDeclaration(constructorDecl(ofClass( - recordDecl(baseOfBoundNode("parent")))))) + cxxConstructExpr(hasDeclaration(cxxConstructorDecl(ofClass( + cxxRecordDecl(baseOfBoundNode("parent")))))) .bind("construct"))), unless(isInTemplateInstantiation())), this); diff --git a/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp b/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp index 0694abc..32916d1 100644 --- a/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp +++ b/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp @@ -24,18 +24,19 @@ void UniqueptrResetReleaseCheck::registerMatchers(MatchFinder *Finder) { return; Finder->addMatcher( - memberCallExpr( + cxxMemberCallExpr( on(expr().bind("left")), callee(memberExpr().bind("reset_member")), - callee(methodDecl(hasName("reset"), - ofClass(recordDecl(hasName("::std::unique_ptr"), - decl().bind("left_class"))))), - has(memberCallExpr( + callee( + cxxMethodDecl(hasName("reset"), + ofClass(cxxRecordDecl(hasName("::std::unique_ptr"), + decl().bind("left_class"))))), + has(cxxMemberCallExpr( on(expr().bind("right")), callee(memberExpr().bind("release_member")), - callee(methodDecl( + callee(cxxMethodDecl( hasName("release"), - ofClass(recordDecl(hasName("::std::unique_ptr"), - decl().bind("right_class")))))))) + ofClass(cxxRecordDecl(hasName("::std::unique_ptr"), + decl().bind("right_class")))))))) .bind("reset_call"), this); } diff --git a/clang-tidy/misc/UnusedRAIICheck.cpp b/clang-tidy/misc/UnusedRAIICheck.cpp index c579894..e62b31d 100644 --- a/clang-tidy/misc/UnusedRAIICheck.cpp +++ b/clang-tidy/misc/UnusedRAIICheck.cpp @@ -33,13 +33,13 @@ void UnusedRAIICheck::registerMatchers(MatchFinder *Finder) { // Look for temporaries that are constructed in-place and immediately // destroyed. Look for temporaries created by a functional cast but not for // those returned from a call. - auto BindTemp = bindTemporaryExpr(unless(has(callExpr()))).bind("temp"); + auto BindTemp = cxxBindTemporaryExpr(unless(has(callExpr()))).bind("temp"); Finder->addMatcher( exprWithCleanups( unless(isInTemplateInstantiation()), hasParent(compoundStmt().bind("compound")), - hasType(recordDecl(hasNonTrivialDestructor())), - anyOf(has(BindTemp), has(functionalCastExpr(has(BindTemp))))) + hasType(cxxRecordDecl(hasNonTrivialDestructor())), + anyOf(has(BindTemp), has(cxxFunctionalCastExpr(has(BindTemp))))) .bind("expr"), this); } diff --git a/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tidy/modernize/LoopConvertCheck.cpp index 73d93e3..15ca113 100644 --- a/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tidy/modernize/LoopConvertCheck.cpp @@ -112,7 +112,8 @@ StatementMatcher makeArrayLoopMatcher() { /// - If the end iterator variable 'g' is defined, it is the same as 'f'. StatementMatcher makeIteratorLoopMatcher() { StatementMatcher BeginCallMatcher = - memberCallExpr(argumentCountIs(0), callee(methodDecl(hasName("begin")))) + cxxMemberCallExpr(argumentCountIs(0), + callee(cxxMethodDecl(hasName("begin")))) .bind(BeginCallName); DeclarationMatcher InitDeclMatcher = @@ -125,8 +126,8 @@ StatementMatcher makeIteratorLoopMatcher() { DeclarationMatcher EndDeclMatcher = varDecl(hasInitializer(anything())).bind(EndVarName); - StatementMatcher EndCallMatcher = - memberCallExpr(argumentCountIs(0), callee(methodDecl(hasName("end")))); + StatementMatcher EndCallMatcher = cxxMemberCallExpr( + argumentCountIs(0), callee(cxxMethodDecl(hasName("end")))); StatementMatcher IteratorBoundMatcher = expr(anyOf(ignoringParenImpCasts( @@ -139,15 +140,15 @@ StatementMatcher makeIteratorLoopMatcher() { ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName))))); StatementMatcher OverloadedNEQMatcher = - operatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2), - hasArgument(0, IteratorComparisonMatcher), - hasArgument(1, IteratorBoundMatcher)); + cxxOperatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2), + hasArgument(0, IteratorComparisonMatcher), + hasArgument(1, IteratorBoundMatcher)); // This matcher tests that a declaration is a CXXRecordDecl that has an // overloaded operator*(). If the operator*() returns by value instead of by // reference then the return type is tagged with DerefByValueResultName. internal::Matcher TestDerefReturnsByValue = - hasType(recordDecl(hasMethod(allOf( + hasType(cxxRecordDecl(hasMethod(allOf( hasOverloadedOperatorName("*"), anyOf( // Tag the return type if it's by value. @@ -178,7 +179,7 @@ StatementMatcher makeIteratorLoopMatcher() { hasUnaryOperand(declRefExpr( to(varDecl(hasType(pointsTo(AnyType))) .bind(IncrementVarName))))), - operatorCallExpr( + cxxOperatorCallExpr( hasOverloadedOperatorName("++"), hasArgument( 0, declRefExpr(to(varDecl(TestDerefReturnsByValue) @@ -229,20 +230,20 @@ StatementMatcher makePseudoArrayLoopMatcher() { // are also allowed. TypeMatcher RecordWithBeginEnd = qualType( anyOf(qualType(isConstQualified(), - hasDeclaration(recordDecl( - hasMethod(methodDecl(hasName("begin"), isConst())), - hasMethod(methodDecl(hasName("end"), - isConst())))) // hasDeclaration - ), // qualType + hasDeclaration(cxxRecordDecl( + hasMethod(cxxMethodDecl(hasName("begin"), isConst())), + hasMethod(cxxMethodDecl(hasName("end"), + isConst())))) // hasDeclaration + ), // qualType qualType(unless(isConstQualified()), hasDeclaration( - recordDecl(hasMethod(hasName("begin")), - hasMethod(hasName("end"))))) // qualType + cxxRecordDecl(hasMethod(hasName("begin")), + hasMethod(hasName("end"))))) // qualType )); - StatementMatcher SizeCallMatcher = memberCallExpr( + StatementMatcher SizeCallMatcher = cxxMemberCallExpr( argumentCountIs(0), - callee(methodDecl(anyOf(hasName("size"), hasName("length")))), + callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), on(anyOf(hasType(pointsTo(RecordWithBeginEnd)), hasType(RecordWithBeginEnd)))); diff --git a/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tidy/modernize/PassByValueCheck.cpp index 0cbb606..3b12c59 100644 --- a/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tidy/modernize/PassByValueCheck.cpp @@ -131,14 +131,14 @@ void PassByValueCheck::registerMatchers(MatchFinder *Finder) { // provide any benefit to other languages, despite being benign. if (getLangOpts().CPlusPlus) { Finder->addMatcher( - constructorDecl( + cxxConstructorDecl( forEachConstructorInitializer( - ctorInitializer( + cxxCtorInitializer( // Clang builds a CXXConstructExpr only whin it knows which // constructor will be called. In dependent contexts a // ParenListExpr is generated instead of a CXXConstructExpr, // filtering out templates automatically for us. - withInitializer(constructExpr( + withInitializer(cxxConstructExpr( has(declRefExpr(to( parmVarDecl( hasType(qualType( @@ -148,10 +148,10 @@ void PassByValueCheck::registerMatchers(MatchFinder *Finder) { anyOf(constRefType(), nonConstValueType())))) .bind("Param")))), - hasDeclaration(constructorDecl( + hasDeclaration(cxxConstructorDecl( isCopyConstructor(), unless(isDeleted()), hasDeclContext( - recordDecl(isMoveConstructible()))))))) + cxxRecordDecl(isMoveConstructible()))))))) .bind("Initializer"))) .bind("Ctor"), this); diff --git a/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp index 4da3efb..c6d6fcc 100644 --- a/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp +++ b/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp @@ -130,11 +130,12 @@ DeclarationMatcher makeAutoPtrUsingDeclMatcher() { /// ~~~~^ /// \endcode StatementMatcher makeTransferOwnershipExprMatcher() { - return anyOf(operatorCallExpr(allOf(hasOverloadedOperatorName("="), - callee(methodDecl(ofClass(AutoPtrDecl))), - hasArgument(1, MovableArgumentMatcher))), - constructExpr(allOf(hasType(AutoPtrType), argumentCountIs(1), - hasArgument(0, MovableArgumentMatcher)))); + return anyOf( + cxxOperatorCallExpr(allOf(hasOverloadedOperatorName("="), + callee(cxxMethodDecl(ofClass(AutoPtrDecl))), + hasArgument(1, MovableArgumentMatcher))), + cxxConstructExpr(allOf(hasType(AutoPtrType), argumentCountIs(1), + hasArgument(0, MovableArgumentMatcher)))); } /// \brief Locates the \c auto_ptr token when it is referred by a \c TypeLoc. diff --git a/clang-tidy/modernize/ShrinkToFitCheck.cpp b/clang-tidy/modernize/ShrinkToFitCheck.cpp index c5e9e5e..60b9843 100644 --- a/clang-tidy/modernize/ShrinkToFitCheck.cpp +++ b/clang-tidy/modernize/ShrinkToFitCheck.cpp @@ -42,7 +42,7 @@ void ShrinkToFitCheck::registerMatchers(MatchFinder *Finder) { memberExpr(member(valueDecl().bind("ContainerDecl"))); const auto ShrinkableAsDecl = declRefExpr(hasDeclaration(valueDecl().bind("ContainerDecl"))); - const auto CopyCtorCall = constructExpr( + const auto CopyCtorCall = cxxConstructExpr( hasArgument(0, anyOf(ShrinkableAsMember, ShrinkableAsDecl, unaryOperator(has(ShrinkableAsMember)), unaryOperator(has(ShrinkableAsDecl))))); @@ -54,11 +54,11 @@ void ShrinkToFitCheck::registerMatchers(MatchFinder *Finder) { has(declRefExpr(hasDeclaration(equalsBoundNode("ContainerDecl"))))))); Finder->addMatcher( - memberCallExpr(on(hasType(namedDecl(stlShrinkableContainer()))), - callee(methodDecl(hasName("swap"))), - has(memberExpr(hasDescendant(CopyCtorCall))), - hasArgument(0, SwapParam.bind("ContainerToShrink")), - unless(isInTemplateInstantiation())) + cxxMemberCallExpr(on(hasType(namedDecl(stlShrinkableContainer()))), + callee(cxxMethodDecl(hasName("swap"))), + has(memberExpr(hasDescendant(CopyCtorCall))), + hasArgument(0, SwapParam.bind("ContainerToShrink")), + unless(isInTemplateInstantiation())) .bind("CopyAndSwapTrick"), this); } diff --git a/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tidy/modernize/UseAutoCheck.cpp index 339bc3c..a940547 100644 --- a/clang-tidy/modernize/UseAutoCheck.cpp +++ b/clang-tidy/modernize/UseAutoCheck.cpp @@ -218,20 +218,21 @@ StatementMatcher makeIteratorDeclMatcher() { } StatementMatcher makeDeclWithNewMatcher() { - return declStmt(has(varDecl()), - unless(has(varDecl(anyOf( - unless(hasInitializer(ignoringParenImpCasts(newExpr()))), - // FIXME: TypeLoc information is not reliable where CV - // qualifiers are concerned so these types can't be - // handled for now. - hasType(pointerType( - pointee(hasCanonicalType(hasLocalQualifiers())))), + return declStmt( + has(varDecl()), + unless(has(varDecl(anyOf( + unless(hasInitializer(ignoringParenImpCasts(cxxNewExpr()))), + // FIXME: TypeLoc information is not reliable where CV + // qualifiers are concerned so these types can't be + // handled for now. + hasType(pointerType( + pointee(hasCanonicalType(hasLocalQualifiers())))), - // FIXME: Handle function pointers. For now we ignore them - // because the replacement replaces the entire type - // specifier source range which includes the identifier. - hasType(pointsTo( - pointsTo(parenType(innerType(functionType())))))))))) + // FIXME: Handle function pointers. For now we ignore them + // because the replacement replaces the entire type + // specifier source range which includes the identifier. + hasType(pointsTo( + pointsTo(parenType(innerType(functionType())))))))))) .bind(DeclWithNewId); } diff --git a/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tidy/modernize/UseOverrideCheck.cpp index e506e83..a335748 100644 --- a/clang-tidy/modernize/UseOverrideCheck.cpp +++ b/clang-tidy/modernize/UseOverrideCheck.cpp @@ -21,7 +21,7 @@ namespace modernize { void UseOverrideCheck::registerMatchers(MatchFinder *Finder) { // Only register the matcher for C++11. if (getLangOpts().CPlusPlus11) - Finder->addMatcher(methodDecl(isOverride()).bind("method"), this); + Finder->addMatcher(cxxMethodDecl(isOverride()).bind("method"), this); } // Re-lex the tokens to get precise locations to insert 'override' and remove diff --git a/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tidy/readability/BracesAroundStatementsCheck.cpp index 39534e2..d6548fc 100644 --- a/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -127,7 +127,7 @@ void BracesAroundStatementsCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher(whileStmt().bind("while"), this); Finder->addMatcher(doStmt().bind("do"), this); Finder->addMatcher(forStmt().bind("for"), this); - Finder->addMatcher(forRangeStmt().bind("for-range"), this); + Finder->addMatcher(cxxForRangeStmt().bind("for-range"), this); } void diff --git a/clang-tidy/readability/ContainerSizeEmptyCheck.cpp b/clang-tidy/readability/ContainerSizeEmptyCheck.cpp index dadfff8..25c8d68 100644 --- a/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ b/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -75,12 +75,13 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) { hasParent(explicitCastExpr(hasDestinationType(isBoolType())))); Finder->addMatcher( - memberCallExpr( + cxxMemberCallExpr( on(expr(anyOf(hasType(namedDecl(stlContainer())), hasType(pointsTo(namedDecl(stlContainer()))), hasType(references(namedDecl(stlContainer()))))) .bind("STLObject")), - callee(methodDecl(hasName("size"))), WrongUse).bind("SizeCallExpr"), + callee(cxxMethodDecl(hasName("size"))), WrongUse) + .bind("SizeCallExpr"), this); } diff --git a/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tidy/readability/FunctionSizeCheck.cpp index 048c01e..42ce65b 100644 --- a/clang-tidy/readability/FunctionSizeCheck.cpp +++ b/clang-tidy/readability/FunctionSizeCheck.cpp @@ -36,7 +36,7 @@ void FunctionSizeCheck::registerMatchers(MatchFinder *Finder) { stmt(unless(compoundStmt()), hasParent(stmt(anyOf(compoundStmt(), ifStmt(), anyOf(whileStmt(), doStmt(), - forRangeStmt(), forStmt()))))) + cxxForRangeStmt(), forStmt()))))) .bind("stmt"))).bind("func"), this); } diff --git a/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tidy/readability/RedundantSmartptrGetCheck.cpp index 5b40d92..2b86c2f 100644 --- a/clang-tidy/readability/RedundantSmartptrGetCheck.cpp +++ b/clang-tidy/readability/RedundantSmartptrGetCheck.cpp @@ -19,24 +19,26 @@ namespace readability { namespace { internal::Matcher callToGet(internal::Matcher OnClass) { - return memberCallExpr( + return cxxMemberCallExpr( on(expr(anyOf(hasType(OnClass), - hasType(qualType(pointsTo(decl(OnClass).bind( - "ptr_to_ptr")))))).bind("smart_pointer")), - unless(callee(memberExpr(hasObjectExpression(thisExpr())))), - callee(methodDecl(hasName("get")))).bind("redundant_get"); + hasType(qualType( + pointsTo(decl(OnClass).bind("ptr_to_ptr")))))) + .bind("smart_pointer")), + unless(callee(memberExpr(hasObjectExpression(cxxThisExpr())))), + callee(cxxMethodDecl(hasName("get")))) + .bind("redundant_get"); } void registerMatchersForGetArrowStart(MatchFinder *Finder, MatchFinder::MatchCallback *Callback) { const auto QuacksLikeASmartptr = recordDecl( recordDecl().bind("duck_typing"), - has(methodDecl(hasName("operator->"), - returns(qualType(pointsTo(type().bind("op->Type")))))), - has(methodDecl(hasName("operator*"), - returns(qualType(references(type().bind("op*Type")))))), - has(methodDecl(hasName("get"), - returns(qualType(pointsTo(type().bind("getType"))))))); + has(cxxMethodDecl(hasName("operator->"), + returns(qualType(pointsTo(type().bind("op->Type")))))), + has(cxxMethodDecl(hasName("operator*"), + returns(qualType(references(type().bind("op*Type")))))), + has(cxxMethodDecl(hasName("get"), + returns(qualType(pointsTo(type().bind("getType"))))))); // Catch 'ptr.get()->Foo()' Finder->addMatcher(memberExpr(expr().bind("memberExpr"), isArrow(), @@ -63,9 +65,10 @@ void registerMatchersForGetEquals(MatchFinder *Finder, // Matches against nullptr. Finder->addMatcher( - binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")), - hasEitherOperand(ignoringImpCasts(nullPtrLiteralExpr())), - hasEitherOperand(callToGet(IsAKnownSmartptr))), + binaryOperator( + anyOf(hasOperatorName("=="), hasOperatorName("!=")), + hasEitherOperand(ignoringImpCasts(cxxNullPtrLiteralExpr())), + hasEitherOperand(callToGet(IsAKnownSmartptr))), Callback); // TODO: Catch ptr.get() == other_ptr.get() } diff --git a/clang-tidy/readability/RedundantStringCStrCheck.cpp b/clang-tidy/readability/RedundantStringCStrCheck.cpp index a3b4515..c58c1dc 100644 --- a/clang-tidy/readability/RedundantStringCStrCheck.cpp +++ b/clang-tidy/readability/RedundantStringCStrCheck.cpp @@ -86,40 +86,42 @@ void RedundantStringCStrCheck::registerMatchers( return; Finder->addMatcher( - constructExpr( - hasDeclaration(methodDecl(hasName(StringConstructor))), + cxxConstructExpr( + hasDeclaration(cxxMethodDecl(hasName(StringConstructor))), argumentCountIs(2), // The first argument must have the form x.c_str() or p->c_str() // where the method is string::c_str(). We can use the copy // constructor of string instead (or the compiler might share // the string object). - hasArgument( - 0, memberCallExpr(callee(memberExpr().bind("member")), - callee(methodDecl(hasName(StringCStrMethod))), - on(expr().bind("arg"))).bind("call")), + hasArgument(0, cxxMemberCallExpr( + callee(memberExpr().bind("member")), + callee(cxxMethodDecl(hasName(StringCStrMethod))), + on(expr().bind("arg"))) + .bind("call")), // The second argument is the alloc object which must not be // present explicitly. - hasArgument(1, defaultArgExpr())), + hasArgument(1, cxxDefaultArgExpr())), this); Finder->addMatcher( - constructExpr( + cxxConstructExpr( // Implicit constructors of these classes are overloaded // wrt. string types and they internally make a StringRef // referring to the argument. Passing a string directly to // them is preferred to passing a char pointer. hasDeclaration( - methodDecl(anyOf(hasName("::llvm::StringRef::StringRef"), - hasName("::llvm::Twine::Twine")))), + cxxMethodDecl(anyOf(hasName("::llvm::StringRef::StringRef"), + hasName("::llvm::Twine::Twine")))), argumentCountIs(1), // The only argument must have the form x.c_str() or p->c_str() // where the method is string::c_str(). StringRef also has // a constructor from string which is more efficient (avoids // strlen), so we can construct StringRef from the string // directly. - hasArgument( - 0, memberCallExpr(callee(memberExpr().bind("member")), - callee(methodDecl(hasName(StringCStrMethod))), - on(expr().bind("arg"))).bind("call"))), + hasArgument(0, cxxMemberCallExpr( + callee(memberExpr().bind("member")), + callee(cxxMethodDecl(hasName(StringCStrMethod))), + on(expr().bind("arg"))) + .bind("call"))), this); } diff --git a/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tidy/readability/SimplifyBooleanExprCheck.cpp index 704a49e..d8f467b 100644 --- a/clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ b/clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -75,7 +75,8 @@ const CXXBoolLiteralExpr *getBoolLiteral(const MatchFinder::MatchResult &Result, internal::Matcher returnsBool(bool Value, StringRef Id = "ignored") { auto SimpleReturnsBool = - returnStmt(has(boolLiteral(equals(Value)).bind(Id))).bind("returns-bool"); + returnStmt(has(cxxBoolLiteral(equals(Value)).bind(Id))) + .bind("returns-bool"); return anyOf(SimpleReturnsBool, compoundStmt(statementCountIs(1), has(SimpleReturnsBool))); } @@ -268,11 +269,12 @@ void SimplifyBooleanExprCheck::matchBoolBinOpExpr(MatchFinder *Finder, StringRef OperatorName, StringRef BooleanId) { Finder->addMatcher( - binaryOperator(isExpansionInMainFile(), hasOperatorName(OperatorName), - hasLHS(allOf(expr().bind(LHSId), - boolLiteral(equals(Value)).bind(BooleanId))), - hasRHS(expr().bind(RHSId)), - unless(hasRHS(hasDescendant(boolLiteral())))), + binaryOperator( + isExpansionInMainFile(), hasOperatorName(OperatorName), + hasLHS(allOf(expr().bind(LHSId), + cxxBoolLiteral(equals(Value)).bind(BooleanId))), + hasRHS(expr().bind(RHSId)), + unless(hasRHS(hasDescendant(cxxBoolLiteral())))), this); } @@ -284,9 +286,10 @@ void SimplifyBooleanExprCheck::matchExprBinOpBool(MatchFinder *Finder, binaryOperator( isExpansionInMainFile(), hasOperatorName(OperatorName), hasLHS(expr().bind(LHSId)), - unless(hasLHS(anyOf(boolLiteral(), hasDescendant(boolLiteral())))), + unless( + hasLHS(anyOf(cxxBoolLiteral(), hasDescendant(cxxBoolLiteral())))), hasRHS(allOf(expr().bind(RHSId), - boolLiteral(equals(Value)).bind(BooleanId)))), + cxxBoolLiteral(equals(Value)).bind(BooleanId)))), this); } @@ -297,10 +300,10 @@ void SimplifyBooleanExprCheck::matchBoolCompOpExpr(MatchFinder *Finder, Finder->addMatcher( binaryOperator(isExpansionInMainFile(), hasOperatorName(OperatorName), hasLHS(allOf(expr().bind(LHSId), - ignoringImpCasts(boolLiteral(equals(Value)) + ignoringImpCasts(cxxBoolLiteral(equals(Value)) .bind(BooleanId)))), hasRHS(expr().bind(RHSId)), - unless(hasRHS(hasDescendant(boolLiteral())))), + unless(hasRHS(hasDescendant(cxxBoolLiteral())))), this); } @@ -310,10 +313,10 @@ void SimplifyBooleanExprCheck::matchExprCompOpBool(MatchFinder *Finder, StringRef BooleanId) { Finder->addMatcher( binaryOperator(isExpansionInMainFile(), hasOperatorName(OperatorName), - unless(hasLHS(hasDescendant(boolLiteral()))), + unless(hasLHS(hasDescendant(cxxBoolLiteral()))), hasLHS(expr().bind(LHSId)), hasRHS(allOf(expr().bind(RHSId), - ignoringImpCasts(boolLiteral(equals(Value)) + ignoringImpCasts(cxxBoolLiteral(equals(Value)) .bind(BooleanId))))), this); } @@ -323,7 +326,7 @@ void SimplifyBooleanExprCheck::matchBoolCondition(MatchFinder *Finder, StringRef BooleanId) { Finder->addMatcher( ifStmt(isExpansionInMainFile(), - hasCondition(boolLiteral(equals(Value)).bind(BooleanId))) + hasCondition(cxxBoolLiteral(equals(Value)).bind(BooleanId))) .bind(IfStmtId), this); } @@ -333,8 +336,8 @@ void SimplifyBooleanExprCheck::matchTernaryResult(MatchFinder *Finder, StringRef TernaryId) { Finder->addMatcher( conditionalOperator(isExpansionInMainFile(), - hasTrueExpression(boolLiteral(equals(Value))), - hasFalseExpression(boolLiteral(equals(!Value)))) + hasTrueExpression(cxxBoolLiteral(equals(Value))), + hasFalseExpression(cxxBoolLiteral(equals(!Value)))) .bind(TernaryId), this); } @@ -363,13 +366,13 @@ void SimplifyBooleanExprCheck::matchIfAssignsBool(MatchFinder *Finder, hasOperatorName("="), hasLHS(declRefExpr(hasDeclaration(decl().bind(IfAssignObjId)))), hasLHS(expr().bind(IfAssignVariableId)), - hasRHS(boolLiteral(equals(Value)).bind(IfAssignLocId))); + hasRHS(cxxBoolLiteral(equals(Value)).bind(IfAssignLocId))); auto Then = anyOf(SimpleThen, compoundStmt(statementCountIs(1), hasAnySubstatement(SimpleThen))); auto SimpleElse = binaryOperator( hasOperatorName("="), hasLHS(declRefExpr(hasDeclaration(equalsBoundNode(IfAssignObjId)))), - hasRHS(boolLiteral(equals(!Value)))); + hasRHS(cxxBoolLiteral(equals(!Value)))); auto Else = anyOf(SimpleElse, compoundStmt(statementCountIs(1), hasAnySubstatement(SimpleElse))); if (ChainedConditionalAssignment) { @@ -389,11 +392,11 @@ void SimplifyBooleanExprCheck::matchCompoundIfReturnsBool(MatchFinder *Finder, bool Value, StringRef Id) { Finder->addMatcher( - compoundStmt( - allOf(hasAnySubstatement(ifStmt(hasThen(returnsBool(Value)), - unless(hasElse(stmt())))), - hasAnySubstatement(returnStmt(has(boolLiteral(equals(!Value)))) - .bind(CompoundReturnId)))) + compoundStmt(allOf(hasAnySubstatement(ifStmt(hasThen(returnsBool(Value)), + unless(hasElse(stmt())))), + hasAnySubstatement( + returnStmt(has(cxxBoolLiteral(equals(!Value)))) + .bind(CompoundReturnId)))) .bind(Id), this); }