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
This commit is contained in:
Aaron Ballman 2015-09-17 13:31:25 +00:00
Родитель eae921a68c
Коммит 61bf08cac6
31 изменённых файлов: 207 добавлений и 187 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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<VarDecl> 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,10 +304,9 @@ StatementMatcher makePseudoArrayLoopMatcher() {
)
);
StatementMatcher SizeCallMatcher =
memberCallExpr(argumentCountIs(0),
callee(methodDecl(anyOf(hasName("size"),
hasName("length")))),
StatementMatcher SizeCallMatcher = cxxMemberCallExpr(
argumentCountIs(0),
callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))),
on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
hasType(RecordWithBeginEnd))));

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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)));

Просмотреть файл

@ -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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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"),
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);

Просмотреть файл

@ -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<std::pair<SourceLocation, StringRef>>

Просмотреть файл

@ -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())),
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);
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -25,15 +25,15 @@ void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
return;
const auto CheckForEndCall = hasArgument(
1,
anyOf(constructExpr(has(memberCallExpr(callee(methodDecl(hasName("end"))))
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)

Просмотреть файл

@ -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")),

Просмотреть файл

@ -23,14 +23,16 @@ void MoveConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
return;
Finder->addMatcher(
constructorDecl(unless(isImplicit()), allOf(
isMoveConstructor(),
cxxConstructorDecl(
unless(isImplicit()),
allOf(isMoveConstructor(),
hasAnyConstructorInitializer(
ctorInitializer(withInitializer(constructExpr(hasDeclaration(
constructorDecl(isCopyConstructor()).bind("ctor")
)))).bind("init")
)
)), this);
cxxCtorInitializer(
withInitializer(cxxConstructExpr(hasDeclaration(
cxxConstructorDecl(isCopyConstructor())
.bind("ctor")))))
.bind("init")))),
this);
}
void MoveConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {

Просмотреть файл

@ -23,7 +23,7 @@ void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
return;
Finder->addMatcher(
methodDecl(anyOf(constructorDecl(), hasOverloadedOperatorName("=")),
cxxMethodDecl(anyOf(cxxConstructorDecl(), hasOverloadedOperatorName("=")),
unless(isImplicit()), unless(isDeleted()))
.bind("decl"),
this);

Просмотреть файл

@ -19,10 +19,11 @@ namespace tidy {
void SizeofContainerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
expr(unless(isInTemplateInstantiation()),
expr(sizeOfExpr(has(expr(hasType(hasCanonicalType(hasDeclaration(
recordDecl(matchesName("^(::std::|::string)"),
expr(sizeOfExpr(has(
expr(hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl(
matchesName("^(::std::|::string)"),
unless(matchesName("^::std::(bitset|array)$")),
hasMethod(methodDecl(hasName("size"), isPublic(),
hasMethod(cxxMethodDecl(hasName("size"), isPublic(),
isConst()))))))))))
.bind("sizeof"),
// Ignore ARRAYSIZE(<array of containers>) pattern.

Просмотреть файл

@ -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")));

Просмотреть файл

@ -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);

Просмотреть файл

@ -24,17 +24,18 @@ 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"),
callee(
cxxMethodDecl(hasName("reset"),
ofClass(cxxRecordDecl(hasName("::std::unique_ptr"),
decl().bind("left_class"))))),
has(memberCallExpr(
has(cxxMemberCallExpr(
on(expr().bind("right")),
callee(memberExpr().bind("release_member")),
callee(methodDecl(
callee(cxxMethodDecl(
hasName("release"),
ofClass(recordDecl(hasName("::std::unique_ptr"),
ofClass(cxxRecordDecl(hasName("::std::unique_ptr"),
decl().bind("right_class"))))))))
.bind("reset_call"),
this);

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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,7 +140,7 @@ StatementMatcher makeIteratorLoopMatcher() {
ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ConditionVarName)))));
StatementMatcher OverloadedNEQMatcher =
operatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2),
cxxOperatorCallExpr(hasOverloadedOperatorName("!="), argumentCountIs(2),
hasArgument(0, IteratorComparisonMatcher),
hasArgument(1, IteratorBoundMatcher));
@ -147,7 +148,7 @@ StatementMatcher makeIteratorLoopMatcher() {
// 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"),
hasDeclaration(cxxRecordDecl(
hasMethod(cxxMethodDecl(hasName("begin"), isConst())),
hasMethod(cxxMethodDecl(hasName("end"),
isConst())))) // hasDeclaration
), // qualType
qualType(unless(isConstQualified()),
hasDeclaration(
recordDecl(hasMethod(hasName("begin")),
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))));

Просмотреть файл

@ -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);

Просмотреть файл

@ -130,10 +130,11 @@ DeclarationMatcher makeAutoPtrUsingDeclMatcher() {
/// ~~~~^
/// \endcode
StatementMatcher makeTransferOwnershipExprMatcher() {
return anyOf(operatorCallExpr(allOf(hasOverloadedOperatorName("="),
callee(methodDecl(ofClass(AutoPtrDecl))),
return anyOf(
cxxOperatorCallExpr(allOf(hasOverloadedOperatorName("="),
callee(cxxMethodDecl(ofClass(AutoPtrDecl))),
hasArgument(1, MovableArgumentMatcher))),
constructExpr(allOf(hasType(AutoPtrType), argumentCountIs(1),
cxxConstructExpr(allOf(hasType(AutoPtrType), argumentCountIs(1),
hasArgument(0, MovableArgumentMatcher))));
}

Просмотреть файл

@ -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,8 +54,8 @@ void ShrinkToFitCheck::registerMatchers(MatchFinder *Finder) {
has(declRefExpr(hasDeclaration(equalsBoundNode("ContainerDecl")))))));
Finder->addMatcher(
memberCallExpr(on(hasType(namedDecl(stlShrinkableContainer()))),
callee(methodDecl(hasName("swap"))),
cxxMemberCallExpr(on(hasType(namedDecl(stlShrinkableContainer()))),
callee(cxxMethodDecl(hasName("swap"))),
has(memberExpr(hasDescendant(CopyCtorCall))),
hasArgument(0, SwapParam.bind("ContainerToShrink")),
unless(isInTemplateInstantiation()))

Просмотреть файл

@ -218,9 +218,10 @@ StatementMatcher makeIteratorDeclMatcher() {
}
StatementMatcher makeDeclWithNewMatcher() {
return declStmt(has(varDecl()),
return declStmt(
has(varDecl()),
unless(has(varDecl(anyOf(
unless(hasInitializer(ignoringParenImpCasts(newExpr()))),
unless(hasInitializer(ignoringParenImpCasts(cxxNewExpr()))),
// FIXME: TypeLoc information is not reliable where CV
// qualifiers are concerned so these types can't be
// handled for now.

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -19,23 +19,25 @@ namespace readability {
namespace {
internal::Matcher<Expr> callToGet(internal::Matcher<Decl> 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->"),
has(cxxMethodDecl(hasName("operator->"),
returns(qualType(pointsTo(type().bind("op->Type")))))),
has(methodDecl(hasName("operator*"),
has(cxxMethodDecl(hasName("operator*"),
returns(qualType(references(type().bind("op*Type")))))),
has(methodDecl(hasName("get"),
has(cxxMethodDecl(hasName("get"),
returns(qualType(pointsTo(type().bind("getType")))))));
// Catch 'ptr.get()->Foo()'
@ -63,8 +65,9 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
// Matches against nullptr.
Finder->addMatcher(
binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!=")),
hasEitherOperand(ignoringImpCasts(nullPtrLiteralExpr())),
binaryOperator(
anyOf(hasOperatorName("=="), hasOperatorName("!=")),
hasEitherOperand(ignoringImpCasts(cxxNullPtrLiteralExpr())),
hasEitherOperand(callToGet(IsAKnownSmartptr))),
Callback);
// TODO: Catch ptr.get() == other_ptr.get()

Просмотреть файл

@ -86,29 +86,30 @@ 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"),
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()
@ -116,10 +117,11 @@ void RedundantStringCStrCheck::registerMatchers(
// 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);
}

Просмотреть файл

@ -75,7 +75,8 @@ const CXXBoolLiteralExpr *getBoolLiteral(const MatchFinder::MatchResult &Result,
internal::Matcher<Stmt> 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),
binaryOperator(
isExpansionInMainFile(), hasOperatorName(OperatorName),
hasLHS(allOf(expr().bind(LHSId),
boolLiteral(equals(Value)).bind(BooleanId))),
cxxBoolLiteral(equals(Value)).bind(BooleanId))),
hasRHS(expr().bind(RHSId)),
unless(hasRHS(hasDescendant(boolLiteral())))),
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,10 +392,10 @@ void SimplifyBooleanExprCheck::matchCompoundIfReturnsBool(MatchFinder *Finder,
bool Value,
StringRef Id) {
Finder->addMatcher(
compoundStmt(
allOf(hasAnySubstatement(ifStmt(hasThen(returnsBool(Value)),
compoundStmt(allOf(hasAnySubstatement(ifStmt(hasThen(returnsBool(Value)),
unless(hasElse(stmt())))),
hasAnySubstatement(returnStmt(has(boolLiteral(equals(!Value))))
hasAnySubstatement(
returnStmt(has(cxxBoolLiteral(equals(!Value))))
.bind(CompoundReturnId))))
.bind(Id),
this);