diff options
author | Piotr Zegar <me@piotrzegar.pl> | 2024-03-31 14:34:25 +0000 |
---|---|---|
committer | Piotr Zegar <me@piotrzegar.pl> | 2024-03-31 14:58:27 +0000 |
commit | b6f6be4b500ff64c23a5103ac3311cb74519542f (patch) | |
tree | 68d134e3d3867627eb133d5a8a859a2b5202f689 /clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp | |
parent | d12e45ad16a62f7d3ff20b90863f42c9ddb0e624 (diff) | |
download | llvm-b6f6be4b500ff64c23a5103ac3311cb74519542f.zip llvm-b6f6be4b500ff64c23a5103ac3311cb74519542f.tar.gz llvm-b6f6be4b500ff64c23a5103ac3311cb74519542f.tar.bz2 |
[clang-tidy][NFC] Remove duplicated code
Remove duplicated matchers by moving some of them to
utils/Matchers.h. Add some anonymous namespaces and
renamed some code to avoid ODR issues.
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp index 1284df6..5b1bf01 100644 --- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp +++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "ConvertMemberFunctionsToStatic.h" +#include "../utils/Matchers.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/RecursiveASTVisitor.h" @@ -18,40 +19,12 @@ using namespace clang::ast_matchers; namespace clang::tidy::readability { -AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); } - -AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); } +namespace { AST_MATCHER(CXXMethodDecl, isOverloadedOperator) { return Node.isOverloadedOperator(); } -AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) { - return Node.hasAnyDependentBases(); -} - -AST_MATCHER(CXXMethodDecl, isTemplate) { - return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate; -} - -AST_MATCHER(CXXMethodDecl, isDependentContext) { - return Node.isDependentContext(); -} - -AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) { - const ASTContext &Ctxt = Finder->getASTContext(); - return clang::Lexer::makeFileCharRange( - clang::CharSourceRange::getCharRange( - Node.getTypeSourceInfo()->getTypeLoc().getSourceRange()), - Ctxt.getSourceManager(), Ctxt.getLangOpts()) - .isInvalid(); -} - -AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl, - ast_matchers::internal::Matcher<CXXMethodDecl>, InnerMatcher) { - return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder); -} - AST_MATCHER(CXXMethodDecl, usesThis) { class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> { public: @@ -74,22 +47,27 @@ AST_MATCHER(CXXMethodDecl, usesThis) { return UsageOfThis.Used; } +} // namespace + void ConvertMemberFunctionsToStatic::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( cxxMethodDecl( isDefinition(), isUserProvided(), unless(anyOf( - isExpansionInSystemHeader(), isVirtual(), isStatic(), - hasTrivialBody(), isOverloadedOperator(), cxxConstructorDecl(), - cxxDestructorDecl(), cxxConversionDecl(), isTemplate(), - isDependentContext(), + isExpansionInSystemHeader(), isVirtual(), + matchers::isStaticMethod(), matchers::hasTrivialBody(), + isOverloadedOperator(), cxxConstructorDecl(), cxxDestructorDecl(), + cxxConversionDecl(), matchers::isTemplate(), + matchers::isDependentContext(), ofClass(anyOf( isLambda(), - hasAnyDependentBases()) // Method might become virtual - // depending on template base class. + matchers::hasAnyDependentBases()) // Method might become + // virtual depending on + // template base class. ), - isInsideMacroDefinition(), - hasCanonicalDecl(isInsideMacroDefinition()), usesThis()))) + matchers::isInsideMacroDefinition(), + matchers::hasCanonicalDecl(matchers::isInsideMacroDefinition()), + usesThis()))) .bind("x"), this); } |