diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-09-17 13:31:25 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-09-17 13:31:25 +0000 |
commit | b9ea09c4451cb8f33ffd41d22b7dd10e8a68c5c8 (patch) | |
tree | 362e33db9c2d4fb7ab5fc96172386893a7d50b10 /clang-tools-extra/clang-tidy/modernize | |
parent | 512fb64765c7d61e89531b8ff697a85d815d9a13 (diff) | |
download | bcm5719-llvm-b9ea09c4451cb8f33ffd41d22b7dd10e8a68c5c8.tar.gz bcm5719-llvm-b9ea09c4451cb8f33ffd41d22b7dd10e8a68c5c8.zip |
Refactors AST matching code to use the new AST matcher names. This patch correlates to r247885 which performs the AST matcher rename in Clang.
llvm-svn: 247886
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize')
6 files changed, 51 insertions, 48 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index 73d93e33ce0..15ca113f6da 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/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<VarDecl> 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-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp index 0cbb606d09a..3b12c594a63 100644 --- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp +++ b/clang-tools-extra/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-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp index 4da3efb9888..c6d6fcc2e2c 100644 --- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp +++ b/clang-tools-extra/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-tools-extra/clang-tidy/modernize/ShrinkToFitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ShrinkToFitCheck.cpp index c5e9e5ea68f..60b9843b94a 100644 --- a/clang-tools-extra/clang-tidy/modernize/ShrinkToFitCheck.cpp +++ b/clang-tools-extra/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-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp index 339bc3c2569..a9405471d29 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp +++ b/clang-tools-extra/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())))), - - // 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())))))))))) + 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())))))))))) .bind(DeclWithNewId); } diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp index e506e834d9a..a335748301c 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp +++ b/clang-tools-extra/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 |