clang-tools  3.9.0
Matchers.h
Go to the documentation of this file.
1 //===--- Matchers.h - clang-tidy-------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
12 
13 #include "clang/ASTMatchers/ASTMatchers.h"
14 #include "TypeTraits.h"
15 
16 namespace clang {
17 namespace tidy {
18 namespace matchers {
19 
20 AST_MATCHER(BinaryOperator, isRelationalOperator) {
21  return Node.isRelationalOp();
22 }
23 
24 AST_MATCHER(BinaryOperator, isEqualityOperator) {
25  return Node.isEqualityOp();
26 }
27 
28 AST_MATCHER(BinaryOperator, isComparisonOperator) {
29  return Node.isComparisonOp();
30 }
31 
33  llvm::Optional<bool> IsExpensive =
34  utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext());
35  return IsExpensive && *IsExpensive;
36 }
37 
40  Node, Finder->getASTContext());
41 }
42 
43 // Returns QualType matcher for references to const.
44 AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst) {
45  using namespace ast_matchers;
46  return referenceType(pointee(qualType(isConstQualified())));
47 }
48 
49 } // namespace matchers
50 } // namespace tidy
51 } // namespace clang
52 
53 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:210
AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst)
Definition: Matchers.h:44
bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl, const ASTContext &Context)
Returns true if RecordDecl is trivially default constructible.
Definition: TypeTraits.cpp:51
llvm::Optional< bool > isExpensiveToCopy(QualType Type, const ASTContext &Context)
Returns true if Type is expensive to copy.
Definition: TypeTraits.cpp:42
bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context)
Returns true if Type is trivially default constructible.
Definition: TypeTraits.cpp:80
AST_MATCHER(BinaryOperator, isRelationalOperator)
Definition: Matchers.h:20