Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===--- Matchers.h - clang-tidy-------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H |
| 11 | |
| 12 | #include "TypeTraits.h" |
| 13 | #include "clang/ASTMatchers/ASTMatchers.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
| 17 | namespace matchers { |
| 18 | |
| 19 | AST_MATCHER(BinaryOperator, isRelationalOperator) { |
| 20 | return Node.isRelationalOp(); |
| 21 | } |
| 22 | |
| 23 | AST_MATCHER(BinaryOperator, isEqualityOperator) { return Node.isEqualityOp(); } |
| 24 | |
| 25 | AST_MATCHER(QualType, isExpensiveToCopy) { |
| 26 | llvm::Optional<bool> IsExpensive = |
| 27 | utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext()); |
| 28 | return IsExpensive && *IsExpensive; |
| 29 | } |
| 30 | |
| 31 | AST_MATCHER(RecordDecl, isTriviallyDefaultConstructible) { |
| 32 | return utils::type_traits::recordIsTriviallyDefaultConstructible( |
| 33 | Node, Finder->getASTContext()); |
| 34 | } |
| 35 | |
| 36 | AST_MATCHER(QualType, isTriviallyDestructible) { |
| 37 | return utils::type_traits::isTriviallyDestructible(Node); |
| 38 | } |
| 39 | |
| 40 | // Returns QualType matcher for references to const. |
| 41 | AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst) { |
| 42 | using namespace ast_matchers; |
| 43 | return referenceType(pointee(qualType(isConstQualified()))); |
| 44 | } |
| 45 | |
| 46 | // Returns QualType matcher for pointers to const. |
| 47 | AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isPointerToConst) { |
| 48 | using namespace ast_matchers; |
| 49 | return pointerType(pointee(qualType(isConstQualified()))); |
| 50 | } |
| 51 | |
| 52 | AST_MATCHER_P(NamedDecl, matchesAnyListedName, std::vector<std::string>, |
| 53 | NameList) { |
| 54 | return llvm::any_of(NameList, [&Node](const std::string &Name) { |
| 55 | return llvm::Regex(Name).match(Node.getName()); |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | } // namespace matchers |
| 60 | } // namespace tidy |
| 61 | } // namespace clang |
| 62 | |
| 63 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H |