9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
13#include "clang/AST/ExprConcepts.h"
14#include "clang/ASTMatchers/ASTMatchers.h"
20 return Node.isRelationalOp();
26 std::optional<bool> IsExpensive =
28 return IsExpensive && *IsExpensive;
33 Node, Finder->getASTContext());
42 using namespace ast_matchers;
43 return referenceType(pointee(qualType(isConstQualified())));
48 using namespace ast_matchers;
49 return pointerType(pointee(qualType(isConstQualified())));
54 const auto ActualType =
Node.getTypePtr();
56 (ActualType->isSpecificBuiltinType(BuiltinType::Char_S) ||
57 ActualType->isSpecificBuiltinType(BuiltinType::Char_U));
61 if (isa<CXXNoexceptExpr>(
Node) || isa<RequiresExpr>(
Node))
63 if (
const auto *UnaryExpr = dyn_cast<UnaryExprOrTypeTraitExpr>(&
Node)) {
64 switch (UnaryExpr->getKind()) {
72 if (
const auto *TypeIDExpr = dyn_cast<CXXTypeidExpr>(&
Node))
73 return !TypeIDExpr->isPotentiallyEvaluated();
85 NameList.begin(), NameList.end(), std::back_inserter(NameMatchers),
86 [](
const llvm::StringRef
Name) { return NameMatcher(Name); });
89 const NamedDecl &Node, ast_matchers::internal::ASTMatchFinder *Finder,
90 ast_matchers::internal::BoundNodesTreeBuilder *
Builder)
const override {
91 return llvm::any_of(NameMatchers, [&
Node](
const NameMatcher &NM) {
92 return NM.match(
Node);
99 enum class MatchMode {
113 NameMatcher(
const llvm::StringRef Regex)
114 : Regex(Regex), Mode(determineMatchMode(Regex)) {}
116 bool match(
const NamedDecl &ND)
const {
118 case MatchMode::MatchQualified:
119 return Regex.match(ND.getQualifiedNameAsString());
120 case MatchMode::MatchFullyQualified:
121 return Regex.match(
"::" + ND.getQualifiedNameAsString());
123 if (
const IdentifierInfo *II = ND.getIdentifier())
124 return Regex.match(II->getName());
130 MatchMode determineMatchMode(llvm::StringRef Regex) {
131 if (Regex.starts_with(
":") || Regex.starts_with(
"^:")) {
132 return MatchMode::MatchFullyQualified;
134 return Regex.contains(
":") ? MatchMode::MatchQualified
135 : MatchMode::MatchUnqualified;
139 std::vector<NameMatcher> NameMatchers;
145inline ::clang::ast_matchers::internal::Matcher<NamedDecl>
147 return ::clang::ast_matchers::internal::makeMatcher(
154 operator()(
const clang::ast_matchers::internal::BoundNodesMap &Nodes)
const;
165 ID, ::clang::DynTypedNode::create(
Node), &(Finder->getASTContext())};
166 return Builder->removeBindings(Predicate);
177 const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
178 ast_matchers::internal::BoundNodesTreeBuilder *
Builder)
const override;
181 std::vector<llvm::Regex> NameMatchers;
185inline ::clang::ast_matchers::internal::Matcher<QualType>
187 return ::clang::ast_matchers::internal::makeMatcher(
llvm::SmallString< 256U > Name
CodeCompletionBuilder Builder
::clang::DynTypedNode Node
MatchesAnyListedNameMatcher(llvm::ArrayRef< StringRef > NameList)
bool matches(const NamedDecl &Node, ast_matchers::internal::ASTMatchFinder *Finder, ast_matchers::internal::BoundNodesTreeBuilder *Builder) const override
~MatchesAnyListedTypeNameMatcher() override
bool matches(const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder, ast_matchers::internal::BoundNodesTreeBuilder *Builder) const override
AST_MATCHER_P(Stmt, isStatementIdenticalToBoundNode, std::string, ID)
AST_MATCHER(BinaryOperator, isRelationalOperator)
AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst)
inline ::clang::ast_matchers::internal::Matcher< NamedDecl > matchesAnyListedName(llvm::ArrayRef< StringRef > NameList)
inline ::clang::ast_matchers::internal::Matcher< QualType > matchesAnyListedTypeName(llvm::ArrayRef< StringRef > NameList)
bool recordIsTriviallyDefaultConstructible(const RecordDecl &RecordDecl, const ASTContext &Context)
Returns true if RecordDecl is trivially default constructible.
std::optional< bool > isExpensiveToCopy(QualType Type, const ASTContext &Context)
Returns true if Type is expensive to copy.
bool isTriviallyDestructible(QualType Type)
Returns true if Type is trivially destructible.
bool operator()(const clang::ast_matchers::internal::BoundNodesMap &Nodes) const
::clang::DynTypedNode Node