44#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
45#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
82#include "llvm/ADT/ArrayRef.h"
83#include "llvm/ADT/SmallVector.h"
84#include "llvm/ADT/StringExtras.h"
85#include "llvm/ADT/StringRef.h"
86#include "llvm/Support/Casting.h"
87#include "llvm/Support/Compiler.h"
88#include "llvm/Support/ErrorHandling.h"
89#include "llvm/Support/Regex.h"
100namespace ast_matchers {
115 template <
typename T>
117 return MyBoundNodes.getNodeAs<
T>(
ID);
127 return MyBoundNodes.getMap();
134 BoundNodes(internal::BoundNodesMap &MyBoundNodes)
135 : MyBoundNodes(MyBoundNodes) {}
137 internal::BoundNodesMap MyBoundNodes;
171inline internal::TrueMatcher
anything() {
return internal::TrueMatcher(); }
184extern const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl>
196extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl>
208extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
220extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
230extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl>
249 auto &
SourceManager = Finder->getASTContext().getSourceManager();
270 auto &
SourceManager = Finder->getASTContext().getSourceManager();
272 if (ExpansionLoc.isInvalid()) {
297 auto &
SourceManager = Finder->getASTContext().getSourceManager();
299 if (ExpansionLoc.isInvalid()) {
318 std::string, MacroName) {
321 auto& Context = Finder->getASTContext();
322 std::optional<SourceLocation> B =
324 if (!B)
return false;
325 std::optional<SourceLocation>
E =
327 if (!
E)
return false;
340extern const internal::VariadicAllOfMatcher<Decl>
decl;
352extern const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl>
362extern const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl>
373extern const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl>
387extern const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl>
namedDecl;
398extern const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl>
labelDecl;
409extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl>
421extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
433extern const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl>
recordDecl;
442extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl>
451extern const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl>
464extern const internal::VariadicDynCastAllOfMatcher<
483extern const internal::VariadicDynCastAllOfMatcher<
496extern const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl>
507extern const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl>
521extern const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl>
531extern const internal::VariadicAllOfMatcher<CXXBaseSpecifier>
cxxBaseSpecifier;
542extern const internal::VariadicAllOfMatcher<CXXCtorInitializer>
554extern const internal::VariadicAllOfMatcher<TemplateArgument>
templateArgument;
565extern const internal::VariadicAllOfMatcher<TemplateArgumentLoc>
577extern const internal::VariadicAllOfMatcher<TemplateName>
templateName;
587extern const internal::VariadicDynCastAllOfMatcher<
Decl,
599extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
610extern const internal::VariadicDynCastAllOfMatcher<
Decl,
694 return Node.isBitField();
711 return Node.isBitField() &&
712 Node.getBitWidthValue(Finder->getASTContext()) == Width;
733 InnerMatcher.matches(*
Initializer, Finder, Builder));
739 return Node.isMain();
753 internal::Matcher<ClassTemplateDecl>, InnerMatcher) {
755 return (
Decl !=
nullptr &&
756 InnerMatcher.matches(*
Decl, Finder, Builder));
764 return Node.isImplicit();
789 hasAnyTemplateArgument,
793 internal::Matcher<TemplateArgument>, InnerMatcher) {
795 internal::getTemplateSpecializationArgs(
Node);
796 return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder,
797 Builder) != List.end();
818 const internal::Matcher<T> &InnerMatcher) {
819 return internal::DynTypedMatcher::constructRestrictedWrapper(
820 new internal::TraversalMatcher<T>(TK, InnerMatcher),
821 InnerMatcher.getID().first)
822 .template unconditionalConvertTo<T>();
826internal::BindableMatcher<T>
828 return internal::BindableMatcher<T>(
829 internal::DynTypedMatcher::constructRestrictedWrapper(
830 new internal::TraversalMatcher<T>(TK, InnerMatcher),
831 InnerMatcher.getID().first)
832 .template unconditionalConvertTo<T>());
835template <
typename...
T>
836internal::TraversalWrapper<internal::VariadicOperatorMatcher<
T...>>
838 const internal::VariadicOperatorMatcher<T...> &InnerMatcher) {
839 return internal::TraversalWrapper<internal::VariadicOperatorMatcher<
T...>>(
843template <
template <
typename ToArg,
typename FromArg>
class ArgumentAdapterT,
844 typename T,
typename ToTypes>
845internal::TraversalWrapper<
846 internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>>
848 ArgumentAdapterT,
T, ToTypes> &InnerMatcher) {
849 return internal::TraversalWrapper<
850 internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT,
T,
851 ToTypes>>(TK, InnerMatcher);
854template <
template <
typename T,
typename...
P>
class MatcherT, typename...
P,
855 typename ReturnTypesF>
856internal::TraversalWrapper<
857 internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>>
859 const internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>
861 return internal::TraversalWrapper<
862 internal::PolymorphicMatcher<MatcherT, ReturnTypesF,
P...>>(TK,
866template <
typename...
T>
867internal::Matcher<
typename internal::GetClade<
T...>::Type>
869 return traverse(TK, InnerMatcher.with());
895 return InnerMatcher.matches(*
Node.IgnoreImplicit(), Finder, Builder);
924 internal::Matcher<Expr>, InnerMatcher) {
925 return InnerMatcher.matches(*
Node.IgnoreImpCasts(), Finder, Builder);
946 return InnerMatcher.matches(*
Node.IgnoreParenCasts(), Finder, Builder);
971 internal::Matcher<Expr>, InnerMatcher) {
972 return InnerMatcher.matches(*
Node.IgnoreParenImpCasts(), Finder, Builder);
988 return InnerMatcher.matches(
Node.IgnoreParens(), Finder, Builder);
1005 return InnerMatcher.matches(*
E, Finder, Builder);
1022 return Node.isInstantiationDependent();
1070 hasTemplateArgument,
1074 unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) {
1076 internal::getTemplateSpecializationArgs(
Node);
1077 if (List.size() <= N)
1079 return InnerMatcher.matches(List[N], Finder, Builder);
1092 templateArgumentCountIs,
1096 return internal::getTemplateSpecializationArgs(
Node).size() == N;
1111 internal::Matcher<QualType>, InnerMatcher) {
1114 return InnerMatcher.matches(
Node.getAsType(), Finder, Builder);
1129 internal::Matcher<TemplateName>, InnerMatcher) {
1132 return InnerMatcher.matches(
Node.getAsTemplate(), Finder, Builder);
1149 internal::Matcher<Decl>, InnerMatcher) {
1151 return InnerMatcher.matches(*
Node.getAsDecl(), Finder, Builder);
1169 return InnerMatcher.matches(*
Node.getAsExpr(), Finder, Builder);
1199 internal::Matcher<QualType>, InnerMatcher) {
1202 return InnerMatcher.matches(
Node.getIntegralType(), Finder, Builder);
1220 std::string,
Value) {
1236extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
1246extern const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl>
valueDecl;
1259extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl>
1271extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl>
1282extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl>
enumDecl;
1292extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl>
1307extern const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl>
tagDecl;
1315extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl>
1324extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
1335extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl>
1345extern const internal::VariadicDynCastAllOfMatcher<Decl, ConceptDecl>
1357extern const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl>
varDecl;
1367extern const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl>
fieldDecl;
1377extern const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl>
1386extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl>
1395extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl>
1406extern const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl>
friendDecl;
1416extern const internal::VariadicAllOfMatcher<Stmt>
stmt;
1426extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt>
declStmt;
1439extern const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr>
memberExpr;
1453extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr>
1465extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
1477extern const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr>
callExpr;
1507extern const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr>
lambdaExpr;
1516extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr>
1528extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
1537extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral>
1547extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl>
1557extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl>
1567extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl>
1577extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl>
1587extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl>
1602extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl>
1615extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl>
1627extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl>
1638extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl>
1647extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt>
1657extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt>
1667extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt>
1677extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt>
1687extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
1700extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr>
1706 internal::Matcher<Expr>, InnerMatcher) {
1707 const Expr *SyntForm =
Node.getSyntacticForm();
1708 return (SyntForm !=
nullptr &&
1709 InnerMatcher.matches(*SyntForm, Finder, Builder));
1723extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
1735extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr>
1753extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr>
1766extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
1779extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl>
usingDecl;
1790extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl>
1802extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl>
1819extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr>
1833extern const internal::VariadicDynCastAllOfMatcher<
Decl,
1852extern const internal::VariadicDynCastAllOfMatcher<
Decl,
1865extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr>
1875extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr>
parenExpr;
1887extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr>
1898extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
1912extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr>
1923extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr>
1944extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
1956extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr>
cxxNewExpr;
1966extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr>
1982extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
2002extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitLoopExpr>
2021extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArrayInitIndexExpr>
2032extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr>
2044extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr>
2063extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr>
2075extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFoldExpr>
2095extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
2105extern const internal::VariadicDynCastAllOfMatcher<Stmt, Expr>
expr;
2114extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr>
2128extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr>
2137extern const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr>
blockExpr;
2145extern const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt>
ifStmt;
2154extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt>
forStmt;
2166 const Stmt *
const Increment =
Node.getInc();
2167 return (Increment !=
nullptr &&
2168 InnerMatcher.matches(*Increment, Finder, Builder));
2182 return (
Init !=
nullptr && InnerMatcher.matches(*
Init, Finder, Builder));
2192extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt>
2205 const VarDecl *
const Var =
Node.getLoopVariable();
2206 return (Var !=
nullptr && InnerMatcher.matches(*Var, Finder, Builder));
2220 return (
Init !=
nullptr && InnerMatcher.matches(*
Init, Finder, Builder));
2231extern const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt>
whileStmt;
2241extern const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt>
doStmt;
2251extern const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt>
breakStmt;
2261extern const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt>
2272extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt>
2283extern const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt>
returnStmt;
2294extern const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt>
gotoStmt;
2305extern const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt>
labelStmt;
2317extern const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr>
2328extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt>
switchStmt;
2338extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase>
switchCase;
2348extern const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt>
caseStmt;
2358extern const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt>
2367extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt>
2377extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt>
2387extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt>
cxxTryStmt;
2396extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr>
2406extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt>
nullStmt;
2416extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt>
asmStmt;
2424extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
2434extern const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral>
2447extern const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral>
2454extern const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
2464extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral>
2469extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral>
2473extern const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
2479extern const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral>
2489extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr>
2500extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr>
2503extern const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr>
2513extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr>
2524extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoroutineBodyStmt>
2528extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr>
2532extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr>
2536extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConvertVectorExpr>
2540extern const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr>
2544extern const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
2552extern const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr>
atomicExpr;
2560extern const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr>
stmtExpr;
2569extern const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator>
2578extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator>
2587extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator>
2596extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
2608extern const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr>
2624extern const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl>
2637extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr>
2653extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr>
2668extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
2679extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
2688extern const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr>
2712extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr>
2719extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr>
2735extern const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr>
castExpr;
2745extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr>
2754extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr>
2763extern const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr>
2772extern const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr>
2787 return Node.size() == N;
2791extern const internal::VariadicAllOfMatcher<QualType>
qualType;
2794extern const internal::VariadicAllOfMatcher<Type>
type;
2797extern const internal::VariadicAllOfMatcher<TypeLoc>
typeLoc;
2818extern const internal::VariadicOperatorMatcherFunc<
2819 2, std::numeric_limits<unsigned>::max()>
2825extern const internal::VariadicOperatorMatcherFunc<
2826 2, std::numeric_limits<unsigned>::max()>
2832extern const internal::VariadicOperatorMatcherFunc<
2833 2, std::numeric_limits<unsigned>::max()>
2860extern const internal::VariadicOperatorMatcherFunc<1, 1>
optionally;
2871extern const internal::VariadicDynCastAllOfMatcher<
Stmt,
2900template <
typename T,
typename...
U>
2901auto mapAnyOf(internal::VariadicDynCastAllOfMatcher<T, U>
const &...) {
2902 return internal::MapAnyOfHelper<
U...>();
3015extern const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr>
invocation;
3026 internal::Matcher<QualType>, InnerMatcher) {
3027 const QualType ArgumentType =
Node.getTypeOfArgument();
3028 return InnerMatcher.matches(ArgumentType, Finder, Builder);
3050 const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) {
3052 allOf(
anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)),
3059 const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) {
3061 allOf(ofKind(UETT_SizeOf), InnerMatcher)));
3079inline internal::Matcher<NamedDecl>
hasName(StringRef Name) {
3080 return internal::Matcher<NamedDecl>(
3081 new internal::HasNameMatcher({std::string(Name)}));
3094extern const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
3115 std::string FullNameString =
"::" +
Node.getQualifiedNameAsString();
3116 return RegExp->match(FullNameString);
3138inline internal::PolymorphicMatcher<
3139 internal::HasOverloadedOperatorNameMatcher,
3141 std::vector<std::string>>
3143 return internal::PolymorphicMatcher<
3144 internal::HasOverloadedOperatorNameMatcher,
3146 std::vector<std::string>>({std::string(Name)});
3157extern const internal::VariadicFunction<
3158 internal::PolymorphicMatcher<internal::HasOverloadedOperatorNameMatcher,
3161 std::vector<std::string>>,
3186 return Node.getMember().getAsString() == N;
3224 std::string, BindingID) {
3225 auto MemberName =
Node.getMember().getAsString();
3227 return Builder->removeBindings(
3228 [
this, MemberName](
const BoundNodesMap &
Nodes) {
3229 const auto &BN =
Nodes.getNode(this->BindingID);
3230 if (
const auto *ND = BN.get<
NamedDecl>()) {
3231 if (!isa<FieldDecl, CXXMethodDecl, VarDecl>(ND))
3233 return ND->getName() != MemberName;
3272 internal::Matcher<NamedDecl>,
Base) {
3274 if (
const auto *RD = dyn_cast<CXXRecordDecl>(&
Node))
3275 return Finder->classIsDerivedFrom(RD,
Base, Builder,
false);
3278 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&
Node);
3279 return Finder->objcClassIsDerivedFrom(InterfaceDecl,
Base, Builder,
3287 std::string, BaseName, 1) {
3288 if (BaseName.empty())
3291 const auto M = isDerivedFrom(
hasName(BaseName));
3293 if (
const auto *RD = dyn_cast<CXXRecordDecl>(&
Node))
3294 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3296 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&
Node);
3297 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3334 return Node.hasDefinition() &&
3336 return BaseSpecMatcher.matches(Base, Finder, Builder);
3343 isSameOrDerivedFrom,
3345 internal::Matcher<NamedDecl>,
Base, 0) {
3348 if (
const auto *RD = dyn_cast<CXXRecordDecl>(&
Node))
3349 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3351 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&
Node);
3352 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3358 isSameOrDerivedFrom,
3360 std::string, BaseName, 1) {
3361 if (BaseName.empty())
3364 const auto M = isSameOrDerivedFrom(
hasName(BaseName));
3366 if (
const auto *RD = dyn_cast<CXXRecordDecl>(&
Node))
3367 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3369 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&
Node);
3370 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3395 isDirectlyDerivedFrom,
3397 internal::Matcher<NamedDecl>,
Base, 0) {
3399 if (
const auto *RD = dyn_cast<CXXRecordDecl>(&
Node))
3400 return Finder->classIsDerivedFrom(RD,
Base, Builder,
true);
3403 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&
Node);
3404 return Finder->objcClassIsDerivedFrom(InterfaceDecl,
Base, Builder,
3410 isDirectlyDerivedFrom,
3412 std::string, BaseName, 1) {
3413 if (BaseName.empty())
3415 const auto M = isDirectlyDerivedFrom(
hasName(BaseName));
3417 if (
const auto *RD = dyn_cast<CXXRecordDecl>(&
Node))
3418 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3420 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&
Node);
3421 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3436 BoundNodesTreeBuilder
Result(*Builder);
3437 auto MatchIt = matchesFirstInPointerRange(InnerMatcher,
Node.method_begin(),
3439 if (MatchIt ==
Node.method_end())
3442 if (Finder->isTraversalIgnoringImplicitNodes() && (*MatchIt)->isImplicit())
3444 *Builder = std::move(
Result);
3458 return Node.isLambda();
3479extern const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher>
has;
3495extern const internal::ArgumentAdaptingMatcherFunc<
3496 internal::HasDescendantMatcher>
3517extern const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher>
3547extern const internal::ArgumentAdaptingMatcherFunc<
3548 internal::ForEachDescendantMatcher>
3567template <
typename T>
3568internal::Matcher<T>
findAll(
const internal::Matcher<T> &Matcher) {
3582extern const internal::ArgumentAdaptingMatcherFunc<
3583 internal::HasParentMatcher,
3584 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
3585 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
3599extern const internal::ArgumentAdaptingMatcherFunc<
3600 internal::HasAncestorMatcher,
3601 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
3602 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
3614extern const internal::VariadicOperatorMatcherFunc<1, 1>
unless;
3650inline internal::PolymorphicMatcher<
3651 internal::HasDeclarationMatcher,
3652 void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
3654 return internal::PolymorphicMatcher<
3655 internal::HasDeclarationMatcher,
3656 void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>(
3675 return UnderlyingDecl !=
nullptr &&
3676 InnerMatcher.matches(*UnderlyingDecl, Finder, Builder);
3699 const Expr *ExprNode =
Node.getImplicitObjectArgument()
3700 ->IgnoreParenImpCasts();
3701 return (ExprNode !=
nullptr &&
3702 InnerMatcher.matches(*ExprNode, Finder, Builder));
3719 return InnerMatcher.matches(
TypeDecl, Finder, Builder);
3735 return Node.isClassMethod();
3751 return Node.isInstanceMethod();
3768 return Node.isClassMessage();
3785 return Node.isInstanceMessage();
3800 const Expr *ReceiverNode =
Node.getInstanceReceiver();
3801 return (ReceiverNode !=
nullptr &&
3828extern const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>,
3842 std::string SelectorString =
Node.getSelector().getAsString();
3843 return RegExp->match(SelectorString);
3851 return Node.getSelector().isNull();
3863 return Node.getSelector().isUnarySelector();
3879 return Node.getSelector().isKeywordSelector();
3894 return Node.getSelector().getNumArgs() == N;
3933 internal::Matcher<Stmt>, InnerMatcher, 0) {
3934 const auto *ExprNode =
Node.getCallee();
3935 return (ExprNode !=
nullptr &&
3936 InnerMatcher.matches(*ExprNode, Finder, Builder));
3962 internal::Matcher<Decl>, InnerMatcher, 1) {
3963 if (isa<CallExpr>(&
Node))
3965 .matches(
Node, Finder, Builder);
3969 const auto *MsgNode = cast<ObjCMessageExpr>(&
Node);
3970 const Decl *DeclNode = MsgNode->getMethodDecl();
3971 return (DeclNode !=
nullptr &&
3972 InnerMatcher.matches(*DeclNode, Finder, Builder));
3996 internal::Matcher<QualType>, InnerMatcher, 0) {
3999 return InnerMatcher.matches(QT, Finder, Builder);
4037 internal::Matcher<Decl>, InnerMatcher, 1) {
4081 internal::Matcher<TypeLoc>, Inner) {
4083 if (source ==
nullptr) {
4087 return Inner.matches(source->
getTypeLoc(), Finder, Builder);
4100 return Name ==
Node.getAsString();
4114 QualType, pointsTo, internal::Matcher<QualType>,
4116 return (!
Node.isNull() &&
Node->isAnyPointerType() &&
4117 InnerMatcher.matches(
Node->getPointeeType(), Finder, Builder));
4124 .matches(
Node, Finder, Builder);
4139 return InnerMatcher.matches(*
Node.getUnqualifiedDesugaredType(), Finder,
4158 return (!
Node.isNull() &&
Node->isReferenceType() &&
4159 InnerMatcher.matches(
Node->getPointeeType(), Finder, Builder));
4178 return InnerMatcher.matches(
Node.getCanonicalType(), Finder, Builder);
4185 .matches(
Node, Finder, Builder);
4206 internal::Matcher<Expr>, InnerMatcher) {
4207 const Expr *ExprNode =
Node.getImplicitObjectArgument();
4208 return (ExprNode !=
nullptr &&
4209 InnerMatcher.matches(*ExprNode, Finder, Builder));
4229 internal::Matcher<QualType>, InnerMatcher, 0) {
4230 return onImplicitObjectArgument(
4231 anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher))))
4232 .matches(
Node, Finder, Builder);
4237 internal::Matcher<Decl>, InnerMatcher, 1) {
4238 return onImplicitObjectArgument(
4239 anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher))))
4240 .matches(
Node, Finder, Builder);
4254 const Decl *DeclNode =
Node.getDecl();
4255 return (DeclNode !=
nullptr &&
4256 InnerMatcher.matches(*DeclNode, Finder, Builder));
4283 internal::Matcher<UsingShadowDecl>, Inner) {
4286 return Inner.matches(*
UsingDecl, Finder, Builder);
4307 return matchesFirstInPointerRange(InnerMatcher,
Node.decls_begin(),
4308 Node.decls_end(), Finder,
4309 Builder) !=
Node.decls_end();
4322 if (
Node.isSingleDecl()) {
4323 const Decl *FoundDecl =
Node.getSingleDecl();
4324 return InnerMatcher.matches(*FoundDecl, Finder, Builder);
4338 VarDecl, hasInitializer, internal::Matcher<Expr>,
4342 InnerMatcher.matches(*
Initializer, Finder, Builder));
4368 internal::Matcher<LambdaCapture>, InnerMatcher) {
4369 BoundNodesTreeBuilder
Result;
4370 bool Matched =
false;
4372 if (Finder->isTraversalIgnoringImplicitNodes() &&
Capture.isImplicit())
4374 BoundNodesTreeBuilder CaptureBuilder(*Builder);
4375 if (InnerMatcher.matches(
Capture, Finder, &CaptureBuilder)) {
4377 Result.addMatch(CaptureBuilder);
4380 *Builder = std::move(
Result);
4395 return Node.isStaticLocal();
4410 return Node.hasLocalStorage();
4424 return Node.hasGlobalStorage();
4491 return Node.isExceptionVariable();
4507 unsigned NumArgs =
Node.getNumArgs();
4508 if (!Finder->isTraversalIgnoringImplicitNodes())
4509 return NumArgs == N;
4511 if (!isa<CXXDefaultArgExpr>(
Node.getArg(NumArgs - 1)))
4515 return NumArgs == N;
4534 unsigned NumArgs =
Node.getNumArgs();
4535 if (!Finder->isTraversalIgnoringImplicitNodes())
4536 return NumArgs >= N;
4538 if (!isa<CXXDefaultArgExpr>(
Node.getArg(NumArgs - 1)))
4542 return NumArgs >= N;
4557 unsigned, N, internal::Matcher<Expr>, InnerMatcher) {
4558 if (N >=
Node.getNumArgs())
4561 if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg))
4584 const auto *
const Init =
Node.getInit();
4585 return Init && InnerMacher.matches(*
Init, Finder, Builder);
4606 const Expr *
const Pattern =
Node.getPattern();
4607 return Pattern && InnerMacher.matches(*Pattern, Finder, Builder);
4688 return N <
Node.getNumInits() &&
4689 InnerMatcher.matches(*
Node.getInit(N), Finder, Builder);
4727 internal::Matcher<Decl>, InnerMatcher) {
4728 const unsigned NumDecls = std::distance(
Node.decl_begin(),
Node.decl_end());
4732 std::advance(Iterator, N);
4733 return InnerMatcher.matches(**Iterator, Finder, Builder);
4750 return Node.getExceptionDecl() ==
nullptr;
4767 internal::Matcher<CXXCtorInitializer>, InnerMatcher) {
4768 auto MatchIt = matchesFirstInPointerRange(InnerMatcher,
Node.init_begin(),
4769 Node.init_end(), Finder, Builder);
4770 if (MatchIt ==
Node.init_end())
4772 return (*MatchIt)->isWritten() || !Finder->isTraversalIgnoringImplicitNodes();
4789 internal::Matcher<FieldDecl>, InnerMatcher) {
4791 return (NodeAsDecl !=
nullptr &&
4792 InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
4809 internal::Matcher<Expr>, InnerMatcher) {
4810 const Expr* NodeAsExpr =
Node.getInit();
4811 return (NodeAsExpr !=
nullptr &&
4812 InnerMatcher.matches(*NodeAsExpr, Finder, Builder));
4829 return Node.isWritten();
4849 return Node.isBaseInitializer();
4869 return Node.isMemberInitializer();
4895 internal::Matcher<Expr>, InnerMatcher) {
4896 for (
const Expr *Arg :
Node.arguments()) {
4897 if (Finder->isTraversalIgnoringImplicitNodes() &&
4898 isa<CXXDefaultArgExpr>(Arg))
4900 BoundNodesTreeBuilder
Result(*Builder);
4901 if (InnerMatcher.matches(*Arg, Finder, &
Result)) {
4902 *Builder = std::move(
Result);
4921extern const internal::VariadicAllOfMatcher<LambdaCapture>
lambdaCapture;
4938 clang::ast_matchers::internal::BoundNodesTreeBuilder
Result(*Builder);
4940 *Builder = std::move(
Result);
4964 if (!
Node.capturesVariable())
4966 auto *capturedVar =
Node.getCapturedVar();
4967 return capturedVar && InnerMatcher.matches(*capturedVar, Finder, Builder);
4988 return Node.isListInitialization();
5004 return Node.requiresZeroInitialization();
5031 unsigned, N, internal::Matcher<ParmVarDecl>,
5033 return (N <
Node.parameters().size()
5034 && InnerMatcher.matches(*
Node.parameters()[N], Finder, Builder));
5053 return Node.isExplicitObjectMemberFunction();
5077 internal::Matcher<Expr>, ArgMatcher,
5078 internal::Matcher<ParmVarDecl>, ParamMatcher) {
5079 BoundNodesTreeBuilder
Result;
5083 BoundNodesTreeBuilder Matches;
5087 .matches(
Node, Finder, &Matches)
5091 bool Matched =
false;
5092 for (; ArgIndex <
Node.getNumArgs(); ++ArgIndex) {
5093 BoundNodesTreeBuilder ArgMatches(*Builder);
5094 if (ArgMatcher.matches(*(
Node.getArg(ArgIndex)->IgnoreParenCasts()),
5095 Finder, &ArgMatches)) {
5096 BoundNodesTreeBuilder ParamMatches(ArgMatches);
5098 hasParameter(ParamIndex, ParamMatcher)))),
5100 hasParameter(ParamIndex, ParamMatcher))))))
5101 .matches(
Node, Finder, &ParamMatches)) {
5102 Result.addMatch(ParamMatches);
5108 *Builder = std::move(
Result);
5140 internal::Matcher<Expr>, ArgMatcher,
5141 internal::Matcher<QualType>, ParamMatcher) {
5142 BoundNodesTreeBuilder
Result;
5146 BoundNodesTreeBuilder Matches;
5150 .matches(
Node, Finder, &Matches)
5155 if (
const auto *
Call = dyn_cast<CallExpr>(&
Node)) {
5156 if (
const auto *
Value =
5157 dyn_cast_or_null<ValueDecl>(
Call->getCalleeDecl())) {
5167 assert(MP &&
"Must be member-pointer if its a memberfunctionpointer");
5170 "The call must have happened through a member function "
5176 unsigned ParamIndex = 0;
5177 bool Matched =
false;
5178 unsigned NumArgs =
Node.getNumArgs();
5182 for (; ArgIndex < NumArgs; ++ArgIndex, ++ParamIndex) {
5183 BoundNodesTreeBuilder ArgMatches(*Builder);
5184 if (ArgMatcher.matches(*(
Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder,
5186 BoundNodesTreeBuilder ParamMatches(ArgMatches);
5192 if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {
5193 Result.addMatch(ParamMatches);
5199 hasParameter(ParamIndex, hasType(ParamMatcher))))),
5201 hasParameter(ParamIndex, hasType(ParamMatcher)))))))
5202 .matches(
Node, Finder, &ParamMatches)) {
5203 Result.addMatch(ParamMatches);
5209 *Builder = std::move(
Result);
5231 if (
const auto *
Decl = dyn_cast_or_null<FunctionDecl>(Context))
5232 return N <
Decl->param_size() &&
Decl->getParamDecl(N) == &
Node;
5233 if (
const auto *
Decl = dyn_cast_or_null<BlockDecl>(Context))
5234 return N <
Decl->param_size() &&
Decl->getParamDecl(N) == &
Node;
5235 if (
const auto *
Decl = dyn_cast_or_null<ObjCMethodDecl>(Context))
5236 return N <
Decl->param_size() &&
Decl->getParamDecl(N) == &
Node;
5276 internal::Matcher<ParmVarDecl>,
5278 return matchesFirstInPointerRange(InnerMatcher,
Node.param_begin(),
5279 Node.param_end(), Finder,
5280 Builder) !=
Node.param_end();
5304 return Node.getNumParams() == N;
5332 forEachTemplateArgument,
5336 internal::Matcher<TemplateArgument>, InnerMatcher) {
5338 clang::ast_matchers::internal::getTemplateSpecializationArgs(
Node);
5339 clang::ast_matchers::internal::BoundNodesTreeBuilder
Result;
5340 bool Matched =
false;
5341 for (
const auto &Arg : TemplateArgs) {
5342 clang::ast_matchers::internal::BoundNodesTreeBuilder ArgBuilder(*Builder);
5343 if (InnerMatcher.matches(Arg, Finder, &ArgBuilder)) {
5345 Result.addMatch(ArgBuilder);
5348 *Builder = std::move(
Result);
5377 internal::Matcher<QualType>, InnerMatcher) {
5378 return InnerMatcher.matches(
Node.getReturnType(), Finder, Builder);
5398 return Node.isExternC();
5431 return Node.isDeleted();
5444 return Node.isDefaulted();
5477 return FnTy->hasDynamicExceptionSpec();
5527 return Node.isConsteval();
5549 return Node.isConstexpr();
5564 if (
const auto *CIA =
Node.getAttr<ConstInitAttr>())
5565 return CIA->isConstinit();
5593 internal::Matcher<Stmt>, InnerMatcher) {
5595 return Init !=
nullptr && InnerMatcher.matches(*
Init, Finder, Builder);
5609 internal::Matcher<Expr>, InnerMatcher) {
5612 InnerMatcher.matches(*
Condition, Finder, Builder));
5623 const Stmt *
const Then =
Node.getThen();
5624 return (Then !=
nullptr && InnerMatcher.matches(*Then, Finder, Builder));
5635 const Stmt *
const Else =
Node.getElse();
5636 return (Else !=
nullptr && InnerMatcher.matches(*Else, Finder, Builder));
5670 internal::NotEqualsBoundNodePredicate Predicate;
5673 return Builder->removeBindings(Predicate);
5685 internal::Matcher<DeclStmt>, InnerMatcher) {
5686 const DeclStmt*
const DeclarationStatement =
5687 Node.getConditionVariableDeclStmt();
5688 return DeclarationStatement !=
nullptr &&
5689 InnerMatcher.matches(*DeclarationStatement, Finder, Builder);
5702 internal::Matcher<Expr>, InnerMatcher) {
5704 return InnerMatcher.matches(*
Expression, Finder, Builder);
5719 internal::Matcher<Expr>, InnerMatcher) {
5721 return InnerMatcher.matches(*
Expression, Finder, Builder);
5753 internal::Matcher<Stmt>, InnerMatcher) {
5754 if (Finder->isTraversalIgnoringImplicitNodes() && isDefaultedHelper(&
Node))
5756 const Stmt *
const Statement = internal::GetBodyMatcher<NodeType>::get(
Node);
5757 return (Statement !=
nullptr &&
5758 InnerMatcher.matches(*Statement, Finder, Builder));
5778 internal::Matcher<Stmt>, InnerMatcher) {
5779 const Stmt *
const Statement =
Node.getBody();
5780 return (Statement !=
nullptr &&
5781 InnerMatcher.matches(*Statement, Finder, Builder));
5799 internal::Matcher<Stmt>, InnerMatcher) {
5801 return CS && matchesFirstInPointerRange(InnerMatcher, CS->
body_begin(),
5817 return Node.size() == N;
5845template <
typename ValueT>
5846internal::PolymorphicMatcher<internal::ValueEqualsMatcher,
5847 void(internal::AllNodeBaseTypes), ValueT>
5849 return internal::PolymorphicMatcher<internal::ValueEqualsMatcher,
5850 void(internal::AllNodeBaseTypes), ValueT>(
5859 return internal::ValueEqualsMatcher<NodeType, ParamT>(
Value)
5867 unsigned,
Value, 1) {
5868 return internal::ValueEqualsMatcher<NodeType, ParamT>(
Value)
5878 return internal::ValueEqualsMatcher<NodeType, ParamT>(
Value)
5903 std::string, Name) {
5904 if (std::optional<StringRef> OpName = internal::getOpName(
Node))
5905 return *OpName == Name;
5915extern const internal::VariadicFunction<
5916 internal::PolymorphicMatcher<internal::HasAnyOperatorNameMatcher,
5920 std::vector<std::string>>,
5939 isAssignmentOperator,
5942 return Node.isAssignmentOp();
5960 isComparisonOperator,
5963 return Node.isComparisonOp();
5977 internal::Matcher<Expr>, InnerMatcher) {
5978 const Expr *LeftHandSide = internal::getLHS(
Node);
5979 return (LeftHandSide !=
nullptr &&
5980 InnerMatcher.matches(*LeftHandSide, Finder, Builder));
5994 internal::Matcher<Expr>, InnerMatcher) {
5995 const Expr *RightHandSide = internal::getRHS(
Node);
5996 return (RightHandSide !=
nullptr &&
5997 InnerMatcher.matches(*RightHandSide, Finder, Builder));
6006 internal::Matcher<Expr>, InnerMatcher) {
6007 return internal::VariadicDynCastAllOfMatcher<Stmt, NodeType>()(
6008 anyOf(hasLHS(InnerMatcher), hasRHS(InnerMatcher)))
6009 .matches(
Node, Finder, Builder);
6027 internal::Matcher<Expr>, Matcher1, internal::Matcher<Expr>, Matcher2) {
6028 return internal::VariadicDynCastAllOfMatcher<Stmt, NodeType>()(
6029 anyOf(
allOf(hasLHS(Matcher1), hasRHS(Matcher2)),