[clang-tidy] Lift common matchers to utils namespace
Summary: This patch is lifting matchers used by more than one checkers to the common namespace. Reviewers: aaron.ballman, alexfh Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D19841 llvm-svn: 269804
This commit is contained in:
parent
de96f39392
commit
e15ef2f609
|
@ -15,14 +15,6 @@ namespace clang {
|
|||
namespace tidy {
|
||||
namespace misc {
|
||||
|
||||
namespace {
|
||||
|
||||
AST_MATCHER(CastExpr, isPointerToBoolean) {
|
||||
return Node.getCastKind() == CK_PointerToBoolean;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void BoolPointerImplicitConversionCheck::registerMatchers(MatchFinder *Finder) {
|
||||
// Look for ifs that have an implicit bool* to bool conversion in the
|
||||
// condition. Filter negations.
|
||||
|
@ -32,7 +24,7 @@ void BoolPointerImplicitConversionCheck::registerMatchers(MatchFinder *Finder) {
|
|||
hasSourceExpression(expr(
|
||||
hasType(pointerType(pointee(booleanType()))),
|
||||
ignoringParenImpCasts(declRefExpr().bind("expr")))),
|
||||
isPointerToBoolean())))),
|
||||
hasCastKind(CK_PointerToBoolean))))),
|
||||
unless(isInTemplateInstantiation())).bind("if"),
|
||||
this);
|
||||
}
|
||||
|
|
|
@ -24,20 +24,6 @@ namespace {
|
|||
|
||||
const char CastSequence[] = "sequence";
|
||||
|
||||
/// \brief Matches cast expressions that have a cast kind of CK_NullToPointer
|
||||
/// or CK_NullToMemberPointer.
|
||||
///
|
||||
/// Given
|
||||
/// \code
|
||||
/// int *p = 0;
|
||||
/// \endcode
|
||||
/// implicitCastExpr(isNullToPointer()) matches the implicit cast clang adds
|
||||
/// around \c 0.
|
||||
AST_MATCHER(CastExpr, isNullToPointer) {
|
||||
return Node.getCastKind() == CK_NullToPointer ||
|
||||
Node.getCastKind() == CK_NullToMemberPointer;
|
||||
}
|
||||
|
||||
AST_MATCHER(Type, sugaredNullptrType) {
|
||||
const Type *DesugaredType = Node.getUnqualifiedDesugaredType();
|
||||
if (const BuiltinType *BT = dyn_cast<BuiltinType>(DesugaredType))
|
||||
|
@ -52,7 +38,8 @@ AST_MATCHER(Type, sugaredNullptrType) {
|
|||
/// can be replaced instead of just the inner-most implicit cast.
|
||||
StatementMatcher makeCastSequenceMatcher() {
|
||||
StatementMatcher ImplicitCastToNull = implicitCastExpr(
|
||||
isNullToPointer(),
|
||||
anyOf(hasCastKind(CK_NullToPointer),
|
||||
hasCastKind(CK_NullToMemberPointer)),
|
||||
unless(hasSourceExpression(hasType(sugaredNullptrType()))));
|
||||
|
||||
return castExpr(anyOf(ImplicitCastToNull,
|
||||
|
|
|
@ -38,8 +38,6 @@ llvm::Optional<std::string> MakeCharacterLiteral(const StringLiteral *Literal) {
|
|||
return Result;
|
||||
}
|
||||
|
||||
AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
|
||||
|
||||
AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<Expr>,
|
||||
hasSubstitutedType) {
|
||||
return hasType(qualType(anyOf(substTemplateTypeParmType(),
|
||||
|
@ -65,7 +63,7 @@ void FasterStringFindCheck::registerMatchers(MatchFinder *Finder) {
|
|||
return;
|
||||
|
||||
const auto SingleChar =
|
||||
expr(ignoringParenCasts(stringLiteral(lengthIsOne()).bind("literal")));
|
||||
expr(ignoringParenCasts(stringLiteral(hasSize(1)).bind("literal")));
|
||||
|
||||
const auto StringFindFunctions =
|
||||
anyOf(hasName("find"), hasName("rfind"), hasName("find_first_of"),
|
||||
|
|
|
@ -20,10 +20,6 @@ namespace readability {
|
|||
|
||||
namespace {
|
||||
|
||||
AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
|
||||
return Node.getCastKind() == Kind;
|
||||
}
|
||||
|
||||
AST_MATCHER(Stmt, isMacroExpansion) {
|
||||
SourceManager &SM = Finder->getASTContext().getSourceManager();
|
||||
SourceLocation Loc = Node.getLocStart();
|
||||
|
|
|
@ -8,25 +8,16 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "RedundantStringInitCheck.h"
|
||||
#include "../utils/Matchers.h"
|
||||
#include "clang/ASTMatchers/ASTMatchers.h"
|
||||
|
||||
using namespace clang::ast_matchers;
|
||||
using namespace clang::tidy::matchers;
|
||||
|
||||
namespace clang {
|
||||
namespace tidy {
|
||||
namespace readability {
|
||||
|
||||
namespace {
|
||||
|
||||
AST_MATCHER(StringLiteral, lengthIsZero) { return Node.getLength() == 0; }
|
||||
|
||||
AST_MATCHER_P(Expr, ignoringImplicit,
|
||||
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
|
||||
return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
|
||||
if (!getLangOpts().CPlusPlus)
|
||||
return;
|
||||
|
@ -45,7 +36,7 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
|
|||
const auto EmptyStringCtorExpr =
|
||||
cxxConstructExpr(StringConstructorExpr,
|
||||
hasArgument(0, ignoringParenImpCasts(
|
||||
stringLiteral(lengthIsZero()))));
|
||||
stringLiteral(hasSize(0)))));
|
||||
|
||||
const auto EmptyStringCtorExprWithTemporaries =
|
||||
expr(ignoringImplicit(
|
||||
|
|
|
@ -17,6 +17,11 @@ namespace clang {
|
|||
namespace tidy {
|
||||
namespace matchers {
|
||||
|
||||
AST_MATCHER_P(Expr, ignoringImplicit,
|
||||
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
|
||||
return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
|
||||
}
|
||||
|
||||
AST_MATCHER(BinaryOperator, isRelationalOperator) {
|
||||
return Node.isRelationalOp();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue