clang-tools 10.0.0

clang-tidy/utils/Matchers.h
Go to the documentation of this file.
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, isAssignmentOperator) {
20 return Node.isAssignmentOp();
21 }
22
23 AST_MATCHER(BinaryOperator, isRelationalOperator) {
24 return Node.isRelationalOp();
25 }
26
27 AST_MATCHER(BinaryOperator, isEqualityOperator) { return Node.isEqualityOp(); }
28
29 AST_MATCHER(BinaryOperator, isComparisonOperator) {
30 return Node.isComparisonOp();
31 }
32
33 AST_MATCHER(QualType, isExpensiveToCopy) {
34 llvm::Optional<bool> IsExpensive =
35 utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext());
36 return IsExpensive && *IsExpensive;
37 }
38
39 AST_MATCHER(RecordDecl, isTriviallyDefaultConstructible) {
40 return utils::type_traits::recordIsTriviallyDefaultConstructible(
41 Node, Finder->getASTContext());
42 }
43
44 AST_MATCHER(QualType, isTriviallyDestructible) {
45 return utils::type_traits::isTriviallyDestructible(Node);
46 }
47
48 // Returns QualType matcher for references to const.
49 AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst) {
50 using namespace ast_matchers;
51 return referenceType(pointee(qualType(isConstQualified())));
52 }
53
54 AST_MATCHER_P(NamedDecl, matchesAnyListedName, std::vector<std::string>,
55 NameList) {
56 return llvm::any_of(NameList, [&Node](const std::string &Name) {
57 return llvm::Regex(Name).match(Node.getName());
58 });
59 }
60
61 } // namespace matchers
62 } // namespace tidy
63 } // namespace clang
64
65 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
clang::tidy::matchers::AST_MATCHER
AST_MATCHER(BinaryOperator, isAssignmentOperator)
Definition: clang-tidy/utils/Matchers.h:19
TypeTraits.h
clang::tidy::matchers::AST_MATCHER_FUNCTION
AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst)
Definition: clang-tidy/utils/Matchers.h:49
clang::tidy::utils::type_traits::recordIsTriviallyDefaultConstructible
bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl, const ASTContext &Context)
Returns true if RecordDecl is trivially default constructible.
Definition: TypeTraits.cpp:51
clang::tidy::utils::type_traits::isExpensiveToCopy
llvm::Optional< bool > isExpensiveToCopy(QualType Type, const ASTContext &Context)
Returns true if Type is expensive to copy.
Definition: TypeTraits.cpp:41
clang::tidy::utils::type_traits::isTriviallyDefaultConstructible
bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context)
Returns true if Type is trivially default constructible.
Definition: TypeTraits.cpp:92
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::matchers::AST_MATCHER_P
AST_MATCHER_P(NamedDecl, matchesAnyListedName, std::vector< std::string >, NameList)
Definition: clang-tidy/utils/Matchers.h:54
clang::tidy::utils::type_traits::isTriviallyDestructible
bool isTriviallyDestructible(QualType Type)
Returns true if Type is trivially destructible.
Definition: TypeTraits.cpp:139