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); });
91 enum class MatchMode {
106 : Regex(Regex), Mode(determineMatchMode(Regex)) {}
108 bool match(
const NamedDecl &ND)
const {
110 case MatchMode::MatchQualified:
111 return Regex.match(ND.getQualifiedNameAsString());
112 case MatchMode::MatchFullyQualified:
113 return Regex.match(
"::" + ND.getQualifiedNameAsString());
115 if (
const IdentifierInfo *II = ND.getIdentifier())
116 return Regex.match(II->getName());
122 MatchMode determineMatchMode(llvm::StringRef Regex) {
123 if (Regex.starts_with(
":") || Regex.starts_with(
"^:")) {
124 return MatchMode::MatchFullyQualified;
126 return Regex.contains(
":") ? MatchMode::MatchQualified
127 : MatchMode::MatchUnqualified;
132 const NamedDecl &Node, ast_matchers::internal::ASTMatchFinder *Finder,
133 ast_matchers::internal::BoundNodesTreeBuilder *
Builder)
const override {
140 std::vector<NameMatcher> NameMatchers;
146inline ::clang::ast_matchers::internal::Matcher<NamedDecl>
148 return ::clang::ast_matchers::internal::makeMatcher(
155 operator()(
const clang::ast_matchers::internal::BoundNodesMap &Nodes)
const;
166 ID, ::clang::DynTypedNode::create(
Node), &(Finder->getASTContext())};
167 return Builder->removeBindings(Predicate);
178 const QualType &Node, ast_matchers::internal::ASTMatchFinder *Finder,
179 ast_matchers::internal::BoundNodesTreeBuilder *
Builder)
const override;
182 std::vector<llvm::Regex> NameMatchers;
186inline ::clang::ast_matchers::internal::Matcher<QualType>
188 return ::clang::ast_matchers::internal::makeMatcher(
llvm::SmallString< 256U > Name
CodeCompletionBuilder Builder
::clang::DynTypedNode Node
bool match(const NamedDecl &ND) const
NameMatcher(const llvm::StringRef Regex)
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