Bug Summary

File:build/source/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
Warning:line 202, column 16
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name StandaloneEmptyCheck.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-17/lib/clang/17 -D CLANG_REPOSITORY_STRING="++20230510111145+7df43bdb42ae-1~exp1~20230510111303.1288" -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/clang/tools/extra/clang-tidy/bugprone -I /build/source/clang-tools-extra/clang-tidy/bugprone -I tools/clang/tools/extra/clang-tidy -I /build/source/clang/include -I tools/clang/include -I include -I /build/source/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-17/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/source/= -source-date-epoch 1683717183 -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-05-10-133810-16478-1 -x c++ /build/source/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp

/build/source/clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp

1//===--- StandaloneEmptyCheck.cpp - 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#include "StandaloneEmptyCheck.h"
10#include "clang/AST/ASTContext.h"
11#include "clang/AST/Decl.h"
12#include "clang/AST/DeclBase.h"
13#include "clang/AST/DeclCXX.h"
14#include "clang/AST/Expr.h"
15#include "clang/AST/ExprCXX.h"
16#include "clang/AST/Stmt.h"
17#include "clang/AST/Type.h"
18#include "clang/ASTMatchers/ASTMatchFinder.h"
19#include "clang/ASTMatchers/ASTMatchers.h"
20#include "clang/Basic/Diagnostic.h"
21#include "clang/Basic/SourceLocation.h"
22#include "clang/Lex/Lexer.h"
23#include "llvm/ADT/STLExtras.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/Support/Casting.h"
26
27namespace clang::tidy::bugprone {
28
29using ast_matchers::BoundNodes;
30using ast_matchers::callee;
31using ast_matchers::callExpr;
32using ast_matchers::classTemplateDecl;
33using ast_matchers::cxxMemberCallExpr;
34using ast_matchers::cxxMethodDecl;
35using ast_matchers::expr;
36using ast_matchers::functionDecl;
37using ast_matchers::hasAncestor;
38using ast_matchers::hasName;
39using ast_matchers::hasParent;
40using ast_matchers::ignoringImplicit;
41using ast_matchers::ignoringParenImpCasts;
42using ast_matchers::MatchFinder;
43using ast_matchers::optionally;
44using ast_matchers::returns;
45using ast_matchers::stmt;
46using ast_matchers::stmtExpr;
47using ast_matchers::unless;
48using ast_matchers::voidType;
49
50const Expr *getCondition(const BoundNodes &Nodes, const StringRef NodeId) {
51 const auto *If = Nodes.getNodeAs<IfStmt>(NodeId);
52 if (If != nullptr)
53 return If->getCond();
54
55 const auto *For = Nodes.getNodeAs<ForStmt>(NodeId);
56 if (For != nullptr)
57 return For->getCond();
58
59 const auto *While = Nodes.getNodeAs<WhileStmt>(NodeId);
60 if (While != nullptr)
61 return While->getCond();
62
63 const auto *Do = Nodes.getNodeAs<DoStmt>(NodeId);
64 if (Do != nullptr)
65 return Do->getCond();
66
67 const auto *Switch = Nodes.getNodeAs<SwitchStmt>(NodeId);
68 if (Switch != nullptr)
69 return Switch->getCond();
70
71 return nullptr;
72}
73
74void StandaloneEmptyCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
75 // Ignore empty calls in a template definition which fall under callExpr
76 // non-member matcher even if they are methods.
77 const auto NonMemberMatcher = expr(ignoringImplicit(ignoringParenImpCasts(
78 callExpr(
79 hasParent(stmt(optionally(hasParent(stmtExpr().bind("stexpr"))))
80 .bind("parent")),
81 unless(hasAncestor(classTemplateDecl())),
82 callee(functionDecl(hasName("empty"), unless(returns(voidType())))))
83 .bind("empty"))));
84 const auto MemberMatcher =
85 expr(ignoringImplicit(ignoringParenImpCasts(cxxMemberCallExpr(
86 hasParent(stmt(optionally(hasParent(stmtExpr().bind("stexpr"))))
87 .bind("parent")),
88 callee(cxxMethodDecl(hasName("empty"),
89 unless(returns(voidType()))))))))
90 .bind("empty");
91
92 Finder->addMatcher(MemberMatcher, this);
93 Finder->addMatcher(NonMemberMatcher, this);
94}
95
96void StandaloneEmptyCheck::check(const MatchFinder::MatchResult &Result) {
97 // Skip if the parent node is Expr.
98 if (Result.Nodes.getNodeAs<Expr>("parent"))
1
Taking false branch
99 return;
100
101 const auto PParentStmtExpr = Result.Nodes.getNodeAs<Expr>("stexpr");
2
Calling 'BoundNodes::getNodeAs'
16
Returning from 'BoundNodes::getNodeAs'
102 const auto ParentCompStmt = Result.Nodes.getNodeAs<CompoundStmt>("parent");
103 const auto *ParentCond = getCondition(Result.Nodes, "parent");
104 const auto *ParentReturnStmt = Result.Nodes.getNodeAs<ReturnStmt>("parent");
17
Calling 'BoundNodes::getNodeAs'
23
Returning from 'BoundNodes::getNodeAs'
105
106 if (const auto *MemberCall
30.1
'MemberCall' is null
30.1
'MemberCall' is null
30.1
'MemberCall' is null
30.1
'MemberCall' is null
30.1
'MemberCall' is null
=
31
Taking false branch
107 Result.Nodes.getNodeAs<CXXMemberCallExpr>("empty")) {
24
Calling 'BoundNodes::getNodeAs'
30
Returning from 'BoundNodes::getNodeAs'
108 // Skip if it's a condition of the parent statement.
109 if (ParentCond == MemberCall->getExprStmt())
110 return;
111 // Skip if it's the last statement in the GNU extension
112 // statement expression.
113 if (PParentStmtExpr && ParentCompStmt &&
114 ParentCompStmt->body_back() == MemberCall->getExprStmt())
115 return;
116 // Skip if it's a return statement
117 if (ParentReturnStmt)
118 return;
119
120 SourceLocation MemberLoc = MemberCall->getBeginLoc();
121 SourceLocation ReplacementLoc = MemberCall->getExprLoc();
122 SourceRange ReplacementRange = SourceRange(ReplacementLoc, ReplacementLoc);
123
124 ASTContext &Context = MemberCall->getRecordDecl()->getASTContext();
125 DeclarationName Name =
126 Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear"));
127
128 auto Candidates = MemberCall->getRecordDecl()->lookupDependentName(
129 Name, [](const NamedDecl *ND) {
130 return isa<CXXMethodDecl>(ND) &&
131 llvm::cast<CXXMethodDecl>(ND)->getMinRequiredArguments() ==
132 0 &&
133 !llvm::cast<CXXMethodDecl>(ND)->isConst();
134 });
135
136 bool HasClear = !Candidates.empty();
137 if (HasClear) {
138 const CXXMethodDecl *Clear = llvm::cast<CXXMethodDecl>(Candidates.at(0));
139 QualType RangeType = MemberCall->getImplicitObjectArgument()->getType();
140 bool QualifierIncompatible =
141 (!Clear->isVolatile() && RangeType.isVolatileQualified()) ||
142 RangeType.isConstQualified();
143 if (!QualifierIncompatible) {
144 diag(MemberLoc,
145 "ignoring the result of 'empty()'; did you mean 'clear()'? ")
146 << FixItHint::CreateReplacement(ReplacementRange, "clear");
147 return;
148 }
149 }
150
151 diag(MemberLoc, "ignoring the result of 'empty()'");
152
153 } else if (const auto *NonMemberCall
46.1
'NonMemberCall' is non-null
46.1
'NonMemberCall' is non-null
46.1
'NonMemberCall' is non-null
46.1
'NonMemberCall' is non-null
46.1
'NonMemberCall' is non-null
=
47
Taking true branch
154 Result.Nodes.getNodeAs<CallExpr>("empty")) {
32
Calling 'BoundNodes::getNodeAs'
46
Returning from 'BoundNodes::getNodeAs'
155 if (ParentCond == NonMemberCall->getExprStmt())
48
Assuming the condition is false
156 return;
157 if (PParentStmtExpr
48.1
'PParentStmtExpr' is null
48.1
'PParentStmtExpr' is null
48.1
'PParentStmtExpr' is null
48.1
'PParentStmtExpr' is null
48.1
'PParentStmtExpr' is null
&& ParentCompStmt &&
158 ParentCompStmt->body_back() == NonMemberCall->getExprStmt())
159 return;
160 if (ParentReturnStmt
48.2
'ParentReturnStmt' is null
48.2
'ParentReturnStmt' is null
48.2
'ParentReturnStmt' is null
48.2
'ParentReturnStmt' is null
48.2
'ParentReturnStmt' is null
)
49
Taking false branch
161 return;
162 if (NonMemberCall->getNumArgs() != 1)
50
Assuming the condition is false
51
Taking false branch
163 return;
164
165 SourceLocation NonMemberLoc = NonMemberCall->getExprLoc();
166 SourceLocation NonMemberEndLoc = NonMemberCall->getEndLoc();
167
168 const Expr *Arg = NonMemberCall->getArg(0);
169 CXXRecordDecl *ArgRecordDecl = Arg->getType()->getAsCXXRecordDecl();
170 if (ArgRecordDecl == nullptr)
52
Assuming the condition is false
53
Taking false branch
171 return;
172
173 ASTContext &Context = ArgRecordDecl->getASTContext();
174 DeclarationName Name =
175 Context.DeclarationNames.getIdentifier(&Context.Idents.get("clear"));
176
177 auto Candidates =
178 ArgRecordDecl->lookupDependentName(Name, [](const NamedDecl *ND) {
179 return isa<CXXMethodDecl>(ND) &&
180 llvm::cast<CXXMethodDecl>(ND)->getMinRequiredArguments() ==
181 0 &&
182 !llvm::cast<CXXMethodDecl>(ND)->isConst();
183 });
184
185 bool HasClear = !Candidates.empty();
54
Assuming the condition is true
186
187 if (HasClear
54.1
'HasClear' is true
54.1
'HasClear' is true
54.1
'HasClear' is true
54.1
'HasClear' is true
54.1
'HasClear' is true
) {
55
Taking true branch
188 const CXXMethodDecl *Clear = llvm::cast<CXXMethodDecl>(Candidates.at(0));
56
The object is a 'CastReturnType'
189 bool QualifierIncompatible =
190 (!Clear->isVolatile() && Arg->getType().isVolatileQualified()) ||
57
Assuming the condition is false
191 Arg->getType().isConstQualified();
192 if (!QualifierIncompatible) {
58
Assuming 'QualifierIncompatible' is false
59
Taking true branch
193 std::string ReplacementText =
194 std::string(Lexer::getSourceText(
195 CharSourceRange::getTokenRange(Arg->getSourceRange()),
196 *Result.SourceManager, getLangOpts())) +
197 ".clear()";
198 SourceRange ReplacementRange =
199 SourceRange(NonMemberLoc, NonMemberEndLoc);
200 diag(NonMemberLoc,
201 "ignoring the result of '%0'; did you mean 'clear()'?")
202 << llvm::dyn_cast<NamedDecl>(NonMemberCall->getCalleeDecl())
60
Assuming the object is not a 'CastReturnType'
61
Called C++ object pointer is null
203 ->getQualifiedNameAsString()
204 << FixItHint::CreateReplacement(ReplacementRange, ReplacementText);
205 return;
206 }
207 }
208
209 diag(NonMemberLoc, "ignoring the result of '%0'")
210 << llvm::dyn_cast<NamedDecl>(NonMemberCall->getCalleeDecl())
211 ->getQualifiedNameAsString();
212 }
213}
214
215} // namespace clang::tidy::bugprone

/build/source/clang/include/clang/ASTMatchers/ASTMatchers.h

1//===- ASTMatchers.h - Structural query framework ---------------*- C++ -*-===//
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// This file implements matchers to be used together with the MatchFinder to
10// match AST nodes.
11//
12// Matchers are created by generator functions, which can be combined in
13// a functional in-language DSL to express queries over the C++ AST.
14//
15// For example, to match a class with a certain name, one would call:
16// cxxRecordDecl(hasName("MyClass"))
17// which returns a matcher that can be used to find all AST nodes that declare
18// a class named 'MyClass'.
19//
20// For more complicated match expressions we're often interested in accessing
21// multiple parts of the matched AST nodes once a match is found. In that case,
22// call `.bind("name")` on match expressions that match the nodes you want to
23// access.
24//
25// For example, when we're interested in child classes of a certain class, we
26// would write:
27// cxxRecordDecl(hasName("MyClass"), has(recordDecl().bind("child")))
28// When the match is found via the MatchFinder, a user provided callback will
29// be called with a BoundNodes instance that contains a mapping from the
30// strings that we provided for the `.bind()` calls to the nodes that were
31// matched.
32// In the given example, each time our matcher finds a match we get a callback
33// where "child" is bound to the RecordDecl node of the matching child
34// class declaration.
35//
36// See ASTMatchersInternal.h for a more in-depth explanation of the
37// implementation details of the matcher framework.
38//
39// See ASTMatchFinder.h for how to use the generated matchers to run over
40// an AST.
41//
42//===----------------------------------------------------------------------===//
43
44#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
45#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
46
47#include "clang/AST/ASTContext.h"
48#include "clang/AST/ASTTypeTraits.h"
49#include "clang/AST/Attr.h"
50#include "clang/AST/CXXInheritance.h"
51#include "clang/AST/Decl.h"
52#include "clang/AST/DeclCXX.h"
53#include "clang/AST/DeclFriend.h"
54#include "clang/AST/DeclObjC.h"
55#include "clang/AST/DeclTemplate.h"
56#include "clang/AST/Expr.h"
57#include "clang/AST/ExprCXX.h"
58#include "clang/AST/ExprObjC.h"
59#include "clang/AST/LambdaCapture.h"
60#include "clang/AST/NestedNameSpecifier.h"
61#include "clang/AST/OpenMPClause.h"
62#include "clang/AST/OperationKinds.h"
63#include "clang/AST/ParentMapContext.h"
64#include "clang/AST/Stmt.h"
65#include "clang/AST/StmtCXX.h"
66#include "clang/AST/StmtObjC.h"
67#include "clang/AST/StmtOpenMP.h"
68#include "clang/AST/TemplateBase.h"
69#include "clang/AST/TemplateName.h"
70#include "clang/AST/Type.h"
71#include "clang/AST/TypeLoc.h"
72#include "clang/ASTMatchers/ASTMatchersInternal.h"
73#include "clang/ASTMatchers/ASTMatchersMacros.h"
74#include "clang/Basic/AttrKinds.h"
75#include "clang/Basic/ExceptionSpecificationType.h"
76#include "clang/Basic/FileManager.h"
77#include "clang/Basic/IdentifierTable.h"
78#include "clang/Basic/LLVM.h"
79#include "clang/Basic/SourceManager.h"
80#include "clang/Basic/Specifiers.h"
81#include "clang/Basic/TypeTraits.h"
82#include "llvm/ADT/ArrayRef.h"
83#include "llvm/ADT/SmallVector.h"
84#include "llvm/ADT/StringRef.h"
85#include "llvm/Support/Casting.h"
86#include "llvm/Support/Compiler.h"
87#include "llvm/Support/ErrorHandling.h"
88#include "llvm/Support/Regex.h"
89#include <cassert>
90#include <cstddef>
91#include <iterator>
92#include <limits>
93#include <optional>
94#include <string>
95#include <utility>
96#include <vector>
97
98namespace clang {
99namespace ast_matchers {
100
101/// Maps string IDs to AST nodes matched by parts of a matcher.
102///
103/// The bound nodes are generated by calling \c bind("id") on the node matchers
104/// of the nodes we want to access later.
105///
106/// The instances of BoundNodes are created by \c MatchFinder when the user's
107/// callbacks are executed every time a match is found.
108class BoundNodes {
109public:
110 /// Returns the AST node bound to \c ID.
111 ///
112 /// Returns NULL if there was no node bound to \c ID or if there is a node but
113 /// it cannot be converted to the specified type.
114 template <typename T>
115 const T *getNodeAs(StringRef ID) const {
116 return MyBoundNodes.getNodeAs<T>(ID);
3
Calling 'BoundNodesMap::getNodeAs'
14
Returning from 'BoundNodesMap::getNodeAs'
15
Returning null pointer, which participates in a condition later
18
Calling 'BoundNodesMap::getNodeAs'
21
Returning from 'BoundNodesMap::getNodeAs'
22
Returning null pointer, which participates in a condition later
25
Calling 'BoundNodesMap::getNodeAs'
28
Returning from 'BoundNodesMap::getNodeAs'
29
Returning null pointer, which participates in a condition later
33
Calling 'BoundNodesMap::getNodeAs'
44
Returning from 'BoundNodesMap::getNodeAs'
45
Returning pointer, which participates in a condition later
117 }
118
119 /// Type of mapping from binding identifiers to bound nodes. This type
120 /// is an associative container with a key type of \c std::string and a value
121 /// type of \c clang::DynTypedNode
122 using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap;
123
124 /// Retrieve mapping from binding identifiers to bound nodes.
125 const IDToNodeMap &getMap() const {
126 return MyBoundNodes.getMap();
127 }
128
129private:
130 friend class internal::BoundNodesTreeBuilder;
131
132 /// Create BoundNodes from a pre-filled map of bindings.
133 BoundNodes(internal::BoundNodesMap &MyBoundNodes)
134 : MyBoundNodes(MyBoundNodes) {}
135
136 internal::BoundNodesMap MyBoundNodes;
137};
138
139/// Types of matchers for the top-level classes in the AST class
140/// hierarchy.
141/// @{
142using DeclarationMatcher = internal::Matcher<Decl>;
143using StatementMatcher = internal::Matcher<Stmt>;
144using TypeMatcher = internal::Matcher<QualType>;
145using TypeLocMatcher = internal::Matcher<TypeLoc>;
146using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>;
147using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>;
148using CXXBaseSpecifierMatcher = internal::Matcher<CXXBaseSpecifier>;
149using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>;
150using TemplateArgumentMatcher = internal::Matcher<TemplateArgument>;
151using TemplateArgumentLocMatcher = internal::Matcher<TemplateArgumentLoc>;
152using LambdaCaptureMatcher = internal::Matcher<LambdaCapture>;
153using AttrMatcher = internal::Matcher<Attr>;
154/// @}
155
156/// Matches any node.
157///
158/// Useful when another matcher requires a child matcher, but there's no
159/// additional constraint. This will often be used with an explicit conversion
160/// to an \c internal::Matcher<> type such as \c TypeMatcher.
161///
162/// Example: \c DeclarationMatcher(anything()) matches all declarations, e.g.,
163/// \code
164/// "int* p" and "void f()" in
165/// int* p;
166/// void f();
167/// \endcode
168///
169/// Usable as: Any Matcher
170inline internal::TrueMatcher anything() { return internal::TrueMatcher(); }
171
172/// Matches the top declaration context.
173///
174/// Given
175/// \code
176/// int X;
177/// namespace NS {
178/// int Y;
179/// } // namespace NS
180/// \endcode
181/// decl(hasDeclContext(translationUnitDecl()))
182/// matches "int X", but not "int Y".
183extern const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl>
184 translationUnitDecl;
185
186/// Matches typedef declarations.
187///
188/// Given
189/// \code
190/// typedef int X;
191/// using Y = int;
192/// \endcode
193/// typedefDecl()
194/// matches "typedef int X", but not "using Y = int"
195extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl>
196 typedefDecl;
197
198/// Matches typedef name declarations.
199///
200/// Given
201/// \code
202/// typedef int X;
203/// using Y = int;
204/// \endcode
205/// typedefNameDecl()
206/// matches "typedef int X" and "using Y = int"
207extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
208 typedefNameDecl;
209
210/// Matches type alias declarations.
211///
212/// Given
213/// \code
214/// typedef int X;
215/// using Y = int;
216/// \endcode
217/// typeAliasDecl()
218/// matches "using Y = int", but not "typedef int X"
219extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
220 typeAliasDecl;
221
222/// Matches type alias template declarations.
223///
224/// typeAliasTemplateDecl() matches
225/// \code
226/// template <typename T>
227/// using Y = X<T>;
228/// \endcode
229extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl>
230 typeAliasTemplateDecl;
231
232/// Matches AST nodes that were expanded within the main-file.
233///
234/// Example matches X but not Y
235/// (matcher = cxxRecordDecl(isExpansionInMainFile())
236/// \code
237/// #include <Y.h>
238/// class X {};
239/// \endcode
240/// Y.h:
241/// \code
242/// class Y {};
243/// \endcode
244///
245/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
246AST_POLYMORPHIC_MATCHER(isExpansionInMainFile,namespace internal { template <typename NodeType> class
matcher_isExpansionInMainFileMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInMainFile() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInMainFileMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
247 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc))namespace internal { template <typename NodeType> class
matcher_isExpansionInMainFileMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInMainFile() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInMainFileMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInMainFileMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
248 auto &SourceManager = Finder->getASTContext().getSourceManager();
249 return SourceManager.isInMainFile(
250 SourceManager.getExpansionLoc(Node.getBeginLoc()));
251}
252
253/// Matches AST nodes that were expanded within system-header-files.
254///
255/// Example matches Y but not X
256/// (matcher = cxxRecordDecl(isExpansionInSystemHeader())
257/// \code
258/// #include <SystemHeader.h>
259/// class X {};
260/// \endcode
261/// SystemHeader.h:
262/// \code
263/// class Y {};
264/// \endcode
265///
266/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
267AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader,namespace internal { template <typename NodeType> class
matcher_isExpansionInSystemHeaderMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInSystemHeader() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInSystemHeaderMatcher<NodeType
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
268 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc))namespace internal { template <typename NodeType> class
matcher_isExpansionInSystemHeaderMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)> isExpansionInSystemHeader() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInSystemHeaderMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>)>(); } template <typename NodeType> bool
internal::matcher_isExpansionInSystemHeaderMatcher<NodeType
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
269 auto &SourceManager = Finder->getASTContext().getSourceManager();
270 auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
271 if (ExpansionLoc.isInvalid()) {
272 return false;
273 }
274 return SourceManager.isInSystemHeader(ExpansionLoc);
275}
276
277/// Matches AST nodes that were expanded within files whose name is
278/// partially matching a given regex.
279///
280/// Example matches Y but not X
281/// (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*"))
282/// \code
283/// #include "ASTMatcher.h"
284/// class X {};
285/// \endcode
286/// ASTMatcher.h:
287/// \code
288/// class Y {};
289/// \endcode
290///
291/// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc>
292AST_POLYMORPHIC_MATCHER_REGEX(isExpansionInFileMatching,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
293 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
294 TypeLoc),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
295 RegExp)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpansionInFileMatching0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: explicit matcher_isExpansionInFileMatching0Matcher
( std::shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE
)) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isExpansionInFileMatching0Matcher, void(::
clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>>( ::clang::ast_matchers
::internal::createAndVerifyRegex( RegExp, RegexFlags, "isExpansionInFileMatching"
)); } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpansionInFileMatching0Matcher, void
(::clang::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc
>), std::shared_ptr<llvm::Regex>> isExpansionInFileMatching
(llvm::StringRef RegExp) { return isExpansionInFileMatching(RegExp
, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> ( &
isExpansionInFileMatching_Type0Flags)( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags); typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpansionInFileMatching0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::shared_ptr<llvm::Regex>> (&
isExpansionInFileMatching_Type0)( llvm::StringRef RegExp); template
<typename NodeType, typename ParamT> bool internal:: matcher_isExpansionInFileMatching0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
296 auto &SourceManager = Finder->getASTContext().getSourceManager();
297 auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc());
298 if (ExpansionLoc.isInvalid()) {
299 return false;
300 }
301 auto FileEntry =
302 SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc));
303 if (!FileEntry) {
304 return false;
305 }
306
307 auto Filename = FileEntry->getName();
308 return RegExp->match(Filename);
309}
310
311/// Matches statements that are (transitively) expanded from the named macro.
312/// Does not match if only part of the statement is expanded from that macro or
313/// if different parts of the statement are expanded from different
314/// appearances of the macro.
315AST_POLYMORPHIC_MATCHER_P(isExpandedFromMacro,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpandedFromMacro0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isExpandedFromMacro0Matcher( std
::string const &AMacroName) : MacroName(AMacroName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string MacroName; };
} inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string> isExpandedFromMacro(std::string const &
MacroName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string>(MacroName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpandedFromMacro0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::string> (&isExpandedFromMacro_Type0
)(std::string const &MacroName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isExpandedFromMacro0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
316 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpandedFromMacro0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isExpandedFromMacro0Matcher( std
::string const &AMacroName) : MacroName(AMacroName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string MacroName; };
} inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string> isExpandedFromMacro(std::string const &
MacroName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string>(MacroName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpandedFromMacro0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::string> (&isExpandedFromMacro_Type0
)(std::string const &MacroName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isExpandedFromMacro0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
317 std::string, MacroName)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isExpandedFromMacro0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isExpandedFromMacro0Matcher( std
::string const &AMacroName) : MacroName(AMacroName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string MacroName; };
} inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string> isExpandedFromMacro(std::string const &
MacroName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExpandedFromMacro0Matcher, void(::clang
::ast_matchers::internal::TypeList<Decl, Stmt, TypeLoc>
), std::string>(MacroName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExpandedFromMacro0Matcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Stmt
, TypeLoc>), std::string> (&isExpandedFromMacro_Type0
)(std::string const &MacroName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isExpandedFromMacro0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
318 // Verifies that the statement' beginning and ending are both expanded from
319 // the same instance of the given macro.
320 auto& Context = Finder->getASTContext();
321 std::optional<SourceLocation> B =
322 internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context);
323 if (!B) return false;
324 std::optional<SourceLocation> E =
325 internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context);
326 if (!E) return false;
327 return *B == *E;
328}
329
330/// Matches declarations.
331///
332/// Examples matches \c X, \c C, and the friend declaration inside \c C;
333/// \code
334/// void X();
335/// class C {
336/// friend X;
337/// };
338/// \endcode
339extern const internal::VariadicAllOfMatcher<Decl> decl;
340
341/// Matches decomposition-declarations.
342///
343/// Examples matches the declaration node with \c foo and \c bar, but not
344/// \c number.
345/// (matcher = declStmt(has(decompositionDecl())))
346///
347/// \code
348/// int number = 42;
349/// auto [foo, bar] = std::make_pair{42, 42};
350/// \endcode
351extern const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl>
352 decompositionDecl;
353
354/// Matches binding declarations
355/// Example matches \c foo and \c bar
356/// (matcher = bindingDecl()
357///
358/// \code
359/// auto [foo, bar] = std::make_pair{42, 42};
360/// \endcode
361extern const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl>
362 bindingDecl;
363
364/// Matches a declaration of a linkage specification.
365///
366/// Given
367/// \code
368/// extern "C" {}
369/// \endcode
370/// linkageSpecDecl()
371/// matches "extern "C" {}"
372extern const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl>
373 linkageSpecDecl;
374
375/// Matches a declaration of anything that could have a name.
376///
377/// Example matches \c X, \c S, the anonymous union type, \c i, and \c U;
378/// \code
379/// typedef int X;
380/// struct S {
381/// union {
382/// int i;
383/// } U;
384/// };
385/// \endcode
386extern const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl;
387
388/// Matches a declaration of label.
389///
390/// Given
391/// \code
392/// goto FOO;
393/// FOO: bar();
394/// \endcode
395/// labelDecl()
396/// matches 'FOO:'
397extern const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl;
398
399/// Matches a declaration of a namespace.
400///
401/// Given
402/// \code
403/// namespace {}
404/// namespace test {}
405/// \endcode
406/// namespaceDecl()
407/// matches "namespace {}" and "namespace test {}"
408extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl>
409 namespaceDecl;
410
411/// Matches a declaration of a namespace alias.
412///
413/// Given
414/// \code
415/// namespace test {}
416/// namespace alias = ::test;
417/// \endcode
418/// namespaceAliasDecl()
419/// matches "namespace alias" but not "namespace test"
420extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl>
421 namespaceAliasDecl;
422
423/// Matches class, struct, and union declarations.
424///
425/// Example matches \c X, \c Z, \c U, and \c S
426/// \code
427/// class X;
428/// template<class T> class Z {};
429/// struct S {};
430/// union U {};
431/// \endcode
432extern const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl;
433
434/// Matches C++ class declarations.
435///
436/// Example matches \c X, \c Z
437/// \code
438/// class X;
439/// template<class T> class Z {};
440/// \endcode
441extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl>
442 cxxRecordDecl;
443
444/// Matches C++ class template declarations.
445///
446/// Example matches \c Z
447/// \code
448/// template<class T> class Z {};
449/// \endcode
450extern const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl>
451 classTemplateDecl;
452
453/// Matches C++ class template specializations.
454///
455/// Given
456/// \code
457/// template<typename T> class A {};
458/// template<> class A<double> {};
459/// A<int> a;
460/// \endcode
461/// classTemplateSpecializationDecl()
462/// matches the specializations \c A<int> and \c A<double>
463extern const internal::VariadicDynCastAllOfMatcher<
464 Decl, ClassTemplateSpecializationDecl>
465 classTemplateSpecializationDecl;
466
467/// Matches C++ class template partial specializations.
468///
469/// Given
470/// \code
471/// template<class T1, class T2, int I>
472/// class A {};
473///
474/// template<class T, int I>
475/// class A<T, T*, I> {};
476///
477/// template<>
478/// class A<int, int, 1> {};
479/// \endcode
480/// classTemplatePartialSpecializationDecl()
481/// matches the specialization \c A<T,T*,I> but not \c A<int,int,1>
482extern const internal::VariadicDynCastAllOfMatcher<
483 Decl, ClassTemplatePartialSpecializationDecl>
484 classTemplatePartialSpecializationDecl;
485
486/// Matches declarator declarations (field, variable, function
487/// and non-type template parameter declarations).
488///
489/// Given
490/// \code
491/// class X { int y; };
492/// \endcode
493/// declaratorDecl()
494/// matches \c int y.
495extern const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl>
496 declaratorDecl;
497
498/// Matches parameter variable declarations.
499///
500/// Given
501/// \code
502/// void f(int x);
503/// \endcode
504/// parmVarDecl()
505/// matches \c int x.
506extern const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl>
507 parmVarDecl;
508
509/// Matches C++ access specifier declarations.
510///
511/// Given
512/// \code
513/// class C {
514/// public:
515/// int a;
516/// };
517/// \endcode
518/// accessSpecDecl()
519/// matches 'public:'
520extern const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl>
521 accessSpecDecl;
522
523/// Matches class bases.
524///
525/// Examples matches \c public virtual B.
526/// \code
527/// class B {};
528/// class C : public virtual B {};
529/// \endcode
530extern const internal::VariadicAllOfMatcher<CXXBaseSpecifier> cxxBaseSpecifier;
531
532/// Matches constructor initializers.
533///
534/// Examples matches \c i(42).
535/// \code
536/// class C {
537/// C() : i(42) {}
538/// int i;
539/// };
540/// \endcode
541extern const internal::VariadicAllOfMatcher<CXXCtorInitializer>
542 cxxCtorInitializer;
543
544/// Matches template arguments.
545///
546/// Given
547/// \code
548/// template <typename T> struct C {};
549/// C<int> c;
550/// \endcode
551/// templateArgument()
552/// matches 'int' in C<int>.
553extern const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument;
554
555/// Matches template arguments (with location info).
556///
557/// Given
558/// \code
559/// template <typename T> struct C {};
560/// C<int> c;
561/// \endcode
562/// templateArgumentLoc()
563/// matches 'int' in C<int>.
564extern const internal::VariadicAllOfMatcher<TemplateArgumentLoc>
565 templateArgumentLoc;
566
567/// Matches template name.
568///
569/// Given
570/// \code
571/// template <typename T> class X { };
572/// X<int> xi;
573/// \endcode
574/// templateName()
575/// matches 'X' in X<int>.
576extern const internal::VariadicAllOfMatcher<TemplateName> templateName;
577
578/// Matches non-type template parameter declarations.
579///
580/// Given
581/// \code
582/// template <typename T, int N> struct C {};
583/// \endcode
584/// nonTypeTemplateParmDecl()
585/// matches 'N', but not 'T'.
586extern const internal::VariadicDynCastAllOfMatcher<Decl,
587 NonTypeTemplateParmDecl>
588 nonTypeTemplateParmDecl;
589
590/// Matches template type parameter declarations.
591///
592/// Given
593/// \code
594/// template <typename T, int N> struct C {};
595/// \endcode
596/// templateTypeParmDecl()
597/// matches 'T', but not 'N'.
598extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
599 templateTypeParmDecl;
600
601/// Matches template template parameter declarations.
602///
603/// Given
604/// \code
605/// template <template <typename> class Z, int N> struct C {};
606/// \endcode
607/// templateTypeParmDecl()
608/// matches 'Z', but not 'N'.
609extern const internal::VariadicDynCastAllOfMatcher<Decl,
610 TemplateTemplateParmDecl>
611 templateTemplateParmDecl;
612
613/// Matches public C++ declarations and C++ base specifers that specify public
614/// inheritance.
615///
616/// Examples:
617/// \code
618/// class C {
619/// public: int a; // fieldDecl(isPublic()) matches 'a'
620/// protected: int b;
621/// private: int c;
622/// };
623/// \endcode
624///
625/// \code
626/// class Base {};
627/// class Derived1 : public Base {}; // matches 'Base'
628/// struct Derived2 : Base {}; // matches 'Base'
629/// \endcode
630AST_POLYMORPHIC_MATCHER(isPublic,namespace internal { template <typename NodeType> class
matcher_isPublicMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPublicMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPublic() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPublicMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPublicMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
631 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl,namespace internal { template <typename NodeType> class
matcher_isPublicMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPublicMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPublic() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPublicMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPublicMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
632 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isPublicMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPublicMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPublic() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPublicMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPublicMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
633 return getAccessSpecifier(Node) == AS_public;
634}
635
636/// Matches protected C++ declarations and C++ base specifers that specify
637/// protected inheritance.
638///
639/// Examples:
640/// \code
641/// class C {
642/// public: int a;
643/// protected: int b; // fieldDecl(isProtected()) matches 'b'
644/// private: int c;
645/// };
646/// \endcode
647///
648/// \code
649/// class Base {};
650/// class Derived : protected Base {}; // matches 'Base'
651/// \endcode
652AST_POLYMORPHIC_MATCHER(isProtected,namespace internal { template <typename NodeType> class
matcher_isProtectedMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isProtected() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isProtectedMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
653 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl,namespace internal { template <typename NodeType> class
matcher_isProtectedMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isProtected() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isProtectedMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
654 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isProtectedMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isProtected() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isProtectedMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isProtectedMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
655 return getAccessSpecifier(Node) == AS_protected;
656}
657
658/// Matches private C++ declarations and C++ base specifers that specify private
659/// inheritance.
660///
661/// Examples:
662/// \code
663/// class C {
664/// public: int a;
665/// protected: int b;
666/// private: int c; // fieldDecl(isPrivate()) matches 'c'
667/// };
668/// \endcode
669///
670/// \code
671/// struct Base {};
672/// struct Derived1 : private Base {}; // matches 'Base'
673/// class Derived2 : Base {}; // matches 'Base'
674/// \endcode
675AST_POLYMORPHIC_MATCHER(isPrivate,namespace internal { template <typename NodeType> class
matcher_isPrivateMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPrivateMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPrivate() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPrivateMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPrivateMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
676 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl,namespace internal { template <typename NodeType> class
matcher_isPrivateMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPrivateMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPrivate() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPrivateMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPrivateMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
677 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isPrivateMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isPrivateMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)> isPrivate() { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_isPrivateMatcher, void
(::clang::ast_matchers::internal::TypeList<Decl, CXXBaseSpecifier
>)>(); } template <typename NodeType> bool internal
::matcher_isPrivateMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
678 return getAccessSpecifier(Node) == AS_private;
679}
680
681/// Matches non-static data members that are bit-fields.
682///
683/// Given
684/// \code
685/// class C {
686/// int a : 2;
687/// int b;
688/// };
689/// \endcode
690/// fieldDecl(isBitField())
691/// matches 'int a;' but not 'int b;'.
692AST_MATCHER(FieldDecl, isBitField)namespace internal { class matcher_isBitFieldMatcher : public
::clang::ast_matchers::internal::MatcherInterface<FieldDecl
> { public: explicit matcher_isBitFieldMatcher() = default
; bool matches(const FieldDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<FieldDecl> isBitField
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isBitFieldMatcher()); } inline bool internal
::matcher_isBitFieldMatcher::matches( const FieldDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
693 return Node.isBitField();
694}
695
696/// Matches non-static data members that are bit-fields of the specified
697/// bit width.
698///
699/// Given
700/// \code
701/// class C {
702/// int a : 2;
703/// int b : 4;
704/// int c : 2;
705/// };
706/// \endcode
707/// fieldDecl(hasBitWidth(2))
708/// matches 'int a;' and 'int c;' but not 'int b;'.
709AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width)namespace internal { class matcher_hasBitWidth0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<FieldDecl
> { public: explicit matcher_hasBitWidth0Matcher( unsigned
const &AWidth) : Width(AWidth) {} bool matches(const FieldDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned Width; }; } inline
::clang::ast_matchers::internal::Matcher<FieldDecl> hasBitWidth
( unsigned const &Width) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasBitWidth0Matcher
(Width)); } typedef ::clang::ast_matchers::internal::Matcher<
FieldDecl> ( &hasBitWidth_Type0)(unsigned const &Width
); inline bool internal::matcher_hasBitWidth0Matcher::matches
( const FieldDecl &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
710 return Node.isBitField() &&
711 Node.getBitWidthValue(Finder->getASTContext()) == Width;
712}
713
714/// Matches non-static data members that have an in-class initializer.
715///
716/// Given
717/// \code
718/// class C {
719/// int a = 2;
720/// int b = 3;
721/// int c;
722/// };
723/// \endcode
724/// fieldDecl(hasInClassInitializer(integerLiteral(equals(2))))
725/// matches 'int a;' but not 'int b;'.
726/// fieldDecl(hasInClassInitializer(anything()))
727/// matches 'int a;' and 'int b;' but not 'int c;'.
728AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher<Expr>,namespace internal { class matcher_hasInClassInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
FieldDecl> { public: explicit matcher_hasInClassInitializer0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const FieldDecl &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FieldDecl
> hasInClassInitializer( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasInClassInitializer0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FieldDecl> ( &hasInClassInitializer_Type0)(internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasInClassInitializer0Matcher::matches( const FieldDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
729 InnerMatcher)namespace internal { class matcher_hasInClassInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
FieldDecl> { public: explicit matcher_hasInClassInitializer0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const FieldDecl &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FieldDecl
> hasInClassInitializer( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasInClassInitializer0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FieldDecl> ( &hasInClassInitializer_Type0)(internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasInClassInitializer0Matcher::matches( const FieldDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
730 const Expr *Initializer = Node.getInClassInitializer();
731 return (Initializer != nullptr &&
732 InnerMatcher.matches(*Initializer, Finder, Builder));
733}
734
735/// Determines whether the function is "main", which is the entry point
736/// into an executable program.
737AST_MATCHER(FunctionDecl, isMain)namespace internal { class matcher_isMainMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<FunctionDecl>
{ public: explicit matcher_isMainMatcher() = default; bool matches
(const FunctionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<FunctionDecl> isMain() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isMainMatcher
()); } inline bool internal::matcher_isMainMatcher::matches( const
FunctionDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
738 return Node.isMain();
739}
740
741/// Matches the specialized template of a specialization declaration.
742///
743/// Given
744/// \code
745/// template<typename T> class A {}; #1
746/// template<> class A<int> {}; #2
747/// \endcode
748/// classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl()))
749/// matches '#2' with classTemplateDecl() matching the class template
750/// declaration of 'A' at #1.
751AST_MATCHER_P(ClassTemplateSpecializationDecl, hasSpecializedTemplate,namespace internal { class matcher_hasSpecializedTemplate0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ClassTemplateSpecializationDecl> { public: explicit matcher_hasSpecializedTemplate0Matcher
( internal::Matcher<ClassTemplateDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<ClassTemplateDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ClassTemplateSpecializationDecl> hasSpecializedTemplate
( internal::Matcher<ClassTemplateDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasSpecializedTemplate0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<ClassTemplateSpecializationDecl
> ( &hasSpecializedTemplate_Type0)(internal::Matcher<
ClassTemplateDecl> const &InnerMatcher); inline bool internal
::matcher_hasSpecializedTemplate0Matcher::matches( const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
752 internal::Matcher<ClassTemplateDecl>, InnerMatcher)namespace internal { class matcher_hasSpecializedTemplate0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ClassTemplateSpecializationDecl> { public: explicit matcher_hasSpecializedTemplate0Matcher
( internal::Matcher<ClassTemplateDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<ClassTemplateDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ClassTemplateSpecializationDecl> hasSpecializedTemplate
( internal::Matcher<ClassTemplateDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasSpecializedTemplate0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<ClassTemplateSpecializationDecl
> ( &hasSpecializedTemplate_Type0)(internal::Matcher<
ClassTemplateDecl> const &InnerMatcher); inline bool internal
::matcher_hasSpecializedTemplate0Matcher::matches( const ClassTemplateSpecializationDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
753 const ClassTemplateDecl* Decl = Node.getSpecializedTemplate();
754 return (Decl != nullptr &&
755 InnerMatcher.matches(*Decl, Finder, Builder));
756}
757
758/// Matches an entity that has been implicitly added by the compiler (e.g.
759/// implicit default/copy constructors).
760AST_POLYMORPHIC_MATCHER(isImplicit,namespace internal { template <typename NodeType> class
matcher_isImplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)> isImplicit() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)>(); } template <typename NodeType>
bool internal::matcher_isImplicitMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
761 AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Attr,namespace internal { template <typename NodeType> class
matcher_isImplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)> isImplicit() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)>(); } template <typename NodeType>
bool internal::matcher_isImplicitMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
762 LambdaCapture))namespace internal { template <typename NodeType> class
matcher_isImplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)> isImplicit() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isImplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<Decl, Attr
, LambdaCapture>)>(); } template <typename NodeType>
bool internal::matcher_isImplicitMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
763 return Node.isImplicit();
764}
765
766/// Matches classTemplateSpecializations, templateSpecializationType and
767/// functionDecl that have at least one TemplateArgument matching the given
768/// InnerMatcher.
769///
770/// Given
771/// \code
772/// template<typename T> class A {};
773/// template<> class A<double> {};
774/// A<int> a;
775///
776/// template<typename T> f() {};
777/// void func() { f<int>(); };
778/// \endcode
779///
780/// \endcode
781/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
782/// refersToType(asString("int"))))
783/// matches the specialization \c A<int>
784///
785/// functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))
786/// matches the specialization \c f<int>
787AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
788 hasAnyTemplateArgument,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
789 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
790 TemplateSpecializationType,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
791 FunctionDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
792 internal::Matcher<TemplateArgument>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnyTemplateArgument0Matcher
( internal::Matcher<TemplateArgument> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgument
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > hasAnyTemplateArgument(internal
::Matcher<TemplateArgument> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), internal::Matcher<TemplateArgument>
>(InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasAnyTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), internal::Matcher
<TemplateArgument> > (&hasAnyTemplateArgument_Type0
)(internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasAnyTemplateArgument0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
793 ArrayRef<TemplateArgument> List =
794 internal::getTemplateSpecializationArgs(Node);
795 return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder,
796 Builder) != List.end();
797}
798
799/// Causes all nested matchers to be matched with the specified traversal kind.
800///
801/// Given
802/// \code
803/// void foo()
804/// {
805/// int i = 3.0;
806/// }
807/// \endcode
808/// The matcher
809/// \code
810/// traverse(TK_IgnoreUnlessSpelledInSource,
811/// varDecl(hasInitializer(floatLiteral().bind("init")))
812/// )
813/// \endcode
814/// matches the variable declaration with "init" bound to the "3.0".
815template <typename T>
816internal::Matcher<T> traverse(TraversalKind TK,
817 const internal::Matcher<T> &InnerMatcher) {
818 return internal::DynTypedMatcher::constructRestrictedWrapper(
819 new internal::TraversalMatcher<T>(TK, InnerMatcher),
820 InnerMatcher.getID().first)
821 .template unconditionalConvertTo<T>();
822}
823
824template <typename T>
825internal::BindableMatcher<T>
826traverse(TraversalKind TK, const internal::BindableMatcher<T> &InnerMatcher) {
827 return internal::BindableMatcher<T>(
828 internal::DynTypedMatcher::constructRestrictedWrapper(
829 new internal::TraversalMatcher<T>(TK, InnerMatcher),
830 InnerMatcher.getID().first)
831 .template unconditionalConvertTo<T>());
832}
833
834template <typename... T>
835internal::TraversalWrapper<internal::VariadicOperatorMatcher<T...>>
836traverse(TraversalKind TK,
837 const internal::VariadicOperatorMatcher<T...> &InnerMatcher) {
838 return internal::TraversalWrapper<internal::VariadicOperatorMatcher<T...>>(
839 TK, InnerMatcher);
840}
841
842template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
843 typename T, typename ToTypes>
844internal::TraversalWrapper<
845 internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>>
846traverse(TraversalKind TK, const internal::ArgumentAdaptingMatcherFuncAdaptor<
847 ArgumentAdapterT, T, ToTypes> &InnerMatcher) {
848 return internal::TraversalWrapper<
849 internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T,
850 ToTypes>>(TK, InnerMatcher);
851}
852
853template <template <typename T, typename... P> class MatcherT, typename... P,
854 typename ReturnTypesF>
855internal::TraversalWrapper<
856 internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>>
857traverse(TraversalKind TK,
858 const internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>
859 &InnerMatcher) {
860 return internal::TraversalWrapper<
861 internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>>(TK,
862 InnerMatcher);
863}
864
865template <typename... T>
866internal::Matcher<typename internal::GetClade<T...>::Type>
867traverse(TraversalKind TK, const internal::MapAnyOfHelper<T...> &InnerMatcher) {
868 return traverse(TK, InnerMatcher.with());
869}
870
871/// Matches expressions that match InnerMatcher after any implicit AST
872/// nodes are stripped off.
873///
874/// Parentheses and explicit casts are not discarded.
875/// Given
876/// \code
877/// class C {};
878/// C a = C();
879/// C b;
880/// C c = b;
881/// \endcode
882/// The matchers
883/// \code
884/// varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr())))
885/// \endcode
886/// would match the declarations for a, b, and c.
887/// While
888/// \code
889/// varDecl(hasInitializer(cxxConstructExpr()))
890/// \endcode
891/// only match the declarations for b and c.
892AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>,namespace internal { class matcher_ignoringImplicit0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImplicit0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImplicit
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImplicit0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImplicit_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImplicit0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
893 InnerMatcher)namespace internal { class matcher_ignoringImplicit0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImplicit0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImplicit
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImplicit0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImplicit_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImplicit0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
894 return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder);
895}
896
897/// Matches expressions that match InnerMatcher after any implicit casts
898/// are stripped off.
899///
900/// Parentheses and explicit casts are not discarded.
901/// Given
902/// \code
903/// int arr[5];
904/// int a = 0;
905/// char b = 0;
906/// const int c = a;
907/// int *d = arr;
908/// long e = (long) 0l;
909/// \endcode
910/// The matchers
911/// \code
912/// varDecl(hasInitializer(ignoringImpCasts(integerLiteral())))
913/// varDecl(hasInitializer(ignoringImpCasts(declRefExpr())))
914/// \endcode
915/// would match the declarations for a, b, c, and d, but not e.
916/// While
917/// \code
918/// varDecl(hasInitializer(integerLiteral()))
919/// varDecl(hasInitializer(declRefExpr()))
920/// \endcode
921/// only match the declarations for a.
922AST_MATCHER_P(Expr, ignoringImpCasts,namespace internal { class matcher_ignoringImpCasts0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImpCasts0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImpCasts0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImpCasts_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImpCasts0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
923 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringImpCasts0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringImpCasts0Matcher(
internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringImpCasts0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringImpCasts_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringImpCasts0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
924 return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder);
925}
926
927/// Matches expressions that match InnerMatcher after parentheses and
928/// casts are stripped off.
929///
930/// Implicit and non-C Style casts are also discarded.
931/// Given
932/// \code
933/// int a = 0;
934/// char b = (0);
935/// void* c = reinterpret_cast<char*>(0);
936/// char d = char(0);
937/// \endcode
938/// The matcher
939/// varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
940/// would match the declarations for a, b, c, and d.
941/// while
942/// varDecl(hasInitializer(integerLiteral()))
943/// only match the declaration for a.
944AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringParenCasts0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringParenCasts0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParenCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParenCasts0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<Expr> ( &ignoringParenCasts_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringParenCasts0Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
945 return InnerMatcher.matches(*Node.IgnoreParenCasts(), Finder, Builder);
946}
947
948/// Matches expressions that match InnerMatcher after implicit casts and
949/// parentheses are stripped off.
950///
951/// Explicit casts are not discarded.
952/// Given
953/// \code
954/// int arr[5];
955/// int a = 0;
956/// char b = (0);
957/// const int c = a;
958/// int *d = (arr);
959/// long e = ((long) 0l);
960/// \endcode
961/// The matchers
962/// varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral())))
963/// varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr())))
964/// would match the declarations for a, b, c, and d, but not e.
965/// while
966/// varDecl(hasInitializer(integerLiteral()))
967/// varDecl(hasInitializer(declRefExpr()))
968/// would only match the declaration for a.
969AST_MATCHER_P(Expr, ignoringParenImpCasts,namespace internal { class matcher_ignoringParenImpCasts0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringParenImpCasts0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParenImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParenImpCasts0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<Expr> ( &
ignoringParenImpCasts_Type0)(internal::Matcher<Expr> const
&InnerMatcher); inline bool internal::matcher_ignoringParenImpCasts0Matcher
::matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
970 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringParenImpCasts0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringParenImpCasts0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Expr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParenImpCasts
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParenImpCasts0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<Expr> ( &
ignoringParenImpCasts_Type0)(internal::Matcher<Expr> const
&InnerMatcher); inline bool internal::matcher_ignoringParenImpCasts0Matcher
::matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
971 return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder);
972}
973
974/// Matches types that match InnerMatcher after any parens are stripped.
975///
976/// Given
977/// \code
978/// void (*fp)(void);
979/// \endcode
980/// The matcher
981/// \code
982/// varDecl(hasType(pointerType(pointee(ignoringParens(functionType())))))
983/// \endcode
984/// would match the declaration for fp.
985AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher<QualType>,namespace internal { class matcher_ignoringParens0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_ignoringParens0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> ignoringParens
( internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_ignoringParens0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<QualType> ( &
ignoringParens_Type0)(internal::Matcher<QualType> const
&InnerMatcher); inline bool internal::matcher_ignoringParens0Matcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
986 InnerMatcher, 0)namespace internal { class matcher_ignoringParens0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_ignoringParens0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> ignoringParens
( internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_ignoringParens0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<QualType> ( &
ignoringParens_Type0)(internal::Matcher<QualType> const
&InnerMatcher); inline bool internal::matcher_ignoringParens0Matcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
987 return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder);
988}
989
990/// Overload \c ignoringParens for \c Expr.
991///
992/// Given
993/// \code
994/// const char* str = ("my-string");
995/// \endcode
996/// The matcher
997/// \code
998/// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral())))
999/// \endcode
1000/// would match the implicit cast resulting from the assignment.
1001AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher<Expr>,namespace internal { class matcher_ignoringParens1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_ignoringParens1Matcher( internal::
Matcher<Expr> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const Expr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParens(
internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParens1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Expr> ( &ignoringParens_Type1
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringParens1Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1002 InnerMatcher, 1)namespace internal { class matcher_ignoringParens1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_ignoringParens1Matcher( internal::
Matcher<Expr> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const Expr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Expr> ignoringParens(
internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringParens1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Expr> ( &ignoringParens_Type1
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringParens1Matcher::matches( const
Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1003 const Expr *E = Node.IgnoreParens();
1004 return InnerMatcher.matches(*E, Finder, Builder);
1005}
1006
1007/// Matches expressions that are instantiation-dependent even if it is
1008/// neither type- nor value-dependent.
1009///
1010/// In the following example, the expression sizeof(sizeof(T() + T()))
1011/// is instantiation-dependent (since it involves a template parameter T),
1012/// but is neither type- nor value-dependent, since the type of the inner
1013/// sizeof is known (std::size_t) and therefore the size of the outer
1014/// sizeof is known.
1015/// \code
1016/// template<typename T>
1017/// void f(T x, T y) { sizeof(sizeof(T() + T()); }
1018/// \endcode
1019/// expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T())
1020AST_MATCHER(Expr, isInstantiationDependent)namespace internal { class matcher_isInstantiationDependentMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_isInstantiationDependentMatcher
() = default; bool matches(const Expr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<Expr> isInstantiationDependent
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isInstantiationDependentMatcher()); } inline
bool internal::matcher_isInstantiationDependentMatcher::matches
( const Expr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1021 return Node.isInstantiationDependent();
1022}
1023
1024/// Matches expressions that are type-dependent because the template type
1025/// is not yet instantiated.
1026///
1027/// For example, the expressions "x" and "x + y" are type-dependent in
1028/// the following code, but "y" is not type-dependent:
1029/// \code
1030/// template<typename T>
1031/// void add(T x, int y) {
1032/// x + y;
1033/// }
1034/// \endcode
1035/// expr(isTypeDependent()) matches x + y
1036AST_MATCHER(Expr, isTypeDependent)namespace internal { class matcher_isTypeDependentMatcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_isTypeDependentMatcher() = default
; bool matches(const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Expr> isTypeDependent() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isTypeDependentMatcher
()); } inline bool internal::matcher_isTypeDependentMatcher::
matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.isTypeDependent(); }
1037
1038/// Matches expression that are value-dependent because they contain a
1039/// non-type template parameter.
1040///
1041/// For example, the array bound of "Chars" in the following example is
1042/// value-dependent.
1043/// \code
1044/// template<int Size> int f() { return Size; }
1045/// \endcode
1046/// expr(isValueDependent()) matches return Size
1047AST_MATCHER(Expr, isValueDependent)namespace internal { class matcher_isValueDependentMatcher : public
::clang::ast_matchers::internal::MatcherInterface<Expr>
{ public: explicit matcher_isValueDependentMatcher() = default
; bool matches(const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Expr> isValueDependent() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isValueDependentMatcher
()); } inline bool internal::matcher_isValueDependentMatcher::
matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.isValueDependent(); }
1048
1049/// Matches classTemplateSpecializations, templateSpecializationType and
1050/// functionDecl where the n'th TemplateArgument matches the given InnerMatcher.
1051///
1052/// Given
1053/// \code
1054/// template<typename T, typename U> class A {};
1055/// A<bool, int> b;
1056/// A<int, bool> c;
1057///
1058/// template<typename T> void f() {}
1059/// void func() { f<int>(); };
1060/// \endcode
1061/// classTemplateSpecializationDecl(hasTemplateArgument(
1062/// 1, refersToType(asString("int"))))
1063/// matches the specialization \c A<bool, int>
1064///
1065/// functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))
1066/// matches the specialization \c f<int>
1067AST_POLYMORPHIC_MATCHER_P2(namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1068 hasTemplateArgument,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1069 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1070 TemplateSpecializationType,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1071 FunctionDecl),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
1072 unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgument0Matcher(unsigned
const &AN, internal::Matcher<TemplateArgument> const
&AInnerMatcher) : N(AN), InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<TemplateArgument> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> > hasTemplateArgument(unsigned
const &N, internal::Matcher<TemplateArgument> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_hasTemplateArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), unsigned, internal
::Matcher<TemplateArgument> >(N, InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), unsigned, internal::Matcher<TemplateArgument
> > (&hasTemplateArgument_Type0)( unsigned const &
N, internal::Matcher<TemplateArgument> const &InnerMatcher
); template <typename NodeType, typename ParamT1, typename
ParamT2> bool internal::matcher_hasTemplateArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
1073 ArrayRef<TemplateArgument> List =
1074 internal::getTemplateSpecializationArgs(Node);
1075 if (List.size() <= N)
1076 return false;
1077 return InnerMatcher.matches(List[N], Finder, Builder);
1078}
1079
1080/// Matches if the number of template arguments equals \p N.
1081///
1082/// Given
1083/// \code
1084/// template<typename T> struct C {};
1085/// C<int> c;
1086/// \endcode
1087/// classTemplateSpecializationDecl(templateArgumentCountIs(1))
1088/// matches C<int>.
1089AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1090 templateArgumentCountIs,namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1091 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1092 TemplateSpecializationType),namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
1093 unsigned, N)namespace internal { template <typename NodeType, typename
ParamT> class matcher_templateArgumentCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_templateArgumentCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> templateArgumentCountIs(unsigned const &
N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_templateArgumentCountIs0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType>), unsigned>(N); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_templateArgumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
>), unsigned> (&templateArgumentCountIs_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_templateArgumentCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
1094 return internal::getTemplateSpecializationArgs(Node).size() == N;
1095}
1096
1097/// Matches a TemplateArgument that refers to a certain type.
1098///
1099/// Given
1100/// \code
1101/// struct X {};
1102/// template<typename T> struct A {};
1103/// A<X> a;
1104/// \endcode
1105/// classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType(
1106/// recordType(hasDeclaration(recordDecl(hasName("X")))))))
1107/// matches the specialization of \c struct A generated by \c A<X>.
1108AST_MATCHER_P(TemplateArgument, refersToType,namespace internal { class matcher_refersToType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_refersToType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_refersToType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<TemplateArgument
> ( &refersToType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_refersToType0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
1109 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_refersToType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_refersToType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_refersToType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<TemplateArgument
> ( &refersToType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_refersToType0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
1110 if (Node.getKind() != TemplateArgument::Type)
1111 return false;
1112 return InnerMatcher.matches(Node.getAsType(), Finder, Builder);
1113}
1114
1115/// Matches a TemplateArgument that refers to a certain template.
1116///
1117/// Given
1118/// \code
1119/// template<template <typename> class S> class X {};
1120/// template<typename T> class Y {};
1121/// X<Y> xi;
1122/// \endcode
1123/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
1124/// refersToTemplate(templateName())))
1125/// matches the specialization \c X<Y>
1126AST_MATCHER_P(TemplateArgument, refersToTemplate,namespace internal { class matcher_refersToTemplate0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToTemplate0Matcher
( internal::Matcher<TemplateName> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateName
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToTemplate( internal::
Matcher<TemplateName> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_refersToTemplate0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<TemplateArgument>
( &refersToTemplate_Type0)(internal::Matcher<TemplateName
> const &InnerMatcher); inline bool internal::matcher_refersToTemplate0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
1127 internal::Matcher<TemplateName>, InnerMatcher)namespace internal { class matcher_refersToTemplate0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToTemplate0Matcher
( internal::Matcher<TemplateName> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateName
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToTemplate( internal::
Matcher<TemplateName> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_refersToTemplate0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<TemplateArgument>
( &refersToTemplate_Type0)(internal::Matcher<TemplateName
> const &InnerMatcher); inline bool internal::matcher_refersToTemplate0Matcher
::matches( const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
1128 if (Node.getKind() != TemplateArgument::Template)
1129 return false;
1130 return InnerMatcher.matches(Node.getAsTemplate(), Finder, Builder);
1131}
1132
1133/// Matches a canonical TemplateArgument that refers to a certain
1134/// declaration.
1135///
1136/// Given
1137/// \code
1138/// struct B { int next; };
1139/// template<int(B::*next_ptr)> struct A {};
1140/// A<&B::next> a;
1141/// \endcode
1142/// classTemplateSpecializationDecl(hasAnyTemplateArgument(
1143/// refersToDeclaration(fieldDecl(hasName("next")))))
1144/// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching
1145/// \c B::next
1146AST_MATCHER_P(TemplateArgument, refersToDeclaration,namespace internal { class matcher_refersToDeclaration0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToDeclaration0Matcher
( internal::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToDeclaration( internal::Matcher<Decl> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_refersToDeclaration0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToDeclaration_Type0)(internal
::Matcher<Decl> const &InnerMatcher); inline bool internal
::matcher_refersToDeclaration0Matcher::matches( const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1147 internal::Matcher<Decl>, InnerMatcher)namespace internal { class matcher_refersToDeclaration0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToDeclaration0Matcher
( internal::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const TemplateArgument &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<TemplateArgument
> refersToDeclaration( internal::Matcher<Decl> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_refersToDeclaration0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToDeclaration_Type0)(internal
::Matcher<Decl> const &InnerMatcher); inline bool internal
::matcher_refersToDeclaration0Matcher::matches( const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1148 if (Node.getKind() == TemplateArgument::Declaration)
1149 return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder);
1150 return false;
1151}
1152
1153/// Matches a sugar TemplateArgument that refers to a certain expression.
1154///
1155/// Given
1156/// \code
1157/// struct B { int next; };
1158/// template<int(B::*next_ptr)> struct A {};
1159/// A<&B::next> a;
1160/// \endcode
1161/// templateSpecializationType(hasAnyTemplateArgument(
1162/// isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next"))))))))
1163/// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching
1164/// \c B::next
1165AST_MATCHER_P(TemplateArgument, isExpr, internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_isExpr0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_isExpr0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const TemplateArgument &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<TemplateArgument> isExpr
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isExpr0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<TemplateArgument> ( &isExpr_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_isExpr0Matcher::matches( const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1166 if (Node.getKind() == TemplateArgument::Expression)
1167 return InnerMatcher.matches(*Node.getAsExpr(), Finder, Builder);
1168 return false;
1169}
1170
1171/// Matches a TemplateArgument that is an integral value.
1172///
1173/// Given
1174/// \code
1175/// template<int T> struct C {};
1176/// C<42> c;
1177/// \endcode
1178/// classTemplateSpecializationDecl(
1179/// hasAnyTemplateArgument(isIntegral()))
1180/// matches the implicit instantiation of C in C<42>
1181/// with isIntegral() matching 42.
1182AST_MATCHER(TemplateArgument, isIntegral)namespace internal { class matcher_isIntegralMatcher : public
::clang::ast_matchers::internal::MatcherInterface<TemplateArgument
> { public: explicit matcher_isIntegralMatcher() = default
; bool matches(const TemplateArgument &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<TemplateArgument
> isIntegral() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isIntegralMatcher()); } inline bool internal
::matcher_isIntegralMatcher::matches( const TemplateArgument &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
1183 return Node.getKind() == TemplateArgument::Integral;
1184}
1185
1186/// Matches a TemplateArgument that refers to an integral type.
1187///
1188/// Given
1189/// \code
1190/// template<int T> struct C {};
1191/// C<42> c;
1192/// \endcode
1193/// classTemplateSpecializationDecl(
1194/// hasAnyTemplateArgument(refersToIntegralType(asString("int"))))
1195/// matches the implicit instantiation of C in C<42>.
1196AST_MATCHER_P(TemplateArgument, refersToIntegralType,namespace internal { class matcher_refersToIntegralType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToIntegralType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToIntegralType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_refersToIntegralType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToIntegralType_Type0)(internal
::Matcher<QualType> const &InnerMatcher); inline bool
internal::matcher_refersToIntegralType0Matcher::matches( const
TemplateArgument &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1197 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_refersToIntegralType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_refersToIntegralType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const TemplateArgument
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateArgument> refersToIntegralType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_refersToIntegralType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<TemplateArgument> ( &refersToIntegralType_Type0)(internal
::Matcher<QualType> const &InnerMatcher); inline bool
internal::matcher_refersToIntegralType0Matcher::matches( const
TemplateArgument &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1198 if (Node.getKind() != TemplateArgument::Integral)
1199 return false;
1200 return InnerMatcher.matches(Node.getIntegralType(), Finder, Builder);
1201}
1202
1203/// Matches a TemplateArgument of integral type with a given value.
1204///
1205/// Note that 'Value' is a string as the template argument's value is
1206/// an arbitrary precision integer. 'Value' must be euqal to the canonical
1207/// representation of that integral value in base 10.
1208///
1209/// Given
1210/// \code
1211/// template<int T> struct C {};
1212/// C<42> c;
1213/// \endcode
1214/// classTemplateSpecializationDecl(
1215/// hasAnyTemplateArgument(equalsIntegralValue("42")))
1216/// matches the implicit instantiation of C in C<42>.
1217AST_MATCHER_P(TemplateArgument, equalsIntegralValue,namespace internal { class matcher_equalsIntegralValue0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_equalsIntegralValue0Matcher
( std::string const &AValue) : Value(AValue) {} bool matches
(const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Value; }; } inline
::clang::ast_matchers::internal::Matcher<TemplateArgument
> equalsIntegralValue( std::string const &Value) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_equalsIntegralValue0Matcher(Value)); } typedef ::clang
::ast_matchers::internal::Matcher<TemplateArgument> ( &
equalsIntegralValue_Type0)(std::string const &Value); inline
bool internal::matcher_equalsIntegralValue0Matcher::matches(
const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
1218 std::string, Value)namespace internal { class matcher_equalsIntegralValue0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateArgument> { public: explicit matcher_equalsIntegralValue0Matcher
( std::string const &AValue) : Value(AValue) {} bool matches
(const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Value; }; } inline
::clang::ast_matchers::internal::Matcher<TemplateArgument
> equalsIntegralValue( std::string const &Value) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_equalsIntegralValue0Matcher(Value)); } typedef ::clang
::ast_matchers::internal::Matcher<TemplateArgument> ( &
equalsIntegralValue_Type0)(std::string const &Value); inline
bool internal::matcher_equalsIntegralValue0Matcher::matches(
const TemplateArgument &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
1219 if (Node.getKind() != TemplateArgument::Integral)
1220 return false;
1221 return toString(Node.getAsIntegral(), 10) == Value;
1222}
1223
1224/// Matches an Objective-C autorelease pool statement.
1225///
1226/// Given
1227/// \code
1228/// @autoreleasepool {
1229/// int x = 0;
1230/// }
1231/// \endcode
1232/// autoreleasePoolStmt(stmt()) matches the declaration of "x"
1233/// inside the autorelease pool.
1234extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1235 ObjCAutoreleasePoolStmt> autoreleasePoolStmt;
1236
1237/// Matches any value declaration.
1238///
1239/// Example matches A, B, C and F
1240/// \code
1241/// enum X { A, B, C };
1242/// void F();
1243/// \endcode
1244extern const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl;
1245
1246/// Matches C++ constructor declarations.
1247///
1248/// Example matches Foo::Foo() and Foo::Foo(int)
1249/// \code
1250/// class Foo {
1251/// public:
1252/// Foo();
1253/// Foo(int);
1254/// int DoSomething();
1255/// };
1256/// \endcode
1257extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl>
1258 cxxConstructorDecl;
1259
1260/// Matches explicit C++ destructor declarations.
1261///
1262/// Example matches Foo::~Foo()
1263/// \code
1264/// class Foo {
1265/// public:
1266/// virtual ~Foo();
1267/// };
1268/// \endcode
1269extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl>
1270 cxxDestructorDecl;
1271
1272/// Matches enum declarations.
1273///
1274/// Example matches X
1275/// \code
1276/// enum X {
1277/// A, B, C
1278/// };
1279/// \endcode
1280extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl;
1281
1282/// Matches enum constants.
1283///
1284/// Example matches A, B, C
1285/// \code
1286/// enum X {
1287/// A, B, C
1288/// };
1289/// \endcode
1290extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl>
1291 enumConstantDecl;
1292
1293/// Matches tag declarations.
1294///
1295/// Example matches X, Z, U, S, E
1296/// \code
1297/// class X;
1298/// template<class T> class Z {};
1299/// struct S {};
1300/// union U {};
1301/// enum E {
1302/// A, B, C
1303/// };
1304/// \endcode
1305extern const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl> tagDecl;
1306
1307/// Matches method declarations.
1308///
1309/// Example matches y
1310/// \code
1311/// class X { void y(); };
1312/// \endcode
1313extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl>
1314 cxxMethodDecl;
1315
1316/// Matches conversion operator declarations.
1317///
1318/// Example matches the operator.
1319/// \code
1320/// class X { operator int() const; };
1321/// \endcode
1322extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
1323 cxxConversionDecl;
1324
1325/// Matches user-defined and implicitly generated deduction guide.
1326///
1327/// Example matches the deduction guide.
1328/// \code
1329/// template<typename T>
1330/// class X { X(int) };
1331/// X(int) -> X<int>;
1332/// \endcode
1333extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl>
1334 cxxDeductionGuideDecl;
1335
1336/// Matches variable declarations.
1337///
1338/// Note: this does not match declarations of member variables, which are
1339/// "field" declarations in Clang parlance.
1340///
1341/// Example matches a
1342/// \code
1343/// int a;
1344/// \endcode
1345extern const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl;
1346
1347/// Matches field declarations.
1348///
1349/// Given
1350/// \code
1351/// class X { int m; };
1352/// \endcode
1353/// fieldDecl()
1354/// matches 'm'.
1355extern const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl;
1356
1357/// Matches indirect field declarations.
1358///
1359/// Given
1360/// \code
1361/// struct X { struct { int a; }; };
1362/// \endcode
1363/// indirectFieldDecl()
1364/// matches 'a'.
1365extern const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl>
1366 indirectFieldDecl;
1367
1368/// Matches function declarations.
1369///
1370/// Example matches f
1371/// \code
1372/// void f();
1373/// \endcode
1374extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl>
1375 functionDecl;
1376
1377/// Matches C++ function template declarations.
1378///
1379/// Example matches f
1380/// \code
1381/// template<class T> void f(T t) {}
1382/// \endcode
1383extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl>
1384 functionTemplateDecl;
1385
1386/// Matches friend declarations.
1387///
1388/// Given
1389/// \code
1390/// class X { friend void foo(); };
1391/// \endcode
1392/// friendDecl()
1393/// matches 'friend void foo()'.
1394extern const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl;
1395
1396/// Matches statements.
1397///
1398/// Given
1399/// \code
1400/// { ++a; }
1401/// \endcode
1402/// stmt()
1403/// matches both the compound statement '{ ++a; }' and '++a'.
1404extern const internal::VariadicAllOfMatcher<Stmt> stmt;
1405
1406/// Matches declaration statements.
1407///
1408/// Given
1409/// \code
1410/// int a;
1411/// \endcode
1412/// declStmt()
1413/// matches 'int a'.
1414extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt;
1415
1416/// Matches member expressions.
1417///
1418/// Given
1419/// \code
1420/// class Y {
1421/// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
1422/// int a; static int b;
1423/// };
1424/// \endcode
1425/// memberExpr()
1426/// matches this->x, x, y.x, a, this->b
1427extern const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr;
1428
1429/// Matches unresolved member expressions.
1430///
1431/// Given
1432/// \code
1433/// struct X {
1434/// template <class T> void f();
1435/// void g();
1436/// };
1437/// template <class T> void h() { X x; x.f<T>(); x.g(); }
1438/// \endcode
1439/// unresolvedMemberExpr()
1440/// matches x.f<T>
1441extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr>
1442 unresolvedMemberExpr;
1443
1444/// Matches member expressions where the actual member referenced could not be
1445/// resolved because the base expression or the member name was dependent.
1446///
1447/// Given
1448/// \code
1449/// template <class T> void f() { T t; t.g(); }
1450/// \endcode
1451/// cxxDependentScopeMemberExpr()
1452/// matches t.g
1453extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1454 CXXDependentScopeMemberExpr>
1455 cxxDependentScopeMemberExpr;
1456
1457/// Matches call expressions.
1458///
1459/// Example matches x.y() and y()
1460/// \code
1461/// X x;
1462/// x.y();
1463/// y();
1464/// \endcode
1465extern const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr;
1466
1467/// Matches call expressions which were resolved using ADL.
1468///
1469/// Example matches y(x) but not y(42) or NS::y(x).
1470/// \code
1471/// namespace NS {
1472/// struct X {};
1473/// void y(X);
1474/// }
1475///
1476/// void y(...);
1477///
1478/// void test() {
1479/// NS::X x;
1480/// y(x); // Matches
1481/// NS::y(x); // Doesn't match
1482/// y(42); // Doesn't match
1483/// using NS::y;
1484/// y(x); // Found by both unqualified lookup and ADL, doesn't match
1485// }
1486/// \endcode
1487AST_MATCHER(CallExpr, usesADL)namespace internal { class matcher_usesADLMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CallExpr>
{ public: explicit matcher_usesADLMatcher() = default; bool matches
(const CallExpr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<CallExpr> usesADL() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_usesADLMatcher
()); } inline bool internal::matcher_usesADLMatcher::matches(
const CallExpr &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.usesADL(); }
1488
1489/// Matches lambda expressions.
1490///
1491/// Example matches [&](){return 5;}
1492/// \code
1493/// [&](){return 5;}
1494/// \endcode
1495extern const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr;
1496
1497/// Matches member call expressions.
1498///
1499/// Example matches x.y()
1500/// \code
1501/// X x;
1502/// x.y();
1503/// \endcode
1504extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr>
1505 cxxMemberCallExpr;
1506
1507/// Matches ObjectiveC Message invocation expressions.
1508///
1509/// The innermost message send invokes the "alloc" class method on the
1510/// NSString class, while the outermost message send invokes the
1511/// "initWithString" instance method on the object returned from
1512/// NSString's "alloc". This matcher should match both message sends.
1513/// \code
1514/// [[NSString alloc] initWithString:@"Hello"]
1515/// \endcode
1516extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr>
1517 objcMessageExpr;
1518
1519/// Matches ObjectiveC String literal expressions.
1520///
1521/// Example matches @"abcd"
1522/// \code
1523/// NSString *s = @"abcd";
1524/// \endcode
1525extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral>
1526 objcStringLiteral;
1527
1528/// Matches Objective-C interface declarations.
1529///
1530/// Example matches Foo
1531/// \code
1532/// @interface Foo
1533/// @end
1534/// \endcode
1535extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl>
1536 objcInterfaceDecl;
1537
1538/// Matches Objective-C implementation declarations.
1539///
1540/// Example matches Foo
1541/// \code
1542/// @implementation Foo
1543/// @end
1544/// \endcode
1545extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl>
1546 objcImplementationDecl;
1547
1548/// Matches Objective-C protocol declarations.
1549///
1550/// Example matches FooDelegate
1551/// \code
1552/// @protocol FooDelegate
1553/// @end
1554/// \endcode
1555extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl>
1556 objcProtocolDecl;
1557
1558/// Matches Objective-C category declarations.
1559///
1560/// Example matches Foo (Additions)
1561/// \code
1562/// @interface Foo (Additions)
1563/// @end
1564/// \endcode
1565extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl>
1566 objcCategoryDecl;
1567
1568/// Matches Objective-C category definitions.
1569///
1570/// Example matches Foo (Additions)
1571/// \code
1572/// @implementation Foo (Additions)
1573/// @end
1574/// \endcode
1575extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl>
1576 objcCategoryImplDecl;
1577
1578/// Matches Objective-C method declarations.
1579///
1580/// Example matches both declaration and definition of -[Foo method]
1581/// \code
1582/// @interface Foo
1583/// - (void)method;
1584/// @end
1585///
1586/// @implementation Foo
1587/// - (void)method {}
1588/// @end
1589/// \endcode
1590extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl>
1591 objcMethodDecl;
1592
1593/// Matches block declarations.
1594///
1595/// Example matches the declaration of the nameless block printing an input
1596/// integer.
1597///
1598/// \code
1599/// myFunc(^(int p) {
1600/// printf("%d", p);
1601/// })
1602/// \endcode
1603extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl>
1604 blockDecl;
1605
1606/// Matches Objective-C instance variable declarations.
1607///
1608/// Example matches _enabled
1609/// \code
1610/// @implementation Foo {
1611/// BOOL _enabled;
1612/// }
1613/// @end
1614/// \endcode
1615extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl>
1616 objcIvarDecl;
1617
1618/// Matches Objective-C property declarations.
1619///
1620/// Example matches enabled
1621/// \code
1622/// @interface Foo
1623/// @property BOOL enabled;
1624/// @end
1625/// \endcode
1626extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl>
1627 objcPropertyDecl;
1628
1629/// Matches Objective-C \@throw statements.
1630///
1631/// Example matches \@throw
1632/// \code
1633/// @throw obj;
1634/// \endcode
1635extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt>
1636 objcThrowStmt;
1637
1638/// Matches Objective-C @try statements.
1639///
1640/// Example matches @try
1641/// \code
1642/// @try {}
1643/// @catch (...) {}
1644/// \endcode
1645extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt>
1646 objcTryStmt;
1647
1648/// Matches Objective-C @catch statements.
1649///
1650/// Example matches @catch
1651/// \code
1652/// @try {}
1653/// @catch (...) {}
1654/// \endcode
1655extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt>
1656 objcCatchStmt;
1657
1658/// Matches Objective-C @finally statements.
1659///
1660/// Example matches @finally
1661/// \code
1662/// @try {}
1663/// @finally {}
1664/// \endcode
1665extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt>
1666 objcFinallyStmt;
1667
1668/// Matches expressions that introduce cleanups to be run at the end
1669/// of the sub-expression's evaluation.
1670///
1671/// Example matches std::string()
1672/// \code
1673/// const std::string str = std::string();
1674/// \endcode
1675extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups>
1676 exprWithCleanups;
1677
1678/// Matches init list expressions.
1679///
1680/// Given
1681/// \code
1682/// int a[] = { 1, 2 };
1683/// struct B { int x, y; };
1684/// B b = { 5, 6 };
1685/// \endcode
1686/// initListExpr()
1687/// matches "{ 1, 2 }" and "{ 5, 6 }"
1688extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr>
1689 initListExpr;
1690
1691/// Matches the syntactic form of init list expressions
1692/// (if expression have it).
1693AST_MATCHER_P(InitListExpr, hasSyntacticForm,namespace internal { class matcher_hasSyntacticForm0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
InitListExpr> { public: explicit matcher_hasSyntacticForm0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const InitListExpr &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<InitListExpr
> hasSyntacticForm( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasSyntacticForm0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<InitListExpr
> ( &hasSyntacticForm_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasSyntacticForm0Matcher
::matches( const InitListExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
1694 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasSyntacticForm0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
InitListExpr> { public: explicit matcher_hasSyntacticForm0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const InitListExpr &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<InitListExpr
> hasSyntacticForm( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasSyntacticForm0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<InitListExpr
> ( &hasSyntacticForm_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasSyntacticForm0Matcher
::matches( const InitListExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
1695 const Expr *SyntForm = Node.getSyntacticForm();
1696 return (SyntForm != nullptr &&
1697 InnerMatcher.matches(*SyntForm, Finder, Builder));
1698}
1699
1700/// Matches C++ initializer list expressions.
1701///
1702/// Given
1703/// \code
1704/// std::vector<int> a({ 1, 2, 3 });
1705/// std::vector<int> b = { 4, 5 };
1706/// int c[] = { 6, 7 };
1707/// std::pair<int, int> d = { 8, 9 };
1708/// \endcode
1709/// cxxStdInitializerListExpr()
1710/// matches "{ 1, 2, 3 }" and "{ 4, 5 }"
1711extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1712 CXXStdInitializerListExpr>
1713 cxxStdInitializerListExpr;
1714
1715/// Matches implicit initializers of init list expressions.
1716///
1717/// Given
1718/// \code
1719/// point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 };
1720/// \endcode
1721/// implicitValueInitExpr()
1722/// matches "[0].y" (implicitly)
1723extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr>
1724 implicitValueInitExpr;
1725
1726/// Matches paren list expressions.
1727/// ParenListExprs don't have a predefined type and are used for late parsing.
1728/// In the final AST, they can be met in template declarations.
1729///
1730/// Given
1731/// \code
1732/// template<typename T> class X {
1733/// void f() {
1734/// X x(*this);
1735/// int a = 0, b = 1; int i = (a, b);
1736/// }
1737/// };
1738/// \endcode
1739/// parenListExpr() matches "*this" but NOT matches (a, b) because (a, b)
1740/// has a predefined type and is a ParenExpr, not a ParenListExpr.
1741extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr>
1742 parenListExpr;
1743
1744/// Matches substitutions of non-type template parameters.
1745///
1746/// Given
1747/// \code
1748/// template <int N>
1749/// struct A { static const int n = N; };
1750/// struct B : public A<42> {};
1751/// \endcode
1752/// substNonTypeTemplateParmExpr()
1753/// matches "N" in the right-hand side of "static const int n = N;"
1754extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1755 SubstNonTypeTemplateParmExpr>
1756 substNonTypeTemplateParmExpr;
1757
1758/// Matches using declarations.
1759///
1760/// Given
1761/// \code
1762/// namespace X { int x; }
1763/// using X::x;
1764/// \endcode
1765/// usingDecl()
1766/// matches \code using X::x \endcode
1767extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl;
1768
1769/// Matches using-enum declarations.
1770///
1771/// Given
1772/// \code
1773/// namespace X { enum x {...}; }
1774/// using enum X::x;
1775/// \endcode
1776/// usingEnumDecl()
1777/// matches \code using enum X::x \endcode
1778extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl>
1779 usingEnumDecl;
1780
1781/// Matches using namespace declarations.
1782///
1783/// Given
1784/// \code
1785/// namespace X { int x; }
1786/// using namespace X;
1787/// \endcode
1788/// usingDirectiveDecl()
1789/// matches \code using namespace X \endcode
1790extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl>
1791 usingDirectiveDecl;
1792
1793/// Matches reference to a name that can be looked up during parsing
1794/// but could not be resolved to a specific declaration.
1795///
1796/// Given
1797/// \code
1798/// template<typename T>
1799/// T foo() { T a; return a; }
1800/// template<typename T>
1801/// void bar() {
1802/// foo<T>();
1803/// }
1804/// \endcode
1805/// unresolvedLookupExpr()
1806/// matches \code foo<T>() \endcode
1807extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr>
1808 unresolvedLookupExpr;
1809
1810/// Matches unresolved using value declarations.
1811///
1812/// Given
1813/// \code
1814/// template<typename X>
1815/// class C : private X {
1816/// using X::x;
1817/// };
1818/// \endcode
1819/// unresolvedUsingValueDecl()
1820/// matches \code using X::x \endcode
1821extern const internal::VariadicDynCastAllOfMatcher<Decl,
1822 UnresolvedUsingValueDecl>
1823 unresolvedUsingValueDecl;
1824
1825/// Matches unresolved using value declarations that involve the
1826/// typename.
1827///
1828/// Given
1829/// \code
1830/// template <typename T>
1831/// struct Base { typedef T Foo; };
1832///
1833/// template<typename T>
1834/// struct S : private Base<T> {
1835/// using typename Base<T>::Foo;
1836/// };
1837/// \endcode
1838/// unresolvedUsingTypenameDecl()
1839/// matches \code using Base<T>::Foo \endcode
1840extern const internal::VariadicDynCastAllOfMatcher<Decl,
1841 UnresolvedUsingTypenameDecl>
1842 unresolvedUsingTypenameDecl;
1843
1844/// Matches a constant expression wrapper.
1845///
1846/// Example matches the constant in the case statement:
1847/// (matcher = constantExpr())
1848/// \code
1849/// switch (a) {
1850/// case 37: break;
1851/// }
1852/// \endcode
1853extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr>
1854 constantExpr;
1855
1856/// Matches parentheses used in expressions.
1857///
1858/// Example matches (foo() + 1)
1859/// \code
1860/// int foo() { return 1; }
1861/// int a = (foo() + 1);
1862/// \endcode
1863extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr;
1864
1865/// Matches constructor call expressions (including implicit ones).
1866///
1867/// Example matches string(ptr, n) and ptr within arguments of f
1868/// (matcher = cxxConstructExpr())
1869/// \code
1870/// void f(const string &a, const string &b);
1871/// char *ptr;
1872/// int n;
1873/// f(string(ptr, n), ptr);
1874/// \endcode
1875extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr>
1876 cxxConstructExpr;
1877
1878/// Matches unresolved constructor call expressions.
1879///
1880/// Example matches T(t) in return statement of f
1881/// (matcher = cxxUnresolvedConstructExpr())
1882/// \code
1883/// template <typename T>
1884/// void f(const T& t) { return T(t); }
1885/// \endcode
1886extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1887 CXXUnresolvedConstructExpr>
1888 cxxUnresolvedConstructExpr;
1889
1890/// Matches implicit and explicit this expressions.
1891///
1892/// Example matches the implicit this expression in "return i".
1893/// (matcher = cxxThisExpr())
1894/// \code
1895/// struct foo {
1896/// int i;
1897/// int f() { return i; }
1898/// };
1899/// \endcode
1900extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr>
1901 cxxThisExpr;
1902
1903/// Matches nodes where temporaries are created.
1904///
1905/// Example matches FunctionTakesString(GetStringByValue())
1906/// (matcher = cxxBindTemporaryExpr())
1907/// \code
1908/// FunctionTakesString(GetStringByValue());
1909/// FunctionTakesStringByPointer(GetStringPointer());
1910/// \endcode
1911extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr>
1912 cxxBindTemporaryExpr;
1913
1914/// Matches nodes where temporaries are materialized.
1915///
1916/// Example: Given
1917/// \code
1918/// struct T {void func();};
1919/// T f();
1920/// void g(T);
1921/// \endcode
1922/// materializeTemporaryExpr() matches 'f()' in these statements
1923/// \code
1924/// T u(f());
1925/// g(f());
1926/// f().func();
1927/// \endcode
1928/// but does not match
1929/// \code
1930/// f();
1931/// \endcode
1932extern const internal::VariadicDynCastAllOfMatcher<Stmt,
1933 MaterializeTemporaryExpr>
1934 materializeTemporaryExpr;
1935
1936/// Matches new expressions.
1937///
1938/// Given
1939/// \code
1940/// new X;
1941/// \endcode
1942/// cxxNewExpr()
1943/// matches 'new X'.
1944extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr;
1945
1946/// Matches delete expressions.
1947///
1948/// Given
1949/// \code
1950/// delete X;
1951/// \endcode
1952/// cxxDeleteExpr()
1953/// matches 'delete X'.
1954extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr>
1955 cxxDeleteExpr;
1956
1957/// Matches noexcept expressions.
1958///
1959/// Given
1960/// \code
1961/// bool a() noexcept;
1962/// bool b() noexcept(true);
1963/// bool c() noexcept(false);
1964/// bool d() noexcept(noexcept(a()));
1965/// bool e = noexcept(b()) || noexcept(c());
1966/// \endcode
1967/// cxxNoexceptExpr()
1968/// matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`.
1969/// doesn't match the noexcept specifier in the declarations a, b, c or d.
1970extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr>
1971 cxxNoexceptExpr;
1972
1973/// Matches array subscript expressions.
1974///
1975/// Given
1976/// \code
1977/// int i = a[1];
1978/// \endcode
1979/// arraySubscriptExpr()
1980/// matches "a[1]"
1981extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr>
1982 arraySubscriptExpr;
1983
1984/// Matches the value of a default argument at the call site.
1985///
1986/// Example matches the CXXDefaultArgExpr placeholder inserted for the
1987/// default value of the second parameter in the call expression f(42)
1988/// (matcher = cxxDefaultArgExpr())
1989/// \code
1990/// void f(int x, int y = 0);
1991/// f(42);
1992/// \endcode
1993extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr>
1994 cxxDefaultArgExpr;
1995
1996/// Matches overloaded operator calls.
1997///
1998/// Note that if an operator isn't overloaded, it won't match. Instead, use
1999/// binaryOperator matcher.
2000/// Currently it does not match operators such as new delete.
2001/// FIXME: figure out why these do not match?
2002///
2003/// Example matches both operator<<((o << b), c) and operator<<(o, b)
2004/// (matcher = cxxOperatorCallExpr())
2005/// \code
2006/// ostream &operator<< (ostream &out, int i) { };
2007/// ostream &o; int b = 1, c = 1;
2008/// o << b << c;
2009/// \endcode
2010/// See also the binaryOperation() matcher for more-general matching of binary
2011/// uses of this AST node.
2012extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr>
2013 cxxOperatorCallExpr;
2014
2015/// Matches rewritten binary operators
2016///
2017/// Example matches use of "<":
2018/// \code
2019/// #include <compare>
2020/// struct HasSpaceshipMem {
2021/// int a;
2022/// constexpr auto operator<=>(const HasSpaceshipMem&) const = default;
2023/// };
2024/// void compare() {
2025/// HasSpaceshipMem hs1, hs2;
2026/// if (hs1 < hs2)
2027/// return;
2028/// }
2029/// \endcode
2030/// See also the binaryOperation() matcher for more-general matching
2031/// of this AST node.
2032extern const internal::VariadicDynCastAllOfMatcher<Stmt,
2033 CXXRewrittenBinaryOperator>
2034 cxxRewrittenBinaryOperator;
2035
2036/// Matches expressions.
2037///
2038/// Example matches x()
2039/// \code
2040/// void f() { x(); }
2041/// \endcode
2042extern const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr;
2043
2044/// Matches expressions that refer to declarations.
2045///
2046/// Example matches x in if (x)
2047/// \code
2048/// bool x;
2049/// if (x) {}
2050/// \endcode
2051extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr>
2052 declRefExpr;
2053
2054/// Matches a reference to an ObjCIvar.
2055///
2056/// Example: matches "a" in "init" method:
2057/// \code
2058/// @implementation A {
2059/// NSString *a;
2060/// }
2061/// - (void) init {
2062/// a = @"hello";
2063/// }
2064/// \endcode
2065extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr>
2066 objcIvarRefExpr;
2067
2068/// Matches a reference to a block.
2069///
2070/// Example: matches "^{}":
2071/// \code
2072/// void f() { ^{}(); }
2073/// \endcode
2074extern const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr;
2075
2076/// Matches if statements.
2077///
2078/// Example matches 'if (x) {}'
2079/// \code
2080/// if (x) {}
2081/// \endcode
2082extern const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt;
2083
2084/// Matches for statements.
2085///
2086/// Example matches 'for (;;) {}'
2087/// \code
2088/// for (;;) {}
2089/// int i[] = {1, 2, 3}; for (auto a : i);
2090/// \endcode
2091extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt;
2092
2093/// Matches the increment statement of a for loop.
2094///
2095/// Example:
2096/// forStmt(hasIncrement(unaryOperator(hasOperatorName("++"))))
2097/// matches '++x' in
2098/// \code
2099/// for (x; x < N; ++x) { }
2100/// \endcode
2101AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>,namespace internal { class matcher_hasIncrement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasIncrement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasIncrement
( internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasIncrement0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasIncrement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasIncrement0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
2102 InnerMatcher)namespace internal { class matcher_hasIncrement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasIncrement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasIncrement
( internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasIncrement0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasIncrement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasIncrement0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
2103 const Stmt *const Increment = Node.getInc();
2104 return (Increment != nullptr &&
2105 InnerMatcher.matches(*Increment, Finder, Builder));
2106}
2107
2108/// Matches the initialization statement of a for loop.
2109///
2110/// Example:
2111/// forStmt(hasLoopInit(declStmt()))
2112/// matches 'int x = 0' in
2113/// \code
2114/// for (int x = 0; x < N; ++x) { }
2115/// \endcode
2116AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>,namespace internal { class matcher_hasLoopInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasLoopInit0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasLoopInit(
internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasLoopInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasLoopInit_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasLoopInit0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
2117 InnerMatcher)namespace internal { class matcher_hasLoopInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ForStmt
> { public: explicit matcher_hasLoopInit0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ForStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ForStmt> hasLoopInit(
internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasLoopInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ForStmt> ( &hasLoopInit_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); inline
bool internal::matcher_hasLoopInit0Matcher::matches( const ForStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
2118 const Stmt *const Init = Node.getInit();
2119 return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder));
2120}
2121
2122/// Matches range-based for statements.
2123///
2124/// cxxForRangeStmt() matches 'for (auto a : i)'
2125/// \code
2126/// int i[] = {1, 2, 3}; for (auto a : i);
2127/// for(int j = 0; j < 5; ++j);
2128/// \endcode
2129extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt>
2130 cxxForRangeStmt;
2131
2132/// Matches the initialization statement of a for loop.
2133///
2134/// Example:
2135/// forStmt(hasLoopVariable(anything()))
2136/// matches 'int x' in
2137/// \code
2138/// for (int x : a) { }
2139/// \endcode
2140AST_MATCHER_P(CXXForRangeStmt, hasLoopVariable, internal::Matcher<VarDecl>,namespace internal { class matcher_hasLoopVariable0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasLoopVariable0Matcher( internal
::Matcher<VarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<VarDecl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasLoopVariable( internal::Matcher<VarDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasLoopVariable0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> ( &hasLoopVariable_Type0)(internal::Matcher<VarDecl
> const &InnerMatcher); inline bool internal::matcher_hasLoopVariable0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
2141 InnerMatcher)namespace internal { class matcher_hasLoopVariable0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasLoopVariable0Matcher( internal
::Matcher<VarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<VarDecl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasLoopVariable( internal::Matcher<VarDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasLoopVariable0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> ( &hasLoopVariable_Type0)(internal::Matcher<VarDecl
> const &InnerMatcher); inline bool internal::matcher_hasLoopVariable0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
2142 const VarDecl *const Var = Node.getLoopVariable();
2143 return (Var != nullptr && InnerMatcher.matches(*Var, Finder, Builder));
2144}
2145
2146/// Matches the range initialization statement of a for loop.
2147///
2148/// Example:
2149/// forStmt(hasRangeInit(anything()))
2150/// matches 'a' in
2151/// \code
2152/// for (int x : a) { }
2153/// \endcode
2154AST_MATCHER_P(CXXForRangeStmt, hasRangeInit, internal::Matcher<Expr>,namespace internal { class matcher_hasRangeInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasRangeInit0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasRangeInit( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasRangeInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CXXForRangeStmt> ( &
hasRangeInit_Type0)(internal::Matcher<Expr> const &
InnerMatcher); inline bool internal::matcher_hasRangeInit0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
2155 InnerMatcher)namespace internal { class matcher_hasRangeInit0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXForRangeStmt
> { public: explicit matcher_hasRangeInit0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXForRangeStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXForRangeStmt
> hasRangeInit( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasRangeInit0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CXXForRangeStmt> ( &
hasRangeInit_Type0)(internal::Matcher<Expr> const &
InnerMatcher); inline bool internal::matcher_hasRangeInit0Matcher
::matches( const CXXForRangeStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
2156 const Expr *const Init = Node.getRangeInit();
2157 return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder));
2158}
2159
2160/// Matches while statements.
2161///
2162/// Given
2163/// \code
2164/// while (true) {}
2165/// \endcode
2166/// whileStmt()
2167/// matches 'while (true) {}'.
2168extern const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt;
2169
2170/// Matches do statements.
2171///
2172/// Given
2173/// \code
2174/// do {} while (true);
2175/// \endcode
2176/// doStmt()
2177/// matches 'do {} while(true)'
2178extern const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt;
2179
2180/// Matches break statements.
2181///
2182/// Given
2183/// \code
2184/// while (true) { break; }
2185/// \endcode
2186/// breakStmt()
2187/// matches 'break'
2188extern const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt;
2189
2190/// Matches continue statements.
2191///
2192/// Given
2193/// \code
2194/// while (true) { continue; }
2195/// \endcode
2196/// continueStmt()
2197/// matches 'continue'
2198extern const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt>
2199 continueStmt;
2200
2201/// Matches co_return statements.
2202///
2203/// Given
2204/// \code
2205/// while (true) { co_return; }
2206/// \endcode
2207/// coreturnStmt()
2208/// matches 'co_return'
2209extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt>
2210 coreturnStmt;
2211
2212/// Matches return statements.
2213///
2214/// Given
2215/// \code
2216/// return 1;
2217/// \endcode
2218/// returnStmt()
2219/// matches 'return 1'
2220extern const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt;
2221
2222/// Matches goto statements.
2223///
2224/// Given
2225/// \code
2226/// goto FOO;
2227/// FOO: bar();
2228/// \endcode
2229/// gotoStmt()
2230/// matches 'goto FOO'
2231extern const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt;
2232
2233/// Matches label statements.
2234///
2235/// Given
2236/// \code
2237/// goto FOO;
2238/// FOO: bar();
2239/// \endcode
2240/// labelStmt()
2241/// matches 'FOO:'
2242extern const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt;
2243
2244/// Matches address of label statements (GNU extension).
2245///
2246/// Given
2247/// \code
2248/// FOO: bar();
2249/// void *ptr = &&FOO;
2250/// goto *bar;
2251/// \endcode
2252/// addrLabelExpr()
2253/// matches '&&FOO'
2254extern const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr>
2255 addrLabelExpr;
2256
2257/// Matches switch statements.
2258///
2259/// Given
2260/// \code
2261/// switch(a) { case 42: break; default: break; }
2262/// \endcode
2263/// switchStmt()
2264/// matches 'switch(a)'.
2265extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt;
2266
2267/// Matches case and default statements inside switch statements.
2268///
2269/// Given
2270/// \code
2271/// switch(a) { case 42: break; default: break; }
2272/// \endcode
2273/// switchCase()
2274/// matches 'case 42:' and 'default:'.
2275extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase;
2276
2277/// Matches case statements inside switch statements.
2278///
2279/// Given
2280/// \code
2281/// switch(a) { case 42: break; default: break; }
2282/// \endcode
2283/// caseStmt()
2284/// matches 'case 42:'.
2285extern const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt;
2286
2287/// Matches default statements inside switch statements.
2288///
2289/// Given
2290/// \code
2291/// switch(a) { case 42: break; default: break; }
2292/// \endcode
2293/// defaultStmt()
2294/// matches 'default:'.
2295extern const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt>
2296 defaultStmt;
2297
2298/// Matches compound statements.
2299///
2300/// Example matches '{}' and '{{}}' in 'for (;;) {{}}'
2301/// \code
2302/// for (;;) {{}}
2303/// \endcode
2304extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt>
2305 compoundStmt;
2306
2307/// Matches catch statements.
2308///
2309/// \code
2310/// try {} catch(int i) {}
2311/// \endcode
2312/// cxxCatchStmt()
2313/// matches 'catch(int i)'
2314extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt>
2315 cxxCatchStmt;
2316
2317/// Matches try statements.
2318///
2319/// \code
2320/// try {} catch(int i) {}
2321/// \endcode
2322/// cxxTryStmt()
2323/// matches 'try {}'
2324extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
2325
2326/// Matches throw expressions.
2327///
2328/// \code
2329/// try { throw 5; } catch(int i) {}
2330/// \endcode
2331/// cxxThrowExpr()
2332/// matches 'throw 5'
2333extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr>
2334 cxxThrowExpr;
2335
2336/// Matches null statements.
2337///
2338/// \code
2339/// foo();;
2340/// \endcode
2341/// nullStmt()
2342/// matches the second ';'
2343extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
2344
2345/// Matches asm statements.
2346///
2347/// \code
2348/// int i = 100;
2349/// __asm("mov al, 2");
2350/// \endcode
2351/// asmStmt()
2352/// matches '__asm("mov al, 2")'
2353extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
2354
2355/// Matches bool literals.
2356///
2357/// Example matches true
2358/// \code
2359/// true
2360/// \endcode
2361extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
2362 cxxBoolLiteral;
2363
2364/// Matches string literals (also matches wide string literals).
2365///
2366/// Example matches "abcd", L"abcd"
2367/// \code
2368/// char *s = "abcd";
2369/// wchar_t *ws = L"abcd";
2370/// \endcode
2371extern const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral>
2372 stringLiteral;
2373
2374/// Matches character literals (also matches wchar_t).
2375///
2376/// Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral),
2377/// though.
2378///
2379/// Example matches 'a', L'a'
2380/// \code
2381/// char ch = 'a';
2382/// wchar_t chw = L'a';
2383/// \endcode
2384extern const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral>
2385 characterLiteral;
2386
2387/// Matches integer literals of all sizes / encodings, e.g.
2388/// 1, 1L, 0x1 and 1U.
2389///
2390/// Does not match character-encoded integers such as L'a'.
2391extern const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral>
2392 integerLiteral;
2393
2394/// Matches float literals of all sizes / encodings, e.g.
2395/// 1.0, 1.0f, 1.0L and 1e10.
2396///
2397/// Does not match implicit conversions such as
2398/// \code
2399/// float a = 10;
2400/// \endcode
2401extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral>
2402 floatLiteral;
2403
2404/// Matches imaginary literals, which are based on integer and floating
2405/// point literals e.g.: 1i, 1.0i
2406extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral>
2407 imaginaryLiteral;
2408
2409/// Matches fixed point literals
2410extern const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral>
2411 fixedPointLiteral;
2412
2413/// Matches user defined literal operator call.
2414///
2415/// Example match: "foo"_suffix
2416extern const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral>
2417 userDefinedLiteral;
2418
2419/// Matches compound (i.e. non-scalar) literals
2420///
2421/// Example match: {1}, (1, 2)
2422/// \code
2423/// int array[4] = {1};
2424/// vector int myvec = (vector int)(1, 2);
2425/// \endcode
2426extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr>
2427 compoundLiteralExpr;
2428
2429/// Matches co_await expressions.
2430///
2431/// Given
2432/// \code
2433/// co_await 1;
2434/// \endcode
2435/// coawaitExpr()
2436/// matches 'co_await 1'
2437extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr>
2438 coawaitExpr;
2439/// Matches co_await expressions where the type of the promise is dependent
2440extern const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr>
2441 dependentCoawaitExpr;
2442/// Matches co_yield expressions.
2443///
2444/// Given
2445/// \code
2446/// co_yield 1;
2447/// \endcode
2448/// coyieldExpr()
2449/// matches 'co_yield 1'
2450extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr>
2451 coyieldExpr;
2452
2453/// Matches coroutine body statements.
2454///
2455/// coroutineBodyStmt() matches the coroutine below
2456/// \code
2457/// generator<int> gen() {
2458/// co_return;
2459/// }
2460/// \endcode
2461extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoroutineBodyStmt>
2462 coroutineBodyStmt;
2463
2464/// Matches nullptr literal.
2465extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr>
2466 cxxNullPtrLiteralExpr;
2467
2468/// Matches GNU __builtin_choose_expr.
2469extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr>
2470 chooseExpr;
2471
2472/// Matches GNU __null expression.
2473extern const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr>
2474 gnuNullExpr;
2475
2476/// Matches C11 _Generic expression.
2477extern const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
2478 genericSelectionExpr;
2479
2480/// Matches atomic builtins.
2481/// Example matches __atomic_load_n(ptr, 1)
2482/// \code
2483/// void foo() { int *ptr; __atomic_load_n(ptr, 1); }
2484/// \endcode
2485extern const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr;
2486
2487/// Matches statement expression (GNU extension).
2488///
2489/// Example match: ({ int X = 4; X; })
2490/// \code
2491/// int C = ({ int X = 4; X; });
2492/// \endcode
2493extern const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr;
2494
2495/// Matches binary operator expressions.
2496///
2497/// Example matches a || b
2498/// \code
2499/// !(a || b)
2500/// \endcode
2501/// See also the binaryOperation() matcher for more-general matching.
2502extern const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator>
2503 binaryOperator;
2504
2505/// Matches unary operator expressions.
2506///
2507/// Example matches !a
2508/// \code
2509/// !a || b
2510/// \endcode
2511extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator>
2512 unaryOperator;
2513
2514/// Matches conditional operator expressions.
2515///
2516/// Example matches a ? b : c
2517/// \code
2518/// (a ? b : c) + 42
2519/// \endcode
2520extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator>
2521 conditionalOperator;
2522
2523/// Matches binary conditional operator expressions (GNU extension).
2524///
2525/// Example matches a ?: b
2526/// \code
2527/// (a ?: b) + 42;
2528/// \endcode
2529extern const internal::VariadicDynCastAllOfMatcher<Stmt,
2530 BinaryConditionalOperator>
2531 binaryConditionalOperator;
2532
2533/// Matches opaque value expressions. They are used as helpers
2534/// to reference another expressions and can be met
2535/// in BinaryConditionalOperators, for example.
2536///
2537/// Example matches 'a'
2538/// \code
2539/// (a ?: c) + 42;
2540/// \endcode
2541extern const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr>
2542 opaqueValueExpr;
2543
2544/// Matches a C++ static_assert declaration.
2545///
2546/// Example:
2547/// staticAssertDecl()
2548/// matches
2549/// static_assert(sizeof(S) == sizeof(int))
2550/// in
2551/// \code
2552/// struct S {
2553/// int x;
2554/// };
2555/// static_assert(sizeof(S) == sizeof(int));
2556/// \endcode
2557extern const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl>
2558 staticAssertDecl;
2559
2560/// Matches a reinterpret_cast expression.
2561///
2562/// Either the source expression or the destination type can be matched
2563/// using has(), but hasDestinationType() is more specific and can be
2564/// more readable.
2565///
2566/// Example matches reinterpret_cast<char*>(&p) in
2567/// \code
2568/// void* p = reinterpret_cast<char*>(&p);
2569/// \endcode
2570extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr>
2571 cxxReinterpretCastExpr;
2572
2573/// Matches a C++ static_cast expression.
2574///
2575/// \see hasDestinationType
2576/// \see reinterpretCast
2577///
2578/// Example:
2579/// cxxStaticCastExpr()
2580/// matches
2581/// static_cast<long>(8)
2582/// in
2583/// \code
2584/// long eight(static_cast<long>(8));
2585/// \endcode
2586extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr>
2587 cxxStaticCastExpr;
2588
2589/// Matches a dynamic_cast expression.
2590///
2591/// Example:
2592/// cxxDynamicCastExpr()
2593/// matches
2594/// dynamic_cast<D*>(&b);
2595/// in
2596/// \code
2597/// struct B { virtual ~B() {} }; struct D : B {};
2598/// B b;
2599/// D* p = dynamic_cast<D*>(&b);
2600/// \endcode
2601extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr>
2602 cxxDynamicCastExpr;
2603
2604/// Matches a const_cast expression.
2605///
2606/// Example: Matches const_cast<int*>(&r) in
2607/// \code
2608/// int n = 42;
2609/// const int &r(n);
2610/// int* p = const_cast<int*>(&r);
2611/// \endcode
2612extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr>
2613 cxxConstCastExpr;
2614
2615/// Matches a C-style cast expression.
2616///
2617/// Example: Matches (int) 2.2f in
2618/// \code
2619/// int i = (int) 2.2f;
2620/// \endcode
2621extern const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr>
2622 cStyleCastExpr;
2623
2624/// Matches explicit cast expressions.
2625///
2626/// Matches any cast expression written in user code, whether it be a
2627/// C-style cast, a functional-style cast, or a keyword cast.
2628///
2629/// Does not match implicit conversions.
2630///
2631/// Note: the name "explicitCast" is chosen to match Clang's terminology, as
2632/// Clang uses the term "cast" to apply to implicit conversions as well as to
2633/// actual cast expressions.
2634///
2635/// \see hasDestinationType.
2636///
2637/// Example: matches all five of the casts in
2638/// \code
2639/// int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42)))))
2640/// \endcode
2641/// but does not match the implicit conversion in
2642/// \code
2643/// long ell = 42;
2644/// \endcode
2645extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr>
2646 explicitCastExpr;
2647
2648/// Matches the implicit cast nodes of Clang's AST.
2649///
2650/// This matches many different places, including function call return value
2651/// eliding, as well as any type conversions.
2652extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr>
2653 implicitCastExpr;
2654
2655/// Matches any cast nodes of Clang's AST.
2656///
2657/// Example: castExpr() matches each of the following:
2658/// \code
2659/// (int) 3;
2660/// const_cast<Expr *>(SubExpr);
2661/// char c = 0;
2662/// \endcode
2663/// but does not match
2664/// \code
2665/// int i = (0);
2666/// int k = 0;
2667/// \endcode
2668extern const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr;
2669
2670/// Matches functional cast expressions
2671///
2672/// Example: Matches Foo(bar);
2673/// \code
2674/// Foo f = bar;
2675/// Foo g = (Foo) bar;
2676/// Foo h = Foo(bar);
2677/// \endcode
2678extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr>
2679 cxxFunctionalCastExpr;
2680
2681/// Matches functional cast expressions having N != 1 arguments
2682///
2683/// Example: Matches Foo(bar, bar)
2684/// \code
2685/// Foo h = Foo(bar, bar);
2686/// \endcode
2687extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr>
2688 cxxTemporaryObjectExpr;
2689
2690/// Matches predefined identifier expressions [C99 6.4.2.2].
2691///
2692/// Example: Matches __func__
2693/// \code
2694/// printf("%s", __func__);
2695/// \endcode
2696extern const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr>
2697 predefinedExpr;
2698
2699/// Matches C99 designated initializer expressions [C99 6.7.8].
2700///
2701/// Example: Matches { [2].y = 1.0, [0].x = 1.0 }
2702/// \code
2703/// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };
2704/// \endcode
2705extern const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr>
2706 designatedInitExpr;
2707
2708/// Matches designated initializer expressions that contain
2709/// a specific number of designators.
2710///
2711/// Example: Given
2712/// \code
2713/// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 };
2714/// point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 };
2715/// \endcode
2716/// designatorCountIs(2)
2717/// matches '{ [2].y = 1.0, [0].x = 1.0 }',
2718/// but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'.
2719AST_MATCHER_P(DesignatedInitExpr, designatorCountIs, unsigned, N)namespace internal { class matcher_designatorCountIs0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
DesignatedInitExpr> { public: explicit matcher_designatorCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const DesignatedInitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::Matcher<DesignatedInitExpr>
designatorCountIs( unsigned const &N) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_designatorCountIs0Matcher
(N)); } typedef ::clang::ast_matchers::internal::Matcher<DesignatedInitExpr
> ( &designatorCountIs_Type0)(unsigned const &N); inline
bool internal::matcher_designatorCountIs0Matcher::matches( const
DesignatedInitExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
2720 return Node.size() == N;
2721}
2722
2723/// Matches \c QualTypes in the clang AST.
2724extern const internal::VariadicAllOfMatcher<QualType> qualType;
2725
2726/// Matches \c Types in the clang AST.
2727extern const internal::VariadicAllOfMatcher<Type> type;
2728
2729/// Matches \c TypeLocs in the clang AST.
2730extern const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;
2731
2732/// Matches if any of the given matchers matches.
2733///
2734/// Unlike \c anyOf, \c eachOf will generate a match result for each
2735/// matching submatcher.
2736///
2737/// For example, in:
2738/// \code
2739/// class A { int a; int b; };
2740/// \endcode
2741/// The matcher:
2742/// \code
2743/// cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
2744/// has(fieldDecl(hasName("b")).bind("v"))))
2745/// \endcode
2746/// will generate two results binding "v", the first of which binds
2747/// the field declaration of \c a, the second the field declaration of
2748/// \c b.
2749///
2750/// Usable as: Any Matcher
2751extern const internal::VariadicOperatorMatcherFunc<
2752 2, std::numeric_limits<unsigned>::max()>
2753 eachOf;
2754
2755/// Matches if any of the given matchers matches.
2756///
2757/// Usable as: Any Matcher
2758extern const internal::VariadicOperatorMatcherFunc<
2759 2, std::numeric_limits<unsigned>::max()>
2760 anyOf;
2761
2762/// Matches if all given matchers match.
2763///
2764/// Usable as: Any Matcher
2765extern const internal::VariadicOperatorMatcherFunc<
2766 2, std::numeric_limits<unsigned>::max()>
2767 allOf;
2768
2769/// Matches any node regardless of the submatcher.
2770///
2771/// However, \c optionally will retain any bindings generated by the submatcher.
2772/// Useful when additional information which may or may not present about a main
2773/// matching node is desired.
2774///
2775/// For example, in:
2776/// \code
2777/// class Foo {
2778/// int bar;
2779/// }
2780/// \endcode
2781/// The matcher:
2782/// \code
2783/// cxxRecordDecl(
2784/// optionally(has(
2785/// fieldDecl(hasName("bar")).bind("var")
2786/// ))).bind("record")
2787/// \endcode
2788/// will produce a result binding for both "record" and "var".
2789/// The matcher will produce a "record" binding for even if there is no data
2790/// member named "bar" in that class.
2791///
2792/// Usable as: Any Matcher
2793extern const internal::VariadicOperatorMatcherFunc<1, 1> optionally;
2794
2795/// Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
2796///
2797/// Given
2798/// \code
2799/// Foo x = bar;
2800/// int y = sizeof(x) + alignof(x);
2801/// \endcode
2802/// unaryExprOrTypeTraitExpr()
2803/// matches \c sizeof(x) and \c alignof(x)
2804extern const internal::VariadicDynCastAllOfMatcher<Stmt,
2805 UnaryExprOrTypeTraitExpr>
2806 unaryExprOrTypeTraitExpr;
2807
2808/// Matches any of the \p NodeMatchers with InnerMatchers nested within
2809///
2810/// Given
2811/// \code
2812/// if (true);
2813/// for (; true; );
2814/// \endcode
2815/// with the matcher
2816/// \code
2817/// mapAnyOf(ifStmt, forStmt).with(
2818/// hasCondition(cxxBoolLiteralExpr(equals(true)))
2819/// ).bind("trueCond")
2820/// \endcode
2821/// matches the \c if and the \c for. It is equivalent to:
2822/// \code
2823/// auto trueCond = hasCondition(cxxBoolLiteralExpr(equals(true)));
2824/// anyOf(
2825/// ifStmt(trueCond).bind("trueCond"),
2826/// forStmt(trueCond).bind("trueCond")
2827/// );
2828/// \endcode
2829///
2830/// The with() chain-call accepts zero or more matchers which are combined
2831/// as-if with allOf() in each of the node matchers.
2832/// Usable as: Any Matcher
2833template <typename T, typename... U>
2834auto mapAnyOf(internal::VariadicDynCastAllOfMatcher<T, U> const &...) {
2835 return internal::MapAnyOfHelper<U...>();
2836}
2837
2838/// Matches nodes which can be used with binary operators.
2839///
2840/// The code
2841/// \code
2842/// var1 != var2;
2843/// \endcode
2844/// might be represented in the clang AST as a binaryOperator, a
2845/// cxxOperatorCallExpr or a cxxRewrittenBinaryOperator, depending on
2846///
2847/// * whether the types of var1 and var2 are fundamental (binaryOperator) or at
2848/// least one is a class type (cxxOperatorCallExpr)
2849/// * whether the code appears in a template declaration, if at least one of the
2850/// vars is a dependent-type (binaryOperator)
2851/// * whether the code relies on a rewritten binary operator, such as a
2852/// spaceship operator or an inverted equality operator
2853/// (cxxRewrittenBinaryOperator)
2854///
2855/// This matcher elides details in places where the matchers for the nodes are
2856/// compatible.
2857///
2858/// Given
2859/// \code
2860/// binaryOperation(
2861/// hasOperatorName("!="),
2862/// hasLHS(expr().bind("lhs")),
2863/// hasRHS(expr().bind("rhs"))
2864/// )
2865/// \endcode
2866/// matches each use of "!=" in:
2867/// \code
2868/// struct S{
2869/// bool operator!=(const S&) const;
2870/// };
2871///
2872/// void foo()
2873/// {
2874/// 1 != 2;
2875/// S() != S();
2876/// }
2877///
2878/// template<typename T>
2879/// void templ()
2880/// {
2881/// 1 != 2;
2882/// T() != S();
2883/// }
2884/// struct HasOpEq
2885/// {
2886/// bool operator==(const HasOpEq &) const;
2887/// };
2888///
2889/// void inverse()
2890/// {
2891/// HasOpEq s1;
2892/// HasOpEq s2;
2893/// if (s1 != s2)
2894/// return;
2895/// }
2896///
2897/// struct HasSpaceship
2898/// {
2899/// bool operator<=>(const HasOpEq &) const;
2900/// };
2901///
2902/// void use_spaceship()
2903/// {
2904/// HasSpaceship s1;
2905/// HasSpaceship s2;
2906/// if (s1 != s2)
2907/// return;
2908/// }
2909/// \endcode
2910extern const internal::MapAnyOfMatcher<BinaryOperator, CXXOperatorCallExpr,
2911 CXXRewrittenBinaryOperator>
2912 binaryOperation;
2913
2914/// Matches function calls and constructor calls
2915///
2916/// Because CallExpr and CXXConstructExpr do not share a common
2917/// base class with API accessing arguments etc, AST Matchers for code
2918/// which should match both are typically duplicated. This matcher
2919/// removes the need for duplication.
2920///
2921/// Given code
2922/// \code
2923/// struct ConstructorTakesInt
2924/// {
2925/// ConstructorTakesInt(int i) {}
2926/// };
2927///
2928/// void callTakesInt(int i)
2929/// {
2930/// }
2931///
2932/// void doCall()
2933/// {
2934/// callTakesInt(42);
2935/// }
2936///
2937/// void doConstruct()
2938/// {
2939/// ConstructorTakesInt cti(42);
2940/// }
2941/// \endcode
2942///
2943/// The matcher
2944/// \code
2945/// invocation(hasArgument(0, integerLiteral(equals(42))))
2946/// \endcode
2947/// matches the expression in both doCall and doConstruct
2948extern const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr> invocation;
2949
2950/// Matches unary expressions that have a specific type of argument.
2951///
2952/// Given
2953/// \code
2954/// int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c);
2955/// \endcode
2956/// unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int"))
2957/// matches \c sizeof(a) and \c alignof(c)
2958AST_MATCHER_P(UnaryExprOrTypeTraitExpr, hasArgumentOfType,namespace internal { class matcher_hasArgumentOfType0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
UnaryExprOrTypeTraitExpr> { public: explicit matcher_hasArgumentOfType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const UnaryExprOrTypeTraitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<UnaryExprOrTypeTraitExpr> hasArgumentOfType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasArgumentOfType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<UnaryExprOrTypeTraitExpr> ( &hasArgumentOfType_Type0
)(internal::Matcher<QualType> const &InnerMatcher);
inline bool internal::matcher_hasArgumentOfType0Matcher::matches
( const UnaryExprOrTypeTraitExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
2959 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_hasArgumentOfType0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
UnaryExprOrTypeTraitExpr> { public: explicit matcher_hasArgumentOfType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const UnaryExprOrTypeTraitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<UnaryExprOrTypeTraitExpr> hasArgumentOfType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasArgumentOfType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<UnaryExprOrTypeTraitExpr> ( &hasArgumentOfType_Type0
)(internal::Matcher<QualType> const &InnerMatcher);
inline bool internal::matcher_hasArgumentOfType0Matcher::matches
( const UnaryExprOrTypeTraitExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
2960 const QualType ArgumentType = Node.getTypeOfArgument();
2961 return InnerMatcher.matches(ArgumentType, Finder, Builder);
2962}
2963
2964/// Matches unary expressions of a certain kind.
2965///
2966/// Given
2967/// \code
2968/// int x;
2969/// int s = sizeof(x) + alignof(x)
2970/// \endcode
2971/// unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
2972/// matches \c sizeof(x)
2973///
2974/// If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter
2975/// should be passed as a quoted string. e.g., ofKind("UETT_SizeOf").
2976AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind)namespace internal { class matcher_ofKind0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<UnaryExprOrTypeTraitExpr
> { public: explicit matcher_ofKind0Matcher( UnaryExprOrTypeTrait
const &AKind) : Kind(AKind) {} bool matches(const UnaryExprOrTypeTraitExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: UnaryExprOrTypeTrait Kind
; }; } inline ::clang::ast_matchers::internal::Matcher<UnaryExprOrTypeTraitExpr
> ofKind( UnaryExprOrTypeTrait const &Kind) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_ofKind0Matcher
(Kind)); } typedef ::clang::ast_matchers::internal::Matcher<
UnaryExprOrTypeTraitExpr> ( &ofKind_Type0)(UnaryExprOrTypeTrait
const &Kind); inline bool internal::matcher_ofKind0Matcher
::matches( const UnaryExprOrTypeTraitExpr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
2977 return Node.getKind() == Kind;
2978}
2979
2980/// Same as unaryExprOrTypeTraitExpr, but only matching
2981/// alignof.
2982inline internal::BindableMatcher<Stmt> alignOfExpr(
2983 const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) {
2984 return stmt(unaryExprOrTypeTraitExpr(
2985 allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)),
2986 InnerMatcher)));
2987}
2988
2989/// Same as unaryExprOrTypeTraitExpr, but only matching
2990/// sizeof.
2991inline internal::BindableMatcher<Stmt> sizeOfExpr(
2992 const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) {
2993 return stmt(unaryExprOrTypeTraitExpr(
2994 allOf(ofKind(UETT_SizeOf), InnerMatcher)));
2995}
2996
2997/// Matches NamedDecl nodes that have the specified name.
2998///
2999/// Supports specifying enclosing namespaces or classes by prefixing the name
3000/// with '<enclosing>::'.
3001/// Does not match typedefs of an underlying type with the given name.
3002///
3003/// Example matches X (Name == "X")
3004/// \code
3005/// class X;
3006/// \endcode
3007///
3008/// Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X")
3009/// \code
3010/// namespace a { namespace b { class X; } }
3011/// \endcode
3012inline internal::Matcher<NamedDecl> hasName(StringRef Name) {
3013 return internal::Matcher<NamedDecl>(
3014 new internal::HasNameMatcher({std::string(Name)}));
3015}
3016
3017/// Matches NamedDecl nodes that have any of the specified names.
3018///
3019/// This matcher is only provided as a performance optimization of hasName.
3020/// \code
3021/// hasAnyName(a, b, c)
3022/// \endcode
3023/// is equivalent to, but faster than
3024/// \code
3025/// anyOf(hasName(a), hasName(b), hasName(c))
3026/// \endcode
3027extern const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
3028 internal::hasAnyNameFunc>
3029 hasAnyName;
3030
3031/// Matches NamedDecl nodes whose fully qualified names contain
3032/// a substring matched by the given RegExp.
3033///
3034/// Supports specifying enclosing namespaces or classes by
3035/// prefixing the name with '<enclosing>::'. Does not match typedefs
3036/// of an underlying type with the given name.
3037///
3038/// Example matches X (regexp == "::X")
3039/// \code
3040/// class X;
3041/// \endcode
3042///
3043/// Example matches X (regexp is one of "::X", "^foo::.*X", among others)
3044/// \code
3045/// namespace foo { namespace bar { class X; } }
3046/// \endcode
3047AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp)namespace internal { class matcher_matchesName0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NamedDecl
> { public: explicit matcher_matchesName0Matcher( std::shared_ptr
<llvm::Regex> RE) : RegExp(std::move(RE)) {} bool matches
(const NamedDecl &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::shared_ptr<llvm::
Regex> RegExp; }; } inline ::clang::ast_matchers::internal
::Matcher<NamedDecl> matchesName( llvm::StringRef RegExp
, llvm::Regex::RegexFlags RegexFlags) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_matchesName0Matcher
( ::clang::ast_matchers::internal::createAndVerifyRegex( RegExp
, RegexFlags, "matchesName"))); } inline ::clang::ast_matchers
::internal::Matcher<NamedDecl> matchesName( llvm::StringRef
RegExp) { return matchesName(RegExp, llvm::Regex::NoFlags); }
typedef ::clang::ast_matchers::internal::Matcher<NamedDecl
> ( &matchesName_Type0Flags)(llvm::StringRef, llvm::Regex
::RegexFlags); typedef ::clang::ast_matchers::internal::Matcher
<NamedDecl> ( &matchesName_Type0)(llvm::StringRef);
inline bool internal::matcher_matchesName0Matcher::matches( const
NamedDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3048 std::string FullNameString = "::" + Node.getQualifiedNameAsString();
3049 return RegExp->match(FullNameString);
3050}
3051
3052/// Matches overloaded operator names.
3053///
3054/// Matches overloaded operator names specified in strings without the
3055/// "operator" prefix: e.g. "<<".
3056///
3057/// Given:
3058/// \code
3059/// class A { int operator*(); };
3060/// const A &operator<<(const A &a, const A &b);
3061/// A a;
3062/// a << a; // <-- This matches
3063/// \endcode
3064///
3065/// \c cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the
3066/// specified line and
3067/// \c cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*")))
3068/// matches the declaration of \c A.
3069///
3070/// Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl>
3071inline internal::PolymorphicMatcher<
3072 internal::HasOverloadedOperatorNameMatcher,
3073 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
,
3074 std::vector<std::string>>
3075hasOverloadedOperatorName(StringRef Name) {
3076 return internal::PolymorphicMatcher<
3077 internal::HasOverloadedOperatorNameMatcher,
3078 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
,
3079 std::vector<std::string>>({std::string(Name)});
3080}
3081
3082/// Matches overloaded operator names.
3083///
3084/// Matches overloaded operator names specified in strings without the
3085/// "operator" prefix: e.g. "<<".
3086///
3087/// hasAnyOverloadedOperatorName("+", "-")
3088/// Is equivalent to
3089/// anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-"))
3090extern const internal::VariadicFunction<
3091 internal::PolymorphicMatcher<internal::HasOverloadedOperatorNameMatcher,
3092 AST_POLYMORPHIC_SUPPORTED_TYPES(void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
3093 CXXOperatorCallExpr, FunctionDecl)void(::clang::ast_matchers::internal::TypeList<CXXOperatorCallExpr
, FunctionDecl>)
,
3094 std::vector<std::string>>,
3095 StringRef, internal::hasAnyOverloadedOperatorNameFunc>
3096 hasAnyOverloadedOperatorName;
3097
3098/// Matches template-dependent, but known, member names.
3099///
3100/// In template declarations, dependent members are not resolved and so can
3101/// not be matched to particular named declarations.
3102///
3103/// This matcher allows to match on the known name of members.
3104///
3105/// Given
3106/// \code
3107/// template <typename T>
3108/// struct S {
3109/// void mem();
3110/// };
3111/// template <typename T>
3112/// void x() {
3113/// S<T> s;
3114/// s.mem();
3115/// }
3116/// \endcode
3117/// \c cxxDependentScopeMemberExpr(hasMemberName("mem")) matches `s.mem()`
3118AST_MATCHER_P(CXXDependentScopeMemberExpr, hasMemberName, std::string, N)namespace internal { class matcher_hasMemberName0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXDependentScopeMemberExpr
> { public: explicit matcher_hasMemberName0Matcher( std::string
const &AN) : N(AN) {} bool matches(const CXXDependentScopeMemberExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string N; }; } inline
::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> hasMemberName( std::string const &N) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasMemberName0Matcher
(N)); } typedef ::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> ( &hasMemberName_Type0)(std::string const &N); inline
bool internal::matcher_hasMemberName0Matcher::matches( const
CXXDependentScopeMemberExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3119 return Node.getMember().getAsString() == N;
3120}
3121
3122/// Matches template-dependent, but known, member names against an already-bound
3123/// node
3124///
3125/// In template declarations, dependent members are not resolved and so can
3126/// not be matched to particular named declarations.
3127///
3128/// This matcher allows to match on the name of already-bound VarDecl, FieldDecl
3129/// and CXXMethodDecl nodes.
3130///
3131/// Given
3132/// \code
3133/// template <typename T>
3134/// struct S {
3135/// void mem();
3136/// };
3137/// template <typename T>
3138/// void x() {
3139/// S<T> s;
3140/// s.mem();
3141/// }
3142/// \endcode
3143/// The matcher
3144/// @code
3145/// \c cxxDependentScopeMemberExpr(
3146/// hasObjectExpression(declRefExpr(hasType(templateSpecializationType(
3147/// hasDeclaration(classTemplateDecl(has(cxxRecordDecl(has(
3148/// cxxMethodDecl(hasName("mem")).bind("templMem")
3149/// )))))
3150/// )))),
3151/// memberHasSameNameAsBoundNode("templMem")
3152/// )
3153/// @endcode
3154/// first matches and binds the @c mem member of the @c S template, then
3155/// compares its name to the usage in @c s.mem() in the @c x function template
3156AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode,namespace internal { class matcher_memberHasSameNameAsBoundNode0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXDependentScopeMemberExpr> { public: explicit matcher_memberHasSameNameAsBoundNode0Matcher
( std::string const &ABindingID) : BindingID(ABindingID) {
} bool matches(const CXXDependentScopeMemberExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: std::string BindingID; }; } inline ::clang
::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> memberHasSameNameAsBoundNode( std::string const &BindingID
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_memberHasSameNameAsBoundNode0Matcher(BindingID)); }
typedef ::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> ( &memberHasSameNameAsBoundNode_Type0)(std::string const
&BindingID); inline bool internal::matcher_memberHasSameNameAsBoundNode0Matcher
::matches( const CXXDependentScopeMemberExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
3157 std::string, BindingID)namespace internal { class matcher_memberHasSameNameAsBoundNode0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXDependentScopeMemberExpr> { public: explicit matcher_memberHasSameNameAsBoundNode0Matcher
( std::string const &ABindingID) : BindingID(ABindingID) {
} bool matches(const CXXDependentScopeMemberExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: std::string BindingID; }; } inline ::clang
::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> memberHasSameNameAsBoundNode( std::string const &BindingID
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_memberHasSameNameAsBoundNode0Matcher(BindingID)); }
typedef ::clang::ast_matchers::internal::Matcher<CXXDependentScopeMemberExpr
> ( &memberHasSameNameAsBoundNode_Type0)(std::string const
&BindingID); inline bool internal::matcher_memberHasSameNameAsBoundNode0Matcher
::matches( const CXXDependentScopeMemberExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
3158 auto MemberName = Node.getMember().getAsString();
3159
3160 return Builder->removeBindings(
3161 [this, MemberName](const BoundNodesMap &Nodes) {
3162 const auto &BN = Nodes.getNode(this->BindingID);
3163 if (const auto *ND = BN.get<NamedDecl>()) {
3164 if (!isa<FieldDecl, CXXMethodDecl, VarDecl>(ND))
3165 return true;
3166 return ND->getName() != MemberName;
3167 }
3168 return true;
3169 });
3170}
3171
3172/// Matches C++ classes that are directly or indirectly derived from a class
3173/// matching \c Base, or Objective-C classes that directly or indirectly
3174/// subclass a class matching \c Base.
3175///
3176/// Note that a class is not considered to be derived from itself.
3177///
3178/// Example matches Y, Z, C (Base == hasName("X"))
3179/// \code
3180/// class X;
3181/// class Y : public X {}; // directly derived
3182/// class Z : public Y {}; // indirectly derived
3183/// typedef X A;
3184/// typedef A B;
3185/// class C : public B {}; // derived from a typedef of X
3186/// \endcode
3187///
3188/// In the following example, Bar matches isDerivedFrom(hasName("X")):
3189/// \code
3190/// class Foo;
3191/// typedef Foo X;
3192/// class Bar : public Foo {}; // derived from a type that X is a typedef of
3193/// \endcode
3194///
3195/// In the following example, Bar matches isDerivedFrom(hasName("NSObject"))
3196/// \code
3197/// @interface NSObject @end
3198/// @interface Bar : NSObject @end
3199/// \endcode
3200///
3201/// Usable as: Matcher<CXXRecordDecl>, Matcher<ObjCInterfaceDecl>
3202AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3203 isDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3204 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3205 internal::Matcher<NamedDecl>, Base)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom0Matcher( internal::Matcher<
NamedDecl> const &ABase) : Base(ABase) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> Base; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > isDerivedFrom(internal
::Matcher<NamedDecl> const &Base) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
(Base); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3206 // Check if the node is a C++ struct/union/class.
3207 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3208 return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false);
3209
3210 // The node must be an Objective-C class.
3211 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3212 return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder,
3213 /*Directly=*/false);
3214}
3215
3216/// Overloaded method as shortcut for \c isDerivedFrom(hasName(...)).
3217AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3218 isDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3219 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3220 std::string, BaseName, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDerivedFrom1Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_isDerivedFrom1Matcher( std::string const &
ABaseName) : BaseName(ABaseName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string> isDerivedFrom(std::string const &BaseName
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDerivedFrom1Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, std::string>(BaseName); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3221 if (BaseName.empty())
3222 return false;
3223
3224 const auto M = isDerivedFrom(hasName(BaseName));
3225
3226 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3227 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3228
3229 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3230 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3231}
3232
3233/// Matches C++ classes that have a direct or indirect base matching \p
3234/// BaseSpecMatcher.
3235///
3236/// Example:
3237/// matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase"))))
3238/// \code
3239/// class Foo;
3240/// class Bar : Foo {};
3241/// class Baz : Bar {};
3242/// class SpecialBase;
3243/// class Proxy : SpecialBase {}; // matches Proxy
3244/// class IndirectlyDerived : Proxy {}; //matches IndirectlyDerived
3245/// \endcode
3246///
3247// FIXME: Refactor this and isDerivedFrom to reuse implementation.
3248AST_MATCHER_P(CXXRecordDecl, hasAnyBase, internal::Matcher<CXXBaseSpecifier>,namespace internal { class matcher_hasAnyBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasAnyBase0Matcher( internal::
Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher) :
BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasAnyBase( internal::Matcher<
CXXBaseSpecifier> const &BaseSpecMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasAnyBase0Matcher
(BaseSpecMatcher)); } typedef ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> ( &hasAnyBase_Type0)(internal
::Matcher<CXXBaseSpecifier> const &BaseSpecMatcher)
; inline bool internal::matcher_hasAnyBase0Matcher::matches( const
CXXRecordDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
3249 BaseSpecMatcher)namespace internal { class matcher_hasAnyBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasAnyBase0Matcher( internal::
Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher) :
BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasAnyBase( internal::Matcher<
CXXBaseSpecifier> const &BaseSpecMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasAnyBase0Matcher
(BaseSpecMatcher)); } typedef ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> ( &hasAnyBase_Type0)(internal
::Matcher<CXXBaseSpecifier> const &BaseSpecMatcher)
; inline bool internal::matcher_hasAnyBase0Matcher::matches( const
CXXRecordDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3250 return internal::matchesAnyBase(Node, BaseSpecMatcher, Finder, Builder);
3251}
3252
3253/// Matches C++ classes that have a direct base matching \p BaseSpecMatcher.
3254///
3255/// Example:
3256/// matcher hasDirectBase(hasType(cxxRecordDecl(hasName("SpecialBase"))))
3257/// \code
3258/// class Foo;
3259/// class Bar : Foo {};
3260/// class Baz : Bar {};
3261/// class SpecialBase;
3262/// class Proxy : SpecialBase {}; // matches Proxy
3263/// class IndirectlyDerived : Proxy {}; // doesn't match
3264/// \endcode
3265AST_MATCHER_P(CXXRecordDecl, hasDirectBase, internal::Matcher<CXXBaseSpecifier>,namespace internal { class matcher_hasDirectBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasDirectBase0Matcher( internal
::Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher
) : BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasDirectBase( internal::Matcher
<CXXBaseSpecifier> const &BaseSpecMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDirectBase0Matcher(BaseSpecMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<CXXRecordDecl> (
&hasDirectBase_Type0)(internal::Matcher<CXXBaseSpecifier
> const &BaseSpecMatcher); inline bool internal::matcher_hasDirectBase0Matcher
::matches( const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
3266 BaseSpecMatcher)namespace internal { class matcher_hasDirectBase0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasDirectBase0Matcher( internal
::Matcher<CXXBaseSpecifier> const &ABaseSpecMatcher
) : BaseSpecMatcher(ABaseSpecMatcher) {} bool matches(const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXBaseSpecifier
> BaseSpecMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasDirectBase( internal::Matcher
<CXXBaseSpecifier> const &BaseSpecMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDirectBase0Matcher(BaseSpecMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<CXXRecordDecl> (
&hasDirectBase_Type0)(internal::Matcher<CXXBaseSpecifier
> const &BaseSpecMatcher); inline bool internal::matcher_hasDirectBase0Matcher
::matches( const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3267 return Node.hasDefinition() &&
3268 llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &Base) {
3269 return BaseSpecMatcher.matches(Base, Finder, Builder);
3270 });
3271}
3272
3273/// Similar to \c isDerivedFrom(), but also matches classes that directly
3274/// match \c Base.
3275AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3276 isSameOrDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3277 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3278 internal::Matcher<NamedDecl>, Base, 0)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom0Matcher( internal
::Matcher<NamedDecl> const &ABase) : Base(ABase) {}
bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isSameOrDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom0Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isSameOrDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isSameOrDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3279 const auto M = anyOf(Base, isDerivedFrom(Base));
3280
3281 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3282 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3283
3284 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3285 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3286}
3287
3288/// Overloaded method as shortcut for
3289/// \c isSameOrDerivedFrom(hasName(...)).
3290AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3291 isSameOrDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3292 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3293 std::string, BaseName, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isSameOrDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isSameOrDerivedFrom1Matcher( std
::string const &ABaseName) : BaseName(ABaseName) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang::
ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isSameOrDerivedFrom(std::string const &
BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isSameOrDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isSameOrDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isSameOrDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isSameOrDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3294 if (BaseName.empty())
3295 return false;
3296
3297 const auto M = isSameOrDerivedFrom(hasName(BaseName));
3298
3299 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3300 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3301
3302 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3303 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3304}
3305
3306/// Matches C++ or Objective-C classes that are directly derived from a class
3307/// matching \c Base.
3308///
3309/// Note that a class is not considered to be derived from itself.
3310///
3311/// Example matches Y, C (Base == hasName("X"))
3312/// \code
3313/// class X;
3314/// class Y : public X {}; // directly derived
3315/// class Z : public Y {}; // indirectly derived
3316/// typedef X A;
3317/// typedef A B;
3318/// class C : public B {}; // derived from a typedef of X
3319/// \endcode
3320///
3321/// In the following example, Bar matches isDerivedFrom(hasName("X")):
3322/// \code
3323/// class Foo;
3324/// typedef Foo X;
3325/// class Bar : public Foo {}; // derived from a type that X is a typedef of
3326/// \endcode
3327AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3328 isDirectlyDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3329 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3330 internal::Matcher<NamedDecl>, Base, 0)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom0Matcher
( internal::Matcher<NamedDecl> const &ABase) : Base
(ABase) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<NamedDecl> Base; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom0Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), internal::Matcher<NamedDecl> >
isDirectlyDerivedFrom(internal::Matcher<NamedDecl> const
&Base) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom0Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), internal::Matcher<NamedDecl> >(Base); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDirectlyDerivedFrom0Matcher, void(::clang::ast_matchers
::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl>)
, internal::Matcher<NamedDecl> > (&isDirectlyDerivedFrom_Type0
)(internal::Matcher<NamedDecl> const &Base); template
<typename NodeType, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3331 // Check if the node is a C++ struct/union/class.
3332 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3333 return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/true);
3334
3335 // The node must be an Objective-C class.
3336 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3337 return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder,
3338 /*Directly=*/true);
3339}
3340
3341/// Overloaded method as shortcut for \c isDirectlyDerivedFrom(hasName(...)).
3342AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3343 isDirectlyDerivedFrom,namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3344 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3345 std::string, BaseName, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_isDirectlyDerivedFrom1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_isDirectlyDerivedFrom1Matcher
( std::string const &ABaseName) : BaseName(ABaseName) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isDirectlyDerivedFrom1Matcher, void(::clang
::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string> isDirectlyDerivedFrom(std::string const
&BaseName) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isDirectlyDerivedFrom1Matcher, void(::
clang::ast_matchers::internal::TypeList<CXXRecordDecl, ObjCInterfaceDecl
>), std::string>(BaseName); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isDirectlyDerivedFrom1Matcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, ObjCInterfaceDecl>), std::string> (&isDirectlyDerivedFrom_Type1
)(std::string const &BaseName); template <typename NodeType
, typename ParamT> bool internal:: matcher_isDirectlyDerivedFrom1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3346 if (BaseName.empty())
3347 return false;
3348 const auto M = isDirectlyDerivedFrom(hasName(BaseName));
3349
3350 if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node))
3351 return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder);
3352
3353 const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node);
3354 return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder);
3355}
3356/// Matches the first method of a class or struct that satisfies \c
3357/// InnerMatcher.
3358///
3359/// Given:
3360/// \code
3361/// class A { void func(); };
3362/// class B { void member(); };
3363/// \endcode
3364///
3365/// \c cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of
3366/// \c A but not \c B.
3367AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>,namespace internal { class matcher_hasMethod0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasMethod0Matcher( internal::
Matcher<CXXMethodDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXRecordDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<CXXMethodDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasMethod( internal::Matcher<
CXXMethodDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasMethod0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXRecordDecl> ( &hasMethod_Type0)(internal::Matcher
<CXXMethodDecl> const &InnerMatcher); inline bool internal
::matcher_hasMethod0Matcher::matches( const CXXRecordDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
3368 InnerMatcher)namespace internal { class matcher_hasMethod0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasMethod0Matcher( internal::
Matcher<CXXMethodDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXRecordDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<CXXMethodDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXRecordDecl> hasMethod( internal::Matcher<
CXXMethodDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasMethod0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXRecordDecl> ( &hasMethod_Type0)(internal::Matcher
<CXXMethodDecl> const &InnerMatcher); inline bool internal
::matcher_hasMethod0Matcher::matches( const CXXRecordDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
3369 BoundNodesTreeBuilder Result(*Builder);
3370 auto MatchIt = matchesFirstInPointerRange(InnerMatcher, Node.method_begin(),
3371 Node.method_end(), Finder, &Result);
3372 if (MatchIt == Node.method_end())
3373 return false;
3374
3375 if (Finder->isTraversalIgnoringImplicitNodes() && (*MatchIt)->isImplicit())
3376 return false;
3377 *Builder = std::move(Result);
3378 return true;
3379}
3380
3381/// Matches the generated class of lambda expressions.
3382///
3383/// Given:
3384/// \code
3385/// auto x = []{};
3386/// \endcode
3387///
3388/// \c cxxRecordDecl(isLambda()) matches the implicit class declaration of
3389/// \c decltype(x)
3390AST_MATCHER(CXXRecordDecl, isLambda)namespace internal { class matcher_isLambdaMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_isLambdaMatcher() = default; bool
matches(const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXRecordDecl>
isLambda() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isLambdaMatcher()); } inline bool internal
::matcher_isLambdaMatcher::matches( const CXXRecordDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
3391 return Node.isLambda();
3392}
3393
3394/// Matches AST nodes that have child AST nodes that match the
3395/// provided matcher.
3396///
3397/// Example matches X, Y
3398/// (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X")))
3399/// \code
3400/// class X {}; // Matches X, because X::X is a class of name X inside X.
3401/// class Y { class X {}; };
3402/// class Z { class Y { class X {}; }; }; // Does not match Z.
3403/// \endcode
3404///
3405/// ChildT must be an AST base type.
3406///
3407/// Usable as: Any Matcher
3408/// Note that has is direct matcher, so it also matches things like implicit
3409/// casts and paren casts. If you are matching with expr then you should
3410/// probably consider using ignoringParenImpCasts like:
3411/// has(ignoringParenImpCasts(expr())).
3412extern const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has;
3413
3414/// Matches AST nodes that have descendant AST nodes that match the
3415/// provided matcher.
3416///
3417/// Example matches X, Y, Z
3418/// (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X")))))
3419/// \code
3420/// class X {}; // Matches X, because X::X is a class of name X inside X.
3421/// class Y { class X {}; };
3422/// class Z { class Y { class X {}; }; };
3423/// \endcode
3424///
3425/// DescendantT must be an AST base type.
3426///
3427/// Usable as: Any Matcher
3428extern const internal::ArgumentAdaptingMatcherFunc<
3429 internal::HasDescendantMatcher>
3430 hasDescendant;
3431
3432/// Matches AST nodes that have child AST nodes that match the
3433/// provided matcher.
3434///
3435/// Example matches X, Y, Y::X, Z::Y, Z::Y::X
3436/// (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))
3437/// \code
3438/// class X {};
3439/// class Y { class X {}; }; // Matches Y, because Y::X is a class of name X
3440/// // inside Y.
3441/// class Z { class Y { class X {}; }; }; // Does not match Z.
3442/// \endcode
3443///
3444/// ChildT must be an AST base type.
3445///
3446/// As opposed to 'has', 'forEach' will cause a match for each result that
3447/// matches instead of only on the first one.
3448///
3449/// Usable as: Any Matcher
3450extern const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher>
3451 forEach;
3452
3453/// Matches AST nodes that have descendant AST nodes that match the
3454/// provided matcher.
3455///
3456/// Example matches X, A, A::X, B, B::C, B::C::X
3457/// (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X")))))
3458/// \code
3459/// class X {};
3460/// class A { class X {}; }; // Matches A, because A::X is a class of name
3461/// // X inside A.
3462/// class B { class C { class X {}; }; };
3463/// \endcode
3464///
3465/// DescendantT must be an AST base type.
3466///
3467/// As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for
3468/// each result that matches instead of only on the first one.
3469///
3470/// Note: Recursively combined ForEachDescendant can cause many matches:
3471/// cxxRecordDecl(forEachDescendant(cxxRecordDecl(
3472/// forEachDescendant(cxxRecordDecl())
3473/// )))
3474/// will match 10 times (plus injected class name matches) on:
3475/// \code
3476/// class A { class B { class C { class D { class E {}; }; }; }; };
3477/// \endcode
3478///
3479/// Usable as: Any Matcher
3480extern const internal::ArgumentAdaptingMatcherFunc<
3481 internal::ForEachDescendantMatcher>
3482 forEachDescendant;
3483
3484/// Matches if the node or any descendant matches.
3485///
3486/// Generates results for each match.
3487///
3488/// For example, in:
3489/// \code
3490/// class A { class B {}; class C {}; };
3491/// \endcode
3492/// The matcher:
3493/// \code
3494/// cxxRecordDecl(hasName("::A"),
3495/// findAll(cxxRecordDecl(isDefinition()).bind("m")))
3496/// \endcode
3497/// will generate results for \c A, \c B and \c C.
3498///
3499/// Usable as: Any Matcher
3500template <typename T>
3501internal::Matcher<T> findAll(const internal::Matcher<T> &Matcher) {
3502 return eachOf(Matcher, forEachDescendant(Matcher));
3503}
3504
3505/// Matches AST nodes that have a parent that matches the provided
3506/// matcher.
3507///
3508/// Given
3509/// \code
3510/// void f() { for (;;) { int x = 42; if (true) { int x = 43; } } }
3511/// \endcode
3512/// \c compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".
3513///
3514/// Usable as: Any Matcher
3515extern const internal::ArgumentAdaptingMatcherFunc<
3516 internal::HasParentMatcher,
3517 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
3518 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
3519 hasParent;
3520
3521/// Matches AST nodes that have an ancestor that matches the provided
3522/// matcher.
3523///
3524/// Given
3525/// \code
3526/// void f() { if (true) { int x = 42; } }
3527/// void g() { for (;;) { int x = 43; } }
3528/// \endcode
3529/// \c expr(integerLiteral(hasAncestor(ifStmt()))) matches \c 42, but not 43.
3530///
3531/// Usable as: Any Matcher
3532extern const internal::ArgumentAdaptingMatcherFunc<
3533 internal::HasAncestorMatcher,
3534 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>,
3535 internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>>
3536 hasAncestor;
3537
3538/// Matches if the provided matcher does not match.
3539///
3540/// Example matches Y (matcher = cxxRecordDecl(unless(hasName("X"))))
3541/// \code
3542/// class X {};
3543/// class Y {};
3544/// \endcode
3545///
3546/// Usable as: Any Matcher
3547extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
3548
3549/// Matches a node if the declaration associated with that node
3550/// matches the given matcher.
3551///
3552/// The associated declaration is:
3553/// - for type nodes, the declaration of the underlying type
3554/// - for CallExpr, the declaration of the callee
3555/// - for MemberExpr, the declaration of the referenced member
3556/// - for CXXConstructExpr, the declaration of the constructor
3557/// - for CXXNewExpr, the declaration of the operator new
3558/// - for ObjCIvarExpr, the declaration of the ivar
3559///
3560/// For type nodes, hasDeclaration will generally match the declaration of the
3561/// sugared type. Given
3562/// \code
3563/// class X {};
3564/// typedef X Y;
3565/// Y y;
3566/// \endcode
3567/// in varDecl(hasType(hasDeclaration(decl()))) the decl will match the
3568/// typedefDecl. A common use case is to match the underlying, desugared type.
3569/// This can be achieved by using the hasUnqualifiedDesugaredType matcher:
3570/// \code
3571/// varDecl(hasType(hasUnqualifiedDesugaredType(
3572/// recordType(hasDeclaration(decl())))))
3573/// \endcode
3574/// In this matcher, the decl will match the CXXRecordDecl of class X.
3575///
3576/// Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>,
3577/// Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>,
3578/// Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>,
3579/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
3580/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
3581/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
3582/// Matcher<UnresolvedUsingType>
3583inline internal::PolymorphicMatcher<
3584 internal::HasDeclarationMatcher,
3585 void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
3586hasDeclaration(const internal::Matcher<Decl> &InnerMatcher) {
3587 return internal::PolymorphicMatcher<
3588 internal::HasDeclarationMatcher,
3589 void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>(
3590 InnerMatcher);
3591}
3592
3593/// Matches a \c NamedDecl whose underlying declaration matches the given
3594/// matcher.
3595///
3596/// Given
3597/// \code
3598/// namespace N { template<class T> void f(T t); }
3599/// template <class T> void g() { using N::f; f(T()); }
3600/// \endcode
3601/// \c unresolvedLookupExpr(hasAnyDeclaration(
3602/// namedDecl(hasUnderlyingDecl(hasName("::N::f")))))
3603/// matches the use of \c f in \c g() .
3604AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher<NamedDecl>,namespace internal { class matcher_hasUnderlyingDecl0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NamedDecl> { public: explicit matcher_hasUnderlyingDecl0Matcher
( internal::Matcher<NamedDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NamedDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NamedDecl> hasUnderlyingDecl( internal::Matcher
<NamedDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasUnderlyingDecl0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<NamedDecl> ( &hasUnderlyingDecl_Type0)(internal::Matcher
<NamedDecl> const &InnerMatcher); inline bool internal
::matcher_hasUnderlyingDecl0Matcher::matches( const NamedDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
3605 InnerMatcher)namespace internal { class matcher_hasUnderlyingDecl0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NamedDecl> { public: explicit matcher_hasUnderlyingDecl0Matcher
( internal::Matcher<NamedDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NamedDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamedDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NamedDecl> hasUnderlyingDecl( internal::Matcher
<NamedDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasUnderlyingDecl0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<NamedDecl> ( &hasUnderlyingDecl_Type0)(internal::Matcher
<NamedDecl> const &InnerMatcher); inline bool internal
::matcher_hasUnderlyingDecl0Matcher::matches( const NamedDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3606 const NamedDecl *UnderlyingDecl = Node.getUnderlyingDecl();
3607
3608 return UnderlyingDecl != nullptr &&
3609 InnerMatcher.matches(*UnderlyingDecl, Finder, Builder);
3610}
3611
3612/// Matches on the implicit object argument of a member call expression, after
3613/// stripping off any parentheses or implicit casts.
3614///
3615/// Given
3616/// \code
3617/// class Y { public: void m(); };
3618/// Y g();
3619/// class X : public Y {};
3620/// void z(Y y, X x) { y.m(); (g()).m(); x.m(); }
3621/// \endcode
3622/// cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y")))))
3623/// matches `y.m()` and `(g()).m()`.
3624/// cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X")))))
3625/// matches `x.m()`.
3626/// cxxMemberCallExpr(on(callExpr()))
3627/// matches `(g()).m()`.
3628///
3629/// FIXME: Overload to allow directly matching types?
3630AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>,namespace internal { class matcher_on0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<CXXMemberCallExpr
> { public: explicit matcher_on0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const CXXMemberCallExpr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<CXXMemberCallExpr> on
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_on0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<CXXMemberCallExpr> ( &on_Type0)
(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_on0Matcher::matches( const CXXMemberCallExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
3631 InnerMatcher)namespace internal { class matcher_on0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<CXXMemberCallExpr
> { public: explicit matcher_on0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const CXXMemberCallExpr &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<CXXMemberCallExpr> on
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_on0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<CXXMemberCallExpr> ( &on_Type0)
(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_on0Matcher::matches( const CXXMemberCallExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3632 const Expr *ExprNode = Node.getImplicitObjectArgument()
3633 ->IgnoreParenImpCasts();
3634 return (ExprNode != nullptr &&
3635 InnerMatcher.matches(*ExprNode, Finder, Builder));
3636}
3637
3638
3639/// Matches on the receiver of an ObjectiveC Message expression.
3640///
3641/// Example
3642/// matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *")));
3643/// matches the [webView ...] message invocation.
3644/// \code
3645/// NSString *webViewJavaScript = ...
3646/// UIWebView *webView = ...
3647/// [webView stringByEvaluatingJavaScriptFromString:webViewJavascript];
3648/// \endcode
3649AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>,namespace internal { class matcher_hasReceiverType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasReceiverType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ObjCMessageExpr &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> hasReceiverType( internal::Matcher<QualType> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasReceiverType0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> ( &hasReceiverType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_hasReceiverType0Matcher
::matches( const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
3650 InnerMatcher)namespace internal { class matcher_hasReceiverType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasReceiverType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ObjCMessageExpr &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> hasReceiverType( internal::Matcher<QualType> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasReceiverType0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> ( &hasReceiverType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_hasReceiverType0Matcher
::matches( const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3651 const QualType TypeDecl = Node.getReceiverType();
3652 return InnerMatcher.matches(TypeDecl, Finder, Builder);
3653}
3654
3655/// Returns true when the Objective-C method declaration is a class method.
3656///
3657/// Example
3658/// matcher = objcMethodDecl(isClassMethod())
3659/// matches
3660/// \code
3661/// @interface I + (void)foo; @end
3662/// \endcode
3663/// but not
3664/// \code
3665/// @interface I - (void)bar; @end
3666/// \endcode
3667AST_MATCHER(ObjCMethodDecl, isClassMethod)namespace internal { class matcher_isClassMethodMatcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMethodDecl
> { public: explicit matcher_isClassMethodMatcher() = default
; bool matches(const ObjCMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<ObjCMethodDecl>
isClassMethod() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isClassMethodMatcher()); } inline bool
internal::matcher_isClassMethodMatcher::matches( const ObjCMethodDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3668 return Node.isClassMethod();
3669}
3670
3671/// Returns true when the Objective-C method declaration is an instance method.
3672///
3673/// Example
3674/// matcher = objcMethodDecl(isInstanceMethod())
3675/// matches
3676/// \code
3677/// @interface I - (void)bar; @end
3678/// \endcode
3679/// but not
3680/// \code
3681/// @interface I + (void)foo; @end
3682/// \endcode
3683AST_MATCHER(ObjCMethodDecl, isInstanceMethod)namespace internal { class matcher_isInstanceMethodMatcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMethodDecl
> { public: explicit matcher_isInstanceMethodMatcher() = default
; bool matches(const ObjCMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<ObjCMethodDecl>
isInstanceMethod() { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_isInstanceMethodMatcher())
; } inline bool internal::matcher_isInstanceMethodMatcher::matches
( const ObjCMethodDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3684 return Node.isInstanceMethod();
3685}
3686
3687/// Returns true when the Objective-C message is sent to a class.
3688///
3689/// Example
3690/// matcher = objcMessageExpr(isClassMessage())
3691/// matches
3692/// \code
3693/// [NSString stringWithFormat:@"format"];
3694/// \endcode
3695/// but not
3696/// \code
3697/// NSString *x = @"hello";
3698/// [x containsString:@"h"];
3699/// \endcode
3700AST_MATCHER(ObjCMessageExpr, isClassMessage)namespace internal { class matcher_isClassMessageMatcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_isClassMessageMatcher() = default
; bool matches(const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<ObjCMessageExpr>
isClassMessage() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isClassMessageMatcher()); } inline bool
internal::matcher_isClassMessageMatcher::matches( const ObjCMessageExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3701 return Node.isClassMessage();
3702}
3703
3704/// Returns true when the Objective-C message is sent to an instance.
3705///
3706/// Example
3707/// matcher = objcMessageExpr(isInstanceMessage())
3708/// matches
3709/// \code
3710/// NSString *x = @"hello";
3711/// [x containsString:@"h"];
3712/// \endcode
3713/// but not
3714/// \code
3715/// [NSString stringWithFormat:@"format"];
3716/// \endcode
3717AST_MATCHER(ObjCMessageExpr, isInstanceMessage)namespace internal { class matcher_isInstanceMessageMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
ObjCMessageExpr> { public: explicit matcher_isInstanceMessageMatcher
() = default; bool matches(const ObjCMessageExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; }; } inline ::clang::ast_matchers::internal::Matcher
<ObjCMessageExpr> isInstanceMessage() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_isInstanceMessageMatcher
()); } inline bool internal::matcher_isInstanceMessageMatcher
::matches( const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3718 return Node.isInstanceMessage();
3719}
3720
3721/// Matches if the Objective-C message is sent to an instance,
3722/// and the inner matcher matches on that instance.
3723///
3724/// For example the method call in
3725/// \code
3726/// NSString *x = @"hello";
3727/// [x containsString:@"h"];
3728/// \endcode
3729/// is matched by
3730/// objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x"))))))
3731AST_MATCHER_P(ObjCMessageExpr, hasReceiver, internal::Matcher<Expr>,namespace internal { class matcher_hasReceiver0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasReceiver0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ObjCMessageExpr &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> hasReceiver( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasReceiver0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ObjCMessageExpr> ( &
hasReceiver_Type0)(internal::Matcher<Expr> const &InnerMatcher
); inline bool internal::matcher_hasReceiver0Matcher::matches
( const ObjCMessageExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
3732 InnerMatcher)namespace internal { class matcher_hasReceiver0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasReceiver0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ObjCMessageExpr &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> hasReceiver( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasReceiver0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ObjCMessageExpr> ( &
hasReceiver_Type0)(internal::Matcher<Expr> const &InnerMatcher
); inline bool internal::matcher_hasReceiver0Matcher::matches
( const ObjCMessageExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3733 const Expr *ReceiverNode = Node.getInstanceReceiver();
3734 return (ReceiverNode != nullptr &&
3735 InnerMatcher.matches(*ReceiverNode->IgnoreParenImpCasts(), Finder,
3736 Builder));
3737}
3738
3739/// Matches when BaseName == Selector.getAsString()
3740///
3741/// matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:"));
3742/// matches the outer message expr in the code below, but NOT the message
3743/// invocation for self.bodyView.
3744/// \code
3745/// [self.bodyView loadHTMLString:html baseURL:NULL];
3746/// \endcode
3747AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName)namespace internal { class matcher_hasSelector0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasSelector0Matcher( std::string
const &ABaseName) : BaseName(ABaseName) {} bool matches(
const ObjCMessageExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string BaseName; }; }
inline ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> hasSelector( std::string const &BaseName) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasSelector0Matcher
(BaseName)); } typedef ::clang::ast_matchers::internal::Matcher
<ObjCMessageExpr> ( &hasSelector_Type0)(std::string
const &BaseName); inline bool internal::matcher_hasSelector0Matcher
::matches( const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3748 Selector Sel = Node.getSelector();
3749 return BaseName == Sel.getAsString();
3750}
3751
3752/// Matches when at least one of the supplied string equals to the
3753/// Selector.getAsString()
3754///
3755/// matcher = objCMessageExpr(hasSelector("methodA:", "methodB:"));
3756/// matches both of the expressions below:
3757/// \code
3758/// [myObj methodA:argA];
3759/// [myObj methodB:argB];
3760/// \endcode
3761extern const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>,
3762 StringRef,
3763 internal::hasAnySelectorFunc>
3764 hasAnySelector;
3765
3766/// Matches ObjC selectors whose name contains
3767/// a substring matched by the given RegExp.
3768/// matcher = objCMessageExpr(matchesSelector("loadHTMLString\:baseURL?"));
3769/// matches the outer message expr in the code below, but NOT the message
3770/// invocation for self.bodyView.
3771/// \code
3772/// [self.bodyView loadHTMLString:html baseURL:NULL];
3773/// \endcode
3774AST_MATCHER_REGEX(ObjCMessageExpr, matchesSelector, RegExp)namespace internal { class matcher_matchesSelector0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_matchesSelector0Matcher( std::
shared_ptr<llvm::Regex> RE) : RegExp(std::move(RE)) {} bool
matches(const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: std
::shared_ptr<llvm::Regex> RegExp; }; } inline ::clang::
ast_matchers::internal::Matcher<ObjCMessageExpr> matchesSelector
( llvm::StringRef RegExp, llvm::Regex::RegexFlags RegexFlags)
{ return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_matchesSelector0Matcher( ::clang::ast_matchers::internal
::createAndVerifyRegex( RegExp, RegexFlags, "matchesSelector"
))); } inline ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> matchesSelector( llvm::StringRef RegExp) { return matchesSelector
(RegExp, llvm::Regex::NoFlags); } typedef ::clang::ast_matchers
::internal::Matcher<ObjCMessageExpr> ( &matchesSelector_Type0Flags
)(llvm::StringRef, llvm::Regex::RegexFlags); typedef ::clang::
ast_matchers::internal::Matcher<ObjCMessageExpr> ( &
matchesSelector_Type0)(llvm::StringRef); inline bool internal
::matcher_matchesSelector0Matcher::matches( const ObjCMessageExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3775 std::string SelectorString = Node.getSelector().getAsString();
3776 return RegExp->match(SelectorString);
3777}
3778
3779/// Matches when the selector is the empty selector
3780///
3781/// Matches only when the selector of the objCMessageExpr is NULL. This may
3782/// represent an error condition in the tree!
3783AST_MATCHER(ObjCMessageExpr, hasNullSelector)namespace internal { class matcher_hasNullSelectorMatcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasNullSelectorMatcher() = default
; bool matches(const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<ObjCMessageExpr>
hasNullSelector() { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasNullSelectorMatcher());
} inline bool internal::matcher_hasNullSelectorMatcher::matches
( const ObjCMessageExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3784 return Node.getSelector().isNull();
3785}
3786
3787/// Matches when the selector is a Unary Selector
3788///
3789/// matcher = objCMessageExpr(matchesSelector(hasUnarySelector());
3790/// matches self.bodyView in the code below, but NOT the outer message
3791/// invocation of "loadHTMLString:baseURL:".
3792/// \code
3793/// [self.bodyView loadHTMLString:html baseURL:NULL];
3794/// \endcode
3795AST_MATCHER(ObjCMessageExpr, hasUnarySelector)namespace internal { class matcher_hasUnarySelectorMatcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_hasUnarySelectorMatcher() = default
; bool matches(const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<ObjCMessageExpr>
hasUnarySelector() { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasUnarySelectorMatcher())
; } inline bool internal::matcher_hasUnarySelectorMatcher::matches
( const ObjCMessageExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3796 return Node.getSelector().isUnarySelector();
3797}
3798
3799/// Matches when the selector is a keyword selector
3800///
3801/// objCMessageExpr(hasKeywordSelector()) matches the generated setFrame
3802/// message expression in
3803///
3804/// \code
3805/// UIWebView *webView = ...;
3806/// CGRect bodyFrame = webView.frame;
3807/// bodyFrame.size.height = self.bodyContentHeight;
3808/// webView.frame = bodyFrame;
3809/// // ^---- matches here
3810/// \endcode
3811AST_MATCHER(ObjCMessageExpr, hasKeywordSelector)namespace internal { class matcher_hasKeywordSelectorMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
ObjCMessageExpr> { public: explicit matcher_hasKeywordSelectorMatcher
() = default; bool matches(const ObjCMessageExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; }; } inline ::clang::ast_matchers::internal::Matcher
<ObjCMessageExpr> hasKeywordSelector() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_hasKeywordSelectorMatcher
()); } inline bool internal::matcher_hasKeywordSelectorMatcher
::matches( const ObjCMessageExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
3812 return Node.getSelector().isKeywordSelector();
3813}
3814
3815/// Matches when the selector has the specified number of arguments
3816///
3817/// matcher = objCMessageExpr(numSelectorArgs(0));
3818/// matches self.bodyView in the code below
3819///
3820/// matcher = objCMessageExpr(numSelectorArgs(2));
3821/// matches the invocation of "loadHTMLString:baseURL:" but not that
3822/// of self.bodyView
3823/// \code
3824/// [self.bodyView loadHTMLString:html baseURL:NULL];
3825/// \endcode
3826AST_MATCHER_P(ObjCMessageExpr, numSelectorArgs, unsigned, N)namespace internal { class matcher_numSelectorArgs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ObjCMessageExpr
> { public: explicit matcher_numSelectorArgs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const ObjCMessageExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::Matcher<ObjCMessageExpr>
numSelectorArgs( unsigned const &N) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_numSelectorArgs0Matcher
(N)); } typedef ::clang::ast_matchers::internal::Matcher<ObjCMessageExpr
> ( &numSelectorArgs_Type0)(unsigned const &N); inline
bool internal::matcher_numSelectorArgs0Matcher::matches( const
ObjCMessageExpr &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3827 return Node.getSelector().getNumArgs() == N;
3828}
3829
3830/// Matches if the call expression's callee expression matches.
3831///
3832/// Given
3833/// \code
3834/// class Y { void x() { this->x(); x(); Y y; y.x(); } };
3835/// void f() { f(); }
3836/// \endcode
3837/// callExpr(callee(expr()))
3838/// matches this->x(), x(), y.x(), f()
3839/// with callee(...)
3840/// matching this->x, x, y.x, f respectively
3841///
3842/// Note: Callee cannot take the more general internal::Matcher<Expr>
3843/// because this introduces ambiguous overloads with calls to Callee taking a
3844/// internal::Matcher<Decl>, as the matcher hierarchy is purely
3845/// implemented in terms of implicit casts.
3846AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>,namespace internal { class matcher_callee0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<CallExpr>
{ public: explicit matcher_callee0Matcher( internal::Matcher
<Stmt> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const CallExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Stmt> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<CallExpr> callee( internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_callee0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CallExpr> ( &callee_Type0)(internal::Matcher<Stmt
> const &InnerMatcher); inline bool internal::matcher_callee0Matcher
::matches( const CallExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
3847 InnerMatcher)namespace internal { class matcher_callee0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<CallExpr>
{ public: explicit matcher_callee0Matcher( internal::Matcher
<Stmt> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const CallExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Stmt> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<CallExpr> callee( internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_callee0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CallExpr> ( &callee_Type0)(internal::Matcher<Stmt
> const &InnerMatcher); inline bool internal::matcher_callee0Matcher
::matches( const CallExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
3848 const Expr *ExprNode = Node.getCallee();
3849 return (ExprNode != nullptr &&
3850 InnerMatcher.matches(*ExprNode, Finder, Builder));
3851}
3852
3853/// Matches 1) if the call expression's callee's declaration matches the
3854/// given matcher; or 2) if the Obj-C message expression's callee's method
3855/// declaration matches the given matcher.
3856///
3857/// Example matches y.x() (matcher = callExpr(callee(
3858/// cxxMethodDecl(hasName("x")))))
3859/// \code
3860/// class Y { public: void x(); };
3861/// void z() { Y y; y.x(); }
3862/// \endcode
3863///
3864/// Example 2. Matches [I foo] with
3865/// objcMessageExpr(callee(objcMethodDecl(hasName("foo"))))
3866///
3867/// \code
3868/// @interface I: NSObject
3869/// +(void)foo;
3870/// @end
3871/// ...
3872/// [I foo]
3873/// \endcode
3874AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_callee1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_callee1Matcher( internal::Matcher<Decl> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_callee1Matcher, void
(::clang::ast_matchers::internal::TypeList<ObjCMessageExpr
, CallExpr>), internal::Matcher<Decl> > callee(internal
::Matcher<Decl> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_callee1Matcher
, void(::clang::ast_matchers::internal::TypeList<ObjCMessageExpr
, CallExpr>), internal::Matcher<Decl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_callee1Matcher, void(::clang::ast_matchers
::internal::TypeList<ObjCMessageExpr, CallExpr>), internal
::Matcher<Decl> > (&callee_Type1)(internal::Matcher
<Decl> const &InnerMatcher); template <typename NodeType
, typename ParamT> bool internal:: matcher_callee1Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
3875 callee, AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCMessageExpr, CallExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_callee1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_callee1Matcher( internal::Matcher<Decl> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_callee1Matcher, void
(::clang::ast_matchers::internal::TypeList<ObjCMessageExpr
, CallExpr>), internal::Matcher<Decl> > callee(internal
::Matcher<Decl> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_callee1Matcher
, void(::clang::ast_matchers::internal::TypeList<ObjCMessageExpr
, CallExpr>), internal::Matcher<Decl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_callee1Matcher, void(::clang::ast_matchers
::internal::TypeList<ObjCMessageExpr, CallExpr>), internal
::Matcher<Decl> > (&callee_Type1)(internal::Matcher
<Decl> const &InnerMatcher); template <typename NodeType
, typename ParamT> bool internal:: matcher_callee1Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
3876 internal::Matcher<Decl>, InnerMatcher, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_callee1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_callee1Matcher( internal::Matcher<Decl> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_callee1Matcher, void
(::clang::ast_matchers::internal::TypeList<ObjCMessageExpr
, CallExpr>), internal::Matcher<Decl> > callee(internal
::Matcher<Decl> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_callee1Matcher
, void(::clang::ast_matchers::internal::TypeList<ObjCMessageExpr
, CallExpr>), internal::Matcher<Decl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_callee1Matcher, void(::clang::ast_matchers
::internal::TypeList<ObjCMessageExpr, CallExpr>), internal
::Matcher<Decl> > (&callee_Type1)(internal::Matcher
<Decl> const &InnerMatcher); template <typename NodeType
, typename ParamT> bool internal:: matcher_callee1Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
3877 if (const auto *CallNode = dyn_cast<CallExpr>(&Node))
3878 return callExpr(hasDeclaration(InnerMatcher))
3879 .matches(Node, Finder, Builder);
3880 else {
3881 // The dynamic cast below is guaranteed to succeed as there are only 2
3882 // supported return types.
3883 const auto *MsgNode = cast<ObjCMessageExpr>(&Node);
3884 const Decl *DeclNode = MsgNode->getMethodDecl();
3885 return (DeclNode != nullptr &&
3886 InnerMatcher.matches(*DeclNode, Finder, Builder));
3887 }
3888}
3889
3890/// Matches if the expression's or declaration's type matches a type
3891/// matcher.
3892///
3893/// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
3894/// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
3895/// and U (matcher = typedefDecl(hasType(asString("int")))
3896/// and friend class X (matcher = friendDecl(hasType("X"))
3897/// and public virtual X (matcher = cxxBaseSpecifier(hasType(
3898/// asString("class X")))
3899/// \code
3900/// class X {};
3901/// void y(X &x) { x; X z; }
3902/// typedef int U;
3903/// class Y { friend class X; };
3904/// class Z : public virtual X {};
3905/// \endcode
3906AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType0Matcher( internal::Matcher<QualType> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType0Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > hasType(internal::Matcher<QualType
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> >(InnerMatcher); } typedef ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > (&hasType_Type0)(internal::
Matcher<QualType> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3907 hasType,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType0Matcher( internal::Matcher<QualType> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType0Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > hasType(internal::Matcher<QualType
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> >(InnerMatcher); } typedef ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > (&hasType_Type0)(internal::
Matcher<QualType> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3908 AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType0Matcher( internal::Matcher<QualType> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType0Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > hasType(internal::Matcher<QualType
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> >(InnerMatcher); } typedef ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > (&hasType_Type0)(internal::
Matcher<QualType> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3909 ValueDecl, CXXBaseSpecifier),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType0Matcher( internal::Matcher<QualType> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType0Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > hasType(internal::Matcher<QualType
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> >(InnerMatcher); } typedef ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > (&hasType_Type0)(internal::
Matcher<QualType> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3910 internal::Matcher<QualType>, InnerMatcher, 0)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType0Matcher( internal::Matcher<QualType> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType0Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > hasType(internal::Matcher<QualType
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> >(InnerMatcher); } typedef ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasType0Matcher
, void(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, TypedefNameDecl, ValueDecl, CXXBaseSpecifier>), internal
::Matcher<QualType> > (&hasType_Type0)(internal::
Matcher<QualType> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3911 QualType QT = internal::getUnderlyingType(Node);
3912 if (!QT.isNull())
3913 return InnerMatcher.matches(QT, Finder, Builder);
3914 return false;
3915}
3916
3917/// Overloaded to match the declaration of the expression's or value
3918/// declaration's type.
3919///
3920/// In case of a value declaration (for example a variable declaration),
3921/// this resolves one layer of indirection. For example, in the value
3922/// declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of
3923/// X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the
3924/// declaration of x.
3925///
3926/// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X")))))
3927/// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X")))))
3928/// and friend class X (matcher = friendDecl(hasType("X"))
3929/// and public virtual X (matcher = cxxBaseSpecifier(hasType(
3930/// cxxRecordDecl(hasName("X"))))
3931/// \code
3932/// class X {};
3933/// void y(X &x) { x; X z; }
3934/// class Y { friend class X; };
3935/// class Z : public virtual X {};
3936/// \endcode
3937///
3938/// Example matches class Derived
3939/// (matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base"))))))
3940/// \code
3941/// class Base {};
3942/// class Derived : Base {};
3943/// \endcode
3944///
3945/// Usable as: Matcher<Expr>, Matcher<FriendDecl>, Matcher<ValueDecl>,
3946/// Matcher<CXXBaseSpecifier>
3947AST_POLYMORPHIC_MATCHER_P_OVERLOAD(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType1Matcher( internal::Matcher<Decl> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType1Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, ValueDecl, CXXBaseSpecifier>), internal::Matcher<Decl
> > hasType(internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasType1Matcher, void(::clang::ast_matchers
::internal::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier
>), internal::Matcher<Decl> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasType1Matcher, void(::clang::ast_matchers::internal
::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier>
), internal::Matcher<Decl> > (&hasType_Type1)(internal
::Matcher<Decl> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3948 hasType,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType1Matcher( internal::Matcher<Decl> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType1Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, ValueDecl, CXXBaseSpecifier>), internal::Matcher<Decl
> > hasType(internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasType1Matcher, void(::clang::ast_matchers
::internal::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier
>), internal::Matcher<Decl> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasType1Matcher, void(::clang::ast_matchers::internal
::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier>
), internal::Matcher<Decl> > (&hasType_Type1)(internal
::Matcher<Decl> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3949 AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, ValueDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType1Matcher( internal::Matcher<Decl> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType1Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, ValueDecl, CXXBaseSpecifier>), internal::Matcher<Decl
> > hasType(internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasType1Matcher, void(::clang::ast_matchers
::internal::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier
>), internal::Matcher<Decl> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasType1Matcher, void(::clang::ast_matchers::internal
::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier>
), internal::Matcher<Decl> > (&hasType_Type1)(internal
::Matcher<Decl> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3950 CXXBaseSpecifier),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType1Matcher( internal::Matcher<Decl> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType1Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, ValueDecl, CXXBaseSpecifier>), internal::Matcher<Decl
> > hasType(internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasType1Matcher, void(::clang::ast_matchers
::internal::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier
>), internal::Matcher<Decl> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasType1Matcher, void(::clang::ast_matchers::internal
::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier>
), internal::Matcher<Decl> > (&hasType_Type1)(internal
::Matcher<Decl> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3951 internal::Matcher<Decl>, InnerMatcher, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasType1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasType1Matcher( internal::Matcher<Decl> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Decl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasType1Matcher, void
(::clang::ast_matchers::internal::TypeList<Expr, FriendDecl
, ValueDecl, CXXBaseSpecifier>), internal::Matcher<Decl
> > hasType(internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasType1Matcher, void(::clang::ast_matchers
::internal::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier
>), internal::Matcher<Decl> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasType1Matcher, void(::clang::ast_matchers::internal
::TypeList<Expr, FriendDecl, ValueDecl, CXXBaseSpecifier>
), internal::Matcher<Decl> > (&hasType_Type1)(internal
::Matcher<Decl> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasType1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3952 QualType QT = internal::getUnderlyingType(Node);
3953 if (!QT.isNull())
3954 return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder);
3955 return false;
3956}
3957
3958/// Matches if the type location of a node matches the inner matcher.
3959///
3960/// Examples:
3961/// \code
3962/// int x;
3963/// \endcode
3964/// declaratorDecl(hasTypeLoc(loc(asString("int"))))
3965/// matches int x
3966///
3967/// \code
3968/// auto x = int(3);
3969/// \endcode
3970/// cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int"))))
3971/// matches int(3)
3972///
3973/// \code
3974/// struct Foo { Foo(int, int); };
3975/// auto x = Foo(1, 2);
3976/// \endcode
3977/// cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo"))))
3978/// matches Foo(1, 2)
3979///
3980/// Usable as: Matcher<BlockDecl>, Matcher<CXXBaseSpecifier>,
3981/// Matcher<CXXCtorInitializer>, Matcher<CXXFunctionalCastExpr>,
3982/// Matcher<CXXNewExpr>, Matcher<CXXTemporaryObjectExpr>,
3983/// Matcher<CXXUnresolvedConstructExpr>,
3984/// Matcher<ClassTemplateSpecializationDecl>, Matcher<CompoundLiteralExpr>,
3985/// Matcher<DeclaratorDecl>, Matcher<ExplicitCastExpr>,
3986/// Matcher<ObjCPropertyDecl>, Matcher<TemplateArgumentLoc>,
3987/// Matcher<TypedefNameDecl>
3988AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3989 hasTypeLoc,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3990 AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3991 BlockDecl, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3992 CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3993 ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3994 ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3995 TypedefNameDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
3996 internal::Matcher<TypeLoc>, Inner)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasTypeLoc0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasTypeLoc0Matcher( internal::Matcher<TypeLoc
> const &AInner) : Inner(AInner) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> Inner; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers
::internal::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > hasTypeLoc(internal
::Matcher<TypeLoc> const &Inner) { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasTypeLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<BlockDecl
, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr
, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasTypeLoc0Matcher, void(::clang::ast_matchers::internal
::TypeList<BlockDecl, CXXBaseSpecifier, CXXCtorInitializer
, CXXFunctionalCastExpr, CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr
, ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl
, ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, TypedefNameDecl
>), internal::Matcher<TypeLoc> > (&hasTypeLoc_Type0
)(internal::Matcher<TypeLoc> const &Inner); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasTypeLoc0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
3997 TypeSourceInfo *source = internal::GetTypeSourceInfo(Node);
3998 if (source == nullptr) {
3999 // This happens for example for implicit destructors.
4000 return false;
4001 }
4002 return Inner.matches(source->getTypeLoc(), Finder, Builder);
4003}
4004
4005/// Matches if the matched type is represented by the given string.
4006///
4007/// Given
4008/// \code
4009/// class Y { public: void x(); };
4010/// void z() { Y* y; y->x(); }
4011/// \endcode
4012/// cxxMemberCallExpr(on(hasType(asString("class Y *"))))
4013/// matches y->x()
4014AST_MATCHER_P(QualType, asString, std::string, Name)namespace internal { class matcher_asString0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_asString0Matcher( std::string const
&AName) : Name(AName) {} bool matches(const QualType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: std::string Name; }; } inline ::clang
::ast_matchers::internal::Matcher<QualType> asString( std
::string const &Name) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_asString0Matcher(Name));
} typedef ::clang::ast_matchers::internal::Matcher<QualType
> ( &asString_Type0)(std::string const &Name); inline
bool internal::matcher_asString0Matcher::matches( const QualType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4015 return Name == Node.getAsString();
4016}
4017
4018/// Matches if the matched type is a pointer type and the pointee type
4019/// matches the specified matcher.
4020///
4021/// Example matches y->x()
4022/// (matcher = cxxMemberCallExpr(on(hasType(pointsTo
4023/// cxxRecordDecl(hasName("Y")))))))
4024/// \code
4025/// class Y { public: void x(); };
4026/// void z() { Y *y; y->x(); }
4027/// \endcode
4028AST_MATCHER_P(namespace internal { class matcher_pointsTo0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_pointsTo0Matcher( internal::Matcher
<QualType> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<QualType> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<QualType> pointsTo( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_pointsTo0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &pointsTo_Type0)(internal::Matcher<
QualType> const &InnerMatcher); inline bool internal::
matcher_pointsTo0Matcher::matches( const QualType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
4029 QualType, pointsTo, internal::Matcher<QualType>,namespace internal { class matcher_pointsTo0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_pointsTo0Matcher( internal::Matcher
<QualType> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<QualType> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<QualType> pointsTo( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_pointsTo0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &pointsTo_Type0)(internal::Matcher<
QualType> const &InnerMatcher); inline bool internal::
matcher_pointsTo0Matcher::matches( const QualType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
4030 InnerMatcher)namespace internal { class matcher_pointsTo0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_pointsTo0Matcher( internal::Matcher
<QualType> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<QualType> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<QualType> pointsTo( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_pointsTo0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &pointsTo_Type0)(internal::Matcher<
QualType> const &InnerMatcher); inline bool internal::
matcher_pointsTo0Matcher::matches( const QualType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
4031 return (!Node.isNull() && Node->isAnyPointerType() &&
4032 InnerMatcher.matches(Node->getPointeeType(), Finder, Builder));
4033}
4034
4035/// Overloaded to match the pointee type's declaration.
4036AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher<Decl>,namespace internal { class matcher_pointsTo1Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_pointsTo1Matcher( internal::Matcher
<Decl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Decl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<QualType> pointsTo( internal::Matcher
<Decl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_pointsTo1Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &pointsTo_Type1)(internal::Matcher<
Decl> const &InnerMatcher); inline bool internal::matcher_pointsTo1Matcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4037 InnerMatcher, 1)namespace internal { class matcher_pointsTo1Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_pointsTo1Matcher( internal::Matcher
<Decl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Decl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<QualType> pointsTo( internal::Matcher
<Decl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_pointsTo1Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &pointsTo_Type1)(internal::Matcher<
Decl> const &InnerMatcher); inline bool internal::matcher_pointsTo1Matcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4038 return pointsTo(qualType(hasDeclaration(InnerMatcher)))
4039 .matches(Node, Finder, Builder);
4040}
4041
4042/// Matches if the matched type matches the unqualified desugared
4043/// type of the matched node.
4044///
4045/// For example, in:
4046/// \code
4047/// class A {};
4048/// using B = A;
4049/// \endcode
4050/// The matcher type(hasUnqualifiedDesugaredType(recordType())) matches
4051/// both B and A.
4052AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher<Type>,namespace internal { class matcher_hasUnqualifiedDesugaredType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Type> { public: explicit matcher_hasUnqualifiedDesugaredType0Matcher
( internal::Matcher<Type> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Type &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Type> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Type> hasUnqualifiedDesugaredType
( internal::Matcher<Type> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasUnqualifiedDesugaredType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<Type>
( &hasUnqualifiedDesugaredType_Type0)(internal::Matcher<
Type> const &InnerMatcher); inline bool internal::matcher_hasUnqualifiedDesugaredType0Matcher
::matches( const Type &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4053 InnerMatcher)namespace internal { class matcher_hasUnqualifiedDesugaredType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Type> { public: explicit matcher_hasUnqualifiedDesugaredType0Matcher
( internal::Matcher<Type> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Type &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Type> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Type> hasUnqualifiedDesugaredType
( internal::Matcher<Type> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasUnqualifiedDesugaredType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<Type>
( &hasUnqualifiedDesugaredType_Type0)(internal::Matcher<
Type> const &InnerMatcher); inline bool internal::matcher_hasUnqualifiedDesugaredType0Matcher
::matches( const Type &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4054 return InnerMatcher.matches(*Node.getUnqualifiedDesugaredType(), Finder,
4055 Builder);
4056}
4057
4058/// Matches if the matched type is a reference type and the referenced
4059/// type matches the specified matcher.
4060///
4061/// Example matches X &x and const X &y
4062/// (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X"))))))
4063/// \code
4064/// class X {
4065/// void a(X b) {
4066/// X &x = b;
4067/// const X &y = b;
4068/// }
4069/// };
4070/// \endcode
4071AST_MATCHER_P(QualType, references, internal::Matcher<QualType>,namespace internal { class matcher_references0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_references0Matcher( internal::
Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> references
( internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_references0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<QualType> ( &references_Type0
)(internal::Matcher<QualType> const &InnerMatcher);
inline bool internal::matcher_references0Matcher::matches( const
QualType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4072 InnerMatcher)namespace internal { class matcher_references0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_references0Matcher( internal::
Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> references
( internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_references0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<QualType> ( &references_Type0
)(internal::Matcher<QualType> const &InnerMatcher);
inline bool internal::matcher_references0Matcher::matches( const
QualType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4073 return (!Node.isNull() && Node->isReferenceType() &&
4074 InnerMatcher.matches(Node->getPointeeType(), Finder, Builder));
4075}
4076
4077/// Matches QualTypes whose canonical type matches InnerMatcher.
4078///
4079/// Given:
4080/// \code
4081/// typedef int &int_ref;
4082/// int a;
4083/// int_ref b = a;
4084/// \endcode
4085///
4086/// \c varDecl(hasType(qualType(referenceType()))))) will not match the
4087/// declaration of b but \c
4088/// varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does.
4089AST_MATCHER_P(QualType, hasCanonicalType, internal::Matcher<QualType>,namespace internal { class matcher_hasCanonicalType0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
QualType> { public: explicit matcher_hasCanonicalType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const QualType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<QualType> hasCanonicalType( internal::Matcher
<QualType> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasCanonicalType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &hasCanonicalType_Type0)(internal::Matcher
<QualType> const &InnerMatcher); inline bool internal
::matcher_hasCanonicalType0Matcher::matches( const QualType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4090 InnerMatcher)namespace internal { class matcher_hasCanonicalType0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
QualType> { public: explicit matcher_hasCanonicalType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const QualType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<QualType> hasCanonicalType( internal::Matcher
<QualType> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasCanonicalType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualType> ( &hasCanonicalType_Type0)(internal::Matcher
<QualType> const &InnerMatcher); inline bool internal
::matcher_hasCanonicalType0Matcher::matches( const QualType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4091 if (Node.isNull())
4092 return false;
4093 return InnerMatcher.matches(Node.getCanonicalType(), Finder, Builder);
4094}
4095
4096/// Overloaded to match the referenced type's declaration.
4097AST_MATCHER_P_OVERLOAD(QualType, references, internal::Matcher<Decl>,namespace internal { class matcher_references1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_references1Matcher( internal::
Matcher<Decl> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Decl> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<QualType> references(
internal::Matcher<Decl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_references1Matcher(InnerMatcher)); } typedef ::clang::
ast_matchers::internal::Matcher<QualType> ( &references_Type1
)(internal::Matcher<Decl> const &InnerMatcher); inline
bool internal::matcher_references1Matcher::matches( const QualType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4098 InnerMatcher, 1)namespace internal { class matcher_references1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_references1Matcher( internal::
Matcher<Decl> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const QualType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Decl> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<QualType> references(
internal::Matcher<Decl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_references1Matcher(InnerMatcher)); } typedef ::clang::
ast_matchers::internal::Matcher<QualType> ( &references_Type1
)(internal::Matcher<Decl> const &InnerMatcher); inline
bool internal::matcher_references1Matcher::matches( const QualType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4099 return references(qualType(hasDeclaration(InnerMatcher)))
4100 .matches(Node, Finder, Builder);
4101}
4102
4103/// Matches on the implicit object argument of a member call expression. Unlike
4104/// `on`, matches the argument directly without stripping away anything.
4105///
4106/// Given
4107/// \code
4108/// class Y { public: void m(); };
4109/// Y g();
4110/// class X : public Y { void g(); };
4111/// void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); }
4112/// \endcode
4113/// cxxMemberCallExpr(onImplicitObjectArgument(hasType(
4114/// cxxRecordDecl(hasName("Y")))))
4115/// matches `y.m()`, `x.m()` and (g()).m(), but not `x.g()`.
4116/// cxxMemberCallExpr(on(callExpr()))
4117/// does not match `(g()).m()`, because the parens are not ignored.
4118///
4119/// FIXME: Overload to allow directly matching types?
4120AST_MATCHER_P(CXXMemberCallExpr, onImplicitObjectArgument,namespace internal { class matcher_onImplicitObjectArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXMemberCallExpr> { public: explicit matcher_onImplicitObjectArgument0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMemberCallExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> onImplicitObjectArgument( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_onImplicitObjectArgument0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXMemberCallExpr> ( &onImplicitObjectArgument_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_onImplicitObjectArgument0Matcher::matches
( const CXXMemberCallExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4121 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_onImplicitObjectArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXMemberCallExpr> { public: explicit matcher_onImplicitObjectArgument0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMemberCallExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> onImplicitObjectArgument( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_onImplicitObjectArgument0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXMemberCallExpr> ( &onImplicitObjectArgument_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_onImplicitObjectArgument0Matcher::matches
( const CXXMemberCallExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4122 const Expr *ExprNode = Node.getImplicitObjectArgument();
4123 return (ExprNode != nullptr &&
4124 InnerMatcher.matches(*ExprNode, Finder, Builder));
4125}
4126
4127/// Matches if the type of the expression's implicit object argument either
4128/// matches the InnerMatcher, or is a pointer to a type that matches the
4129/// InnerMatcher.
4130///
4131/// Given
4132/// \code
4133/// class Y { public: void m(); };
4134/// class X : public Y { void g(); };
4135/// void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); }
4136/// \endcode
4137/// cxxMemberCallExpr(thisPointerType(hasDeclaration(
4138/// cxxRecordDecl(hasName("Y")))))
4139/// matches `y.m()`, `p->m()` and `x.m()`.
4140/// cxxMemberCallExpr(thisPointerType(hasDeclaration(
4141/// cxxRecordDecl(hasName("X")))))
4142/// matches `x.g()`.
4143AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType,namespace internal { class matcher_thisPointerType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXMemberCallExpr
> { public: explicit matcher_thisPointerType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMemberCallExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> thisPointerType( internal::Matcher<QualType> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_thisPointerType0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> ( &thisPointerType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_thisPointerType0Matcher
::matches( const CXXMemberCallExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4144 internal::Matcher<QualType>, InnerMatcher, 0)namespace internal { class matcher_thisPointerType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXMemberCallExpr
> { public: explicit matcher_thisPointerType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMemberCallExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> thisPointerType( internal::Matcher<QualType> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_thisPointerType0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> ( &thisPointerType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_thisPointerType0Matcher
::matches( const CXXMemberCallExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4145 return onImplicitObjectArgument(
4146 anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher))))
4147 .matches(Node, Finder, Builder);
4148}
4149
4150/// Overloaded to match the type's declaration.
4151AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType,namespace internal { class matcher_thisPointerType1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXMemberCallExpr
> { public: explicit matcher_thisPointerType1Matcher( internal
::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMemberCallExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> thisPointerType( internal::Matcher<Decl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_thisPointerType1Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> ( &thisPointerType_Type1)(internal::Matcher<Decl>
const &InnerMatcher); inline bool internal::matcher_thisPointerType1Matcher
::matches( const CXXMemberCallExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4152 internal::Matcher<Decl>, InnerMatcher, 1)namespace internal { class matcher_thisPointerType1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXMemberCallExpr
> { public: explicit matcher_thisPointerType1Matcher( internal
::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMemberCallExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> thisPointerType( internal::Matcher<Decl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_thisPointerType1Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXMemberCallExpr
> ( &thisPointerType_Type1)(internal::Matcher<Decl>
const &InnerMatcher); inline bool internal::matcher_thisPointerType1Matcher
::matches( const CXXMemberCallExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4153 return onImplicitObjectArgument(
4154 anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher))))
4155 .matches(Node, Finder, Builder);
4156}
4157
4158/// Matches a DeclRefExpr that refers to a declaration that matches the
4159/// specified matcher.
4160///
4161/// Example matches x in if(x)
4162/// (matcher = declRefExpr(to(varDecl(hasName("x")))))
4163/// \code
4164/// bool x;
4165/// if (x) {}
4166/// \endcode
4167AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>,namespace internal { class matcher_to0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<DeclRefExpr>
{ public: explicit matcher_to0Matcher( internal::Matcher<
Decl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const DeclRefExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Decl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<DeclRefExpr> to( internal::Matcher<
Decl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_to0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<DeclRefExpr
> ( &to_Type0)(internal::Matcher<Decl> const &
InnerMatcher); inline bool internal::matcher_to0Matcher::matches
( const DeclRefExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4168 InnerMatcher)namespace internal { class matcher_to0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<DeclRefExpr>
{ public: explicit matcher_to0Matcher( internal::Matcher<
Decl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const DeclRefExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Decl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<DeclRefExpr> to( internal::Matcher<
Decl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_to0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<DeclRefExpr
> ( &to_Type0)(internal::Matcher<Decl> const &
InnerMatcher); inline bool internal::matcher_to0Matcher::matches
( const DeclRefExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4169 const Decl *DeclNode = Node.getDecl();
4170 return (DeclNode != nullptr &&
4171 InnerMatcher.matches(*DeclNode, Finder, Builder));
4172}
4173
4174/// Matches if a node refers to a declaration through a specific
4175/// using shadow declaration.
4176///
4177/// Examples:
4178/// \code
4179/// namespace a { int f(); }
4180/// using a::f;
4181/// int x = f();
4182/// \endcode
4183/// declRefExpr(throughUsingDecl(anything()))
4184/// matches \c f
4185///
4186/// \code
4187/// namespace a { class X{}; }
4188/// using a::X;
4189/// X x;
4190/// \endcode
4191/// typeLoc(loc(usingType(throughUsingDecl(anything()))))
4192/// matches \c X
4193///
4194/// Usable as: Matcher<DeclRefExpr>, Matcher<UsingType>
4195AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_throughUsingDecl0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_throughUsingDecl0Matcher( internal
::Matcher<UsingShadowDecl> const &AInner) : Inner(AInner
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<UsingShadowDecl> Inner; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_throughUsingDecl0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, UsingType>), internal::Matcher<UsingShadowDecl> >
throughUsingDecl(internal::Matcher<UsingShadowDecl> const
&Inner) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_throughUsingDecl0Matcher, void(::clang
::ast_matchers::internal::TypeList<DeclRefExpr, UsingType>
), internal::Matcher<UsingShadowDecl> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_throughUsingDecl0Matcher, void(::clang::ast_matchers
::internal::TypeList<DeclRefExpr, UsingType>), internal
::Matcher<UsingShadowDecl> > (&throughUsingDecl_Type0
)(internal::Matcher<UsingShadowDecl> const &Inner);
template <typename NodeType, typename ParamT> bool internal
:: matcher_throughUsingDecl0Matcher<NodeType, ParamT>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4196 AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_throughUsingDecl0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_throughUsingDecl0Matcher( internal
::Matcher<UsingShadowDecl> const &AInner) : Inner(AInner
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<UsingShadowDecl> Inner; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_throughUsingDecl0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, UsingType>), internal::Matcher<UsingShadowDecl> >
throughUsingDecl(internal::Matcher<UsingShadowDecl> const
&Inner) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_throughUsingDecl0Matcher, void(::clang
::ast_matchers::internal::TypeList<DeclRefExpr, UsingType>
), internal::Matcher<UsingShadowDecl> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_throughUsingDecl0Matcher, void(::clang::ast_matchers
::internal::TypeList<DeclRefExpr, UsingType>), internal
::Matcher<UsingShadowDecl> > (&throughUsingDecl_Type0
)(internal::Matcher<UsingShadowDecl> const &Inner);
template <typename NodeType, typename ParamT> bool internal
:: matcher_throughUsingDecl0Matcher<NodeType, ParamT>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4197 UsingType),namespace internal { template <typename NodeType, typename
ParamT> class matcher_throughUsingDecl0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_throughUsingDecl0Matcher( internal
::Matcher<UsingShadowDecl> const &AInner) : Inner(AInner
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<UsingShadowDecl> Inner; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_throughUsingDecl0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, UsingType>), internal::Matcher<UsingShadowDecl> >
throughUsingDecl(internal::Matcher<UsingShadowDecl> const
&Inner) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_throughUsingDecl0Matcher, void(::clang
::ast_matchers::internal::TypeList<DeclRefExpr, UsingType>
), internal::Matcher<UsingShadowDecl> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_throughUsingDecl0Matcher, void(::clang::ast_matchers
::internal::TypeList<DeclRefExpr, UsingType>), internal
::Matcher<UsingShadowDecl> > (&throughUsingDecl_Type0
)(internal::Matcher<UsingShadowDecl> const &Inner);
template <typename NodeType, typename ParamT> bool internal
:: matcher_throughUsingDecl0Matcher<NodeType, ParamT>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4198 internal::Matcher<UsingShadowDecl>, Inner)namespace internal { template <typename NodeType, typename
ParamT> class matcher_throughUsingDecl0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_throughUsingDecl0Matcher( internal
::Matcher<UsingShadowDecl> const &AInner) : Inner(AInner
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<UsingShadowDecl> Inner; }; } inline ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_throughUsingDecl0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, UsingType>), internal::Matcher<UsingShadowDecl> >
throughUsingDecl(internal::Matcher<UsingShadowDecl> const
&Inner) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_throughUsingDecl0Matcher, void(::clang
::ast_matchers::internal::TypeList<DeclRefExpr, UsingType>
), internal::Matcher<UsingShadowDecl> >(Inner); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_throughUsingDecl0Matcher, void(::clang::ast_matchers
::internal::TypeList<DeclRefExpr, UsingType>), internal
::Matcher<UsingShadowDecl> > (&throughUsingDecl_Type0
)(internal::Matcher<UsingShadowDecl> const &Inner);
template <typename NodeType, typename ParamT> bool internal
:: matcher_throughUsingDecl0Matcher<NodeType, ParamT>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4199 const NamedDecl *FoundDecl = Node.getFoundDecl();
4200 if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
4201 return Inner.matches(*UsingDecl, Finder, Builder);
4202 return false;
4203}
4204
4205/// Matches an \c OverloadExpr if any of the declarations in the set of
4206/// overloads matches the given matcher.
4207///
4208/// Given
4209/// \code
4210/// template <typename T> void foo(T);
4211/// template <typename T> void bar(T);
4212/// template <typename T> void baz(T t) {
4213/// foo(t);
4214/// bar(t);
4215/// }
4216/// \endcode
4217/// unresolvedLookupExpr(hasAnyDeclaration(
4218/// functionTemplateDecl(hasName("foo"))))
4219/// matches \c foo in \c foo(t); but not \c bar in \c bar(t);
4220AST_MATCHER_P(OverloadExpr, hasAnyDeclaration, internal::Matcher<Decl>,namespace internal { class matcher_hasAnyDeclaration0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
OverloadExpr> { public: explicit matcher_hasAnyDeclaration0Matcher
( internal::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const OverloadExpr &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<OverloadExpr
> hasAnyDeclaration( internal::Matcher<Decl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasAnyDeclaration0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<OverloadExpr
> ( &hasAnyDeclaration_Type0)(internal::Matcher<Decl
> const &InnerMatcher); inline bool internal::matcher_hasAnyDeclaration0Matcher
::matches( const OverloadExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4221 InnerMatcher)namespace internal { class matcher_hasAnyDeclaration0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
OverloadExpr> { public: explicit matcher_hasAnyDeclaration0Matcher
( internal::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const OverloadExpr &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Decl> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<OverloadExpr
> hasAnyDeclaration( internal::Matcher<Decl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasAnyDeclaration0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<OverloadExpr
> ( &hasAnyDeclaration_Type0)(internal::Matcher<Decl
> const &InnerMatcher); inline bool internal::matcher_hasAnyDeclaration0Matcher
::matches( const OverloadExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4222 return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(),
4223 Node.decls_end(), Finder,
4224 Builder) != Node.decls_end();
4225}
4226
4227/// Matches the Decl of a DeclStmt which has a single declaration.
4228///
4229/// Given
4230/// \code
4231/// int a, b;
4232/// int c;
4233/// \endcode
4234/// declStmt(hasSingleDecl(anything()))
4235/// matches 'int c;' but not 'int a, b;'.
4236AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher)namespace internal { class matcher_hasSingleDecl0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DeclStmt
> { public: explicit matcher_hasSingleDecl0Matcher( internal
::Matcher<Decl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const DeclStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Decl> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<DeclStmt> hasSingleDecl
( internal::Matcher<Decl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasSingleDecl0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<DeclStmt> ( &hasSingleDecl_Type0
)(internal::Matcher<Decl> const &InnerMatcher); inline
bool internal::matcher_hasSingleDecl0Matcher::matches( const
DeclStmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4237 if (Node.isSingleDecl()) {
4238 const Decl *FoundDecl = Node.getSingleDecl();
4239 return InnerMatcher.matches(*FoundDecl, Finder, Builder);
4240 }
4241 return false;
4242}
4243
4244/// Matches a variable declaration that has an initializer expression
4245/// that matches the given matcher.
4246///
4247/// Example matches x (matcher = varDecl(hasInitializer(callExpr())))
4248/// \code
4249/// bool y() { return true; }
4250/// bool x = y();
4251/// \endcode
4252AST_MATCHER_P(namespace internal { class matcher_hasInitializer0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_hasInitializer0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const VarDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<VarDecl> hasInitializer
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasInitializer0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<VarDecl> ( &hasInitializer_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasInitializer0Matcher::matches( const
VarDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4253 VarDecl, hasInitializer, internal::Matcher<Expr>,namespace internal { class matcher_hasInitializer0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_hasInitializer0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const VarDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<VarDecl> hasInitializer
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasInitializer0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<VarDecl> ( &hasInitializer_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasInitializer0Matcher::matches( const
VarDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4254 InnerMatcher)namespace internal { class matcher_hasInitializer0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_hasInitializer0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const VarDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<VarDecl> hasInitializer
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasInitializer0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<VarDecl> ( &hasInitializer_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasInitializer0Matcher::matches( const
VarDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4255 const Expr *Initializer = Node.getAnyInitializer();
4256 return (Initializer != nullptr &&
4257 InnerMatcher.matches(*Initializer, Finder, Builder));
4258}
4259
4260/// Matches a variable serving as the implicit variable for a lambda init-
4261/// capture.
4262///
4263/// Example matches x (matcher = varDecl(isInitCapture()))
4264/// \code
4265/// auto f = [x=3]() { return x; };
4266/// \endcode
4267AST_MATCHER(VarDecl, isInitCapture)namespace internal { class matcher_isInitCaptureMatcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_isInitCaptureMatcher() = default
; bool matches(const VarDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<VarDecl> isInitCapture
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isInitCaptureMatcher()); } inline bool internal
::matcher_isInitCaptureMatcher::matches( const VarDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{ return Node.isInitCapture(); }
4268
4269/// Matches each lambda capture in a lambda expression.
4270///
4271/// Given
4272/// \code
4273/// int main() {
4274/// int x, y;
4275/// float z;
4276/// auto f = [=]() { return x + y + z; };
4277/// }
4278/// \endcode
4279/// lambdaExpr(forEachLambdaCapture(
4280/// lambdaCapture(capturesVar(varDecl(hasType(isInteger()))))))
4281/// will trigger two matches, binding for 'x' and 'y' respectively.
4282AST_MATCHER_P(LambdaExpr, forEachLambdaCapture,namespace internal { class matcher_forEachLambdaCapture0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
LambdaExpr> { public: explicit matcher_forEachLambdaCapture0Matcher
( internal::Matcher<LambdaCapture> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const LambdaExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<LambdaCapture
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<LambdaExpr> forEachLambdaCapture( internal::Matcher
<LambdaCapture> const &InnerMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_forEachLambdaCapture0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<LambdaExpr> ( &forEachLambdaCapture_Type0)(internal
::Matcher<LambdaCapture> const &InnerMatcher); inline
bool internal::matcher_forEachLambdaCapture0Matcher::matches
( const LambdaExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
4283 internal::Matcher<LambdaCapture>, InnerMatcher)namespace internal { class matcher_forEachLambdaCapture0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
LambdaExpr> { public: explicit matcher_forEachLambdaCapture0Matcher
( internal::Matcher<LambdaCapture> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const LambdaExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<LambdaCapture
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<LambdaExpr> forEachLambdaCapture( internal::Matcher
<LambdaCapture> const &InnerMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_forEachLambdaCapture0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<LambdaExpr> ( &forEachLambdaCapture_Type0)(internal
::Matcher<LambdaCapture> const &InnerMatcher); inline
bool internal::matcher_forEachLambdaCapture0Matcher::matches
( const LambdaExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4284 BoundNodesTreeBuilder Result;
4285 bool Matched = false;
4286 for (const auto &Capture : Node.captures()) {
4287 if (Finder->isTraversalIgnoringImplicitNodes() && Capture.isImplicit())
4288 continue;
4289 BoundNodesTreeBuilder CaptureBuilder(*Builder);
4290 if (InnerMatcher.matches(Capture, Finder, &CaptureBuilder)) {
4291 Matched = true;
4292 Result.addMatch(CaptureBuilder);
4293 }
4294 }
4295 *Builder = std::move(Result);
4296 return Matched;
4297}
4298
4299/// \brief Matches a static variable with local scope.
4300///
4301/// Example matches y (matcher = varDecl(isStaticLocal()))
4302/// \code
4303/// void f() {
4304/// int x;
4305/// static int y;
4306/// }
4307/// static int z;
4308/// \endcode
4309AST_MATCHER(VarDecl, isStaticLocal)namespace internal { class matcher_isStaticLocalMatcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_isStaticLocalMatcher() = default
; bool matches(const VarDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<VarDecl> isStaticLocal
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isStaticLocalMatcher()); } inline bool internal
::matcher_isStaticLocalMatcher::matches( const VarDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4310 return Node.isStaticLocal();
4311}
4312
4313/// Matches a variable declaration that has function scope and is a
4314/// non-static local variable.
4315///
4316/// Example matches x (matcher = varDecl(hasLocalStorage())
4317/// \code
4318/// void f() {
4319/// int x;
4320/// static int y;
4321/// }
4322/// int z;
4323/// \endcode
4324AST_MATCHER(VarDecl, hasLocalStorage)namespace internal { class matcher_hasLocalStorageMatcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_hasLocalStorageMatcher() = default
; bool matches(const VarDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<VarDecl> hasLocalStorage
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_hasLocalStorageMatcher()); } inline bool internal
::matcher_hasLocalStorageMatcher::matches( const VarDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4325 return Node.hasLocalStorage();
4326}
4327
4328/// Matches a variable declaration that does not have local storage.
4329///
4330/// Example matches y and z (matcher = varDecl(hasGlobalStorage())
4331/// \code
4332/// void f() {
4333/// int x;
4334/// static int y;
4335/// }
4336/// int z;
4337/// \endcode
4338AST_MATCHER(VarDecl, hasGlobalStorage)namespace internal { class matcher_hasGlobalStorageMatcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_hasGlobalStorageMatcher() = default
; bool matches(const VarDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<VarDecl> hasGlobalStorage
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_hasGlobalStorageMatcher()); } inline bool internal
::matcher_hasGlobalStorageMatcher::matches( const VarDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4339 return Node.hasGlobalStorage();
4340}
4341
4342/// Matches a variable declaration that has automatic storage duration.
4343///
4344/// Example matches x, but not y, z, or a.
4345/// (matcher = varDecl(hasAutomaticStorageDuration())
4346/// \code
4347/// void f() {
4348/// int x;
4349/// static int y;
4350/// thread_local int z;
4351/// }
4352/// int a;
4353/// \endcode
4354AST_MATCHER(VarDecl, hasAutomaticStorageDuration)namespace internal { class matcher_hasAutomaticStorageDurationMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
VarDecl> { public: explicit matcher_hasAutomaticStorageDurationMatcher
() = default; bool matches(const VarDecl &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<VarDecl
> hasAutomaticStorageDuration() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasAutomaticStorageDurationMatcher
()); } inline bool internal::matcher_hasAutomaticStorageDurationMatcher
::matches( const VarDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4355 return Node.getStorageDuration() == SD_Automatic;
4356}
4357
4358/// Matches a variable declaration that has static storage duration.
4359/// It includes the variable declared at namespace scope and those declared
4360/// with "static" and "extern" storage class specifiers.
4361///
4362/// \code
4363/// void f() {
4364/// int x;
4365/// static int y;
4366/// thread_local int z;
4367/// }
4368/// int a;
4369/// static int b;
4370/// extern int c;
4371/// varDecl(hasStaticStorageDuration())
4372/// matches the function declaration y, a, b and c.
4373/// \endcode
4374AST_MATCHER(VarDecl, hasStaticStorageDuration)namespace internal { class matcher_hasStaticStorageDurationMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
VarDecl> { public: explicit matcher_hasStaticStorageDurationMatcher
() = default; bool matches(const VarDecl &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<VarDecl
> hasStaticStorageDuration() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasStaticStorageDurationMatcher
()); } inline bool internal::matcher_hasStaticStorageDurationMatcher
::matches( const VarDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4375 return Node.getStorageDuration() == SD_Static;
4376}
4377
4378/// Matches a variable declaration that has thread storage duration.
4379///
4380/// Example matches z, but not x, z, or a.
4381/// (matcher = varDecl(hasThreadStorageDuration())
4382/// \code
4383/// void f() {
4384/// int x;
4385/// static int y;
4386/// thread_local int z;
4387/// }
4388/// int a;
4389/// \endcode
4390AST_MATCHER(VarDecl, hasThreadStorageDuration)namespace internal { class matcher_hasThreadStorageDurationMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
VarDecl> { public: explicit matcher_hasThreadStorageDurationMatcher
() = default; bool matches(const VarDecl &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<VarDecl
> hasThreadStorageDuration() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasThreadStorageDurationMatcher
()); } inline bool internal::matcher_hasThreadStorageDurationMatcher
::matches( const VarDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4391 return Node.getStorageDuration() == SD_Thread;
4392}
4393
4394/// Matches a variable declaration that is an exception variable from
4395/// a C++ catch block, or an Objective-C \@catch statement.
4396///
4397/// Example matches x (matcher = varDecl(isExceptionVariable())
4398/// \code
4399/// void f(int y) {
4400/// try {
4401/// } catch (int x) {
4402/// }
4403/// }
4404/// \endcode
4405AST_MATCHER(VarDecl, isExceptionVariable)namespace internal { class matcher_isExceptionVariableMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
VarDecl> { public: explicit matcher_isExceptionVariableMatcher
() = default; bool matches(const VarDecl &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<VarDecl
> isExceptionVariable() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_isExceptionVariableMatcher
()); } inline bool internal::matcher_isExceptionVariableMatcher
::matches( const VarDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4406 return Node.isExceptionVariable();
4407}
4408
4409/// Checks that a call expression or a constructor call expression has
4410/// a specific number of arguments (including absent default arguments).
4411///
4412/// Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
4413/// \code
4414/// void f(int x, int y);
4415/// f(0, 0);
4416/// \endcode
4417AST_POLYMORPHIC_MATCHER_P(argumentCountIs,namespace internal { template <typename NodeType, typename
ParamT> class matcher_argumentCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_argumentCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> argumentCountIs(unsigned const &N) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_argumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> (&argumentCountIs_Type0)(unsigned const
&N); template <typename NodeType, typename ParamT>
bool internal:: matcher_argumentCountIs0Matcher<NodeType,
ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4418 AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType, typename
ParamT> class matcher_argumentCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_argumentCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> argumentCountIs(unsigned const &N) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_argumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> (&argumentCountIs_Type0)(unsigned const
&N); template <typename NodeType, typename ParamT>
bool internal:: matcher_argumentCountIs0Matcher<NodeType,
ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4419 CallExpr, CXXConstructExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_argumentCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_argumentCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> argumentCountIs(unsigned const &N) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_argumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> (&argumentCountIs_Type0)(unsigned const
&N); template <typename NodeType, typename ParamT>
bool internal:: matcher_argumentCountIs0Matcher<NodeType,
ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4420 CXXUnresolvedConstructExpr, ObjCMessageExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_argumentCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_argumentCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> argumentCountIs(unsigned const &N) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_argumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> (&argumentCountIs_Type0)(unsigned const
&N); template <typename NodeType, typename ParamT>
bool internal:: matcher_argumentCountIs0Matcher<NodeType,
ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4421 unsigned, N)namespace internal { template <typename NodeType, typename
ParamT> class matcher_argumentCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_argumentCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> argumentCountIs(unsigned const &N) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_argumentCountIs0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_argumentCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned> (&argumentCountIs_Type0)(unsigned const
&N); template <typename NodeType, typename ParamT>
bool internal:: matcher_argumentCountIs0Matcher<NodeType,
ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4422 unsigned NumArgs = Node.getNumArgs();
4423 if (!Finder->isTraversalIgnoringImplicitNodes())
4424 return NumArgs == N;
4425 while (NumArgs) {
4426 if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1)))
4427 break;
4428 --NumArgs;
4429 }
4430 return NumArgs == N;
4431}
4432
4433/// Matches the n'th argument of a call expression or a constructor
4434/// call expression.
4435///
4436/// Example matches y in x(y)
4437/// (matcher = callExpr(hasArgument(0, declRefExpr())))
4438/// \code
4439/// void x(int) { int y; x(y); }
4440/// \endcode
4441AST_POLYMORPHIC_MATCHER_P2(hasArgument,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasArgument0Matcher(unsigned const
&AN, internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Expr> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > hasArgument
(unsigned const &N, internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned, internal::Matcher<Expr>
>(N, InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > (&hasArgument_Type0
)( unsigned const &N, internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT1, typename ParamT2> bool internal::matcher_hasArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4442 AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasArgument0Matcher(unsigned const
&AN, internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Expr> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > hasArgument
(unsigned const &N, internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned, internal::Matcher<Expr>
>(N, InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > (&hasArgument_Type0
)( unsigned const &N, internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT1, typename ParamT2> bool internal::matcher_hasArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4443 CallExpr, CXXConstructExpr,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasArgument0Matcher(unsigned const
&AN, internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Expr> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > hasArgument
(unsigned const &N, internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned, internal::Matcher<Expr>
>(N, InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > (&hasArgument_Type0
)( unsigned const &N, internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT1, typename ParamT2> bool internal::matcher_hasArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4444 CXXUnresolvedConstructExpr, ObjCMessageExpr),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasArgument0Matcher(unsigned const
&AN, internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Expr> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > hasArgument
(unsigned const &N, internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned, internal::Matcher<Expr>
>(N, InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > (&hasArgument_Type0
)( unsigned const &N, internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT1, typename ParamT2> bool internal::matcher_hasArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4445 unsigned, N, internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasArgument0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasArgument0Matcher(unsigned const
&AN, internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Expr> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > hasArgument
(unsigned const &N, internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), unsigned, internal::Matcher<Expr>
>(N, InnerMatcher); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), unsigned, internal::Matcher<Expr> > (&hasArgument_Type0
)( unsigned const &N, internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT1, typename ParamT2> bool internal::matcher_hasArgument0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4446 if (N >= Node.getNumArgs())
4447 return false;
4448 const Expr *Arg = Node.getArg(N);
4449 if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg))
4450 return false;
4451 return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder);
4452}
4453
4454/// Matches the n'th item of an initializer list expression.
4455///
4456/// Example matches y.
4457/// (matcher = initListExpr(hasInit(0, expr())))
4458/// \code
4459/// int x{y}.
4460/// \endcode
4461AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N,namespace internal { class matcher_hasInit0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<InitListExpr
> { public: matcher_hasInit0Matcher(unsigned const &AN
, ast_matchers::internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const InitListExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; ast_matchers::
internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<InitListExpr> hasInit
( unsigned const &N, ast_matchers::internal::Matcher<Expr
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasInit0Matcher(
N, InnerMatcher)); } typedef ::clang::ast_matchers::internal::
Matcher<InitListExpr> ( &hasInit_Type0)(unsigned const
&N, ast_matchers::internal::Matcher<Expr> const &
InnerMatcher); inline bool internal::matcher_hasInit0Matcher::
matches( const InitListExpr &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4462 ast_matchers::internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasInit0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<InitListExpr
> { public: matcher_hasInit0Matcher(unsigned const &AN
, ast_matchers::internal::Matcher<Expr> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const InitListExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; ast_matchers::
internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<InitListExpr> hasInit
( unsigned const &N, ast_matchers::internal::Matcher<Expr
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasInit0Matcher(
N, InnerMatcher)); } typedef ::clang::ast_matchers::internal::
Matcher<InitListExpr> ( &hasInit_Type0)(unsigned const
&N, ast_matchers::internal::Matcher<Expr> const &
InnerMatcher); inline bool internal::matcher_hasInit0Matcher::
matches( const InitListExpr &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4463 return N < Node.getNumInits() &&
4464 InnerMatcher.matches(*Node.getInit(N), Finder, Builder);
4465}
4466
4467/// Matches declaration statements that contain a specific number of
4468/// declarations.
4469///
4470/// Example: Given
4471/// \code
4472/// int a, b;
4473/// int c;
4474/// int d = 2, e;
4475/// \endcode
4476/// declCountIs(2)
4477/// matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'.
4478AST_MATCHER_P(DeclStmt, declCountIs, unsigned, N)namespace internal { class matcher_declCountIs0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DeclStmt
> { public: explicit matcher_declCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const DeclStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::Matcher<DeclStmt> declCountIs( unsigned const
&N) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_declCountIs0Matcher(N)); } typedef ::
clang::ast_matchers::internal::Matcher<DeclStmt> ( &
declCountIs_Type0)(unsigned const &N); inline bool internal
::matcher_declCountIs0Matcher::matches( const DeclStmt &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4479 return std::distance(Node.decl_begin(), Node.decl_end()) == (ptrdiff_t)N;
4480}
4481
4482/// Matches the n'th declaration of a declaration statement.
4483///
4484/// Note that this does not work for global declarations because the AST
4485/// breaks up multiple-declaration DeclStmt's into multiple single-declaration
4486/// DeclStmt's.
4487/// Example: Given non-global declarations
4488/// \code
4489/// int a, b = 0;
4490/// int c;
4491/// int d = 2, e;
4492/// \endcode
4493/// declStmt(containsDeclaration(
4494/// 0, varDecl(hasInitializer(anything()))))
4495/// matches only 'int d = 2, e;', and
4496/// declStmt(containsDeclaration(1, varDecl()))
4497/// \code
4498/// matches 'int a, b = 0' as well as 'int d = 2, e;'
4499/// but 'int c;' is not matched.
4500/// \endcode
4501AST_MATCHER_P2(DeclStmt, containsDeclaration, unsigned, N,namespace internal { class matcher_containsDeclaration0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
DeclStmt> { public: matcher_containsDeclaration0Matcher(unsigned
const &AN, internal::Matcher<Decl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const DeclStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Decl> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::Matcher<DeclStmt> containsDeclaration( unsigned
const &N, internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_containsDeclaration0Matcher(N, InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<DeclStmt> ( &
containsDeclaration_Type0)(unsigned const &N, internal::Matcher
<Decl> const &InnerMatcher); inline bool internal::
matcher_containsDeclaration0Matcher::matches( const DeclStmt &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4502 internal::Matcher<Decl>, InnerMatcher)namespace internal { class matcher_containsDeclaration0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
DeclStmt> { public: matcher_containsDeclaration0Matcher(unsigned
const &AN, internal::Matcher<Decl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const DeclStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<Decl> InnerMatcher; }; } inline ::clang::ast_matchers::
internal::Matcher<DeclStmt> containsDeclaration( unsigned
const &N, internal::Matcher<Decl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_containsDeclaration0Matcher(N, InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<DeclStmt> ( &
containsDeclaration_Type0)(unsigned const &N, internal::Matcher
<Decl> const &InnerMatcher); inline bool internal::
matcher_containsDeclaration0Matcher::matches( const DeclStmt &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4503 const unsigned NumDecls = std::distance(Node.decl_begin(), Node.decl_end());
4504 if (N >= NumDecls)
4505 return false;
4506 DeclStmt::const_decl_iterator Iterator = Node.decl_begin();
4507 std::advance(Iterator, N);
4508 return InnerMatcher.matches(**Iterator, Finder, Builder);
4509}
4510
4511/// Matches a C++ catch statement that has a catch-all handler.
4512///
4513/// Given
4514/// \code
4515/// try {
4516/// // ...
4517/// } catch (int) {
4518/// // ...
4519/// } catch (...) {
4520/// // ...
4521/// }
4522/// \endcode
4523/// cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int).
4524AST_MATCHER(CXXCatchStmt, isCatchAll)namespace internal { class matcher_isCatchAllMatcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXCatchStmt
> { public: explicit matcher_isCatchAllMatcher() = default
; bool matches(const CXXCatchStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXCatchStmt>
isCatchAll() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isCatchAllMatcher()); } inline bool internal
::matcher_isCatchAllMatcher::matches( const CXXCatchStmt &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4525 return Node.getExceptionDecl() == nullptr;
4526}
4527
4528/// Matches a constructor initializer.
4529///
4530/// Given
4531/// \code
4532/// struct Foo {
4533/// Foo() : foo_(1) { }
4534/// int foo_;
4535/// };
4536/// \endcode
4537/// cxxRecordDecl(has(cxxConstructorDecl(
4538/// hasAnyConstructorInitializer(anything())
4539/// )))
4540/// record matches Foo, hasAnyConstructorInitializer matches foo_(1)
4541AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer,namespace internal { class matcher_hasAnyConstructorInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_hasAnyConstructorInitializer0Matcher
( internal::Matcher<CXXCtorInitializer> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXCtorInitializer
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> hasAnyConstructorInitializer
( internal::Matcher<CXXCtorInitializer> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasAnyConstructorInitializer0Matcher(InnerMatcher))
; } typedef ::clang::ast_matchers::internal::Matcher<CXXConstructorDecl
> ( &hasAnyConstructorInitializer_Type0)(internal::Matcher
<CXXCtorInitializer> const &InnerMatcher); inline bool
internal::matcher_hasAnyConstructorInitializer0Matcher::matches
( const CXXConstructorDecl &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4542 internal::Matcher<CXXCtorInitializer>, InnerMatcher)namespace internal { class matcher_hasAnyConstructorInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_hasAnyConstructorInitializer0Matcher
( internal::Matcher<CXXCtorInitializer> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXCtorInitializer
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> hasAnyConstructorInitializer
( internal::Matcher<CXXCtorInitializer> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasAnyConstructorInitializer0Matcher(InnerMatcher))
; } typedef ::clang::ast_matchers::internal::Matcher<CXXConstructorDecl
> ( &hasAnyConstructorInitializer_Type0)(internal::Matcher
<CXXCtorInitializer> const &InnerMatcher); inline bool
internal::matcher_hasAnyConstructorInitializer0Matcher::matches
( const CXXConstructorDecl &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4543 auto MatchIt = matchesFirstInPointerRange(InnerMatcher, Node.init_begin(),
4544 Node.init_end(), Finder, Builder);
4545 if (MatchIt == Node.init_end())
4546 return false;
4547 return (*MatchIt)->isWritten() || !Finder->isTraversalIgnoringImplicitNodes();
4548}
4549
4550/// Matches the field declaration of a constructor initializer.
4551///
4552/// Given
4553/// \code
4554/// struct Foo {
4555/// Foo() : foo_(1) { }
4556/// int foo_;
4557/// };
4558/// \endcode
4559/// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(
4560/// forField(hasName("foo_"))))))
4561/// matches Foo
4562/// with forField matching foo_
4563AST_MATCHER_P(CXXCtorInitializer, forField,namespace internal { class matcher_forField0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXCtorInitializer
> { public: explicit matcher_forField0Matcher( internal::Matcher
<FieldDecl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const CXXCtorInitializer &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<FieldDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> forField( internal::Matcher<FieldDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_forField0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> ( &forField_Type0)(internal::Matcher<FieldDecl>
const &InnerMatcher); inline bool internal::matcher_forField0Matcher
::matches( const CXXCtorInitializer &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4564 internal::Matcher<FieldDecl>, InnerMatcher)namespace internal { class matcher_forField0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXCtorInitializer
> { public: explicit matcher_forField0Matcher( internal::Matcher
<FieldDecl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const CXXCtorInitializer &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<FieldDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> forField( internal::Matcher<FieldDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_forField0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> ( &forField_Type0)(internal::Matcher<FieldDecl>
const &InnerMatcher); inline bool internal::matcher_forField0Matcher
::matches( const CXXCtorInitializer &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4565 const FieldDecl *NodeAsDecl = Node.getAnyMember();
4566 return (NodeAsDecl != nullptr &&
4567 InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
4568}
4569
4570/// Matches the initializer expression of a constructor initializer.
4571///
4572/// Given
4573/// \code
4574/// struct Foo {
4575/// Foo() : foo_(1) { }
4576/// int foo_;
4577/// };
4578/// \endcode
4579/// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer(
4580/// withInitializer(integerLiteral(equals(1)))))))
4581/// matches Foo
4582/// with withInitializer matching (1)
4583AST_MATCHER_P(CXXCtorInitializer, withInitializer,namespace internal { class matcher_withInitializer0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXCtorInitializer
> { public: explicit matcher_withInitializer0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXCtorInitializer &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> withInitializer( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_withInitializer0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> ( &withInitializer_Type0)(internal::Matcher<Expr>
const &InnerMatcher); inline bool internal::matcher_withInitializer0Matcher
::matches( const CXXCtorInitializer &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4584 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_withInitializer0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXCtorInitializer
> { public: explicit matcher_withInitializer0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXCtorInitializer &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> withInitializer( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_withInitializer0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> ( &withInitializer_Type0)(internal::Matcher<Expr>
const &InnerMatcher); inline bool internal::matcher_withInitializer0Matcher
::matches( const CXXCtorInitializer &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4585 const Expr* NodeAsExpr = Node.getInit();
4586 return (NodeAsExpr != nullptr &&
4587 InnerMatcher.matches(*NodeAsExpr, Finder, Builder));
4588}
4589
4590/// Matches a constructor initializer if it is explicitly written in
4591/// code (as opposed to implicitly added by the compiler).
4592///
4593/// Given
4594/// \code
4595/// struct Foo {
4596/// Foo() { }
4597/// Foo(int) : foo_("A") { }
4598/// string foo_;
4599/// };
4600/// \endcode
4601/// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten()))
4602/// will match Foo(int), but not Foo()
4603AST_MATCHER(CXXCtorInitializer, isWritten)namespace internal { class matcher_isWrittenMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXCtorInitializer
> { public: explicit matcher_isWrittenMatcher() = default;
bool matches(const CXXCtorInitializer &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXCtorInitializer
> isWritten() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isWrittenMatcher()); } inline bool internal
::matcher_isWrittenMatcher::matches( const CXXCtorInitializer
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4604 return Node.isWritten();
4605}
4606
4607/// Matches a constructor initializer if it is initializing a base, as
4608/// opposed to a member.
4609///
4610/// Given
4611/// \code
4612/// struct B {};
4613/// struct D : B {
4614/// int I;
4615/// D(int i) : I(i) {}
4616/// };
4617/// struct E : B {
4618/// E() : B() {}
4619/// };
4620/// \endcode
4621/// cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer()))
4622/// will match E(), but not match D(int).
4623AST_MATCHER(CXXCtorInitializer, isBaseInitializer)namespace internal { class matcher_isBaseInitializerMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CXXCtorInitializer> { public: explicit matcher_isBaseInitializerMatcher
() = default; bool matches(const CXXCtorInitializer &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXCtorInitializer> isBaseInitializer() { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isBaseInitializerMatcher()); } inline bool internal::
matcher_isBaseInitializerMatcher::matches( const CXXCtorInitializer
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4624 return Node.isBaseInitializer();
4625}
4626
4627/// Matches a constructor initializer if it is initializing a member, as
4628/// opposed to a base.
4629///
4630/// Given
4631/// \code
4632/// struct B {};
4633/// struct D : B {
4634/// int I;
4635/// D(int i) : I(i) {}
4636/// };
4637/// struct E : B {
4638/// E() : B() {}
4639/// };
4640/// \endcode
4641/// cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
4642/// will match D(int), but not match E().
4643AST_MATCHER(CXXCtorInitializer, isMemberInitializer)namespace internal { class matcher_isMemberInitializerMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXCtorInitializer> { public: explicit matcher_isMemberInitializerMatcher
() = default; bool matches(const CXXCtorInitializer &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXCtorInitializer> isMemberInitializer() { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isMemberInitializerMatcher()); } inline bool internal
::matcher_isMemberInitializerMatcher::matches( const CXXCtorInitializer
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4644 return Node.isMemberInitializer();
4645}
4646
4647/// Matches any argument of a call expression or a constructor call
4648/// expression, or an ObjC-message-send expression.
4649///
4650/// Given
4651/// \code
4652/// void x(int, int, int) { int y; x(1, y, 42); }
4653/// \endcode
4654/// callExpr(hasAnyArgument(declRefExpr()))
4655/// matches x(1, y, 42)
4656/// with hasAnyArgument(...)
4657/// matching y
4658///
4659/// For ObjectiveC, given
4660/// \code
4661/// @interface I - (void) f:(int) y; @end
4662/// void foo(I *i) { [i f:12]; }
4663/// \endcode
4664/// objcMessageExpr(hasAnyArgument(integerLiteral(equals(12))))
4665/// matches [i f:12]
4666AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyArgument0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasAnyArgument0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> > hasAnyArgument(internal
::Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyArgument0Matcher, void(::clang::ast_matchers::
internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), internal::Matcher<Expr> > (&
hasAnyArgument_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasAnyArgument0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4667 AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyArgument0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasAnyArgument0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> > hasAnyArgument(internal
::Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyArgument0Matcher, void(::clang::ast_matchers::
internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), internal::Matcher<Expr> > (&
hasAnyArgument_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasAnyArgument0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4668 CallExpr, CXXConstructExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyArgument0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasAnyArgument0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> > hasAnyArgument(internal
::Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyArgument0Matcher, void(::clang::ast_matchers::
internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), internal::Matcher<Expr> > (&
hasAnyArgument_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasAnyArgument0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4669 CXXUnresolvedConstructExpr, ObjCMessageExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyArgument0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasAnyArgument0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> > hasAnyArgument(internal
::Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyArgument0Matcher, void(::clang::ast_matchers::
internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), internal::Matcher<Expr> > (&
hasAnyArgument_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasAnyArgument0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4670 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyArgument0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasAnyArgument0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> > hasAnyArgument(internal
::Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnyArgument0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyArgument0Matcher, void(::clang::ast_matchers::
internal::TypeList<CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr
, ObjCMessageExpr>), internal::Matcher<Expr> > (&
hasAnyArgument_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasAnyArgument0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4671 for (const Expr *Arg : Node.arguments()) {
4672 if (Finder->isTraversalIgnoringImplicitNodes() &&
4673 isa<CXXDefaultArgExpr>(Arg))
4674 break;
4675 BoundNodesTreeBuilder Result(*Builder);
4676 if (InnerMatcher.matches(*Arg, Finder, &Result)) {
4677 *Builder = std::move(Result);
4678 return true;
4679 }
4680 }
4681 return false;
4682}
4683
4684/// Matches lambda captures.
4685///
4686/// Given
4687/// \code
4688/// int main() {
4689/// int x;
4690/// auto f = [x](){};
4691/// auto g = [x = 1](){};
4692/// }
4693/// \endcode
4694/// In the matcher `lambdaExpr(hasAnyCapture(lambdaCapture()))`,
4695/// `lambdaCapture()` matches `x` and `x=1`.
4696extern const internal::VariadicAllOfMatcher<LambdaCapture> lambdaCapture;
4697
4698/// Matches any capture in a lambda expression.
4699///
4700/// Given
4701/// \code
4702/// void foo() {
4703/// int t = 5;
4704/// auto f = [=](){ return t; };
4705/// }
4706/// \endcode
4707/// lambdaExpr(hasAnyCapture(lambdaCapture())) and
4708/// lambdaExpr(hasAnyCapture(lambdaCapture(refersToVarDecl(hasName("t")))))
4709/// both match `[=](){ return t; }`.
4710AST_MATCHER_P(LambdaExpr, hasAnyCapture, internal::Matcher<LambdaCapture>,namespace internal { class matcher_hasAnyCapture0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<LambdaExpr
> { public: explicit matcher_hasAnyCapture0Matcher( internal
::Matcher<LambdaCapture> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const LambdaExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<LambdaCapture> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<LambdaExpr
> hasAnyCapture( internal::Matcher<LambdaCapture> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasAnyCapture0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<LambdaExpr
> ( &hasAnyCapture_Type0)(internal::Matcher<LambdaCapture
> const &InnerMatcher); inline bool internal::matcher_hasAnyCapture0Matcher
::matches( const LambdaExpr &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4711 InnerMatcher)namespace internal { class matcher_hasAnyCapture0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<LambdaExpr
> { public: explicit matcher_hasAnyCapture0Matcher( internal
::Matcher<LambdaCapture> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const LambdaExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<LambdaCapture> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<LambdaExpr
> hasAnyCapture( internal::Matcher<LambdaCapture> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasAnyCapture0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<LambdaExpr
> ( &hasAnyCapture_Type0)(internal::Matcher<LambdaCapture
> const &InnerMatcher); inline bool internal::matcher_hasAnyCapture0Matcher
::matches( const LambdaExpr &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4712 for (const LambdaCapture &Capture : Node.captures()) {
4713 clang::ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
4714 if (InnerMatcher.matches(Capture, Finder, &Result)) {
4715 *Builder = std::move(Result);
4716 return true;
4717 }
4718 }
4719 return false;
4720}
4721
4722/// Matches a `LambdaCapture` that refers to the specified `VarDecl`. The
4723/// `VarDecl` can be a separate variable that is captured by value or
4724/// reference, or a synthesized variable if the capture has an initializer.
4725///
4726/// Given
4727/// \code
4728/// void foo() {
4729/// int x;
4730/// auto f = [x](){};
4731/// auto g = [x = 1](){};
4732/// }
4733/// \endcode
4734/// In the matcher
4735/// lambdaExpr(hasAnyCapture(lambdaCapture(capturesVar(hasName("x")))),
4736/// capturesVar(hasName("x")) matches `x` and `x = 1`.
4737AST_MATCHER_P(LambdaCapture, capturesVar, internal::Matcher<ValueDecl>,namespace internal { class matcher_capturesVar0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<LambdaCapture
> { public: explicit matcher_capturesVar0Matcher( internal
::Matcher<ValueDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const LambdaCapture &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<ValueDecl>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<LambdaCapture> capturesVar( internal::Matcher<ValueDecl
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_capturesVar0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<LambdaCapture> ( &capturesVar_Type0)(internal::Matcher
<ValueDecl> const &InnerMatcher); inline bool internal
::matcher_capturesVar0Matcher::matches( const LambdaCapture &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4738 InnerMatcher)namespace internal { class matcher_capturesVar0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<LambdaCapture
> { public: explicit matcher_capturesVar0Matcher( internal
::Matcher<ValueDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const LambdaCapture &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<ValueDecl>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<LambdaCapture> capturesVar( internal::Matcher<ValueDecl
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_capturesVar0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<LambdaCapture> ( &capturesVar_Type0)(internal::Matcher
<ValueDecl> const &InnerMatcher); inline bool internal
::matcher_capturesVar0Matcher::matches( const LambdaCapture &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4739 auto *capturedVar = Node.getCapturedVar();
4740 return capturedVar && InnerMatcher.matches(*capturedVar, Finder, Builder);
4741}
4742
4743/// Matches a `LambdaCapture` that refers to 'this'.
4744///
4745/// Given
4746/// \code
4747/// class C {
4748/// int cc;
4749/// int f() {
4750/// auto l = [this]() { return cc; };
4751/// return l();
4752/// }
4753/// };
4754/// \endcode
4755/// lambdaExpr(hasAnyCapture(lambdaCapture(capturesThis())))
4756/// matches `[this]() { return cc; }`.
4757AST_MATCHER(LambdaCapture, capturesThis)namespace internal { class matcher_capturesThisMatcher : public
::clang::ast_matchers::internal::MatcherInterface<LambdaCapture
> { public: explicit matcher_capturesThisMatcher() = default
; bool matches(const LambdaCapture &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<LambdaCapture>
capturesThis() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_capturesThisMatcher()); } inline bool
internal::matcher_capturesThisMatcher::matches( const LambdaCapture
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.capturesThis(); }
4758
4759/// Matches a constructor call expression which uses list initialization.
4760AST_MATCHER(CXXConstructExpr, isListInitialization)namespace internal { class matcher_isListInitializationMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructExpr> { public: explicit matcher_isListInitializationMatcher
() = default; bool matches(const CXXConstructExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; }; } inline ::clang::ast_matchers::internal::Matcher
<CXXConstructExpr> isListInitialization() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isListInitializationMatcher
()); } inline bool internal::matcher_isListInitializationMatcher
::matches( const CXXConstructExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4761 return Node.isListInitialization();
4762}
4763
4764/// Matches a constructor call expression which requires
4765/// zero initialization.
4766///
4767/// Given
4768/// \code
4769/// void foo() {
4770/// struct point { double x; double y; };
4771/// point pt[2] = { { 1.0, 2.0 } };
4772/// }
4773/// \endcode
4774/// initListExpr(has(cxxConstructExpr(requiresZeroInitialization()))
4775/// will match the implicit array filler for pt[1].
4776AST_MATCHER(CXXConstructExpr, requiresZeroInitialization)namespace internal { class matcher_requiresZeroInitializationMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructExpr> { public: explicit matcher_requiresZeroInitializationMatcher
() = default; bool matches(const CXXConstructExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; }; } inline ::clang::ast_matchers::internal::Matcher
<CXXConstructExpr> requiresZeroInitialization() { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_requiresZeroInitializationMatcher()); } inline bool internal
::matcher_requiresZeroInitializationMatcher::matches( const CXXConstructExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
4777 return Node.requiresZeroInitialization();
4778}
4779
4780/// Matches the n'th parameter of a function or an ObjC method
4781/// declaration or a block.
4782///
4783/// Given
4784/// \code
4785/// class X { void f(int x) {} };
4786/// \endcode
4787/// cxxMethodDecl(hasParameter(0, hasType(varDecl())))
4788/// matches f(int x) {}
4789/// with hasParameter(...)
4790/// matching int x
4791///
4792/// For ObjectiveC, given
4793/// \code
4794/// @interface I - (void) f:(int) y; @end
4795/// \endcode
4796//
4797/// the matcher objcMethodDecl(hasParameter(0, hasName("y")))
4798/// matches the declaration of method f with hasParameter
4799/// matching y.
4800AST_POLYMORPHIC_MATCHER_P2(hasParameter,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasParameter0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasParameter0Matcher(unsigned const
&AN, internal::Matcher<ParmVarDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<ParmVarDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasParameter0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, ObjCMethodDecl, BlockDecl>), unsigned, internal::Matcher
<ParmVarDecl> > hasParameter(unsigned const &N, internal
::Matcher<ParmVarDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasParameter0Matcher, void(::clang::ast_matchers::internal
::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl>), unsigned
, internal::Matcher<ParmVarDecl> >(N, InnerMatcher);
} typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), unsigned, internal::Matcher<ParmVarDecl> > (&
hasParameter_Type0)( unsigned const &N, internal::Matcher
<ParmVarDecl> const &InnerMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_hasParameter0Matcher< NodeType, ParamT1, ParamT2
>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4801 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasParameter0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasParameter0Matcher(unsigned const
&AN, internal::Matcher<ParmVarDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<ParmVarDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasParameter0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, ObjCMethodDecl, BlockDecl>), unsigned, internal::Matcher
<ParmVarDecl> > hasParameter(unsigned const &N, internal
::Matcher<ParmVarDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasParameter0Matcher, void(::clang::ast_matchers::internal
::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl>), unsigned
, internal::Matcher<ParmVarDecl> >(N, InnerMatcher);
} typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), unsigned, internal::Matcher<ParmVarDecl> > (&
hasParameter_Type0)( unsigned const &N, internal::Matcher
<ParmVarDecl> const &InnerMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_hasParameter0Matcher< NodeType, ParamT1, ParamT2
>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4802 ObjCMethodDecl,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasParameter0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasParameter0Matcher(unsigned const
&AN, internal::Matcher<ParmVarDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<ParmVarDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasParameter0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, ObjCMethodDecl, BlockDecl>), unsigned, internal::Matcher
<ParmVarDecl> > hasParameter(unsigned const &N, internal
::Matcher<ParmVarDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasParameter0Matcher, void(::clang::ast_matchers::internal
::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl>), unsigned
, internal::Matcher<ParmVarDecl> >(N, InnerMatcher);
} typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), unsigned, internal::Matcher<ParmVarDecl> > (&
hasParameter_Type0)( unsigned const &N, internal::Matcher
<ParmVarDecl> const &InnerMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_hasParameter0Matcher< NodeType, ParamT1, ParamT2
>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4803 BlockDecl),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasParameter0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasParameter0Matcher(unsigned const
&AN, internal::Matcher<ParmVarDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<ParmVarDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasParameter0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, ObjCMethodDecl, BlockDecl>), unsigned, internal::Matcher
<ParmVarDecl> > hasParameter(unsigned const &N, internal
::Matcher<ParmVarDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasParameter0Matcher, void(::clang::ast_matchers::internal
::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl>), unsigned
, internal::Matcher<ParmVarDecl> >(N, InnerMatcher);
} typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), unsigned, internal::Matcher<ParmVarDecl> > (&
hasParameter_Type0)( unsigned const &N, internal::Matcher
<ParmVarDecl> const &InnerMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_hasParameter0Matcher< NodeType, ParamT1, ParamT2
>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4804 unsigned, N, internal::Matcher<ParmVarDecl>,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasParameter0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasParameter0Matcher(unsigned const
&AN, internal::Matcher<ParmVarDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<ParmVarDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasParameter0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, ObjCMethodDecl, BlockDecl>), unsigned, internal::Matcher
<ParmVarDecl> > hasParameter(unsigned const &N, internal
::Matcher<ParmVarDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasParameter0Matcher, void(::clang::ast_matchers::internal
::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl>), unsigned
, internal::Matcher<ParmVarDecl> >(N, InnerMatcher);
} typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), unsigned, internal::Matcher<ParmVarDecl> > (&
hasParameter_Type0)( unsigned const &N, internal::Matcher
<ParmVarDecl> const &InnerMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_hasParameter0Matcher< NodeType, ParamT1, ParamT2
>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4805 InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasParameter0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasParameter0Matcher(unsigned const
&AN, internal::Matcher<ParmVarDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<ParmVarDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasParameter0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, ObjCMethodDecl, BlockDecl>), unsigned, internal::Matcher
<ParmVarDecl> > hasParameter(unsigned const &N, internal
::Matcher<ParmVarDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasParameter0Matcher, void(::clang::ast_matchers::internal
::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl>), unsigned
, internal::Matcher<ParmVarDecl> >(N, InnerMatcher);
} typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), unsigned, internal::Matcher<ParmVarDecl> > (&
hasParameter_Type0)( unsigned const &N, internal::Matcher
<ParmVarDecl> const &InnerMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_hasParameter0Matcher< NodeType, ParamT1, ParamT2
>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4806 return (N < Node.parameters().size()
4807 && InnerMatcher.matches(*Node.parameters()[N], Finder, Builder));
4808}
4809
4810/// Matches all arguments and their respective ParmVarDecl.
4811///
4812/// Given
4813/// \code
4814/// void f(int i);
4815/// int y;
4816/// f(y);
4817/// \endcode
4818/// callExpr(
4819/// forEachArgumentWithParam(
4820/// declRefExpr(to(varDecl(hasName("y")))),
4821/// parmVarDecl(hasType(isInteger()))
4822/// ))
4823/// matches f(y);
4824/// with declRefExpr(...)
4825/// matching int y
4826/// and parmVarDecl(...)
4827/// matching int i
4828AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParam0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParam0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<ParmVarDecl> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<ParmVarDecl> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParam0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > forEachArgumentWithParam(internal::Matcher<Expr>
const &ArgMatcher, internal::Matcher<ParmVarDecl> const
&ParamMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_forEachArgumentWithParam0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<ParmVarDecl> >(ArgMatcher, ParamMatcher); }
typedef ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_forEachArgumentWithParam0Matcher, void(::clang
::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > (&forEachArgumentWithParam_Type0)( internal::Matcher
<Expr> const &ArgMatcher, internal::Matcher<ParmVarDecl
> const &ParamMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_forEachArgumentWithParam0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4829 AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParam0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParam0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<ParmVarDecl> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<ParmVarDecl> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParam0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > forEachArgumentWithParam(internal::Matcher<Expr>
const &ArgMatcher, internal::Matcher<ParmVarDecl> const
&ParamMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_forEachArgumentWithParam0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<ParmVarDecl> >(ArgMatcher, ParamMatcher); }
typedef ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_forEachArgumentWithParam0Matcher, void(::clang
::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > (&forEachArgumentWithParam_Type0)( internal::Matcher
<Expr> const &ArgMatcher, internal::Matcher<ParmVarDecl
> const &ParamMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_forEachArgumentWithParam0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4830 CXXConstructExpr),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParam0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParam0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<ParmVarDecl> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<ParmVarDecl> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParam0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > forEachArgumentWithParam(internal::Matcher<Expr>
const &ArgMatcher, internal::Matcher<ParmVarDecl> const
&ParamMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_forEachArgumentWithParam0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<ParmVarDecl> >(ArgMatcher, ParamMatcher); }
typedef ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_forEachArgumentWithParam0Matcher, void(::clang
::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > (&forEachArgumentWithParam_Type0)( internal::Matcher
<Expr> const &ArgMatcher, internal::Matcher<ParmVarDecl
> const &ParamMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_forEachArgumentWithParam0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4831 internal::Matcher<Expr>, ArgMatcher,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParam0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParam0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<ParmVarDecl> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<ParmVarDecl> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParam0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > forEachArgumentWithParam(internal::Matcher<Expr>
const &ArgMatcher, internal::Matcher<ParmVarDecl> const
&ParamMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_forEachArgumentWithParam0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<ParmVarDecl> >(ArgMatcher, ParamMatcher); }
typedef ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_forEachArgumentWithParam0Matcher, void(::clang
::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > (&forEachArgumentWithParam_Type0)( internal::Matcher
<Expr> const &ArgMatcher, internal::Matcher<ParmVarDecl
> const &ParamMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_forEachArgumentWithParam0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
4832 internal::Matcher<ParmVarDecl>, ParamMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParam0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParam0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<ParmVarDecl> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<ParmVarDecl> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParam0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > forEachArgumentWithParam(internal::Matcher<Expr>
const &ArgMatcher, internal::Matcher<ParmVarDecl> const
&ParamMatcher) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_forEachArgumentWithParam0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<ParmVarDecl> >(ArgMatcher, ParamMatcher); }
typedef ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_forEachArgumentWithParam0Matcher, void(::clang
::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<ParmVarDecl
> > (&forEachArgumentWithParam_Type0)( internal::Matcher
<Expr> const &ArgMatcher, internal::Matcher<ParmVarDecl
> const &ParamMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_forEachArgumentWithParam0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4833 BoundNodesTreeBuilder Result;
4834 // The first argument of an overloaded member operator is the implicit object
4835 // argument of the method which should not be matched against a parameter, so
4836 // we skip over it here.
4837 BoundNodesTreeBuilder Matches;
4838 unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl()))
4839 .matches(Node, Finder, &Matches)
4840 ? 1
4841 : 0;
4842 int ParamIndex = 0;
4843 bool Matched = false;
4844 for (; ArgIndex < Node.getNumArgs(); ++ArgIndex) {
4845 BoundNodesTreeBuilder ArgMatches(*Builder);
4846 if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()),
4847 Finder, &ArgMatches)) {
4848 BoundNodesTreeBuilder ParamMatches(ArgMatches);
4849 if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
4850 hasParameter(ParamIndex, ParamMatcher)))),
4851 callExpr(callee(functionDecl(
4852 hasParameter(ParamIndex, ParamMatcher))))))
4853 .matches(Node, Finder, &ParamMatches)) {
4854 Result.addMatch(ParamMatches);
4855 Matched = true;
4856 }
4857 }
4858 ++ParamIndex;
4859 }
4860 *Builder = std::move(Result);
4861 return Matched;
4862}
4863
4864/// Matches all arguments and their respective types for a \c CallExpr or
4865/// \c CXXConstructExpr. It is very similar to \c forEachArgumentWithParam but
4866/// it works on calls through function pointers as well.
4867///
4868/// The difference is, that function pointers do not provide access to a
4869/// \c ParmVarDecl, but only the \c QualType for each argument.
4870///
4871/// Given
4872/// \code
4873/// void f(int i);
4874/// int y;
4875/// f(y);
4876/// void (*f_ptr)(int) = f;
4877/// f_ptr(y);
4878/// \endcode
4879/// callExpr(
4880/// forEachArgumentWithParamType(
4881/// declRefExpr(to(varDecl(hasName("y")))),
4882/// qualType(isInteger()).bind("type)
4883/// ))
4884/// matches f(y) and f_ptr(y)
4885/// with declRefExpr(...)
4886/// matching int y
4887/// and qualType(...)
4888/// matching int
4889AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParamType,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParamType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParamType0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<QualType> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<QualType> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParamType0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > forEachArgumentWithParamType(internal::Matcher<Expr
> const &ArgMatcher, internal::Matcher<QualType>
const &ParamMatcher) { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_forEachArgumentWithParamType0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<QualType> >(ArgMatcher, ParamMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachArgumentWithParamType0Matcher, void(::clang::
ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > (&forEachArgumentWithParamType_Type0)( internal
::Matcher<Expr> const &ArgMatcher, internal::Matcher
<QualType> const &ParamMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_forEachArgumentWithParamType0Matcher< NodeType, ParamT1
, ParamT2>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4890 AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParamType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParamType0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<QualType> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<QualType> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParamType0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > forEachArgumentWithParamType(internal::Matcher<Expr
> const &ArgMatcher, internal::Matcher<QualType>
const &ParamMatcher) { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_forEachArgumentWithParamType0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<QualType> >(ArgMatcher, ParamMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachArgumentWithParamType0Matcher, void(::clang::
ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > (&forEachArgumentWithParamType_Type0)( internal
::Matcher<Expr> const &ArgMatcher, internal::Matcher
<QualType> const &ParamMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_forEachArgumentWithParamType0Matcher< NodeType, ParamT1
, ParamT2>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4891 CXXConstructExpr),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParamType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParamType0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<QualType> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<QualType> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParamType0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > forEachArgumentWithParamType(internal::Matcher<Expr
> const &ArgMatcher, internal::Matcher<QualType>
const &ParamMatcher) { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_forEachArgumentWithParamType0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<QualType> >(ArgMatcher, ParamMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachArgumentWithParamType0Matcher, void(::clang::
ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > (&forEachArgumentWithParamType_Type0)( internal
::Matcher<Expr> const &ArgMatcher, internal::Matcher
<QualType> const &ParamMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_forEachArgumentWithParamType0Matcher< NodeType, ParamT1
, ParamT2>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4892 internal::Matcher<Expr>, ArgMatcher,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParamType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParamType0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<QualType> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<QualType> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParamType0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > forEachArgumentWithParamType(internal::Matcher<Expr
> const &ArgMatcher, internal::Matcher<QualType>
const &ParamMatcher) { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_forEachArgumentWithParamType0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<QualType> >(ArgMatcher, ParamMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachArgumentWithParamType0Matcher, void(::clang::
ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > (&forEachArgumentWithParamType_Type0)( internal
::Matcher<Expr> const &ArgMatcher, internal::Matcher
<QualType> const &ParamMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_forEachArgumentWithParamType0Matcher< NodeType, ParamT1
, ParamT2>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
4893 internal::Matcher<QualType>, ParamMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_forEachArgumentWithParamType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_forEachArgumentWithParamType0Matcher
(internal::Matcher<Expr> const &AArgMatcher, internal
::Matcher<QualType> const &AParamMatcher) : ArgMatcher
(AArgMatcher), ParamMatcher(AParamMatcher) {} bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> ArgMatcher; internal::Matcher<QualType> ParamMatcher
; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachArgumentWithParamType0Matcher, void
(::clang::ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > forEachArgumentWithParamType(internal::Matcher<Expr
> const &ArgMatcher, internal::Matcher<QualType>
const &ParamMatcher) { return ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_forEachArgumentWithParamType0Matcher
, void(::clang::ast_matchers::internal::TypeList<CallExpr,
CXXConstructExpr>), internal::Matcher<Expr>, internal
::Matcher<QualType> >(ArgMatcher, ParamMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachArgumentWithParamType0Matcher, void(::clang::
ast_matchers::internal::TypeList<CallExpr, CXXConstructExpr
>), internal::Matcher<Expr>, internal::Matcher<QualType
> > (&forEachArgumentWithParamType_Type0)( internal
::Matcher<Expr> const &ArgMatcher, internal::Matcher
<QualType> const &ParamMatcher); template <typename
NodeType, typename ParamT1, typename ParamT2> bool internal
::matcher_forEachArgumentWithParamType0Matcher< NodeType, ParamT1
, ParamT2>:: matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
4894 BoundNodesTreeBuilder Result;
4895 // The first argument of an overloaded member operator is the implicit object
4896 // argument of the method which should not be matched against a parameter, so
4897 // we skip over it here.
4898 BoundNodesTreeBuilder Matches;
4899 unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl()))
4900 .matches(Node, Finder, &Matches)
4901 ? 1
4902 : 0;
4903
4904 const FunctionProtoType *FProto = nullptr;
4905
4906 if (const auto *Call = dyn_cast<CallExpr>(&Node)) {
4907 if (const auto *Value =
4908 dyn_cast_or_null<ValueDecl>(Call->getCalleeDecl())) {
4909 QualType QT = Value->getType().getCanonicalType();
4910
4911 // This does not necessarily lead to a `FunctionProtoType`,
4912 // e.g. K&R functions do not have a function prototype.
4913 if (QT->isFunctionPointerType())
4914 FProto = QT->getPointeeType()->getAs<FunctionProtoType>();
4915
4916 if (QT->isMemberFunctionPointerType()) {
4917 const auto *MP = QT->getAs<MemberPointerType>();
4918 assert(MP && "Must be member-pointer if its a memberfunctionpointer")(static_cast <bool> (MP && "Must be member-pointer if its a memberfunctionpointer"
) ? void (0) : __assert_fail ("MP && \"Must be member-pointer if its a memberfunctionpointer\""
, "clang/include/clang/ASTMatchers/ASTMatchers.h", 4918, __extension__
__PRETTY_FUNCTION__))
;
4919 FProto = MP->getPointeeType()->getAs<FunctionProtoType>();
4920 assert(FProto &&(static_cast <bool> (FProto && "The call must have happened through a member function "
"pointer") ? void (0) : __assert_fail ("FProto && \"The call must have happened through a member function \" \"pointer\""
, "clang/include/clang/ASTMatchers/ASTMatchers.h", 4922, __extension__
__PRETTY_FUNCTION__))
4921 "The call must have happened through a member function "(static_cast <bool> (FProto && "The call must have happened through a member function "
"pointer") ? void (0) : __assert_fail ("FProto && \"The call must have happened through a member function \" \"pointer\""
, "clang/include/clang/ASTMatchers/ASTMatchers.h", 4922, __extension__
__PRETTY_FUNCTION__))
4922 "pointer")(static_cast <bool> (FProto && "The call must have happened through a member function "
"pointer") ? void (0) : __assert_fail ("FProto && \"The call must have happened through a member function \" \"pointer\""
, "clang/include/clang/ASTMatchers/ASTMatchers.h", 4922, __extension__
__PRETTY_FUNCTION__))
;
4923 }
4924 }
4925 }
4926
4927 unsigned ParamIndex = 0;
4928 bool Matched = false;
4929 unsigned NumArgs = Node.getNumArgs();
4930 if (FProto && FProto->isVariadic())
4931 NumArgs = std::min(NumArgs, FProto->getNumParams());
4932
4933 for (; ArgIndex < NumArgs; ++ArgIndex, ++ParamIndex) {
4934 BoundNodesTreeBuilder ArgMatches(*Builder);
4935 if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder,
4936 &ArgMatches)) {
4937 BoundNodesTreeBuilder ParamMatches(ArgMatches);
4938
4939 // This test is cheaper compared to the big matcher in the next if.
4940 // Therefore, please keep this order.
4941 if (FProto && FProto->getNumParams() > ParamIndex) {
4942 QualType ParamType = FProto->getParamType(ParamIndex);
4943 if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {
4944 Result.addMatch(ParamMatches);
4945 Matched = true;
4946 continue;
4947 }
4948 }
4949 if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
4950 hasParameter(ParamIndex, hasType(ParamMatcher))))),
4951 callExpr(callee(functionDecl(
4952 hasParameter(ParamIndex, hasType(ParamMatcher)))))))
4953 .matches(Node, Finder, &ParamMatches)) {
4954 Result.addMatch(ParamMatches);
4955 Matched = true;
4956 continue;
4957 }
4958 }
4959 }
4960 *Builder = std::move(Result);
4961 return Matched;
4962}
4963
4964/// Matches the ParmVarDecl nodes that are at the N'th position in the parameter
4965/// list. The parameter list could be that of either a block, function, or
4966/// objc-method.
4967///
4968///
4969/// Given
4970///
4971/// \code
4972/// void f(int a, int b, int c) {
4973/// }
4974/// \endcode
4975///
4976/// ``parmVarDecl(isAtPosition(0))`` matches ``int a``.
4977///
4978/// ``parmVarDecl(isAtPosition(1))`` matches ``int b``.
4979AST_MATCHER_P(ParmVarDecl, isAtPosition, unsigned, N)namespace internal { class matcher_isAtPosition0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ParmVarDecl
> { public: explicit matcher_isAtPosition0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const ParmVarDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::Matcher<ParmVarDecl> isAtPosition( unsigned
const &N) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isAtPosition0Matcher(N)); } typedef ::
clang::ast_matchers::internal::Matcher<ParmVarDecl> ( &
isAtPosition_Type0)(unsigned const &N); inline bool internal
::matcher_isAtPosition0Matcher::matches( const ParmVarDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
4980 const clang::DeclContext *Context = Node.getParentFunctionOrMethod();
4981
4982 if (const auto *Decl = dyn_cast_or_null<FunctionDecl>(Context))
4983 return N < Decl->param_size() && Decl->getParamDecl(N) == &Node;
4984 if (const auto *Decl = dyn_cast_or_null<BlockDecl>(Context))
4985 return N < Decl->param_size() && Decl->getParamDecl(N) == &Node;
4986 if (const auto *Decl = dyn_cast_or_null<ObjCMethodDecl>(Context))
4987 return N < Decl->param_size() && Decl->getParamDecl(N) == &Node;
4988
4989 return false;
4990}
4991
4992/// Matches any parameter of a function or an ObjC method declaration or a
4993/// block.
4994///
4995/// Does not match the 'this' parameter of a method.
4996///
4997/// Given
4998/// \code
4999/// class X { void f(int x, int y, int z) {} };
5000/// \endcode
5001/// cxxMethodDecl(hasAnyParameter(hasName("y")))
5002/// matches f(int x, int y, int z) {}
5003/// with hasAnyParameter(...)
5004/// matching int y
5005///
5006/// For ObjectiveC, given
5007/// \code
5008/// @interface I - (void) f:(int) y; @end
5009/// \endcode
5010//
5011/// the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
5012/// matches the declaration of method f with hasParameter
5013/// matching y.
5014///
5015/// For blocks, given
5016/// \code
5017/// b = ^(int y) { printf("%d", y) };
5018/// \endcode
5019///
5020/// the matcher blockDecl(hasAnyParameter(hasName("y")))
5021/// matches the declaration of the block b with hasParameter
5022/// matching y.
5023AST_POLYMORPHIC_MATCHER_P(hasAnyParameter,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyParameter0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasAnyParameter0Matcher( internal
::Matcher<ParmVarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<ParmVarDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), internal::Matcher<ParmVarDecl> > hasAnyParameter
(internal::Matcher<ParmVarDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> > (
&hasAnyParameter_Type0)(internal::Matcher<ParmVarDecl>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasAnyParameter0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5024 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyParameter0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasAnyParameter0Matcher( internal
::Matcher<ParmVarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<ParmVarDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), internal::Matcher<ParmVarDecl> > hasAnyParameter
(internal::Matcher<ParmVarDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> > (
&hasAnyParameter_Type0)(internal::Matcher<ParmVarDecl>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasAnyParameter0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5025 ObjCMethodDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyParameter0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasAnyParameter0Matcher( internal
::Matcher<ParmVarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<ParmVarDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), internal::Matcher<ParmVarDecl> > hasAnyParameter
(internal::Matcher<ParmVarDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> > (
&hasAnyParameter_Type0)(internal::Matcher<ParmVarDecl>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasAnyParameter0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5026 BlockDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyParameter0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasAnyParameter0Matcher( internal
::Matcher<ParmVarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<ParmVarDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), internal::Matcher<ParmVarDecl> > hasAnyParameter
(internal::Matcher<ParmVarDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> > (
&hasAnyParameter_Type0)(internal::Matcher<ParmVarDecl>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasAnyParameter0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5027 internal::Matcher<ParmVarDecl>,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyParameter0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasAnyParameter0Matcher( internal
::Matcher<ParmVarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<ParmVarDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), internal::Matcher<ParmVarDecl> > hasAnyParameter
(internal::Matcher<ParmVarDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> > (
&hasAnyParameter_Type0)(internal::Matcher<ParmVarDecl>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasAnyParameter0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5028 InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnyParameter0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasAnyParameter0Matcher( internal
::Matcher<ParmVarDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<ParmVarDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnyParameter0Matcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, ObjCMethodDecl, BlockDecl
>), internal::Matcher<ParmVarDecl> > hasAnyParameter
(internal::Matcher<ParmVarDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasAnyParameter0Matcher, void(::clang::
ast_matchers::internal::TypeList<FunctionDecl, ObjCMethodDecl
, BlockDecl>), internal::Matcher<ParmVarDecl> > (
&hasAnyParameter_Type0)(internal::Matcher<ParmVarDecl>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasAnyParameter0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5029 return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(),
5030 Node.param_end(), Finder,
5031 Builder) != Node.param_end();
5032}
5033
5034/// Matches \c FunctionDecls and \c FunctionProtoTypes that have a
5035/// specific parameter count.
5036///
5037/// Given
5038/// \code
5039/// void f(int i) {}
5040/// void g(int i, int j) {}
5041/// void h(int i, int j);
5042/// void j(int i);
5043/// void k(int x, int y, int z, ...);
5044/// \endcode
5045/// functionDecl(parameterCountIs(2))
5046/// matches \c g and \c h
5047/// functionProtoType(parameterCountIs(2))
5048/// matches \c g and \c h
5049/// functionProtoType(parameterCountIs(3))
5050/// matches \c k
5051AST_POLYMORPHIC_MATCHER_P(parameterCountIs,namespace internal { template <typename NodeType, typename
ParamT> class matcher_parameterCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_parameterCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> parameterCountIs(unsigned
const &N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_parameterCountIs0Matcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, FunctionProtoType
>), unsigned>(N); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> (&parameterCountIs_Type0
)(unsigned const &N); template <typename NodeType, typename
ParamT> bool internal:: matcher_parameterCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5052 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_parameterCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_parameterCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> parameterCountIs(unsigned
const &N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_parameterCountIs0Matcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, FunctionProtoType
>), unsigned>(N); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> (&parameterCountIs_Type0
)(unsigned const &N); template <typename NodeType, typename
ParamT> bool internal:: matcher_parameterCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5053 FunctionProtoType),namespace internal { template <typename NodeType, typename
ParamT> class matcher_parameterCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_parameterCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> parameterCountIs(unsigned
const &N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_parameterCountIs0Matcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, FunctionProtoType
>), unsigned>(N); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> (&parameterCountIs_Type0
)(unsigned const &N); template <typename NodeType, typename
ParamT> bool internal:: matcher_parameterCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5054 unsigned, N)namespace internal { template <typename NodeType, typename
ParamT> class matcher_parameterCountIs0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_parameterCountIs0Matcher( unsigned
const &AN) : N(AN) {} bool matches(const NodeType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: unsigned N; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> parameterCountIs(unsigned
const &N) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_parameterCountIs0Matcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, FunctionProtoType
>), unsigned>(N); } typedef ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_parameterCountIs0Matcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>), unsigned> (&parameterCountIs_Type0
)(unsigned const &N); template <typename NodeType, typename
ParamT> bool internal:: matcher_parameterCountIs0Matcher<
NodeType, ParamT>::matches( const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5055 return Node.getNumParams() == N;
5056}
5057
5058/// Matches classTemplateSpecialization, templateSpecializationType and
5059/// functionDecl nodes where the template argument matches the inner matcher.
5060/// This matcher may produce multiple matches.
5061///
5062/// Given
5063/// \code
5064/// template <typename T, unsigned N, unsigned M>
5065/// struct Matrix {};
5066///
5067/// constexpr unsigned R = 2;
5068/// Matrix<int, R * 2, R * 4> M;
5069///
5070/// template <typename T, typename U>
5071/// void f(T&& t, U&& u) {}
5072///
5073/// bool B = false;
5074/// f(R, B);
5075/// \endcode
5076/// templateSpecializationType(forEachTemplateArgument(isExpr(expr())))
5077/// matches twice, with expr() matching 'R * 2' and 'R * 4'
5078/// functionDecl(forEachTemplateArgument(refersToType(builtinType())))
5079/// matches the specialization f<unsigned, bool> twice, for 'unsigned'
5080/// and 'bool'
5081AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_forEachTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_forEachTemplateArgument0Matcher
( clang::ast_matchers::internal::Matcher<TemplateArgument>
const &AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: clang::ast_matchers::internal
::Matcher<TemplateArgument> InnerMatcher; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), clang::ast_matchers::internal::Matcher<
TemplateArgument> > forEachTemplateArgument(clang::ast_matchers
::internal::Matcher<TemplateArgument> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> > (&forEachTemplateArgument_Type0
)(clang::ast_matchers::internal::Matcher<TemplateArgument>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_forEachTemplateArgument0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5082 forEachTemplateArgument,namespace internal { template <typename NodeType, typename
ParamT> class matcher_forEachTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_forEachTemplateArgument0Matcher
( clang::ast_matchers::internal::Matcher<TemplateArgument>
const &AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: clang::ast_matchers::internal
::Matcher<TemplateArgument> InnerMatcher; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), clang::ast_matchers::internal::Matcher<
TemplateArgument> > forEachTemplateArgument(clang::ast_matchers
::internal::Matcher<TemplateArgument> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> > (&forEachTemplateArgument_Type0
)(clang::ast_matchers::internal::Matcher<TemplateArgument>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_forEachTemplateArgument0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5083 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,namespace internal { template <typename NodeType, typename
ParamT> class matcher_forEachTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_forEachTemplateArgument0Matcher
( clang::ast_matchers::internal::Matcher<TemplateArgument>
const &AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: clang::ast_matchers::internal
::Matcher<TemplateArgument> InnerMatcher; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), clang::ast_matchers::internal::Matcher<
TemplateArgument> > forEachTemplateArgument(clang::ast_matchers
::internal::Matcher<TemplateArgument> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> > (&forEachTemplateArgument_Type0
)(clang::ast_matchers::internal::Matcher<TemplateArgument>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_forEachTemplateArgument0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5084 TemplateSpecializationType, FunctionDecl),namespace internal { template <typename NodeType, typename
ParamT> class matcher_forEachTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_forEachTemplateArgument0Matcher
( clang::ast_matchers::internal::Matcher<TemplateArgument>
const &AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: clang::ast_matchers::internal
::Matcher<TemplateArgument> InnerMatcher; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), clang::ast_matchers::internal::Matcher<
TemplateArgument> > forEachTemplateArgument(clang::ast_matchers
::internal::Matcher<TemplateArgument> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> > (&forEachTemplateArgument_Type0
)(clang::ast_matchers::internal::Matcher<TemplateArgument>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_forEachTemplateArgument0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5085 clang::ast_matchers::internal::Matcher<TemplateArgument>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_forEachTemplateArgument0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_forEachTemplateArgument0Matcher
( clang::ast_matchers::internal::Matcher<TemplateArgument>
const &AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: clang::ast_matchers::internal
::Matcher<TemplateArgument> InnerMatcher; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_forEachTemplateArgument0Matcher, void(::clang::ast_matchers
::internal::TypeList<ClassTemplateSpecializationDecl, TemplateSpecializationType
, FunctionDecl>), clang::ast_matchers::internal::Matcher<
TemplateArgument> > forEachTemplateArgument(clang::ast_matchers
::internal::Matcher<TemplateArgument> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> >(InnerMatcher
); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_forEachTemplateArgument0Matcher, void(
::clang::ast_matchers::internal::TypeList<ClassTemplateSpecializationDecl
, TemplateSpecializationType, FunctionDecl>), clang::ast_matchers
::internal::Matcher<TemplateArgument> > (&forEachTemplateArgument_Type0
)(clang::ast_matchers::internal::Matcher<TemplateArgument>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_forEachTemplateArgument0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5086 ArrayRef<TemplateArgument> TemplateArgs =
5087 clang::ast_matchers::internal::getTemplateSpecializationArgs(Node);
5088 clang::ast_matchers::internal::BoundNodesTreeBuilder Result;
5089 bool Matched = false;
5090 for (const auto &Arg : TemplateArgs) {
5091 clang::ast_matchers::internal::BoundNodesTreeBuilder ArgBuilder(*Builder);
5092 if (InnerMatcher.matches(Arg, Finder, &ArgBuilder)) {
5093 Matched = true;
5094 Result.addMatch(ArgBuilder);
5095 }
5096 }
5097 *Builder = std::move(Result);
5098 return Matched;
5099}
5100
5101/// Matches \c FunctionDecls that have a noreturn attribute.
5102///
5103/// Given
5104/// \code
5105/// void nope();
5106/// [[noreturn]] void a();
5107/// __attribute__((noreturn)) void b();
5108/// struct c { [[noreturn]] c(); };
5109/// \endcode
5110/// functionDecl(isNoReturn())
5111/// matches all of those except
5112/// \code
5113/// void nope();
5114/// \endcode
5115AST_MATCHER(FunctionDecl, isNoReturn)namespace internal { class matcher_isNoReturnMatcher : public
::clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_isNoReturnMatcher() = default
; bool matches(const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<FunctionDecl>
isNoReturn() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isNoReturnMatcher()); } inline bool internal
::matcher_isNoReturnMatcher::matches( const FunctionDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{ return Node.isNoReturn(); }
5116
5117/// Matches the return type of a function declaration.
5118///
5119/// Given:
5120/// \code
5121/// class X { int f() { return 1; } };
5122/// \endcode
5123/// cxxMethodDecl(returns(asString("int")))
5124/// matches int f() { return 1; }
5125AST_MATCHER_P(FunctionDecl, returns,namespace internal { class matcher_returns0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_returns0Matcher( internal::Matcher
<QualType> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<QualType> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<FunctionDecl> returns( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_returns0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FunctionDecl> ( &returns_Type0)(internal::Matcher<
QualType> const &InnerMatcher); inline bool internal::
matcher_returns0Matcher::matches( const FunctionDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
5126 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_returns0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_returns0Matcher( internal::Matcher
<QualType> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<QualType> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<FunctionDecl> returns( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_returns0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FunctionDecl> ( &returns_Type0)(internal::Matcher<
QualType> const &InnerMatcher); inline bool internal::
matcher_returns0Matcher::matches( const FunctionDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5127 return InnerMatcher.matches(Node.getReturnType(), Finder, Builder);
5128}
5129
5130/// Matches extern "C" function or variable declarations.
5131///
5132/// Given:
5133/// \code
5134/// extern "C" void f() {}
5135/// extern "C" { void g() {} }
5136/// void h() {}
5137/// extern "C" int x = 1;
5138/// extern "C" int y = 2;
5139/// int z = 3;
5140/// \endcode
5141/// functionDecl(isExternC())
5142/// matches the declaration of f and g, but not the declaration of h.
5143/// varDecl(isExternC())
5144/// matches the declaration of x and y, but not the declaration of z.
5145AST_POLYMORPHIC_MATCHER(isExternC, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType> class
matcher_isExternCMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExternCMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)> isExternC() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExternCMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)>(); } template <typename NodeType> bool
internal::matcher_isExternCMatcher<NodeType>::matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5146 VarDecl))namespace internal { template <typename NodeType> class
matcher_isExternCMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExternCMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)> isExternC() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isExternCMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)>(); } template <typename NodeType> bool
internal::matcher_isExternCMatcher<NodeType>::matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5147 return Node.isExternC();
5148}
5149
5150/// Matches variable/function declarations that have "static" storage
5151/// class specifier ("static" keyword) written in the source.
5152///
5153/// Given:
5154/// \code
5155/// static void f() {}
5156/// static int i = 0;
5157/// extern int j;
5158/// int k;
5159/// \endcode
5160/// functionDecl(isStaticStorageClass())
5161/// matches the function declaration f.
5162/// varDecl(isStaticStorageClass())
5163/// matches the variable declaration i.
5164AST_POLYMORPHIC_MATCHER(isStaticStorageClass,namespace internal { template <typename NodeType> class
matcher_isStaticStorageClassMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isStaticStorageClassMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)> isStaticStorageClass() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isStaticStorageClassMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)>(); } template <typename NodeType> bool
internal::matcher_isStaticStorageClassMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5165 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType> class
matcher_isStaticStorageClassMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isStaticStorageClassMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)> isStaticStorageClass() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isStaticStorageClassMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)>(); } template <typename NodeType> bool
internal::matcher_isStaticStorageClassMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5166 VarDecl))namespace internal { template <typename NodeType> class
matcher_isStaticStorageClassMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isStaticStorageClassMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)> isStaticStorageClass() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isStaticStorageClassMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl>)>(); } template <typename NodeType> bool
internal::matcher_isStaticStorageClassMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5167 return Node.getStorageClass() == SC_Static;
5168}
5169
5170/// Matches deleted function declarations.
5171///
5172/// Given:
5173/// \code
5174/// void Func();
5175/// void DeletedFunc() = delete;
5176/// \endcode
5177/// functionDecl(isDeleted())
5178/// matches the declaration of DeletedFunc, but not Func.
5179AST_MATCHER(FunctionDecl, isDeleted)namespace internal { class matcher_isDeletedMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_isDeletedMatcher() = default;
bool matches(const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<FunctionDecl>
isDeleted() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isDeletedMatcher()); } inline bool internal
::matcher_isDeletedMatcher::matches( const FunctionDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5180 return Node.isDeleted();
5181}
5182
5183/// Matches defaulted function declarations.
5184///
5185/// Given:
5186/// \code
5187/// class A { ~A(); };
5188/// class B { ~B() = default; };
5189/// \endcode
5190/// functionDecl(isDefaulted())
5191/// matches the declaration of ~B, but not ~A.
5192AST_MATCHER(FunctionDecl, isDefaulted)namespace internal { class matcher_isDefaultedMatcher : public
::clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_isDefaultedMatcher() = default
; bool matches(const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<FunctionDecl>
isDefaulted() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isDefaultedMatcher()); } inline bool internal
::matcher_isDefaultedMatcher::matches( const FunctionDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5193 return Node.isDefaulted();
5194}
5195
5196/// Matches weak function declarations.
5197///
5198/// Given:
5199/// \code
5200/// void foo() __attribute__((__weakref__("__foo")));
5201/// void bar();
5202/// \endcode
5203/// functionDecl(isWeak())
5204/// matches the weak declaration "foo", but not "bar".
5205AST_MATCHER(FunctionDecl, isWeak)namespace internal { class matcher_isWeakMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<FunctionDecl>
{ public: explicit matcher_isWeakMatcher() = default; bool matches
(const FunctionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<FunctionDecl> isWeak() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isWeakMatcher
()); } inline bool internal::matcher_isWeakMatcher::matches( const
FunctionDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.isWeak(); }
5206
5207/// Matches functions that have a dynamic exception specification.
5208///
5209/// Given:
5210/// \code
5211/// void f();
5212/// void g() noexcept;
5213/// void h() noexcept(true);
5214/// void i() noexcept(false);
5215/// void j() throw();
5216/// void k() throw(int);
5217/// void l() throw(...);
5218/// \endcode
5219/// functionDecl(hasDynamicExceptionSpec()) and
5220/// functionProtoType(hasDynamicExceptionSpec())
5221/// match the declarations of j, k, and l, but not f, g, h, or i.
5222AST_POLYMORPHIC_MATCHER(hasDynamicExceptionSpec,namespace internal { template <typename NodeType> class
matcher_hasDynamicExceptionSpecMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasDynamicExceptionSpecMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)> hasDynamicExceptionSpec() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasDynamicExceptionSpecMatcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, FunctionProtoType>)>
(); } template <typename NodeType> bool internal::matcher_hasDynamicExceptionSpecMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5223 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType> class
matcher_hasDynamicExceptionSpecMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasDynamicExceptionSpecMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)> hasDynamicExceptionSpec() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasDynamicExceptionSpecMatcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, FunctionProtoType>)>
(); } template <typename NodeType> bool internal::matcher_hasDynamicExceptionSpecMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5224 FunctionProtoType))namespace internal { template <typename NodeType> class
matcher_hasDynamicExceptionSpecMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasDynamicExceptionSpecMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)> hasDynamicExceptionSpec() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasDynamicExceptionSpecMatcher, void(::clang::ast_matchers
::internal::TypeList<FunctionDecl, FunctionProtoType>)>
(); } template <typename NodeType> bool internal::matcher_hasDynamicExceptionSpecMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5225 if (const FunctionProtoType *FnTy = internal::getFunctionProtoType(Node))
5226 return FnTy->hasDynamicExceptionSpec();
5227 return false;
5228}
5229
5230/// Matches functions that have a non-throwing exception specification.
5231///
5232/// Given:
5233/// \code
5234/// void f();
5235/// void g() noexcept;
5236/// void h() throw();
5237/// void i() throw(int);
5238/// void j() noexcept(false);
5239/// \endcode
5240/// functionDecl(isNoThrow()) and functionProtoType(isNoThrow())
5241/// match the declarations of g, and h, but not f, i or j.
5242AST_POLYMORPHIC_MATCHER(isNoThrow,namespace internal { template <typename NodeType> class
matcher_isNoThrowMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isNoThrowMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)> isNoThrow() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isNoThrowMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)>(); } template <typename NodeType
> bool internal::matcher_isNoThrowMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5243 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,namespace internal { template <typename NodeType> class
matcher_isNoThrowMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isNoThrowMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)> isNoThrow() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isNoThrowMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)>(); } template <typename NodeType
> bool internal::matcher_isNoThrowMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5244 FunctionProtoType))namespace internal { template <typename NodeType> class
matcher_isNoThrowMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isNoThrowMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)> isNoThrow() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isNoThrowMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, FunctionProtoType>)>(); } template <typename NodeType
> bool internal::matcher_isNoThrowMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5245 const FunctionProtoType *FnTy = internal::getFunctionProtoType(Node);
5246
5247 // If the function does not have a prototype, then it is assumed to be a
5248 // throwing function (as it would if the function did not have any exception
5249 // specification).
5250 if (!FnTy)
5251 return false;
5252
5253 // Assume the best for any unresolved exception specification.
5254 if (isUnresolvedExceptionSpec(FnTy->getExceptionSpecType()))
5255 return true;
5256
5257 return FnTy->isNothrow();
5258}
5259
5260/// Matches consteval function declarations and if consteval/if ! consteval
5261/// statements.
5262///
5263/// Given:
5264/// \code
5265/// consteval int a();
5266/// void b() { if consteval {} }
5267/// void c() { if ! consteval {} }
5268/// void d() { if ! consteval {} else {} }
5269/// \endcode
5270/// functionDecl(isConsteval())
5271/// matches the declaration of "int a()".
5272/// ifStmt(isConsteval())
5273/// matches the if statement in "void b()", "void c()", "void d()".
5274AST_POLYMORPHIC_MATCHER(isConsteval,namespace internal { template <typename NodeType> class
matcher_isConstevalMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isConstevalMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, IfStmt>)> isConsteval() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isConstevalMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, IfStmt>)>(); } template <typename NodeType> bool
internal::matcher_isConstevalMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5275 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, IfStmt))namespace internal { template <typename NodeType> class
matcher_isConstevalMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isConstevalMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, IfStmt>)> isConsteval() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isConstevalMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, IfStmt>)>(); } template <typename NodeType> bool
internal::matcher_isConstevalMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5276 return Node.isConsteval();
5277}
5278
5279/// Matches constexpr variable and function declarations,
5280/// and if constexpr.
5281///
5282/// Given:
5283/// \code
5284/// constexpr int foo = 42;
5285/// constexpr int bar();
5286/// void baz() { if constexpr(1 > 0) {} }
5287/// \endcode
5288/// varDecl(isConstexpr())
5289/// matches the declaration of foo.
5290/// functionDecl(isConstexpr())
5291/// matches the declaration of bar.
5292/// ifStmt(isConstexpr())
5293/// matches the if statement in baz.
5294AST_POLYMORPHIC_MATCHER(isConstexpr,namespace internal { template <typename NodeType> class
matcher_isConstexprMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)> isConstexpr() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)>(); } template <typename NodeType> bool
internal::matcher_isConstexprMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5295 AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl,namespace internal { template <typename NodeType> class
matcher_isConstexprMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)> isConstexpr() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)>(); } template <typename NodeType> bool
internal::matcher_isConstexprMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5296 FunctionDecl,namespace internal { template <typename NodeType> class
matcher_isConstexprMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)> isConstexpr() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)>(); } template <typename NodeType> bool
internal::matcher_isConstexprMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5297 IfStmt))namespace internal { template <typename NodeType> class
matcher_isConstexprMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)> isConstexpr() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isConstexprMatcher
, void(::clang::ast_matchers::internal::TypeList<VarDecl, FunctionDecl
, IfStmt>)>(); } template <typename NodeType> bool
internal::matcher_isConstexprMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5298 return Node.isConstexpr();
5299}
5300
5301/// Matches constinit variable declarations.
5302///
5303/// Given:
5304/// \code
5305/// constinit int foo = 42;
5306/// constinit const char* bar = "bar";
5307/// int baz = 42;
5308/// [[clang::require_constant_initialization]] int xyz = 42;
5309/// \endcode
5310/// varDecl(isConstinit())
5311/// matches the declaration of `foo` and `bar`, but not `baz` and `xyz`.
5312AST_MATCHER(VarDecl, isConstinit)namespace internal { class matcher_isConstinitMatcher : public
::clang::ast_matchers::internal::MatcherInterface<VarDecl
> { public: explicit matcher_isConstinitMatcher() = default
; bool matches(const VarDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<VarDecl> isConstinit
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isConstinitMatcher()); } inline bool internal
::matcher_isConstinitMatcher::matches( const VarDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5313 if (const auto *CIA = Node.getAttr<ConstInitAttr>())
5314 return CIA->isConstinit();
5315 return false;
5316}
5317
5318/// Matches selection statements with initializer.
5319///
5320/// Given:
5321/// \code
5322/// void foo() {
5323/// if (int i = foobar(); i > 0) {}
5324/// switch (int i = foobar(); i) {}
5325/// for (auto& a = get_range(); auto& x : a) {}
5326/// }
5327/// void bar() {
5328/// if (foobar() > 0) {}
5329/// switch (foobar()) {}
5330/// for (auto& x : get_range()) {}
5331/// }
5332/// \endcode
5333/// ifStmt(hasInitStatement(anything()))
5334/// matches the if statement in foo but not in bar.
5335/// switchStmt(hasInitStatement(anything()))
5336/// matches the switch statement in foo but not in bar.
5337/// cxxForRangeStmt(hasInitStatement(anything()))
5338/// matches the range for statement in foo but not in bar.
5339AST_POLYMORPHIC_MATCHER_P(hasInitStatement,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasInitStatement0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasInitStatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasInitStatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, SwitchStmt
, CXXForRangeStmt>), internal::Matcher<Stmt> > hasInitStatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> > (&hasInitStatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasInitStatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5340 AST_POLYMORPHIC_SUPPORTED_TYPES(IfStmt, SwitchStmt,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasInitStatement0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasInitStatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasInitStatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, SwitchStmt
, CXXForRangeStmt>), internal::Matcher<Stmt> > hasInitStatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> > (&hasInitStatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasInitStatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5341 CXXForRangeStmt),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasInitStatement0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasInitStatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasInitStatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, SwitchStmt
, CXXForRangeStmt>), internal::Matcher<Stmt> > hasInitStatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> > (&hasInitStatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasInitStatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5342 internal::Matcher<Stmt>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasInitStatement0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasInitStatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasInitStatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, SwitchStmt
, CXXForRangeStmt>), internal::Matcher<Stmt> > hasInitStatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasInitStatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<IfStmt, SwitchStmt, CXXForRangeStmt>
), internal::Matcher<Stmt> > (&hasInitStatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasInitStatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5343 const Stmt *Init = Node.getInit();
5344 return Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder);
5345}
5346
5347/// Matches the condition expression of an if statement, for loop,
5348/// switch statement or conditional operator.
5349///
5350/// Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true))))
5351/// \code
5352/// if (true) {}
5353/// \endcode
5354AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasCondition0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasCondition0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> > hasCondition(internal::
Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasCondition0Matcher, void(::clang::ast_matchers::internal
::TypeList<IfStmt, ForStmt, WhileStmt, DoStmt, SwitchStmt,
AbstractConditionalOperator>), internal::Matcher<Expr>
> (&hasCondition_Type0)(internal::Matcher<Expr>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasCondition0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5355 hasCondition,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasCondition0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasCondition0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> > hasCondition(internal::
Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasCondition0Matcher, void(::clang::ast_matchers::internal
::TypeList<IfStmt, ForStmt, WhileStmt, DoStmt, SwitchStmt,
AbstractConditionalOperator>), internal::Matcher<Expr>
> (&hasCondition_Type0)(internal::Matcher<Expr>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasCondition0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5356 AST_POLYMORPHIC_SUPPORTED_TYPES(IfStmt, ForStmt, WhileStmt, DoStmt,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasCondition0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasCondition0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> > hasCondition(internal::
Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasCondition0Matcher, void(::clang::ast_matchers::internal
::TypeList<IfStmt, ForStmt, WhileStmt, DoStmt, SwitchStmt,
AbstractConditionalOperator>), internal::Matcher<Expr>
> (&hasCondition_Type0)(internal::Matcher<Expr>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasCondition0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5357 SwitchStmt, AbstractConditionalOperator),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasCondition0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasCondition0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> > hasCondition(internal::
Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasCondition0Matcher, void(::clang::ast_matchers::internal
::TypeList<IfStmt, ForStmt, WhileStmt, DoStmt, SwitchStmt,
AbstractConditionalOperator>), internal::Matcher<Expr>
> (&hasCondition_Type0)(internal::Matcher<Expr>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasCondition0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5358 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasCondition0Matcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: explicit matcher_hasCondition0Matcher( internal::Matcher<
Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> > hasCondition(internal::
Matcher<Expr> const &InnerMatcher) { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasCondition0Matcher
, void(::clang::ast_matchers::internal::TypeList<IfStmt, ForStmt
, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator>
), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasCondition0Matcher, void(::clang::ast_matchers::internal
::TypeList<IfStmt, ForStmt, WhileStmt, DoStmt, SwitchStmt,
AbstractConditionalOperator>), internal::Matcher<Expr>
> (&hasCondition_Type0)(internal::Matcher<Expr>
const &InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasCondition0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
5359 const Expr *const Condition = Node.getCond();
5360 return (Condition != nullptr &&
5361 InnerMatcher.matches(*Condition, Finder, Builder));
5362}
5363
5364/// Matches the then-statement of an if statement.
5365///
5366/// Examples matches the if statement
5367/// (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true)))))
5368/// \code
5369/// if (false) true; else false;
5370/// \endcode
5371AST_MATCHER_P(IfStmt, hasThen, internal::Matcher<Stmt>, InnerMatcher)namespace internal { class matcher_hasThen0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<IfStmt>
{ public: explicit matcher_hasThen0Matcher( internal::Matcher
<Stmt> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const IfStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Stmt> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<IfStmt> hasThen( internal::Matcher<
Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasThen0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<IfStmt> ( &hasThen_Type0)(internal::Matcher<Stmt
> const &InnerMatcher); inline bool internal::matcher_hasThen0Matcher
::matches( const IfStmt &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5372 const Stmt *const Then = Node.getThen();
5373 return (Then != nullptr && InnerMatcher.matches(*Then, Finder, Builder));
5374}
5375
5376/// Matches the else-statement of an if statement.
5377///
5378/// Examples matches the if statement
5379/// (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true)))))
5380/// \code
5381/// if (false) false; else true;
5382/// \endcode
5383AST_MATCHER_P(IfStmt, hasElse, internal::Matcher<Stmt>, InnerMatcher)namespace internal { class matcher_hasElse0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<IfStmt>
{ public: explicit matcher_hasElse0Matcher( internal::Matcher
<Stmt> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const IfStmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Stmt> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<IfStmt> hasElse( internal::Matcher<
Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasElse0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<IfStmt> ( &hasElse_Type0)(internal::Matcher<Stmt
> const &InnerMatcher); inline bool internal::matcher_hasElse0Matcher
::matches( const IfStmt &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5384 const Stmt *const Else = Node.getElse();
5385 return (Else != nullptr && InnerMatcher.matches(*Else, Finder, Builder));
5386}
5387
5388/// Matches if a node equals a previously bound node.
5389///
5390/// Matches a node if it equals the node previously bound to \p ID.
5391///
5392/// Given
5393/// \code
5394/// class X { int a; int b; };
5395/// \endcode
5396/// cxxRecordDecl(
5397/// has(fieldDecl(hasName("a"), hasType(type().bind("t")))),
5398/// has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t"))))))
5399/// matches the class \c X, as \c a and \c b have the same type.
5400///
5401/// Note that when multiple matches are involved via \c forEach* matchers,
5402/// \c equalsBoundNodes acts as a filter.
5403/// For example:
5404/// compoundStmt(
5405/// forEachDescendant(varDecl().bind("d")),
5406/// forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d"))))))
5407/// will trigger a match for each combination of variable declaration
5408/// and reference to that variable declaration within a compound statement.
5409AST_POLYMORPHIC_MATCHER_P(equalsBoundNode,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equalsBoundNode0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_equalsBoundNode0Matcher( std::string
const &AID) : ID(AID) {} bool matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: std::string ID; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> equalsBoundNode(std::string
const &ID) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equalsBoundNode0Matcher, void(::clang::
ast_matchers::internal::TypeList<Stmt, Decl, Type, QualType
>), std::string>(ID); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> (&equalsBoundNode_Type0
)(std::string const &ID); template <typename NodeType,
typename ParamT> bool internal:: matcher_equalsBoundNode0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5410 AST_POLYMORPHIC_SUPPORTED_TYPES(Stmt, Decl, Type,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equalsBoundNode0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_equalsBoundNode0Matcher( std::string
const &AID) : ID(AID) {} bool matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: std::string ID; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> equalsBoundNode(std::string
const &ID) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equalsBoundNode0Matcher, void(::clang::
ast_matchers::internal::TypeList<Stmt, Decl, Type, QualType
>), std::string>(ID); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> (&equalsBoundNode_Type0
)(std::string const &ID); template <typename NodeType,
typename ParamT> bool internal:: matcher_equalsBoundNode0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5411 QualType),namespace internal { template <typename NodeType, typename
ParamT> class matcher_equalsBoundNode0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_equalsBoundNode0Matcher( std::string
const &AID) : ID(AID) {} bool matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: std::string ID; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> equalsBoundNode(std::string
const &ID) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equalsBoundNode0Matcher, void(::clang::
ast_matchers::internal::TypeList<Stmt, Decl, Type, QualType
>), std::string>(ID); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> (&equalsBoundNode_Type0
)(std::string const &ID); template <typename NodeType,
typename ParamT> bool internal:: matcher_equalsBoundNode0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5412 std::string, ID)namespace internal { template <typename NodeType, typename
ParamT> class matcher_equalsBoundNode0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_equalsBoundNode0Matcher( std::string
const &AID) : ID(AID) {} bool matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: std::string ID; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> equalsBoundNode(std::string
const &ID) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equalsBoundNode0Matcher, void(::clang::
ast_matchers::internal::TypeList<Stmt, Decl, Type, QualType
>), std::string>(ID); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_equalsBoundNode0Matcher
, void(::clang::ast_matchers::internal::TypeList<Stmt, Decl
, Type, QualType>), std::string> (&equalsBoundNode_Type0
)(std::string const &ID); template <typename NodeType,
typename ParamT> bool internal:: matcher_equalsBoundNode0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5413 // FIXME: Figure out whether it makes sense to allow this
5414 // on any other node types.
5415 // For *Loc it probably does not make sense, as those seem
5416 // unique. For NestedNameSepcifier it might make sense, as
5417 // those also have pointer identity, but I'm not sure whether
5418 // they're ever reused.
5419 internal::NotEqualsBoundNodePredicate Predicate;
5420 Predicate.ID = ID;
5421 Predicate.Node = DynTypedNode::create(Node);
5422 return Builder->removeBindings(Predicate);
5423}
5424
5425/// Matches the condition variable statement in an if statement.
5426///
5427/// Given
5428/// \code
5429/// if (A* a = GetAPointer()) {}
5430/// \endcode
5431/// hasConditionVariableStatement(...)
5432/// matches 'A* a = GetAPointer()'.
5433AST_MATCHER_P(IfStmt, hasConditionVariableStatement,namespace internal { class matcher_hasConditionVariableStatement0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
IfStmt> { public: explicit matcher_hasConditionVariableStatement0Matcher
( internal::Matcher<DeclStmt> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const IfStmt &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<DeclStmt> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<IfStmt
> hasConditionVariableStatement( internal::Matcher<DeclStmt
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasConditionVariableStatement0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<IfStmt> ( &hasConditionVariableStatement_Type0)(internal
::Matcher<DeclStmt> const &InnerMatcher); inline bool
internal::matcher_hasConditionVariableStatement0Matcher::matches
( const IfStmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5434 internal::Matcher<DeclStmt>, InnerMatcher)namespace internal { class matcher_hasConditionVariableStatement0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
IfStmt> { public: explicit matcher_hasConditionVariableStatement0Matcher
( internal::Matcher<DeclStmt> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const IfStmt &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<DeclStmt> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<IfStmt
> hasConditionVariableStatement( internal::Matcher<DeclStmt
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasConditionVariableStatement0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<IfStmt> ( &hasConditionVariableStatement_Type0)(internal
::Matcher<DeclStmt> const &InnerMatcher); inline bool
internal::matcher_hasConditionVariableStatement0Matcher::matches
( const IfStmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5435 const DeclStmt* const DeclarationStatement =
5436 Node.getConditionVariableDeclStmt();
5437 return DeclarationStatement != nullptr &&
5438 InnerMatcher.matches(*DeclarationStatement, Finder, Builder);
5439}
5440
5441/// Matches the index expression of an array subscript expression.
5442///
5443/// Given
5444/// \code
5445/// int i[5];
5446/// void f() { i[1] = 42; }
5447/// \endcode
5448/// arraySubscriptExpression(hasIndex(integerLiteral()))
5449/// matches \c i[1] with the \c integerLiteral() matching \c 1
5450AST_MATCHER_P(ArraySubscriptExpr, hasIndex,namespace internal { class matcher_hasIndex0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<ArraySubscriptExpr
> { public: explicit matcher_hasIndex0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const ArraySubscriptExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ArraySubscriptExpr> hasIndex
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasIndex0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<ArraySubscriptExpr> ( &hasIndex_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasIndex0Matcher::matches( const ArraySubscriptExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5451 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasIndex0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<ArraySubscriptExpr
> { public: explicit matcher_hasIndex0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const ArraySubscriptExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ArraySubscriptExpr> hasIndex
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasIndex0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<ArraySubscriptExpr> ( &hasIndex_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasIndex0Matcher::matches( const ArraySubscriptExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5452 if (const Expr* Expression = Node.getIdx())
5453 return InnerMatcher.matches(*Expression, Finder, Builder);
5454 return false;
5455}
5456
5457/// Matches the base expression of an array subscript expression.
5458///
5459/// Given
5460/// \code
5461/// int i[5];
5462/// void f() { i[1] = 42; }
5463/// \endcode
5464/// arraySubscriptExpression(hasBase(implicitCastExpr(
5465/// hasSourceExpression(declRefExpr()))))
5466/// matches \c i[1] with the \c declRefExpr() matching \c i
5467AST_MATCHER_P(ArraySubscriptExpr, hasBase,namespace internal { class matcher_hasBase0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<ArraySubscriptExpr
> { public: explicit matcher_hasBase0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const ArraySubscriptExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ArraySubscriptExpr> hasBase
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasBase0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<ArraySubscriptExpr> ( &hasBase_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasBase0Matcher::matches( const ArraySubscriptExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5468 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasBase0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<ArraySubscriptExpr
> { public: explicit matcher_hasBase0Matcher( internal::Matcher
<Expr> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const ArraySubscriptExpr &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<ArraySubscriptExpr> hasBase
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasBase0Matcher(InnerMatcher)); } typedef ::clang::ast_matchers
::internal::Matcher<ArraySubscriptExpr> ( &hasBase_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasBase0Matcher::matches( const ArraySubscriptExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5469 if (const Expr* Expression = Node.getBase())
5470 return InnerMatcher.matches(*Expression, Finder, Builder);
5471 return false;
5472}
5473
5474/// Matches a 'for', 'while', 'while' statement or a function or coroutine
5475/// definition that has a given body. Note that in case of functions or
5476/// coroutines this matcher only matches the definition itself and not the
5477/// other declarations of the same function or coroutine.
5478///
5479/// Given
5480/// \code
5481/// for (;;) {}
5482/// \endcode
5483/// forStmt(hasBody(compoundStmt()))
5484/// matches 'for (;;) {}'
5485/// with compoundStmt()
5486/// matching '{}'
5487///
5488/// Given
5489/// \code
5490/// void f();
5491/// void f() {}
5492/// \endcode
5493/// functionDecl(hasBody(compoundStmt()))
5494/// matches 'void f() {}'
5495/// with compoundStmt()
5496/// matching '{}'
5497/// but does not match 'void f();'
5498AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasBody0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasBody0Matcher( internal::Matcher<Stmt> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Stmt
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasBody0Matcher, void
(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> > hasBody(internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasBody0Matcher
, void(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasBody0Matcher, void(::clang::ast_matchers::internal
::TypeList<DoStmt, ForStmt, WhileStmt, CXXForRangeStmt, FunctionDecl
, CoroutineBodyStmt>), internal::Matcher<Stmt> > (
&hasBody_Type0)(internal::Matcher<Stmt> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasBody0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5499 hasBody,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasBody0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasBody0Matcher( internal::Matcher<Stmt> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Stmt
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasBody0Matcher, void
(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> > hasBody(internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasBody0Matcher
, void(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasBody0Matcher, void(::clang::ast_matchers::internal
::TypeList<DoStmt, ForStmt, WhileStmt, CXXForRangeStmt, FunctionDecl
, CoroutineBodyStmt>), internal::Matcher<Stmt> > (
&hasBody_Type0)(internal::Matcher<Stmt> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasBody0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5500 AST_POLYMORPHIC_SUPPORTED_TYPES(DoStmt, ForStmt, WhileStmt, CXXForRangeStmt,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasBody0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasBody0Matcher( internal::Matcher<Stmt> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Stmt
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasBody0Matcher, void
(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> > hasBody(internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasBody0Matcher
, void(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasBody0Matcher, void(::clang::ast_matchers::internal
::TypeList<DoStmt, ForStmt, WhileStmt, CXXForRangeStmt, FunctionDecl
, CoroutineBodyStmt>), internal::Matcher<Stmt> > (
&hasBody_Type0)(internal::Matcher<Stmt> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasBody0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5501 FunctionDecl, CoroutineBodyStmt),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasBody0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasBody0Matcher( internal::Matcher<Stmt> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Stmt
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasBody0Matcher, void
(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> > hasBody(internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasBody0Matcher
, void(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasBody0Matcher, void(::clang::ast_matchers::internal
::TypeList<DoStmt, ForStmt, WhileStmt, CXXForRangeStmt, FunctionDecl
, CoroutineBodyStmt>), internal::Matcher<Stmt> > (
&hasBody_Type0)(internal::Matcher<Stmt> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasBody0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5502 internal::Matcher<Stmt>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasBody0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasBody0Matcher( internal::Matcher<Stmt> const
&AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Stmt
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasBody0Matcher, void
(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> > hasBody(internal::Matcher
<Stmt> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasBody0Matcher
, void(::clang::ast_matchers::internal::TypeList<DoStmt, ForStmt
, WhileStmt, CXXForRangeStmt, FunctionDecl, CoroutineBodyStmt
>), internal::Matcher<Stmt> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasBody0Matcher, void(::clang::ast_matchers::internal
::TypeList<DoStmt, ForStmt, WhileStmt, CXXForRangeStmt, FunctionDecl
, CoroutineBodyStmt>), internal::Matcher<Stmt> > (
&hasBody_Type0)(internal::Matcher<Stmt> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasBody0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
5503 if (Finder->isTraversalIgnoringImplicitNodes() && isDefaultedHelper(&Node))
5504 return false;
5505 const Stmt *const Statement = internal::GetBodyMatcher<NodeType>::get(Node);
5506 return (Statement != nullptr &&
5507 InnerMatcher.matches(*Statement, Finder, Builder));
5508}
5509
5510/// Matches a function declaration that has a given body present in the AST.
5511/// Note that this matcher matches all the declarations of a function whose
5512/// body is present in the AST.
5513///
5514/// Given
5515/// \code
5516/// void f();
5517/// void f() {}
5518/// void g();
5519/// \endcode
5520/// functionDecl(hasAnyBody(compoundStmt()))
5521/// matches both 'void f();'
5522/// and 'void f() {}'
5523/// with compoundStmt()
5524/// matching '{}'
5525/// but does not match 'void g();'
5526AST_MATCHER_P(FunctionDecl, hasAnyBody,namespace internal { class matcher_hasAnyBody0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_hasAnyBody0Matcher( internal::
Matcher<Stmt> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const FunctionDecl &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Stmt> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FunctionDecl
> hasAnyBody( internal::Matcher<Stmt> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasAnyBody0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<FunctionDecl> ( &
hasAnyBody_Type0)(internal::Matcher<Stmt> const &InnerMatcher
); inline bool internal::matcher_hasAnyBody0Matcher::matches(
const FunctionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5527 internal::Matcher<Stmt>, InnerMatcher)namespace internal { class matcher_hasAnyBody0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_hasAnyBody0Matcher( internal::
Matcher<Stmt> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const FunctionDecl &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Stmt> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FunctionDecl
> hasAnyBody( internal::Matcher<Stmt> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasAnyBody0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<FunctionDecl> ( &
hasAnyBody_Type0)(internal::Matcher<Stmt> const &InnerMatcher
); inline bool internal::matcher_hasAnyBody0Matcher::matches(
const FunctionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5528 const Stmt *const Statement = Node.getBody();
5529 return (Statement != nullptr &&
5530 InnerMatcher.matches(*Statement, Finder, Builder));
5531}
5532
5533
5534/// Matches compound statements where at least one substatement matches
5535/// a given matcher. Also matches StmtExprs that have CompoundStmt as children.
5536///
5537/// Given
5538/// \code
5539/// { {}; 1+2; }
5540/// \endcode
5541/// hasAnySubstatement(compoundStmt())
5542/// matches '{ {}; 1+2; }'
5543/// with compoundStmt()
5544/// matching '{}'
5545AST_POLYMORPHIC_MATCHER_P(hasAnySubstatement,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnySubstatement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnySubstatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > hasAnySubstatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnySubstatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<CompoundStmt, StmtExpr>), internal
::Matcher<Stmt> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > (&hasAnySubstatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasAnySubstatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5546 AST_POLYMORPHIC_SUPPORTED_TYPES(CompoundStmt,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnySubstatement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnySubstatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > hasAnySubstatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnySubstatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<CompoundStmt, StmtExpr>), internal
::Matcher<Stmt> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > (&hasAnySubstatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasAnySubstatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5547 StmtExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnySubstatement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnySubstatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > hasAnySubstatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnySubstatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<CompoundStmt, StmtExpr>), internal
::Matcher<Stmt> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > (&hasAnySubstatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasAnySubstatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5548 internal::Matcher<Stmt>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasAnySubstatement0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasAnySubstatement0Matcher( internal
::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Stmt> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > hasAnySubstatement
(internal::Matcher<Stmt> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasAnySubstatement0Matcher, void(::clang::ast_matchers
::internal::TypeList<CompoundStmt, StmtExpr>), internal
::Matcher<Stmt> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasAnySubstatement0Matcher
, void(::clang::ast_matchers::internal::TypeList<CompoundStmt
, StmtExpr>), internal::Matcher<Stmt> > (&hasAnySubstatement_Type0
)(internal::Matcher<Stmt> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasAnySubstatement0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5549 const CompoundStmt *CS = CompoundStmtMatcher<NodeType>::get(Node);
5550 return CS && matchesFirstInPointerRange(InnerMatcher, CS->body_begin(),
5551 CS->body_end(), Finder,
5552 Builder) != CS->body_end();
5553}
5554
5555/// Checks that a compound statement contains a specific number of
5556/// child statements.
5557///
5558/// Example: Given
5559/// \code
5560/// { for (;;) {} }
5561/// \endcode
5562/// compoundStmt(statementCountIs(0)))
5563/// matches '{}'
5564/// but does not match the outer compound statement.
5565AST_MATCHER_P(CompoundStmt, statementCountIs, unsigned, N)namespace internal { class matcher_statementCountIs0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CompoundStmt> { public: explicit matcher_statementCountIs0Matcher
( unsigned const &AN) : N(AN) {} bool matches(const CompoundStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::Matcher<CompoundStmt> statementCountIs
( unsigned const &N) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_statementCountIs0Matcher
(N)); } typedef ::clang::ast_matchers::internal::Matcher<CompoundStmt
> ( &statementCountIs_Type0)(unsigned const &N); inline
bool internal::matcher_statementCountIs0Matcher::matches( const
CompoundStmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5566 return Node.size() == N;
5567}
5568
5569/// Matches literals that are equal to the given value of type ValueT.
5570///
5571/// Given
5572/// \code
5573/// f('\0', false, 3.14, 42);
5574/// \endcode
5575/// characterLiteral(equals(0))
5576/// matches '\0'
5577/// cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))
5578/// match false
5579/// floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))
5580/// match 3.14
5581/// integerLiteral(equals(42))
5582/// matches 42
5583///
5584/// Note that you cannot directly match a negative numeric literal because the
5585/// minus sign is not part of the literal: It is a unary operator whose operand
5586/// is the positive numeric literal. Instead, you must use a unaryOperator()
5587/// matcher to match the minus sign:
5588///
5589/// unaryOperator(hasOperatorName("-"),
5590/// hasUnaryOperand(integerLiteral(equals(13))))
5591///
5592/// Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>,
5593/// Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
5594template <typename ValueT>
5595internal::PolymorphicMatcher<internal::ValueEqualsMatcher,
5596 void(internal::AllNodeBaseTypes), ValueT>
5597equals(const ValueT &Value) {
5598 return internal::PolymorphicMatcher<internal::ValueEqualsMatcher,
5599 void(internal::AllNodeBaseTypes), ValueT>(
5600 Value);
5601}
5602
5603AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals0Matcher( bool const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: bool
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool> equals(bool const &Value) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool>(Value); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_equals0Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), bool> (&equals_Type0
)(bool const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5604 AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals0Matcher( bool const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: bool
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool> equals(bool const &Value) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool>(Value); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_equals0Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), bool> (&equals_Type0
)(bool const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5605 CXXBoolLiteralExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals0Matcher( bool const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: bool
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool> equals(bool const &Value) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool>(Value); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_equals0Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), bool> (&equals_Type0
)(bool const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5606 IntegerLiteral),namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals0Matcher( bool const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: bool
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool> equals(bool const &Value) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool>(Value); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_equals0Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), bool> (&equals_Type0
)(bool const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5607 bool, Value, 0)namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals0Matcher( bool const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: bool
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool> equals(bool const &Value) {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_equals0Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), bool>(Value); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_equals0Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), bool> (&equals_Type0
)(bool const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals0Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
5608 return internal::ValueEqualsMatcher<NodeType, ParamT>(Value)
5609 .matchesNode(Node);
5610}
5611
5612AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals1Matcher( unsigned const &AValue) : Value(
AValue) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: unsigned
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned> equals(unsigned const &
Value) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned>(Value); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_equals1Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), unsigned> (&
equals_Type1)(unsigned const &Value); template <typename
NodeType, typename ParamT> bool internal:: matcher_equals1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5613 AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals1Matcher( unsigned const &AValue) : Value(
AValue) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: unsigned
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned> equals(unsigned const &
Value) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned>(Value); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_equals1Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), unsigned> (&
equals_Type1)(unsigned const &Value); template <typename
NodeType, typename ParamT> bool internal:: matcher_equals1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5614 CXXBoolLiteralExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals1Matcher( unsigned const &AValue) : Value(
AValue) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: unsigned
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned> equals(unsigned const &
Value) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned>(Value); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_equals1Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), unsigned> (&
equals_Type1)(unsigned const &Value); template <typename
NodeType, typename ParamT> bool internal:: matcher_equals1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5615 IntegerLiteral),namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals1Matcher( unsigned const &AValue) : Value(
AValue) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: unsigned
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned> equals(unsigned const &
Value) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned>(Value); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_equals1Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), unsigned> (&
equals_Type1)(unsigned const &Value); template <typename
NodeType, typename ParamT> bool internal:: matcher_equals1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5616 unsigned, Value, 1)namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals1Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals1Matcher( unsigned const &AValue) : Value(
AValue) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: unsigned
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned> equals(unsigned const &
Value) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals1Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
IntegerLiteral>), unsigned>(Value); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_equals1Matcher
, void(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, IntegerLiteral>), unsigned> (&
equals_Type1)(unsigned const &Value); template <typename
NodeType, typename ParamT> bool internal:: matcher_equals1Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5617 return internal::ValueEqualsMatcher<NodeType, ParamT>(Value)
5618 .matchesNode(Node);
5619}
5620
5621AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals2Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals2Matcher( double const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: double
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> equals(double
const &Value) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_equals2Matcher, void
(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral>), double
>(Value); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> (&equals_Type2
)(double const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals2Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5622 AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals2Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals2Matcher( double const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: double
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> equals(double
const &Value) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_equals2Matcher, void
(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral>), double
>(Value); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> (&equals_Type2
)(double const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals2Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5623 CXXBoolLiteralExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals2Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals2Matcher( double const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: double
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> equals(double
const &Value) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_equals2Matcher, void
(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral>), double
>(Value); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> (&equals_Type2
)(double const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals2Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5624 FloatingLiteral,namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals2Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals2Matcher( double const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: double
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> equals(double
const &Value) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_equals2Matcher, void
(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral>), double
>(Value); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> (&equals_Type2
)(double const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals2Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5625 IntegerLiteral),namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals2Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals2Matcher( double const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: double
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> equals(double
const &Value) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_equals2Matcher, void
(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral>), double
>(Value); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> (&equals_Type2
)(double const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals2Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5626 double, Value, 2)namespace internal { template <typename NodeType, typename
ParamT> class matcher_equals2Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_equals2Matcher( double const &AValue) : Value(AValue
) {} bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: double
Value; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> equals(double
const &Value) { return ::clang::ast_matchers::internal::
PolymorphicMatcher< internal::matcher_equals2Matcher, void
(::clang::ast_matchers::internal::TypeList<CharacterLiteral
, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral>), double
>(Value); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_equals2Matcher, void(::clang::ast_matchers
::internal::TypeList<CharacterLiteral, CXXBoolLiteralExpr,
FloatingLiteral, IntegerLiteral>), double> (&equals_Type2
)(double const &Value); template <typename NodeType, typename
ParamT> bool internal:: matcher_equals2Matcher<NodeType
, ParamT>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
5627 return internal::ValueEqualsMatcher<NodeType, ParamT>(Value)
5628 .matchesNode(Node);
5629}
5630
5631/// Matches the operator Name of operator expressions (binary or
5632/// unary).
5633///
5634/// Example matches a || b (matcher = binaryOperator(hasOperatorName("||")))
5635/// \code
5636/// !(a || b)
5637/// \endcode
5638AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasOperatorName0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasOperatorName0Matcher( std::string
const &AName) : Name(AName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Name; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasOperatorName0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, UnaryOperator>), std::string> hasOperatorName(std::string
const &Name) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
>(Name); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
> (&hasOperatorName_Type0)(std::string const &Name
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasOperatorName0Matcher<NodeType, ParamT>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5639 hasOperatorName,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasOperatorName0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasOperatorName0Matcher( std::string
const &AName) : Name(AName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Name; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasOperatorName0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, UnaryOperator>), std::string> hasOperatorName(std::string
const &Name) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
>(Name); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
> (&hasOperatorName_Type0)(std::string const &Name
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasOperatorName0Matcher<NodeType, ParamT>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5640 AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasOperatorName0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasOperatorName0Matcher( std::string
const &AName) : Name(AName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Name; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasOperatorName0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, UnaryOperator>), std::string> hasOperatorName(std::string
const &Name) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
>(Name); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
> (&hasOperatorName_Type0)(std::string const &Name
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasOperatorName0Matcher<NodeType, ParamT>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5641 CXXRewrittenBinaryOperator, UnaryOperator),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasOperatorName0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasOperatorName0Matcher( std::string
const &AName) : Name(AName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Name; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasOperatorName0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, UnaryOperator>), std::string> hasOperatorName(std::string
const &Name) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
>(Name); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
> (&hasOperatorName_Type0)(std::string const &Name
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasOperatorName0Matcher<NodeType, ParamT>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5642 std::string, Name)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasOperatorName0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasOperatorName0Matcher( std::string
const &AName) : Name(AName) {} bool matches(const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: std::string Name; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasOperatorName0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, UnaryOperator>), std::string> hasOperatorName(std::string
const &Name) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
>(Name); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperatorName0Matcher, void(::clang::
ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator, UnaryOperator>), std::string
> (&hasOperatorName_Type0)(std::string const &Name
); template <typename NodeType, typename ParamT> bool internal
:: matcher_hasOperatorName0Matcher<NodeType, ParamT>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5643 if (std::optional<StringRef> OpName = internal::getOpName(Node))
5644 return *OpName == Name;
5645 return false;
5646}
5647
5648/// Matches operator expressions (binary or unary) that have any of the
5649/// specified names.
5650///
5651/// hasAnyOperatorName("+", "-")
5652/// Is equivalent to
5653/// anyOf(hasOperatorName("+"), hasOperatorName("-"))
5654extern const internal::VariadicFunction<
5655 internal::PolymorphicMatcher<internal::HasAnyOperatorNameMatcher,
5656 AST_POLYMORPHIC_SUPPORTED_TYPES(void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, UnaryOperator
>)
5657 BinaryOperator, CXXOperatorCallExpr,void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, UnaryOperator
>)
5658 CXXRewrittenBinaryOperator, UnaryOperator)void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, UnaryOperator
>)
,
5659 std::vector<std::string>>,
5660 StringRef, internal::hasAnyOperatorNameFunc>
5661 hasAnyOperatorName;
5662
5663/// Matches all kinds of assignment operators.
5664///
5665/// Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator()))
5666/// \code
5667/// if (a == b)
5668/// a += b;
5669/// \endcode
5670///
5671/// Example 2: matches s1 = s2
5672/// (matcher = cxxOperatorCallExpr(isAssignmentOperator()))
5673/// \code
5674/// struct S { S& operator=(const S&); };
5675/// void x() { S s1, s2; s1 = s2; }
5676/// \endcode
5677AST_POLYMORPHIC_MATCHER(namespace internal { template <typename NodeType> class
matcher_isAssignmentOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isAssignmentOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isAssignmentOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isAssignmentOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isAssignmentOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5678 isAssignmentOperator,namespace internal { template <typename NodeType> class
matcher_isAssignmentOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isAssignmentOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isAssignmentOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isAssignmentOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isAssignmentOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5679 AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType> class
matcher_isAssignmentOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isAssignmentOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isAssignmentOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isAssignmentOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isAssignmentOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5680 CXXRewrittenBinaryOperator))namespace internal { template <typename NodeType> class
matcher_isAssignmentOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isAssignmentOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isAssignmentOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isAssignmentOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isAssignmentOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5681 return Node.isAssignmentOp();
5682}
5683
5684/// Matches comparison operators.
5685///
5686/// Example 1: matches a == b (matcher = binaryOperator(isComparisonOperator()))
5687/// \code
5688/// if (a == b)
5689/// a += b;
5690/// \endcode
5691///
5692/// Example 2: matches s1 < s2
5693/// (matcher = cxxOperatorCallExpr(isComparisonOperator()))
5694/// \code
5695/// struct S { bool operator<(const S& other); };
5696/// void x(S s1, S s2) { bool b1 = s1 < s2; }
5697/// \endcode
5698AST_POLYMORPHIC_MATCHER(namespace internal { template <typename NodeType> class
matcher_isComparisonOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isComparisonOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isComparisonOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isComparisonOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isComparisonOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5699 isComparisonOperator,namespace internal { template <typename NodeType> class
matcher_isComparisonOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isComparisonOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isComparisonOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isComparisonOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isComparisonOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5700 AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType> class
matcher_isComparisonOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isComparisonOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isComparisonOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isComparisonOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isComparisonOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5701 CXXRewrittenBinaryOperator))namespace internal { template <typename NodeType> class
matcher_isComparisonOperatorMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isComparisonOperatorMatcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>)> isComparisonOperator
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isComparisonOperatorMatcher, void(::clang
::ast_matchers::internal::TypeList<BinaryOperator, CXXOperatorCallExpr
, CXXRewrittenBinaryOperator>)>(); } template <typename
NodeType> bool internal::matcher_isComparisonOperatorMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5702 return Node.isComparisonOp();
5703}
5704
5705/// Matches the left hand side of binary operator expressions.
5706///
5707/// Example matches a (matcher = binaryOperator(hasLHS()))
5708/// \code
5709/// a || b
5710/// \endcode
5711AST_POLYMORPHIC_MATCHER_P(hasLHS,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasLHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasLHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasLHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasLHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasLHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasLHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasLHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasLHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5712 AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasLHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasLHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasLHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasLHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasLHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasLHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasLHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasLHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5713 BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasLHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasLHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasLHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasLHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasLHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasLHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasLHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasLHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5714 CXXRewrittenBinaryOperator, ArraySubscriptExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasLHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasLHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasLHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasLHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasLHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasLHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasLHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasLHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5715 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasLHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasLHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasLHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasLHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasLHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasLHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasLHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasLHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
5716 const Expr *LeftHandSide = internal::getLHS(Node);
5717 return (LeftHandSide != nullptr &&
5718 InnerMatcher.matches(*LeftHandSide, Finder, Builder));
5719}
5720
5721/// Matches the right hand side of binary operator expressions.
5722///
5723/// Example matches b (matcher = binaryOperator(hasRHS()))
5724/// \code
5725/// a || b
5726/// \endcode
5727AST_POLYMORPHIC_MATCHER_P(hasRHS,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasRHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasRHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasRHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasRHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasRHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasRHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasRHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasRHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5728 AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasRHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasRHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasRHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasRHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasRHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasRHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasRHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasRHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5729 BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasRHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasRHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasRHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasRHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasRHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasRHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasRHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasRHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5730 CXXRewrittenBinaryOperator, ArraySubscriptExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasRHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasRHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasRHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasRHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasRHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasRHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasRHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasRHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
5731 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasRHS0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasRHS0Matcher( internal::Matcher<Expr> const &
AInnerMatcher) : InnerMatcher(AInnerMatcher) {} bool matches(
const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasRHS0Matcher, void
(::clang::ast_matchers::internal::TypeList<BinaryOperator,
CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> > hasRHS(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasRHS0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator, ArraySubscriptExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasRHS0Matcher, void(::clang::ast_matchers::internal
::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
, ArraySubscriptExpr>), internal::Matcher<Expr> >
(&hasRHS_Type0)(internal::Matcher<Expr> const &
InnerMatcher); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasRHS0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
5732 const Expr *RightHandSide = internal::getRHS(Node);
5733 return (RightHandSide != nullptr &&
5734 InnerMatcher.matches(*RightHandSide, Finder, Builder));
5735}
5736
5737/// Matches if either the left hand side or the right hand side of a
5738/// binary operator matches.
5739AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasEitherOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasEitherOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > hasEitherOperand(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > (&hasEitherOperand_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasEitherOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5740 hasEitherOperand,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasEitherOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasEitherOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > hasEitherOperand(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > (&hasEitherOperand_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasEitherOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5741 AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasEitherOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasEitherOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > hasEitherOperand(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > (&hasEitherOperand_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasEitherOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5742 CXXRewrittenBinaryOperator),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasEitherOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasEitherOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > hasEitherOperand(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > (&hasEitherOperand_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasEitherOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5743 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasEitherOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasEitherOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > hasEitherOperand(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasEitherOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr> > (&hasEitherOperand_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasEitherOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5744 return internal::VariadicDynCastAllOfMatcher<Stmt, NodeType>()(
5745 anyOf(hasLHS(InnerMatcher), hasRHS(InnerMatcher)))
5746 .matches(Node, Finder, Builder);
5747}
5748
5749/// Matches if both matchers match with opposite sides of the binary operator.
5750///
5751/// Example matcher = binaryOperator(hasOperands(integerLiteral(equals(1),
5752/// integerLiteral(equals(2)))
5753/// \code
5754/// 1 + 2 // Match
5755/// 2 + 1 // Match
5756/// 1 + 1 // No match
5757/// 2 + 2 // No match
5758/// \endcode
5759AST_POLYMORPHIC_MATCHER_P2(namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasOperands0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasOperands0Matcher(internal::
Matcher<Expr> const &AMatcher1, internal::Matcher<
Expr> const &AMatcher2) : Matcher1(AMatcher1), Matcher2
(AMatcher2) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> Matcher1; internal::Matcher<
Expr> Matcher2; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> > hasOperands
(internal::Matcher<Expr> const &Matcher1, internal::
Matcher<Expr> const &Matcher2) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> >(Matcher1
, Matcher2); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperands0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
>), internal::Matcher<Expr>, internal::Matcher<Expr
> > (&hasOperands_Type0)( internal::Matcher<Expr
> const &Matcher1, internal::Matcher<Expr> const
&Matcher2); template <typename NodeType, typename ParamT1
, typename ParamT2> bool internal::matcher_hasOperands0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
5760 hasOperands,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasOperands0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasOperands0Matcher(internal::
Matcher<Expr> const &AMatcher1, internal::Matcher<
Expr> const &AMatcher2) : Matcher1(AMatcher1), Matcher2
(AMatcher2) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> Matcher1; internal::Matcher<
Expr> Matcher2; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> > hasOperands
(internal::Matcher<Expr> const &Matcher1, internal::
Matcher<Expr> const &Matcher2) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> >(Matcher1
, Matcher2); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperands0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
>), internal::Matcher<Expr>, internal::Matcher<Expr
> > (&hasOperands_Type0)( internal::Matcher<Expr
> const &Matcher1, internal::Matcher<Expr> const
&Matcher2); template <typename NodeType, typename ParamT1
, typename ParamT2> bool internal::matcher_hasOperands0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
5761 AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasOperands0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasOperands0Matcher(internal::
Matcher<Expr> const &AMatcher1, internal::Matcher<
Expr> const &AMatcher2) : Matcher1(AMatcher1), Matcher2
(AMatcher2) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> Matcher1; internal::Matcher<
Expr> Matcher2; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> > hasOperands
(internal::Matcher<Expr> const &Matcher1, internal::
Matcher<Expr> const &Matcher2) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> >(Matcher1
, Matcher2); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperands0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
>), internal::Matcher<Expr>, internal::Matcher<Expr
> > (&hasOperands_Type0)( internal::Matcher<Expr
> const &Matcher1, internal::Matcher<Expr> const
&Matcher2); template <typename NodeType, typename ParamT1
, typename ParamT2> bool internal::matcher_hasOperands0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
5762 CXXRewrittenBinaryOperator),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasOperands0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasOperands0Matcher(internal::
Matcher<Expr> const &AMatcher1, internal::Matcher<
Expr> const &AMatcher2) : Matcher1(AMatcher1), Matcher2
(AMatcher2) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> Matcher1; internal::Matcher<
Expr> Matcher2; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> > hasOperands
(internal::Matcher<Expr> const &Matcher1, internal::
Matcher<Expr> const &Matcher2) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> >(Matcher1
, Matcher2); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperands0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
>), internal::Matcher<Expr>, internal::Matcher<Expr
> > (&hasOperands_Type0)( internal::Matcher<Expr
> const &Matcher1, internal::Matcher<Expr> const
&Matcher2); template <typename NodeType, typename ParamT1
, typename ParamT2> bool internal::matcher_hasOperands0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
5763 internal::Matcher<Expr>, Matcher1, internal::Matcher<Expr>, Matcher2)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasOperands0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasOperands0Matcher(internal::
Matcher<Expr> const &AMatcher1, internal::Matcher<
Expr> const &AMatcher2) : Matcher1(AMatcher1), Matcher2
(AMatcher2) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> Matcher1; internal::Matcher<
Expr> Matcher2; }; } inline ::clang::ast_matchers::internal
::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> > hasOperands
(internal::Matcher<Expr> const &Matcher1, internal::
Matcher<Expr> const &Matcher2) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasOperands0Matcher
, void(::clang::ast_matchers::internal::TypeList<BinaryOperator
, CXXOperatorCallExpr, CXXRewrittenBinaryOperator>), internal
::Matcher<Expr>, internal::Matcher<Expr> >(Matcher1
, Matcher2); } typedef ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasOperands0Matcher, void(::clang::ast_matchers
::internal::TypeList<BinaryOperator, CXXOperatorCallExpr, CXXRewrittenBinaryOperator
>), internal::Matcher<Expr>, internal::Matcher<Expr
> > (&hasOperands_Type0)( internal::Matcher<Expr
> const &Matcher1, internal::Matcher<Expr> const
&Matcher2); template <typename NodeType, typename ParamT1
, typename ParamT2> bool internal::matcher_hasOperands0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5764 return internal::VariadicDynCastAllOfMatcher<Stmt, NodeType>()(
5765 anyOf(allOf(hasLHS(Matcher1), hasRHS(Matcher2)),
5766 allOf(hasLHS(Matcher2), hasRHS(Matcher1))))
5767 .matches(Node, Finder, Builder);
5768}
5769
5770/// Matches if the operand of a unary operator matches.
5771///
5772/// Example matches true (matcher = hasUnaryOperand(
5773/// cxxBoolLiteral(equals(true))))
5774/// \code
5775/// !true
5776/// \endcode
5777AST_POLYMORPHIC_MATCHER_P(hasUnaryOperand,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasUnaryOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasUnaryOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasUnaryOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<UnaryOperator
, CXXOperatorCallExpr>), internal::Matcher<Expr> >
hasUnaryOperand(internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasUnaryOperand0Matcher, void(::clang::
ast_matchers::internal::TypeList<UnaryOperator, CXXOperatorCallExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasUnaryOperand0Matcher, void(::clang::ast_matchers
::internal::TypeList<UnaryOperator, CXXOperatorCallExpr>
), internal::Matcher<Expr> > (&hasUnaryOperand_Type0
)(internal::Matcher<Expr> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasUnaryOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5778 AST_POLYMORPHIC_SUPPORTED_TYPES(UnaryOperator,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasUnaryOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasUnaryOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasUnaryOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<UnaryOperator
, CXXOperatorCallExpr>), internal::Matcher<Expr> >
hasUnaryOperand(internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasUnaryOperand0Matcher, void(::clang::
ast_matchers::internal::TypeList<UnaryOperator, CXXOperatorCallExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasUnaryOperand0Matcher, void(::clang::ast_matchers
::internal::TypeList<UnaryOperator, CXXOperatorCallExpr>
), internal::Matcher<Expr> > (&hasUnaryOperand_Type0
)(internal::Matcher<Expr> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasUnaryOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5779 CXXOperatorCallExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasUnaryOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasUnaryOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasUnaryOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<UnaryOperator
, CXXOperatorCallExpr>), internal::Matcher<Expr> >
hasUnaryOperand(internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasUnaryOperand0Matcher, void(::clang::
ast_matchers::internal::TypeList<UnaryOperator, CXXOperatorCallExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasUnaryOperand0Matcher, void(::clang::ast_matchers
::internal::TypeList<UnaryOperator, CXXOperatorCallExpr>
), internal::Matcher<Expr> > (&hasUnaryOperand_Type0
)(internal::Matcher<Expr> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasUnaryOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5780 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasUnaryOperand0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<NodeType>
{ public: explicit matcher_hasUnaryOperand0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasUnaryOperand0Matcher
, void(::clang::ast_matchers::internal::TypeList<UnaryOperator
, CXXOperatorCallExpr>), internal::Matcher<Expr> >
hasUnaryOperand(internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasUnaryOperand0Matcher, void(::clang::
ast_matchers::internal::TypeList<UnaryOperator, CXXOperatorCallExpr
>), internal::Matcher<Expr> >(InnerMatcher); } typedef
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasUnaryOperand0Matcher, void(::clang::ast_matchers
::internal::TypeList<UnaryOperator, CXXOperatorCallExpr>
), internal::Matcher<Expr> > (&hasUnaryOperand_Type0
)(internal::Matcher<Expr> const &InnerMatcher); template
<typename NodeType, typename ParamT> bool internal:: matcher_hasUnaryOperand0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5781 const Expr *const Operand = internal::getSubExpr(Node);
5782 return (Operand != nullptr &&
5783 InnerMatcher.matches(*Operand, Finder, Builder));
5784}
5785
5786/// Matches if the cast's source expression
5787/// or opaque value's source expression matches the given matcher.
5788///
5789/// Example 1: matches "a string"
5790/// (matcher = castExpr(hasSourceExpression(cxxConstructExpr())))
5791/// \code
5792/// class URL { URL(string); };
5793/// URL url = "a string";
5794/// \endcode
5795///
5796/// Example 2: matches 'b' (matcher =
5797/// opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr())))
5798/// \code
5799/// int a = b ?: 1;
5800/// \endcode
5801AST_POLYMORPHIC_MATCHER_P(hasSourceExpression,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSourceExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasSourceExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > hasSourceExpression
(internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSourceExpression0Matcher, void(::clang::ast_matchers
::internal::TypeList<CastExpr, OpaqueValueExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > (&
hasSourceExpression_Type0)(internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasSourceExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5802 AST_POLYMORPHIC_SUPPORTED_TYPES(CastExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSourceExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasSourceExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > hasSourceExpression
(internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSourceExpression0Matcher, void(::clang::ast_matchers
::internal::TypeList<CastExpr, OpaqueValueExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > (&
hasSourceExpression_Type0)(internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasSourceExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5803 OpaqueValueExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSourceExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasSourceExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > hasSourceExpression
(internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSourceExpression0Matcher, void(::clang::ast_matchers
::internal::TypeList<CastExpr, OpaqueValueExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > (&
hasSourceExpression_Type0)(internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasSourceExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
5804 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSourceExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasSourceExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > hasSourceExpression
(internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSourceExpression0Matcher, void(::clang::ast_matchers
::internal::TypeList<CastExpr, OpaqueValueExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasSourceExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<CastExpr,
OpaqueValueExpr>), internal::Matcher<Expr> > (&
hasSourceExpression_Type0)(internal::Matcher<Expr> const
&InnerMatcher); template <typename NodeType, typename
ParamT> bool internal:: matcher_hasSourceExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
5805 const Expr *const SubExpression =
5806 internal::GetSourceExpressionMatcher<NodeType>::get(Node);
5807 return (SubExpression != nullptr &&
5808 InnerMatcher.matches(*SubExpression, Finder, Builder));
5809}
5810
5811/// Matches casts that has a given cast kind.
5812///
5813/// Example: matches the implicit cast around \c 0
5814/// (matcher = castExpr(hasCastKind(CK_NullToPointer)))
5815/// \code
5816/// int *p = 0;
5817/// \endcode
5818///
5819/// If the matcher is use from clang-query, CastKind parameter
5820/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
5821AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind)namespace internal { class matcher_hasCastKind0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CastExpr
> { public: explicit matcher_hasCastKind0Matcher( CastKind
const &AKind) : Kind(AKind) {} bool matches(const CastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: CastKind Kind; }; } inline
::clang::ast_matchers::internal::Matcher<CastExpr> hasCastKind
( CastKind const &Kind) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_hasCastKind0Matcher(Kind
)); } typedef ::clang::ast_matchers::internal::Matcher<CastExpr
> ( &hasCastKind_Type0)(CastKind const &Kind); inline
bool internal::matcher_hasCastKind0Matcher::matches( const CastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5822 return Node.getCastKind() == Kind;
5823}
5824
5825/// Matches casts whose destination type matches a given matcher.
5826///
5827/// (Note: Clang's AST refers to other conversions as "casts" too, and calls
5828/// actual casts "explicit" casts.)
5829AST_MATCHER_P(ExplicitCastExpr, hasDestinationType,namespace internal { class matcher_hasDestinationType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ExplicitCastExpr> { public: explicit matcher_hasDestinationType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const ExplicitCastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ExplicitCastExpr> hasDestinationType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasDestinationType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<ExplicitCastExpr> ( &hasDestinationType_Type0)(internal
::Matcher<QualType> const &InnerMatcher); inline bool
internal::matcher_hasDestinationType0Matcher::matches( const
ExplicitCastExpr &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5830 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_hasDestinationType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ExplicitCastExpr> { public: explicit matcher_hasDestinationType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const ExplicitCastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ExplicitCastExpr> hasDestinationType( internal
::Matcher<QualType> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasDestinationType0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<ExplicitCastExpr> ( &hasDestinationType_Type0)(internal
::Matcher<QualType> const &InnerMatcher); inline bool
internal::matcher_hasDestinationType0Matcher::matches( const
ExplicitCastExpr &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5831 const QualType NodeType = Node.getTypeAsWritten();
5832 return InnerMatcher.matches(NodeType, Finder, Builder);
5833}
5834
5835/// Matches implicit casts whose destination type matches a given
5836/// matcher.
5837AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType,namespace internal { class matcher_hasImplicitDestinationType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ImplicitCastExpr> { public: explicit matcher_hasImplicitDestinationType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const ImplicitCastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ImplicitCastExpr> hasImplicitDestinationType(
internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasImplicitDestinationType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<ImplicitCastExpr
> ( &hasImplicitDestinationType_Type0)(internal::Matcher
<QualType> const &InnerMatcher); inline bool internal
::matcher_hasImplicitDestinationType0Matcher::matches( const ImplicitCastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5838 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_hasImplicitDestinationType0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
ImplicitCastExpr> { public: explicit matcher_hasImplicitDestinationType0Matcher
( internal::Matcher<QualType> const &AInnerMatcher)
: InnerMatcher(AInnerMatcher) {} bool matches(const ImplicitCastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<QualType
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ImplicitCastExpr> hasImplicitDestinationType(
internal::Matcher<QualType> const &InnerMatcher) {
return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasImplicitDestinationType0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<ImplicitCastExpr
> ( &hasImplicitDestinationType_Type0)(internal::Matcher
<QualType> const &InnerMatcher); inline bool internal
::matcher_hasImplicitDestinationType0Matcher::matches( const ImplicitCastExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5839 return InnerMatcher.matches(Node.getType(), Finder, Builder);
5840}
5841
5842/// Matches TagDecl object that are spelled with "struct."
5843///
5844/// Example matches S, but not C, U or E.
5845/// \code
5846/// struct S {};
5847/// class C {};
5848/// union U {};
5849/// enum E {};
5850/// \endcode
5851AST_MATCHER(TagDecl, isStruct)namespace internal { class matcher_isStructMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<TagDecl>
{ public: explicit matcher_isStructMatcher() = default; bool
matches(const TagDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<TagDecl> isStruct() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_isStructMatcher
()); } inline bool internal::matcher_isStructMatcher::matches
( const TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5852 return Node.isStruct();
5853}
5854
5855/// Matches TagDecl object that are spelled with "union."
5856///
5857/// Example matches U, but not C, S or E.
5858/// \code
5859/// struct S {};
5860/// class C {};
5861/// union U {};
5862/// enum E {};
5863/// \endcode
5864AST_MATCHER(TagDecl, isUnion)namespace internal { class matcher_isUnionMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<TagDecl>
{ public: explicit matcher_isUnionMatcher() = default; bool matches
(const TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<TagDecl> isUnion() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_isUnionMatcher
()); } inline bool internal::matcher_isUnionMatcher::matches(
const TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5865 return Node.isUnion();
5866}
5867
5868/// Matches TagDecl object that are spelled with "class."
5869///
5870/// Example matches C, but not S, U or E.
5871/// \code
5872/// struct S {};
5873/// class C {};
5874/// union U {};
5875/// enum E {};
5876/// \endcode
5877AST_MATCHER(TagDecl, isClass)namespace internal { class matcher_isClassMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<TagDecl>
{ public: explicit matcher_isClassMatcher() = default; bool matches
(const TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<TagDecl> isClass() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_isClassMatcher
()); } inline bool internal::matcher_isClassMatcher::matches(
const TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5878 return Node.isClass();
5879}
5880
5881/// Matches TagDecl object that are spelled with "enum."
5882///
5883/// Example matches E, but not C, S or U.
5884/// \code
5885/// struct S {};
5886/// class C {};
5887/// union U {};
5888/// enum E {};
5889/// \endcode
5890AST_MATCHER(TagDecl, isEnum)namespace internal { class matcher_isEnumMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<TagDecl> { public
: explicit matcher_isEnumMatcher() = default; bool matches(const
TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<TagDecl> isEnum() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_isEnumMatcher(
)); } inline bool internal::matcher_isEnumMatcher::matches( const
TagDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5891 return Node.isEnum();
5892}
5893
5894/// Matches the true branch expression of a conditional operator.
5895///
5896/// Example 1 (conditional ternary operator): matches a
5897/// \code
5898/// condition ? a : b
5899/// \endcode
5900///
5901/// Example 2 (conditional binary operator): matches opaqueValueExpr(condition)
5902/// \code
5903/// condition ?: b
5904/// \endcode
5905AST_MATCHER_P(AbstractConditionalOperator, hasTrueExpression,namespace internal { class matcher_hasTrueExpression0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
AbstractConditionalOperator> { public: explicit matcher_hasTrueExpression0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const AbstractConditionalOperator
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<AbstractConditionalOperator> hasTrueExpression
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasTrueExpression0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<AbstractConditionalOperator
> ( &hasTrueExpression_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasTrueExpression0Matcher
::matches( const AbstractConditionalOperator &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5906 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasTrueExpression0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
AbstractConditionalOperator> { public: explicit matcher_hasTrueExpression0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const AbstractConditionalOperator
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<AbstractConditionalOperator> hasTrueExpression
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasTrueExpression0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<AbstractConditionalOperator
> ( &hasTrueExpression_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasTrueExpression0Matcher
::matches( const AbstractConditionalOperator &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5907 const Expr *Expression = Node.getTrueExpr();
5908 return (Expression != nullptr &&
5909 InnerMatcher.matches(*Expression, Finder, Builder));
5910}
5911
5912/// Matches the false branch expression of a conditional operator
5913/// (binary or ternary).
5914///
5915/// Example matches b
5916/// \code
5917/// condition ? a : b
5918/// condition ?: b
5919/// \endcode
5920AST_MATCHER_P(AbstractConditionalOperator, hasFalseExpression,namespace internal { class matcher_hasFalseExpression0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
AbstractConditionalOperator> { public: explicit matcher_hasFalseExpression0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const AbstractConditionalOperator
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<AbstractConditionalOperator> hasFalseExpression
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasFalseExpression0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<AbstractConditionalOperator
> ( &hasFalseExpression_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasFalseExpression0Matcher
::matches( const AbstractConditionalOperator &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
5921 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasFalseExpression0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
AbstractConditionalOperator> { public: explicit matcher_hasFalseExpression0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const AbstractConditionalOperator
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<Expr
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<AbstractConditionalOperator> hasFalseExpression
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasFalseExpression0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<AbstractConditionalOperator
> ( &hasFalseExpression_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasFalseExpression0Matcher
::matches( const AbstractConditionalOperator &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
5922 const Expr *Expression = Node.getFalseExpr();
5923 return (Expression != nullptr &&
5924 InnerMatcher.matches(*Expression, Finder, Builder));
5925}
5926
5927/// Matches if a declaration has a body attached.
5928///
5929/// Example matches A, va, fa
5930/// \code
5931/// class A {};
5932/// class B; // Doesn't match, as it has no body.
5933/// int va;
5934/// extern int vb; // Doesn't match, as it doesn't define the variable.
5935/// void fa() {}
5936/// void fb(); // Doesn't match, as it has no body.
5937/// @interface X
5938/// - (void)ma; // Doesn't match, interface is declaration.
5939/// @end
5940/// @implementation X
5941/// - (void)ma {}
5942/// @end
5943/// \endcode
5944///
5945/// Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>,
5946/// Matcher<ObjCMethodDecl>
5947AST_POLYMORPHIC_MATCHER(isDefinition,namespace internal { template <typename NodeType> class
matcher_isDefinitionMatcher : public ::clang::ast_matchers::
internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDefinitionMatcher
, void(::clang::ast_matchers::internal::TypeList<TagDecl, VarDecl
, ObjCMethodDecl, FunctionDecl>)> isDefinition() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDefinitionMatcher, void(::clang::ast_matchers::internal
::TypeList<TagDecl, VarDecl, ObjCMethodDecl, FunctionDecl>
)>(); } template <typename NodeType> bool internal::
matcher_isDefinitionMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5948 AST_POLYMORPHIC_SUPPORTED_TYPES(TagDecl, VarDecl,namespace internal { template <typename NodeType> class
matcher_isDefinitionMatcher : public ::clang::ast_matchers::
internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDefinitionMatcher
, void(::clang::ast_matchers::internal::TypeList<TagDecl, VarDecl
, ObjCMethodDecl, FunctionDecl>)> isDefinition() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDefinitionMatcher, void(::clang::ast_matchers::internal
::TypeList<TagDecl, VarDecl, ObjCMethodDecl, FunctionDecl>
)>(); } template <typename NodeType> bool internal::
matcher_isDefinitionMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5949 ObjCMethodDecl,namespace internal { template <typename NodeType> class
matcher_isDefinitionMatcher : public ::clang::ast_matchers::
internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDefinitionMatcher
, void(::clang::ast_matchers::internal::TypeList<TagDecl, VarDecl
, ObjCMethodDecl, FunctionDecl>)> isDefinition() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDefinitionMatcher, void(::clang::ast_matchers::internal
::TypeList<TagDecl, VarDecl, ObjCMethodDecl, FunctionDecl>
)>(); } template <typename NodeType> bool internal::
matcher_isDefinitionMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
5950 FunctionDecl))namespace internal { template <typename NodeType> class
matcher_isDefinitionMatcher : public ::clang::ast_matchers::
internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isDefinitionMatcher
, void(::clang::ast_matchers::internal::TypeList<TagDecl, VarDecl
, ObjCMethodDecl, FunctionDecl>)> isDefinition() { return
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isDefinitionMatcher, void(::clang::ast_matchers::internal
::TypeList<TagDecl, VarDecl, ObjCMethodDecl, FunctionDecl>
)>(); } template <typename NodeType> bool internal::
matcher_isDefinitionMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
5951 return Node.isThisDeclarationADefinition();
5952}
5953
5954/// Matches if a function declaration is variadic.
5955///
5956/// Example matches f, but not g or h. The function i will not match, even when
5957/// compiled in C mode.
5958/// \code
5959/// void f(...);
5960/// void g(int);
5961/// template <typename... Ts> void h(Ts...);
5962/// void i();
5963/// \endcode
5964AST_MATCHER(FunctionDecl, isVariadic)namespace internal { class matcher_isVariadicMatcher : public
::clang::ast_matchers::internal::MatcherInterface<FunctionDecl
> { public: explicit matcher_isVariadicMatcher() = default
; bool matches(const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<FunctionDecl>
isVariadic() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isVariadicMatcher()); } inline bool internal
::matcher_isVariadicMatcher::matches( const FunctionDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5965 return Node.isVariadic();
5966}
5967
5968/// Matches the class declaration that the given method declaration
5969/// belongs to.
5970///
5971/// FIXME: Generalize this for other kinds of declarations.
5972/// FIXME: What other kind of declarations would we need to generalize
5973/// this to?
5974///
5975/// Example matches A() in the last line
5976/// (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl(
5977/// ofClass(hasName("A"))))))
5978/// \code
5979/// class A {
5980/// public:
5981/// A();
5982/// };
5983/// A a = A();
5984/// \endcode
5985AST_MATCHER_P(CXXMethodDecl, ofClass,namespace internal { class matcher_ofClass0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXMethodDecl
> { public: explicit matcher_ofClass0Matcher( internal::Matcher
<CXXRecordDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMethodDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<CXXRecordDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXMethodDecl> ofClass( internal::Matcher<
CXXRecordDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_ofClass0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXMethodDecl> ( &ofClass_Type0)(internal::Matcher
<CXXRecordDecl> const &InnerMatcher); inline bool internal
::matcher_ofClass0Matcher::matches( const CXXMethodDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
5986 internal::Matcher<CXXRecordDecl>, InnerMatcher)namespace internal { class matcher_ofClass0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXMethodDecl
> { public: explicit matcher_ofClass0Matcher( internal::Matcher
<CXXRecordDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXMethodDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<CXXRecordDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXMethodDecl> ofClass( internal::Matcher<
CXXRecordDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_ofClass0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXMethodDecl> ( &ofClass_Type0)(internal::Matcher
<CXXRecordDecl> const &InnerMatcher); inline bool internal
::matcher_ofClass0Matcher::matches( const CXXMethodDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
5987
5988 ASTChildrenNotSpelledInSourceScope RAII(Finder, false);
5989
5990 const CXXRecordDecl *Parent = Node.getParent();
5991 return (Parent != nullptr &&
5992 InnerMatcher.matches(*Parent, Finder, Builder));
5993}
5994
5995/// Matches each method overridden by the given method. This matcher may
5996/// produce multiple matches.
5997///
5998/// Given
5999/// \code
6000/// class A { virtual void f(); };
6001/// class B : public A { void f(); };
6002/// class C : public B { void f(); };
6003/// \endcode
6004/// cxxMethodDecl(ofClass(hasName("C")),
6005/// forEachOverridden(cxxMethodDecl().bind("b"))).bind("d")
6006/// matches once, with "b" binding "A::f" and "d" binding "C::f" (Note
6007/// that B::f is not overridden by C::f).
6008///
6009/// The check can produce multiple matches in case of multiple inheritance, e.g.
6010/// \code
6011/// class A1 { virtual void f(); };
6012/// class A2 { virtual void f(); };
6013/// class C : public A1, public A2 { void f(); };
6014/// \endcode
6015/// cxxMethodDecl(ofClass(hasName("C")),
6016/// forEachOverridden(cxxMethodDecl().bind("b"))).bind("d")
6017/// matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and
6018/// once with "b" binding "A2::f" and "d" binding "C::f".
6019AST_MATCHER_P(CXXMethodDecl, forEachOverridden,namespace internal { class matcher_forEachOverridden0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CXXMethodDecl> { public: explicit matcher_forEachOverridden0Matcher
( internal::Matcher<CXXMethodDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const CXXMethodDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXMethodDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXMethodDecl> forEachOverridden( internal::Matcher
<CXXMethodDecl> const &InnerMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_forEachOverridden0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXMethodDecl> ( &forEachOverridden_Type0)(internal
::Matcher<CXXMethodDecl> const &InnerMatcher); inline
bool internal::matcher_forEachOverridden0Matcher::matches( const
CXXMethodDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6020 internal::Matcher<CXXMethodDecl>, InnerMatcher)namespace internal { class matcher_forEachOverridden0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CXXMethodDecl> { public: explicit matcher_forEachOverridden0Matcher
( internal::Matcher<CXXMethodDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const CXXMethodDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXMethodDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXMethodDecl> forEachOverridden( internal::Matcher
<CXXMethodDecl> const &InnerMatcher) { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_forEachOverridden0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<CXXMethodDecl> ( &forEachOverridden_Type0)(internal
::Matcher<CXXMethodDecl> const &InnerMatcher); inline
bool internal::matcher_forEachOverridden0Matcher::matches( const
CXXMethodDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6021 BoundNodesTreeBuilder Result;
6022 bool Matched = false;
6023 for (const auto *Overridden : Node.overridden_methods()) {
6024 BoundNodesTreeBuilder OverriddenBuilder(*Builder);
6025 const bool OverriddenMatched =
6026 InnerMatcher.matches(*Overridden, Finder, &OverriddenBuilder);
6027 if (OverriddenMatched) {
6028 Matched = true;
6029 Result.addMatch(OverriddenBuilder);
6030 }
6031 }
6032 *Builder = std::move(Result);
6033 return Matched;
6034}
6035
6036/// Matches declarations of virtual methods and C++ base specifers that specify
6037/// virtual inheritance.
6038///
6039/// Example:
6040/// \code
6041/// class A {
6042/// public:
6043/// virtual void x(); // matches x
6044/// };
6045/// \endcode
6046///
6047/// Example:
6048/// \code
6049/// class Base {};
6050/// class DirectlyDerived : virtual Base {}; // matches Base
6051/// class IndirectlyDerived : DirectlyDerived, Base {}; // matches Base
6052/// \endcode
6053///
6054/// Usable as: Matcher<CXXMethodDecl>, Matcher<CXXBaseSpecifier>
6055AST_POLYMORPHIC_MATCHER(isVirtual,namespace internal { template <typename NodeType> class
matcher_isVirtualMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isVirtualMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXMethodDecl
, CXXBaseSpecifier>)> isVirtual() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isVirtualMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXMethodDecl
, CXXBaseSpecifier>)>(); } template <typename NodeType
> bool internal::matcher_isVirtualMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6056 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXMethodDecl,namespace internal { template <typename NodeType> class
matcher_isVirtualMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isVirtualMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXMethodDecl
, CXXBaseSpecifier>)> isVirtual() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isVirtualMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXMethodDecl
, CXXBaseSpecifier>)>(); } template <typename NodeType
> bool internal::matcher_isVirtualMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6057 CXXBaseSpecifier))namespace internal { template <typename NodeType> class
matcher_isVirtualMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isVirtualMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXMethodDecl
, CXXBaseSpecifier>)> isVirtual() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isVirtualMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXMethodDecl
, CXXBaseSpecifier>)>(); } template <typename NodeType
> bool internal::matcher_isVirtualMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6058 return Node.isVirtual();
6059}
6060
6061/// Matches if the given method declaration has an explicit "virtual".
6062///
6063/// Given
6064/// \code
6065/// class A {
6066/// public:
6067/// virtual void x();
6068/// };
6069/// class B : public A {
6070/// public:
6071/// void x();
6072/// };
6073/// \endcode
6074/// matches A::x but not B::x
6075AST_MATCHER(CXXMethodDecl, isVirtualAsWritten)namespace internal { class matcher_isVirtualAsWrittenMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CXXMethodDecl> { public: explicit matcher_isVirtualAsWrittenMatcher
() = default; bool matches(const CXXMethodDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<CXXMethodDecl
> isVirtualAsWritten() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_isVirtualAsWrittenMatcher
()); } inline bool internal::matcher_isVirtualAsWrittenMatcher
::matches( const CXXMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6076 return Node.isVirtualAsWritten();
6077}
6078
6079AST_MATCHER(CXXConstructorDecl, isInheritingConstructor)namespace internal { class matcher_isInheritingConstructorMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_isInheritingConstructorMatcher
() = default; bool matches(const CXXConstructorDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> isInheritingConstructor()
{ return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_isInheritingConstructorMatcher()); } inline bool internal
::matcher_isInheritingConstructorMatcher::matches( const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6080 return Node.isInheritingConstructor();
6081}
6082
6083/// Matches if the given method or class declaration is final.
6084///
6085/// Given:
6086/// \code
6087/// class A final {};
6088///
6089/// struct B {
6090/// virtual void f();
6091/// };
6092///
6093/// struct C : B {
6094/// void f() final;
6095/// };
6096/// \endcode
6097/// matches A and C::f, but not B, C, or B::f
6098AST_POLYMORPHIC_MATCHER(isFinal,namespace internal { template <typename NodeType> class
matcher_isFinalMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isFinalMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, CXXMethodDecl>)> isFinal() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isFinalMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, CXXMethodDecl>)>(); } template <typename NodeType>
bool internal::matcher_isFinalMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6099 AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl,namespace internal { template <typename NodeType> class
matcher_isFinalMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isFinalMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, CXXMethodDecl>)> isFinal() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isFinalMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, CXXMethodDecl>)>(); } template <typename NodeType>
bool internal::matcher_isFinalMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6100 CXXMethodDecl))namespace internal { template <typename NodeType> class
matcher_isFinalMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isFinalMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, CXXMethodDecl>)> isFinal() { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_isFinalMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXRecordDecl
, CXXMethodDecl>)>(); } template <typename NodeType>
bool internal::matcher_isFinalMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6101 return Node.template hasAttr<FinalAttr>();
6102}
6103
6104/// Matches if the given method declaration is pure.
6105///
6106/// Given
6107/// \code
6108/// class A {
6109/// public:
6110/// virtual void x() = 0;
6111/// };
6112/// \endcode
6113/// matches A::x
6114AST_MATCHER(CXXMethodDecl, isPure)namespace internal { class matcher_isPureMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<CXXMethodDecl>
{ public: explicit matcher_isPureMatcher() = default; bool matches
(const CXXMethodDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<CXXMethodDecl> isPure() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isPureMatcher
()); } inline bool internal::matcher_isPureMatcher::matches( const
CXXMethodDecl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6115 return Node.isPure();
6116}
6117
6118/// Matches if the given method declaration is const.
6119///
6120/// Given
6121/// \code
6122/// struct A {
6123/// void foo() const;
6124/// void bar();
6125/// };
6126/// \endcode
6127///
6128/// cxxMethodDecl(isConst()) matches A::foo() but not A::bar()
6129AST_MATCHER(CXXMethodDecl, isConst)namespace internal { class matcher_isConstMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXMethodDecl
> { public: explicit matcher_isConstMatcher() = default; bool
matches(const CXXMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXMethodDecl>
isConst() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isConstMatcher()); } inline bool internal
::matcher_isConstMatcher::matches( const CXXMethodDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6130 return Node.isConst();
6131}
6132
6133/// Matches if the given method declaration declares a copy assignment
6134/// operator.
6135///
6136/// Given
6137/// \code
6138/// struct A {
6139/// A &operator=(const A &);
6140/// A &operator=(A &&);
6141/// };
6142/// \endcode
6143///
6144/// cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not
6145/// the second one.
6146AST_MATCHER(CXXMethodDecl, isCopyAssignmentOperator)namespace internal { class matcher_isCopyAssignmentOperatorMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXMethodDecl> { public: explicit matcher_isCopyAssignmentOperatorMatcher
() = default; bool matches(const CXXMethodDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<CXXMethodDecl
> isCopyAssignmentOperator() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_isCopyAssignmentOperatorMatcher
()); } inline bool internal::matcher_isCopyAssignmentOperatorMatcher
::matches( const CXXMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6147 return Node.isCopyAssignmentOperator();
6148}
6149
6150/// Matches if the given method declaration declares a move assignment
6151/// operator.
6152///
6153/// Given
6154/// \code
6155/// struct A {
6156/// A &operator=(const A &);
6157/// A &operator=(A &&);
6158/// };
6159/// \endcode
6160///
6161/// cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not
6162/// the first one.
6163AST_MATCHER(CXXMethodDecl, isMoveAssignmentOperator)namespace internal { class matcher_isMoveAssignmentOperatorMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXMethodDecl> { public: explicit matcher_isMoveAssignmentOperatorMatcher
() = default; bool matches(const CXXMethodDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<CXXMethodDecl
> isMoveAssignmentOperator() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_isMoveAssignmentOperatorMatcher
()); } inline bool internal::matcher_isMoveAssignmentOperatorMatcher
::matches( const CXXMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6164 return Node.isMoveAssignmentOperator();
6165}
6166
6167/// Matches if the given method declaration overrides another method.
6168///
6169/// Given
6170/// \code
6171/// class A {
6172/// public:
6173/// virtual void x();
6174/// };
6175/// class B : public A {
6176/// public:
6177/// virtual void x();
6178/// };
6179/// \endcode
6180/// matches B::x
6181AST_MATCHER(CXXMethodDecl, isOverride)namespace internal { class matcher_isOverrideMatcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXMethodDecl
> { public: explicit matcher_isOverrideMatcher() = default
; bool matches(const CXXMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXMethodDecl>
isOverride() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isOverrideMatcher()); } inline bool internal
::matcher_isOverrideMatcher::matches( const CXXMethodDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6182 return Node.size_overridden_methods() > 0 || Node.hasAttr<OverrideAttr>();
6183}
6184
6185/// Matches method declarations that are user-provided.
6186///
6187/// Given
6188/// \code
6189/// struct S {
6190/// S(); // #1
6191/// S(const S &) = default; // #2
6192/// S(S &&) = delete; // #3
6193/// };
6194/// \endcode
6195/// cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3.
6196AST_MATCHER(CXXMethodDecl, isUserProvided)namespace internal { class matcher_isUserProvidedMatcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXMethodDecl
> { public: explicit matcher_isUserProvidedMatcher() = default
; bool matches(const CXXMethodDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXMethodDecl>
isUserProvided() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isUserProvidedMatcher()); } inline bool
internal::matcher_isUserProvidedMatcher::matches( const CXXMethodDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6197 return Node.isUserProvided();
6198}
6199
6200/// Matches member expressions that are called with '->' as opposed
6201/// to '.'.
6202///
6203/// Member calls on the implicit this pointer match as called with '->'.
6204///
6205/// Given
6206/// \code
6207/// class Y {
6208/// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
6209/// template <class T> void f() { this->f<T>(); f<T>(); }
6210/// int a;
6211/// static int b;
6212/// };
6213/// template <class T>
6214/// class Z {
6215/// void x() { this->m; }
6216/// };
6217/// \endcode
6218/// memberExpr(isArrow())
6219/// matches this->x, x, y.x, a, this->b
6220/// cxxDependentScopeMemberExpr(isArrow())
6221/// matches this->m
6222/// unresolvedMemberExpr(isArrow())
6223/// matches this->f<T>, f<T>
6224AST_POLYMORPHIC_MATCHER(namespace internal { template <typename NodeType> class
matcher_isArrowMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isArrowMatcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>)> isArrow
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isArrowMatcher, void(::clang::ast_matchers
::internal::TypeList<MemberExpr, UnresolvedMemberExpr, CXXDependentScopeMemberExpr
>)>(); } template <typename NodeType> bool internal
::matcher_isArrowMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6225 isArrow, AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, UnresolvedMemberExpr,namespace internal { template <typename NodeType> class
matcher_isArrowMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isArrowMatcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>)> isArrow
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isArrowMatcher, void(::clang::ast_matchers
::internal::TypeList<MemberExpr, UnresolvedMemberExpr, CXXDependentScopeMemberExpr
>)>(); } template <typename NodeType> bool internal
::matcher_isArrowMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6226 CXXDependentScopeMemberExpr))namespace internal { template <typename NodeType> class
matcher_isArrowMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isArrowMatcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>)> isArrow
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isArrowMatcher, void(::clang::ast_matchers
::internal::TypeList<MemberExpr, UnresolvedMemberExpr, CXXDependentScopeMemberExpr
>)>(); } template <typename NodeType> bool internal
::matcher_isArrowMatcher<NodeType>::matches( const NodeType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6227 return Node.isArrow();
6228}
6229
6230/// Matches QualType nodes that are of integer type.
6231///
6232/// Given
6233/// \code
6234/// void a(int);
6235/// void b(long);
6236/// void c(double);
6237/// \endcode
6238/// functionDecl(hasAnyParameter(hasType(isInteger())))
6239/// matches "a(int)", "b(long)", but not "c(double)".
6240AST_MATCHER(QualType, isInteger)namespace internal { class matcher_isIntegerMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<QualType>
{ public: explicit matcher_isIntegerMatcher() = default; bool
matches(const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<QualType> isInteger() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isIntegerMatcher
()); } inline bool internal::matcher_isIntegerMatcher::matches
( const QualType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6241 return Node->isIntegerType();
6242}
6243
6244/// Matches QualType nodes that are of unsigned integer type.
6245///
6246/// Given
6247/// \code
6248/// void a(int);
6249/// void b(unsigned long);
6250/// void c(double);
6251/// \endcode
6252/// functionDecl(hasAnyParameter(hasType(isUnsignedInteger())))
6253/// matches "b(unsigned long)", but not "a(int)" and "c(double)".
6254AST_MATCHER(QualType, isUnsignedInteger)namespace internal { class matcher_isUnsignedIntegerMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
QualType> { public: explicit matcher_isUnsignedIntegerMatcher
() = default; bool matches(const QualType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<QualType
> isUnsignedInteger() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_isUnsignedIntegerMatcher
()); } inline bool internal::matcher_isUnsignedIntegerMatcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6255 return Node->isUnsignedIntegerType();
6256}
6257
6258/// Matches QualType nodes that are of signed integer type.
6259///
6260/// Given
6261/// \code
6262/// void a(int);
6263/// void b(unsigned long);
6264/// void c(double);
6265/// \endcode
6266/// functionDecl(hasAnyParameter(hasType(isSignedInteger())))
6267/// matches "a(int)", but not "b(unsigned long)" and "c(double)".
6268AST_MATCHER(QualType, isSignedInteger)namespace internal { class matcher_isSignedIntegerMatcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_isSignedIntegerMatcher() = default
; bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> isSignedInteger
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isSignedIntegerMatcher()); } inline bool internal
::matcher_isSignedIntegerMatcher::matches( const QualType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6269 return Node->isSignedIntegerType();
6270}
6271
6272/// Matches QualType nodes that are of character type.
6273///
6274/// Given
6275/// \code
6276/// void a(char);
6277/// void b(wchar_t);
6278/// void c(double);
6279/// \endcode
6280/// functionDecl(hasAnyParameter(hasType(isAnyCharacter())))
6281/// matches "a(char)", "b(wchar_t)", but not "c(double)".
6282AST_MATCHER(QualType, isAnyCharacter)namespace internal { class matcher_isAnyCharacterMatcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_isAnyCharacterMatcher() = default
; bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> isAnyCharacter
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isAnyCharacterMatcher()); } inline bool internal
::matcher_isAnyCharacterMatcher::matches( const QualType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6283 return Node->isAnyCharacterType();
6284}
6285
6286/// Matches QualType nodes that are of any pointer type; this includes
6287/// the Objective-C object pointer type, which is different despite being
6288/// syntactically similar.
6289///
6290/// Given
6291/// \code
6292/// int *i = nullptr;
6293///
6294/// @interface Foo
6295/// @end
6296/// Foo *f;
6297///
6298/// int j;
6299/// \endcode
6300/// varDecl(hasType(isAnyPointer()))
6301/// matches "int *i" and "Foo *f", but not "int j".
6302AST_MATCHER(QualType, isAnyPointer)namespace internal { class matcher_isAnyPointerMatcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_isAnyPointerMatcher() = default
; bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> isAnyPointer
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isAnyPointerMatcher()); } inline bool internal
::matcher_isAnyPointerMatcher::matches( const QualType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6303 return Node->isAnyPointerType();
6304}
6305
6306/// Matches QualType nodes that are const-qualified, i.e., that
6307/// include "top-level" const.
6308///
6309/// Given
6310/// \code
6311/// void a(int);
6312/// void b(int const);
6313/// void c(const int);
6314/// void d(const int*);
6315/// void e(int const) {};
6316/// \endcode
6317/// functionDecl(hasAnyParameter(hasType(isConstQualified())))
6318/// matches "void b(int const)", "void c(const int)" and
6319/// "void e(int const) {}". It does not match d as there
6320/// is no top-level const on the parameter type "const int *".
6321AST_MATCHER(QualType, isConstQualified)namespace internal { class matcher_isConstQualifiedMatcher : public
::clang::ast_matchers::internal::MatcherInterface<QualType
> { public: explicit matcher_isConstQualifiedMatcher() = default
; bool matches(const QualType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<QualType> isConstQualified
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isConstQualifiedMatcher()); } inline bool internal
::matcher_isConstQualifiedMatcher::matches( const QualType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6322 return Node.isConstQualified();
6323}
6324
6325/// Matches QualType nodes that are volatile-qualified, i.e., that
6326/// include "top-level" volatile.
6327///
6328/// Given
6329/// \code
6330/// void a(int);
6331/// void b(int volatile);
6332/// void c(volatile int);
6333/// void d(volatile int*);
6334/// void e(int volatile) {};
6335/// \endcode
6336/// functionDecl(hasAnyParameter(hasType(isVolatileQualified())))
6337/// matches "void b(int volatile)", "void c(volatile int)" and
6338/// "void e(int volatile) {}". It does not match d as there
6339/// is no top-level volatile on the parameter type "volatile int *".
6340AST_MATCHER(QualType, isVolatileQualified)namespace internal { class matcher_isVolatileQualifiedMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
QualType> { public: explicit matcher_isVolatileQualifiedMatcher
() = default; bool matches(const QualType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<QualType
> isVolatileQualified() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_isVolatileQualifiedMatcher
()); } inline bool internal::matcher_isVolatileQualifiedMatcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6341 return Node.isVolatileQualified();
6342}
6343
6344/// Matches QualType nodes that have local CV-qualifiers attached to
6345/// the node, not hidden within a typedef.
6346///
6347/// Given
6348/// \code
6349/// typedef const int const_int;
6350/// const_int i;
6351/// int *const j;
6352/// int *volatile k;
6353/// int m;
6354/// \endcode
6355/// \c varDecl(hasType(hasLocalQualifiers())) matches only \c j and \c k.
6356/// \c i is const-qualified but the qualifier is not local.
6357AST_MATCHER(QualType, hasLocalQualifiers)namespace internal { class matcher_hasLocalQualifiersMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
QualType> { public: explicit matcher_hasLocalQualifiersMatcher
() = default; bool matches(const QualType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<QualType
> hasLocalQualifiers() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_hasLocalQualifiersMatcher
()); } inline bool internal::matcher_hasLocalQualifiersMatcher
::matches( const QualType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6358 return Node.hasLocalQualifiers();
6359}
6360
6361/// Matches a member expression where the member is matched by a
6362/// given matcher.
6363///
6364/// Given
6365/// \code
6366/// struct { int first, second; } first, second;
6367/// int i(second.first);
6368/// int j(first.second);
6369/// \endcode
6370/// memberExpr(member(hasName("first")))
6371/// matches second.first
6372/// but not first.second (because the member name there is "second").
6373AST_MATCHER_P(MemberExpr, member,namespace internal { class matcher_member0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<MemberExpr
> { public: explicit matcher_member0Matcher( internal::Matcher
<ValueDecl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const MemberExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<ValueDecl> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<MemberExpr> member( internal
::Matcher<ValueDecl> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_member0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<MemberExpr> ( &member_Type0)(internal::Matcher<
ValueDecl> const &InnerMatcher); inline bool internal::
matcher_member0Matcher::matches( const MemberExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
6374 internal::Matcher<ValueDecl>, InnerMatcher)namespace internal { class matcher_member0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<MemberExpr
> { public: explicit matcher_member0Matcher( internal::Matcher
<ValueDecl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const MemberExpr &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<ValueDecl> InnerMatcher; }; } inline ::clang::
ast_matchers::internal::Matcher<MemberExpr> member( internal
::Matcher<ValueDecl> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_member0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<MemberExpr> ( &member_Type0)(internal::Matcher<
ValueDecl> const &InnerMatcher); inline bool internal::
matcher_member0Matcher::matches( const MemberExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
6375 return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder);
6376}
6377
6378/// Matches a member expression where the object expression is matched by a
6379/// given matcher. Implicit object expressions are included; that is, it matches
6380/// use of implicit `this`.
6381///
6382/// Given
6383/// \code
6384/// struct X {
6385/// int m;
6386/// int f(X x) { x.m; return m; }
6387/// };
6388/// \endcode
6389/// memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X")))))
6390/// matches `x.m`, but not `m`; however,
6391/// memberExpr(hasObjectExpression(hasType(pointsTo(
6392// cxxRecordDecl(hasName("X"))))))
6393/// matches `m` (aka. `this->m`), but not `x.m`.
6394AST_POLYMORPHIC_MATCHER_P(namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasObjectExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasObjectExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > hasObjectExpression(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > (&hasObjectExpression_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasObjectExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
6395 hasObjectExpression,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasObjectExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasObjectExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > hasObjectExpression(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > (&hasObjectExpression_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasObjectExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
6396 AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, UnresolvedMemberExpr,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasObjectExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasObjectExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > hasObjectExpression(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > (&hasObjectExpression_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasObjectExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
6397 CXXDependentScopeMemberExpr),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasObjectExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasObjectExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > hasObjectExpression(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > (&hasObjectExpression_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasObjectExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
6398 internal::Matcher<Expr>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasObjectExpression0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NodeType
> { public: explicit matcher_hasObjectExpression0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > hasObjectExpression(internal::Matcher
<Expr> const &InnerMatcher) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> >(InnerMatcher); } typedef ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_hasObjectExpression0Matcher
, void(::clang::ast_matchers::internal::TypeList<MemberExpr
, UnresolvedMemberExpr, CXXDependentScopeMemberExpr>), internal
::Matcher<Expr> > (&hasObjectExpression_Type0)(internal
::Matcher<Expr> const &InnerMatcher); template <
typename NodeType, typename ParamT> bool internal:: matcher_hasObjectExpression0Matcher
<NodeType, ParamT>::matches( const NodeType &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
{
6399 if (const auto *E = dyn_cast<UnresolvedMemberExpr>(&Node))
6400 if (E->isImplicitAccess())
6401 return false;
6402 if (const auto *E = dyn_cast<CXXDependentScopeMemberExpr>(&Node))
6403 if (E->isImplicitAccess())
6404 return false;
6405 return InnerMatcher.matches(*Node.getBase(), Finder, Builder);
6406}
6407
6408/// Matches any using shadow declaration.
6409///
6410/// Given
6411/// \code
6412/// namespace X { void b(); }
6413/// using X::b;
6414/// \endcode
6415/// usingDecl(hasAnyUsingShadowDecl(hasName("b"))))
6416/// matches \code using X::b \endcode
6417AST_MATCHER_P(BaseUsingDecl, hasAnyUsingShadowDecl,namespace internal { class matcher_hasAnyUsingShadowDecl0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
BaseUsingDecl> { public: explicit matcher_hasAnyUsingShadowDecl0Matcher
( internal::Matcher<UsingShadowDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const BaseUsingDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<UsingShadowDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<BaseUsingDecl> hasAnyUsingShadowDecl( internal
::Matcher<UsingShadowDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasAnyUsingShadowDecl0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<BaseUsingDecl>
( &hasAnyUsingShadowDecl_Type0)(internal::Matcher<UsingShadowDecl
> const &InnerMatcher); inline bool internal::matcher_hasAnyUsingShadowDecl0Matcher
::matches( const BaseUsingDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6418 internal::Matcher<UsingShadowDecl>, InnerMatcher)namespace internal { class matcher_hasAnyUsingShadowDecl0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
BaseUsingDecl> { public: explicit matcher_hasAnyUsingShadowDecl0Matcher
( internal::Matcher<UsingShadowDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const BaseUsingDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<UsingShadowDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<BaseUsingDecl> hasAnyUsingShadowDecl( internal
::Matcher<UsingShadowDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasAnyUsingShadowDecl0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<BaseUsingDecl>
( &hasAnyUsingShadowDecl_Type0)(internal::Matcher<UsingShadowDecl
> const &InnerMatcher); inline bool internal::matcher_hasAnyUsingShadowDecl0Matcher
::matches( const BaseUsingDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6419 return matchesFirstInPointerRange(InnerMatcher, Node.shadow_begin(),
6420 Node.shadow_end(), Finder,
6421 Builder) != Node.shadow_end();
6422}
6423
6424/// Matches a using shadow declaration where the target declaration is
6425/// matched by the given matcher.
6426///
6427/// Given
6428/// \code
6429/// namespace X { int a; void b(); }
6430/// using X::a;
6431/// using X::b;
6432/// \endcode
6433/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl())))
6434/// matches \code using X::b \endcode
6435/// but not \code using X::a \endcode
6436AST_MATCHER_P(UsingShadowDecl, hasTargetDecl,namespace internal { class matcher_hasTargetDecl0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<UsingShadowDecl
> { public: explicit matcher_hasTargetDecl0Matcher( internal
::Matcher<NamedDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const UsingShadowDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<NamedDecl>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<UsingShadowDecl> hasTargetDecl( internal::Matcher<NamedDecl
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasTargetDecl0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<UsingShadowDecl> ( &hasTargetDecl_Type0)(internal::
Matcher<NamedDecl> const &InnerMatcher); inline bool
internal::matcher_hasTargetDecl0Matcher::matches( const UsingShadowDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6437 internal::Matcher<NamedDecl>, InnerMatcher)namespace internal { class matcher_hasTargetDecl0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<UsingShadowDecl
> { public: explicit matcher_hasTargetDecl0Matcher( internal
::Matcher<NamedDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const UsingShadowDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<NamedDecl>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<UsingShadowDecl> hasTargetDecl( internal::Matcher<NamedDecl
> const &InnerMatcher) { return ::clang::ast_matchers::
internal::makeMatcher( new internal::matcher_hasTargetDecl0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<UsingShadowDecl> ( &hasTargetDecl_Type0)(internal::
Matcher<NamedDecl> const &InnerMatcher); inline bool
internal::matcher_hasTargetDecl0Matcher::matches( const UsingShadowDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6438 return InnerMatcher.matches(*Node.getTargetDecl(), Finder, Builder);
6439}
6440
6441/// Matches template instantiations of function, class, or static
6442/// member variable template instantiations.
6443///
6444/// Given
6445/// \code
6446/// template <typename T> class X {}; class A {}; X<A> x;
6447/// \endcode
6448/// or
6449/// \code
6450/// template <typename T> class X {}; class A {}; template class X<A>;
6451/// \endcode
6452/// or
6453/// \code
6454/// template <typename T> class X {}; class A {}; extern template class X<A>;
6455/// \endcode
6456/// cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
6457/// matches the template instantiation of X<A>.
6458///
6459/// But given
6460/// \code
6461/// template <typename T> class X {}; class A {};
6462/// template <> class X<A> {}; X<A> x;
6463/// \endcode
6464/// cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
6465/// does not match, as X<A> is an explicit template specialization.
6466///
6467/// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
6468AST_POLYMORPHIC_MATCHER(isTemplateInstantiation,namespace internal { template <typename NodeType> class
matcher_isTemplateInstantiationMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isTemplateInstantiationMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl, CXXRecordDecl>)> isTemplateInstantiation() {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isTemplateInstantiationMatcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, VarDecl, CXXRecordDecl
>)>(); } template <typename NodeType> bool internal
::matcher_isTemplateInstantiationMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6469 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl,namespace internal { template <typename NodeType> class
matcher_isTemplateInstantiationMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isTemplateInstantiationMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl, CXXRecordDecl>)> isTemplateInstantiation() {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isTemplateInstantiationMatcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, VarDecl, CXXRecordDecl
>)>(); } template <typename NodeType> bool internal
::matcher_isTemplateInstantiationMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6470 CXXRecordDecl))namespace internal { template <typename NodeType> class
matcher_isTemplateInstantiationMatcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: bool matches
(const NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isTemplateInstantiationMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl, CXXRecordDecl>)> isTemplateInstantiation() {
return ::clang::ast_matchers::internal::PolymorphicMatcher<
internal::matcher_isTemplateInstantiationMatcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, VarDecl, CXXRecordDecl
>)>(); } template <typename NodeType> bool internal
::matcher_isTemplateInstantiationMatcher<NodeType>::matches
( const NodeType &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6471 return (Node.getTemplateSpecializationKind() == TSK_ImplicitInstantiation ||
6472 Node.getTemplateSpecializationKind() ==
6473 TSK_ExplicitInstantiationDefinition ||
6474 Node.getTemplateSpecializationKind() ==
6475 TSK_ExplicitInstantiationDeclaration);
6476}
6477
6478/// Matches declarations that are template instantiations or are inside
6479/// template instantiations.
6480///
6481/// Given
6482/// \code
6483/// template<typename T> void A(T t) { T i; }
6484/// A(0);
6485/// A(0U);
6486/// \endcode
6487/// functionDecl(isInstantiated())
6488/// matches 'A(int) {...};' and 'A(unsigned) {...}'.
6489AST_MATCHER_FUNCTION(internal::Matcher<Decl>, isInstantiated)inline internal::Matcher<Decl> isInstantiated_getInstance
(); inline internal::Matcher<Decl> isInstantiated() { return
::clang::ast_matchers::internal::MemoizedMatcher< internal
::Matcher<Decl>, isInstantiated_getInstance>::getInstance
(); } inline internal::Matcher<Decl> isInstantiated_getInstance
()
{
6490 auto IsInstantiation = decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
6491 functionDecl(isTemplateInstantiation())));
6492 return decl(anyOf(IsInstantiation, hasAncestor(IsInstantiation)));
6493}
6494
6495/// Matches statements inside of a template instantiation.
6496///
6497/// Given
6498/// \code
6499/// int j;
6500/// template<typename T> void A(T t) { T i; j += 42;}
6501/// A(0);
6502/// A(0U);
6503/// \endcode
6504/// declStmt(isInTemplateInstantiation())
6505/// matches 'int i;' and 'unsigned i'.
6506/// unless(stmt(isInTemplateInstantiation()))
6507/// will NOT match j += 42; as it's shared between the template definition and
6508/// instantiation.
6509AST_MATCHER_FUNCTION(internal::Matcher<Stmt>, isInTemplateInstantiation)inline internal::Matcher<Stmt> isInTemplateInstantiation_getInstance
(); inline internal::Matcher<Stmt> isInTemplateInstantiation
() { return ::clang::ast_matchers::internal::MemoizedMatcher<
internal::Matcher<Stmt>, isInTemplateInstantiation_getInstance
>::getInstance(); } inline internal::Matcher<Stmt> isInTemplateInstantiation_getInstance
()
{
6510 return stmt(
6511 hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
6512 functionDecl(isTemplateInstantiation())))));
6513}
6514
6515/// Matches explicit template specializations of function, class, or
6516/// static member variable template instantiations.
6517///
6518/// Given
6519/// \code
6520/// template<typename T> void A(T t) { }
6521/// template<> void A(int N) { }
6522/// \endcode
6523/// functionDecl(isExplicitTemplateSpecialization())
6524/// matches the specialization A<int>().
6525///
6526/// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl>
6527AST_POLYMORPHIC_MATCHER(isExplicitTemplateSpecialization,namespace internal { template <typename NodeType> class
matcher_isExplicitTemplateSpecializationMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isExplicitTemplateSpecializationMatcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, VarDecl, CXXRecordDecl
>)> isExplicitTemplateSpecialization() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExplicitTemplateSpecializationMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl, CXXRecordDecl>)>(); } template <typename NodeType
> bool internal::matcher_isExplicitTemplateSpecializationMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
6528 AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl,namespace internal { template <typename NodeType> class
matcher_isExplicitTemplateSpecializationMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isExplicitTemplateSpecializationMatcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, VarDecl, CXXRecordDecl
>)> isExplicitTemplateSpecialization() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExplicitTemplateSpecializationMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl, CXXRecordDecl>)>(); } template <typename NodeType
> bool internal::matcher_isExplicitTemplateSpecializationMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
6529 CXXRecordDecl))namespace internal { template <typename NodeType> class
matcher_isExplicitTemplateSpecializationMatcher : public ::clang
::ast_matchers::internal::MatcherInterface<NodeType> { public
: bool matches(const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_isExplicitTemplateSpecializationMatcher, void(::clang
::ast_matchers::internal::TypeList<FunctionDecl, VarDecl, CXXRecordDecl
>)> isExplicitTemplateSpecialization() { return ::clang
::ast_matchers::internal::PolymorphicMatcher< internal::matcher_isExplicitTemplateSpecializationMatcher
, void(::clang::ast_matchers::internal::TypeList<FunctionDecl
, VarDecl, CXXRecordDecl>)>(); } template <typename NodeType
> bool internal::matcher_isExplicitTemplateSpecializationMatcher
<NodeType>::matches( const NodeType &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const
{
6530 return (Node.getTemplateSpecializationKind() == TSK_ExplicitSpecialization);
6531}
6532
6533/// Matches \c TypeLocs for which the given inner
6534/// QualType-matcher matches.
6535AST_MATCHER_FUNCTION_P_OVERLOAD(internal::BindableMatcher<TypeLoc>, loc,inline internal::BindableMatcher<TypeLoc> loc(internal::
Matcher<QualType> const &InnerMatcher); typedef internal
::BindableMatcher<TypeLoc> (&loc_Type0)(internal::Matcher
<QualType> const &); inline internal::BindableMatcher
<TypeLoc> loc(internal::Matcher<QualType> const &
InnerMatcher)
6536 internal::Matcher<QualType>, InnerMatcher, 0)inline internal::BindableMatcher<TypeLoc> loc(internal::
Matcher<QualType> const &InnerMatcher); typedef internal
::BindableMatcher<TypeLoc> (&loc_Type0)(internal::Matcher
<QualType> const &); inline internal::BindableMatcher
<TypeLoc> loc(internal::Matcher<QualType> const &
InnerMatcher)
{
6537 return internal::BindableMatcher<TypeLoc>(
6538 new internal::TypeLocTypeMatcher(InnerMatcher));
6539}
6540
6541/// Matches `QualifiedTypeLoc`s in the clang AST.
6542///
6543/// Given
6544/// \code
6545/// const int x = 0;
6546/// \endcode
6547/// qualifiedTypeLoc()
6548/// matches `const int`.
6549extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, QualifiedTypeLoc>
6550 qualifiedTypeLoc;
6551
6552/// Matches `QualifiedTypeLoc`s that have an unqualified `TypeLoc` matching
6553/// `InnerMatcher`.
6554///
6555/// Given
6556/// \code
6557/// int* const x;
6558/// const int y;
6559/// \endcode
6560/// qualifiedTypeLoc(hasUnqualifiedLoc(pointerTypeLoc()))
6561/// matches the `TypeLoc` of the variable declaration of `x`, but not `y`.
6562AST_MATCHER_P(QualifiedTypeLoc, hasUnqualifiedLoc, internal::Matcher<TypeLoc>,namespace internal { class matcher_hasUnqualifiedLoc0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
QualifiedTypeLoc> { public: explicit matcher_hasUnqualifiedLoc0Matcher
( internal::Matcher<TypeLoc> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const QualifiedTypeLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<QualifiedTypeLoc> hasUnqualifiedLoc( internal
::Matcher<TypeLoc> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasUnqualifiedLoc0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualifiedTypeLoc> ( &hasUnqualifiedLoc_Type0)(internal
::Matcher<TypeLoc> const &InnerMatcher); inline bool
internal::matcher_hasUnqualifiedLoc0Matcher::matches( const QualifiedTypeLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6563 InnerMatcher)namespace internal { class matcher_hasUnqualifiedLoc0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
QualifiedTypeLoc> { public: explicit matcher_hasUnqualifiedLoc0Matcher
( internal::Matcher<TypeLoc> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const QualifiedTypeLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<QualifiedTypeLoc> hasUnqualifiedLoc( internal
::Matcher<TypeLoc> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_hasUnqualifiedLoc0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<QualifiedTypeLoc> ( &hasUnqualifiedLoc_Type0)(internal
::Matcher<TypeLoc> const &InnerMatcher); inline bool
internal::matcher_hasUnqualifiedLoc0Matcher::matches( const QualifiedTypeLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6564 return InnerMatcher.matches(Node.getUnqualifiedLoc(), Finder, Builder);
6565}
6566
6567/// Matches a function declared with the specified return `TypeLoc`.
6568///
6569/// Given
6570/// \code
6571/// int f() { return 5; }
6572/// void g() {}
6573/// \endcode
6574/// functionDecl(hasReturnTypeLoc(loc(asString("int"))))
6575/// matches the declaration of `f`, but not `g`.
6576AST_MATCHER_P(FunctionDecl, hasReturnTypeLoc, internal::Matcher<TypeLoc>,namespace internal { class matcher_hasReturnTypeLoc0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
FunctionDecl> { public: explicit matcher_hasReturnTypeLoc0Matcher
( internal::Matcher<TypeLoc> const &AReturnMatcher)
: ReturnMatcher(AReturnMatcher) {} bool matches(const FunctionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> ReturnMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<FunctionDecl> hasReturnTypeLoc( internal::Matcher
<TypeLoc> const &ReturnMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasReturnTypeLoc0Matcher
(ReturnMatcher)); } typedef ::clang::ast_matchers::internal::
Matcher<FunctionDecl> ( &hasReturnTypeLoc_Type0)(internal
::Matcher<TypeLoc> const &ReturnMatcher); inline bool
internal::matcher_hasReturnTypeLoc0Matcher::matches( const FunctionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6577 ReturnMatcher)namespace internal { class matcher_hasReturnTypeLoc0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
FunctionDecl> { public: explicit matcher_hasReturnTypeLoc0Matcher
( internal::Matcher<TypeLoc> const &AReturnMatcher)
: ReturnMatcher(AReturnMatcher) {} bool matches(const FunctionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> ReturnMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<FunctionDecl> hasReturnTypeLoc( internal::Matcher
<TypeLoc> const &ReturnMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasReturnTypeLoc0Matcher
(ReturnMatcher)); } typedef ::clang::ast_matchers::internal::
Matcher<FunctionDecl> ( &hasReturnTypeLoc_Type0)(internal
::Matcher<TypeLoc> const &ReturnMatcher); inline bool
internal::matcher_hasReturnTypeLoc0Matcher::matches( const FunctionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6578 auto Loc = Node.getFunctionTypeLoc();
6579 return Loc && ReturnMatcher.matches(Loc.getReturnLoc(), Finder, Builder);
6580}
6581
6582/// Matches pointer `TypeLoc`s.
6583///
6584/// Given
6585/// \code
6586/// int* x;
6587/// \endcode
6588/// pointerTypeLoc()
6589/// matches `int*`.
6590extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, PointerTypeLoc>
6591 pointerTypeLoc;
6592
6593/// Matches pointer `TypeLoc`s that have a pointee `TypeLoc` matching
6594/// `PointeeMatcher`.
6595///
6596/// Given
6597/// \code
6598/// int* x;
6599/// \endcode
6600/// pointerTypeLoc(hasPointeeLoc(loc(asString("int"))))
6601/// matches `int*`.
6602AST_MATCHER_P(PointerTypeLoc, hasPointeeLoc, internal::Matcher<TypeLoc>,namespace internal { class matcher_hasPointeeLoc0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<PointerTypeLoc
> { public: explicit matcher_hasPointeeLoc0Matcher( internal
::Matcher<TypeLoc> const &APointeeMatcher) : PointeeMatcher
(APointeeMatcher) {} bool matches(const PointerTypeLoc &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<TypeLoc> PointeeMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<PointerTypeLoc
> hasPointeeLoc( internal::Matcher<TypeLoc> const &
PointeeMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasPointeeLoc0Matcher(PointeeMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<PointerTypeLoc
> ( &hasPointeeLoc_Type0)(internal::Matcher<TypeLoc
> const &PointeeMatcher); inline bool internal::matcher_hasPointeeLoc0Matcher
::matches( const PointerTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6603 PointeeMatcher)namespace internal { class matcher_hasPointeeLoc0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<PointerTypeLoc
> { public: explicit matcher_hasPointeeLoc0Matcher( internal
::Matcher<TypeLoc> const &APointeeMatcher) : PointeeMatcher
(APointeeMatcher) {} bool matches(const PointerTypeLoc &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<TypeLoc> PointeeMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<PointerTypeLoc
> hasPointeeLoc( internal::Matcher<TypeLoc> const &
PointeeMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasPointeeLoc0Matcher(PointeeMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<PointerTypeLoc
> ( &hasPointeeLoc_Type0)(internal::Matcher<TypeLoc
> const &PointeeMatcher); inline bool internal::matcher_hasPointeeLoc0Matcher
::matches( const PointerTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6604 return PointeeMatcher.matches(Node.getPointeeLoc(), Finder, Builder);
6605}
6606
6607/// Matches reference `TypeLoc`s.
6608///
6609/// Given
6610/// \code
6611/// int x = 3;
6612/// int& l = x;
6613/// int&& r = 3;
6614/// \endcode
6615/// referenceTypeLoc()
6616/// matches `int&` and `int&&`.
6617extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ReferenceTypeLoc>
6618 referenceTypeLoc;
6619
6620/// Matches reference `TypeLoc`s that have a referent `TypeLoc` matching
6621/// `ReferentMatcher`.
6622///
6623/// Given
6624/// \code
6625/// int x = 3;
6626/// int& xx = x;
6627/// \endcode
6628/// referenceTypeLoc(hasReferentLoc(loc(asString("int"))))
6629/// matches `int&`.
6630AST_MATCHER_P(ReferenceTypeLoc, hasReferentLoc, internal::Matcher<TypeLoc>,namespace internal { class matcher_hasReferentLoc0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ReferenceTypeLoc
> { public: explicit matcher_hasReferentLoc0Matcher( internal
::Matcher<TypeLoc> const &AReferentMatcher) : ReferentMatcher
(AReferentMatcher) {} bool matches(const ReferenceTypeLoc &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<TypeLoc> ReferentMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ReferenceTypeLoc
> hasReferentLoc( internal::Matcher<TypeLoc> const &
ReferentMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasReferentLoc0Matcher(ReferentMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<ReferenceTypeLoc
> ( &hasReferentLoc_Type0)(internal::Matcher<TypeLoc
> const &ReferentMatcher); inline bool internal::matcher_hasReferentLoc0Matcher
::matches( const ReferenceTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6631 ReferentMatcher)namespace internal { class matcher_hasReferentLoc0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ReferenceTypeLoc
> { public: explicit matcher_hasReferentLoc0Matcher( internal
::Matcher<TypeLoc> const &AReferentMatcher) : ReferentMatcher
(AReferentMatcher) {} bool matches(const ReferenceTypeLoc &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<TypeLoc> ReferentMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ReferenceTypeLoc
> hasReferentLoc( internal::Matcher<TypeLoc> const &
ReferentMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasReferentLoc0Matcher(ReferentMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<ReferenceTypeLoc
> ( &hasReferentLoc_Type0)(internal::Matcher<TypeLoc
> const &ReferentMatcher); inline bool internal::matcher_hasReferentLoc0Matcher
::matches( const ReferenceTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6632 return ReferentMatcher.matches(Node.getPointeeLoc(), Finder, Builder);
6633}
6634
6635/// Matches template specialization `TypeLoc`s.
6636///
6637/// Given
6638/// \code
6639/// template <typename T> class C {};
6640/// C<char> var;
6641/// \endcode
6642/// varDecl(hasTypeLoc(templateSpecializationTypeLoc(typeLoc())))
6643/// matches `C<char> var`.
6644extern const internal::VariadicDynCastAllOfMatcher<
6645 TypeLoc, TemplateSpecializationTypeLoc>
6646 templateSpecializationTypeLoc;
6647
6648/// Matches template specialization `TypeLoc`s that have at least one
6649/// `TemplateArgumentLoc` matching the given `InnerMatcher`.
6650///
6651/// Given
6652/// \code
6653/// template<typename T> class A {};
6654/// A<int> a;
6655/// \endcode
6656/// varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasAnyTemplateArgumentLoc(
6657/// hasTypeLoc(loc(asString("int")))))))
6658/// matches `A<int> a`.
6659AST_MATCHER_P(TemplateSpecializationTypeLoc, hasAnyTemplateArgumentLoc,namespace internal { class matcher_hasAnyTemplateArgumentLoc0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateSpecializationTypeLoc> { public: explicit matcher_hasAnyTemplateArgumentLoc0Matcher
( internal::Matcher<TemplateArgumentLoc> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const TemplateSpecializationTypeLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgumentLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateSpecializationTypeLoc> hasAnyTemplateArgumentLoc
( internal::Matcher<TemplateArgumentLoc> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasAnyTemplateArgumentLoc0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<TemplateSpecializationTypeLoc
> ( &hasAnyTemplateArgumentLoc_Type0)(internal::Matcher
<TemplateArgumentLoc> const &InnerMatcher); inline bool
internal::matcher_hasAnyTemplateArgumentLoc0Matcher::matches
( const TemplateSpecializationTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6660 internal::Matcher<TemplateArgumentLoc>, InnerMatcher)namespace internal { class matcher_hasAnyTemplateArgumentLoc0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
TemplateSpecializationTypeLoc> { public: explicit matcher_hasAnyTemplateArgumentLoc0Matcher
( internal::Matcher<TemplateArgumentLoc> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const TemplateSpecializationTypeLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TemplateArgumentLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<TemplateSpecializationTypeLoc> hasAnyTemplateArgumentLoc
( internal::Matcher<TemplateArgumentLoc> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasAnyTemplateArgumentLoc0Matcher(InnerMatcher)); }
typedef ::clang::ast_matchers::internal::Matcher<TemplateSpecializationTypeLoc
> ( &hasAnyTemplateArgumentLoc_Type0)(internal::Matcher
<TemplateArgumentLoc> const &InnerMatcher); inline bool
internal::matcher_hasAnyTemplateArgumentLoc0Matcher::matches
( const TemplateSpecializationTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6661 for (unsigned Index = 0, N = Node.getNumArgs(); Index < N; ++Index) {
6662 clang::ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
6663 if (InnerMatcher.matches(Node.getArgLoc(Index), Finder, &Result)) {
6664 *Builder = std::move(Result);
6665 return true;
6666 }
6667 }
6668 return false;
6669}
6670
6671/// Matches template specialization `TypeLoc`s where the n'th
6672/// `TemplateArgumentLoc` matches the given `InnerMatcher`.
6673///
6674/// Given
6675/// \code
6676/// template<typename T, typename U> class A {};
6677/// A<double, int> b;
6678/// A<int, double> c;
6679/// \endcode
6680/// varDecl(hasTypeLoc(templateSpecializationTypeLoc(hasTemplateArgumentLoc(0,
6681/// hasTypeLoc(loc(asString("double")))))))
6682/// matches `A<double, int> b`, but not `A<int, double> c`.
6683AST_POLYMORPHIC_MATCHER_P2(namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgumentLoc0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgumentLoc0Matcher
(unsigned const &AIndex, internal::Matcher<TemplateArgumentLoc
> const &AInnerMatcher) : Index(AIndex), InnerMatcher(
AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: unsigned Index; internal::Matcher<TemplateArgumentLoc>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
> hasTemplateArgumentLoc(unsigned const &Index, internal
::Matcher<TemplateArgumentLoc> const &InnerMatcher)
{ return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
>(Index, InnerMatcher); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasTemplateArgumentLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, TemplateSpecializationTypeLoc>), unsigned, internal::Matcher
<TemplateArgumentLoc> > (&hasTemplateArgumentLoc_Type0
)( unsigned const &Index, internal::Matcher<TemplateArgumentLoc
> const &InnerMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_hasTemplateArgumentLoc0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
6684 hasTemplateArgumentLoc,namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgumentLoc0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgumentLoc0Matcher
(unsigned const &AIndex, internal::Matcher<TemplateArgumentLoc
> const &AInnerMatcher) : Index(AIndex), InnerMatcher(
AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: unsigned Index; internal::Matcher<TemplateArgumentLoc>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
> hasTemplateArgumentLoc(unsigned const &Index, internal
::Matcher<TemplateArgumentLoc> const &InnerMatcher)
{ return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
>(Index, InnerMatcher); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasTemplateArgumentLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, TemplateSpecializationTypeLoc>), unsigned, internal::Matcher
<TemplateArgumentLoc> > (&hasTemplateArgumentLoc_Type0
)( unsigned const &Index, internal::Matcher<TemplateArgumentLoc
> const &InnerMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_hasTemplateArgumentLoc0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
6685 AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr, TemplateSpecializationTypeLoc),namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgumentLoc0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgumentLoc0Matcher
(unsigned const &AIndex, internal::Matcher<TemplateArgumentLoc
> const &AInnerMatcher) : Index(AIndex), InnerMatcher(
AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: unsigned Index; internal::Matcher<TemplateArgumentLoc>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
> hasTemplateArgumentLoc(unsigned const &Index, internal
::Matcher<TemplateArgumentLoc> const &InnerMatcher)
{ return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
>(Index, InnerMatcher); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasTemplateArgumentLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, TemplateSpecializationTypeLoc>), unsigned, internal::Matcher
<TemplateArgumentLoc> > (&hasTemplateArgumentLoc_Type0
)( unsigned const &Index, internal::Matcher<TemplateArgumentLoc
> const &InnerMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_hasTemplateArgumentLoc0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
6686 unsigned, Index, internal::Matcher<TemplateArgumentLoc>, InnerMatcher)namespace internal { template <typename NodeType, typename
ParamT1, typename ParamT2> class matcher_hasTemplateArgumentLoc0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NodeType> { public: matcher_hasTemplateArgumentLoc0Matcher
(unsigned const &AIndex, internal::Matcher<TemplateArgumentLoc
> const &AInnerMatcher) : Index(AIndex), InnerMatcher(
AInnerMatcher) {} bool matches(const NodeType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: unsigned Index; internal::Matcher<TemplateArgumentLoc>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
> hasTemplateArgumentLoc(unsigned const &Index, internal
::Matcher<TemplateArgumentLoc> const &InnerMatcher)
{ return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_hasTemplateArgumentLoc0Matcher, void(::
clang::ast_matchers::internal::TypeList<DeclRefExpr, TemplateSpecializationTypeLoc
>), unsigned, internal::Matcher<TemplateArgumentLoc>
>(Index, InnerMatcher); } typedef ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_hasTemplateArgumentLoc0Matcher
, void(::clang::ast_matchers::internal::TypeList<DeclRefExpr
, TemplateSpecializationTypeLoc>), unsigned, internal::Matcher
<TemplateArgumentLoc> > (&hasTemplateArgumentLoc_Type0
)( unsigned const &Index, internal::Matcher<TemplateArgumentLoc
> const &InnerMatcher); template <typename NodeType
, typename ParamT1, typename ParamT2> bool internal::matcher_hasTemplateArgumentLoc0Matcher
< NodeType, ParamT1, ParamT2>:: matches(const NodeType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
6687 return internal::MatchTemplateArgLocAt(Node, Index, InnerMatcher, Finder,
6688 Builder);
6689}
6690
6691/// Matches C or C++ elaborated `TypeLoc`s.
6692///
6693/// Given
6694/// \code
6695/// struct s {};
6696/// struct s ss;
6697/// \endcode
6698/// elaboratedTypeLoc()
6699/// matches the `TypeLoc` of the variable declaration of `ss`.
6700extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
6701 elaboratedTypeLoc;
6702
6703/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
6704/// `InnerMatcher`.
6705///
6706/// Given
6707/// \code
6708/// template <typename T>
6709/// class C {};
6710/// class C<int> c;
6711///
6712/// class D {};
6713/// class D d;
6714/// \endcode
6715/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
6716/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
6717AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,namespace internal { class matcher_hasNamedTypeLoc0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ElaboratedTypeLoc
> { public: explicit matcher_hasNamedTypeLoc0Matcher( internal
::Matcher<TypeLoc> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ElaboratedTypeLoc &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<TypeLoc> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ElaboratedTypeLoc
> hasNamedTypeLoc( internal::Matcher<TypeLoc> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasNamedTypeLoc0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<ElaboratedTypeLoc
> ( &hasNamedTypeLoc_Type0)(internal::Matcher<TypeLoc
> const &InnerMatcher); inline bool internal::matcher_hasNamedTypeLoc0Matcher
::matches( const ElaboratedTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6718 InnerMatcher)namespace internal { class matcher_hasNamedTypeLoc0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ElaboratedTypeLoc
> { public: explicit matcher_hasNamedTypeLoc0Matcher( internal
::Matcher<TypeLoc> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ElaboratedTypeLoc &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<TypeLoc> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ElaboratedTypeLoc
> hasNamedTypeLoc( internal::Matcher<TypeLoc> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasNamedTypeLoc0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<ElaboratedTypeLoc
> ( &hasNamedTypeLoc_Type0)(internal::Matcher<TypeLoc
> const &InnerMatcher); inline bool internal::matcher_hasNamedTypeLoc0Matcher
::matches( const ElaboratedTypeLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6719 return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
6720}
6721
6722/// Matches type \c bool.
6723///
6724/// Given
6725/// \code
6726/// struct S { bool func(); };
6727/// \endcode
6728/// functionDecl(returns(booleanType()))
6729/// matches "bool func();"
6730AST_MATCHER(Type, booleanType)namespace internal { class matcher_booleanTypeMatcher : public
::clang::ast_matchers::internal::MatcherInterface<Type>
{ public: explicit matcher_booleanTypeMatcher() = default; bool
matches(const Type &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Type> booleanType() { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_booleanTypeMatcher
()); } inline bool internal::matcher_booleanTypeMatcher::matches
( const Type &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6731 return Node.isBooleanType();
6732}
6733
6734/// Matches type \c void.
6735///
6736/// Given
6737/// \code
6738/// struct S { void func(); };
6739/// \endcode
6740/// functionDecl(returns(voidType()))
6741/// matches "void func();"
6742AST_MATCHER(Type, voidType)namespace internal { class matcher_voidTypeMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<Type> {
public: explicit matcher_voidTypeMatcher() = default; bool matches
(const Type &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Type> voidType() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_voidTypeMatcher
()); } inline bool internal::matcher_voidTypeMatcher::matches
( const Type &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6743 return Node.isVoidType();
6744}
6745
6746template <typename NodeType>
6747using AstTypeMatcher = internal::VariadicDynCastAllOfMatcher<Type, NodeType>;
6748
6749/// Matches builtin Types.
6750///
6751/// Given
6752/// \code
6753/// struct A {};
6754/// A a;
6755/// int b;
6756/// float c;
6757/// bool d;
6758/// \endcode
6759/// builtinType()
6760/// matches "int b", "float c" and "bool d"
6761extern const AstTypeMatcher<BuiltinType> builtinType;
6762
6763/// Matches all kinds of arrays.
6764///
6765/// Given
6766/// \code
6767/// int a[] = { 2, 3 };
6768/// int b[4];
6769/// void f() { int c[a[0]]; }
6770/// \endcode
6771/// arrayType()
6772/// matches "int a[]", "int b[4]" and "int c[a[0]]";
6773extern const AstTypeMatcher<ArrayType> arrayType;
6774
6775/// Matches C99 complex types.
6776///
6777/// Given
6778/// \code
6779/// _Complex float f;
6780/// \endcode
6781/// complexType()
6782/// matches "_Complex float f"
6783extern const AstTypeMatcher<ComplexType> complexType;
6784
6785/// Matches any real floating-point type (float, double, long double).
6786///
6787/// Given
6788/// \code
6789/// int i;
6790/// float f;
6791/// \endcode
6792/// realFloatingPointType()
6793/// matches "float f" but not "int i"
6794AST_MATCHER(Type, realFloatingPointType)namespace internal { class matcher_realFloatingPointTypeMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Type> { public: explicit matcher_realFloatingPointTypeMatcher
() = default; bool matches(const Type &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<Type> realFloatingPointType
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_realFloatingPointTypeMatcher()); } inline bool
internal::matcher_realFloatingPointTypeMatcher::matches( const
Type &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6795 return Node.isRealFloatingType();
6796}
6797
6798/// Matches arrays and C99 complex types that have a specific element
6799/// type.
6800///
6801/// Given
6802/// \code
6803/// struct A {};
6804/// A a[7];
6805/// int b[7];
6806/// \endcode
6807/// arrayType(hasElementType(builtinType()))
6808/// matches "int b[7]"
6809///
6810/// Usable as: Matcher<ArrayType>, Matcher<ComplexType>
6811AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasElementType, getElement,namespace internal { template <typename T> struct TypeLocMatcherhasElementTypeGetter
{ static TypeLoc (T::*value())() const { return &T::getElementLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherhasElementTypeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<ArrayType, ComplexType
>)>::Func hasElementTypeLoc; namespace internal { template
<typename T> struct TypeMatcherhasElementTypeGetter { static
QualType (T::*value())() const { return &T::getElementType
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasElementTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<ArrayType, ComplexType
>)>::Func hasElementType
6812 AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType,namespace internal { template <typename T> struct TypeLocMatcherhasElementTypeGetter
{ static TypeLoc (T::*value())() const { return &T::getElementLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherhasElementTypeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<ArrayType, ComplexType
>)>::Func hasElementTypeLoc; namespace internal { template
<typename T> struct TypeMatcherhasElementTypeGetter { static
QualType (T::*value())() const { return &T::getElementType
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasElementTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<ArrayType, ComplexType
>)>::Func hasElementType
6813 ComplexType))namespace internal { template <typename T> struct TypeLocMatcherhasElementTypeGetter
{ static TypeLoc (T::*value())() const { return &T::getElementLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherhasElementTypeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<ArrayType, ComplexType
>)>::Func hasElementTypeLoc; namespace internal { template
<typename T> struct TypeMatcherhasElementTypeGetter { static
QualType (T::*value())() const { return &T::getElementType
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasElementTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<ArrayType, ComplexType
>)>::Func hasElementType
;
6814
6815/// Matches C arrays with a specified constant size.
6816///
6817/// Given
6818/// \code
6819/// void() {
6820/// int a[2];
6821/// int b[] = { 2, 3 };
6822/// int c[b[0]];
6823/// }
6824/// \endcode
6825/// constantArrayType()
6826/// matches "int a[2]"
6827extern const AstTypeMatcher<ConstantArrayType> constantArrayType;
6828
6829/// Matches nodes that have the specified size.
6830///
6831/// Given
6832/// \code
6833/// int a[42];
6834/// int b[2 * 21];
6835/// int c[41], d[43];
6836/// char *s = "abcd";
6837/// wchar_t *ws = L"abcd";
6838/// char *w = "a";
6839/// \endcode
6840/// constantArrayType(hasSize(42))
6841/// matches "int a[42]" and "int b[2 * 21]"
6842/// stringLiteral(hasSize(4))
6843/// matches "abcd", L"abcd"
6844AST_POLYMORPHIC_MATCHER_P(hasSize,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSize0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasSize0Matcher( unsigned const &AN) : N(AN) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSize0Matcher, void(::clang::ast_matchers::internal
::TypeList<ConstantArrayType, StringLiteral>), unsigned
> hasSize(unsigned const &N) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned> (&hasSize_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasSize0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6845 AST_POLYMORPHIC_SUPPORTED_TYPES(ConstantArrayType,namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSize0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasSize0Matcher( unsigned const &AN) : N(AN) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSize0Matcher, void(::clang::ast_matchers::internal
::TypeList<ConstantArrayType, StringLiteral>), unsigned
> hasSize(unsigned const &N) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned> (&hasSize_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasSize0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6846 StringLiteral),namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSize0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasSize0Matcher( unsigned const &AN) : N(AN) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSize0Matcher, void(::clang::ast_matchers::internal
::TypeList<ConstantArrayType, StringLiteral>), unsigned
> hasSize(unsigned const &N) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned> (&hasSize_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasSize0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
6847 unsigned, N)namespace internal { template <typename NodeType, typename
ParamT> class matcher_hasSize0Matcher : public ::clang::ast_matchers
::internal::MatcherInterface<NodeType> { public: explicit
matcher_hasSize0Matcher( unsigned const &AN) : N(AN) {} bool
matches(const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; }; } inline ::
clang::ast_matchers::internal::PolymorphicMatcher< internal
::matcher_hasSize0Matcher, void(::clang::ast_matchers::internal
::TypeList<ConstantArrayType, StringLiteral>), unsigned
> hasSize(unsigned const &N) { return ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned>(N); } typedef ::clang::ast_matchers
::internal::PolymorphicMatcher< internal::matcher_hasSize0Matcher
, void(::clang::ast_matchers::internal::TypeList<ConstantArrayType
, StringLiteral>), unsigned> (&hasSize_Type0)(unsigned
const &N); template <typename NodeType, typename ParamT
> bool internal:: matcher_hasSize0Matcher<NodeType, ParamT
>::matches( const NodeType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
6848 return internal::HasSizeMatcher<NodeType>::hasSize(Node, N);
6849}
6850
6851/// Matches C++ arrays whose size is a value-dependent expression.
6852///
6853/// Given
6854/// \code
6855/// template<typename T, int Size>
6856/// class array {
6857/// T data[Size];
6858/// };
6859/// \endcode
6860/// dependentSizedArrayType
6861/// matches "T data[Size]"
6862extern const AstTypeMatcher<DependentSizedArrayType> dependentSizedArrayType;
6863
6864/// Matches C arrays with unspecified size.
6865///
6866/// Given
6867/// \code
6868/// int a[] = { 2, 3 };
6869/// int b[42];
6870/// void f(int c[]) { int d[a[0]]; };
6871/// \endcode
6872/// incompleteArrayType()
6873/// matches "int a[]" and "int c[]"
6874extern const AstTypeMatcher<IncompleteArrayType> incompleteArrayType;
6875
6876/// Matches C arrays with a specified size that is not an
6877/// integer-constant-expression.
6878///
6879/// Given
6880/// \code
6881/// void f() {
6882/// int a[] = { 2, 3 }
6883/// int b[42];
6884/// int c[a[0]];
6885/// }
6886/// \endcode
6887/// variableArrayType()
6888/// matches "int c[a[0]]"
6889extern const AstTypeMatcher<VariableArrayType> variableArrayType;
6890
6891/// Matches \c VariableArrayType nodes that have a specific size
6892/// expression.
6893///
6894/// Given
6895/// \code
6896/// void f(int b) {
6897/// int a[b];
6898/// }
6899/// \endcode
6900/// variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to(
6901/// varDecl(hasName("b")))))))
6902/// matches "int a[b]"
6903AST_MATCHER_P(VariableArrayType, hasSizeExpr,namespace internal { class matcher_hasSizeExpr0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<VariableArrayType
> { public: explicit matcher_hasSizeExpr0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const VariableArrayType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<VariableArrayType
> hasSizeExpr( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasSizeExpr0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<VariableArrayType> ( &
hasSizeExpr_Type0)(internal::Matcher<Expr> const &InnerMatcher
); inline bool internal::matcher_hasSizeExpr0Matcher::matches
( const VariableArrayType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
6904 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasSizeExpr0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<VariableArrayType
> { public: explicit matcher_hasSizeExpr0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const VariableArrayType &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<VariableArrayType
> hasSizeExpr( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasSizeExpr0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<VariableArrayType> ( &
hasSizeExpr_Type0)(internal::Matcher<Expr> const &InnerMatcher
); inline bool internal::matcher_hasSizeExpr0Matcher::matches
( const VariableArrayType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
6905 return InnerMatcher.matches(*Node.getSizeExpr(), Finder, Builder);
6906}
6907
6908/// Matches atomic types.
6909///
6910/// Given
6911/// \code
6912/// _Atomic(int) i;
6913/// \endcode
6914/// atomicType()
6915/// matches "_Atomic(int) i"
6916extern const AstTypeMatcher<AtomicType> atomicType;
6917
6918/// Matches atomic types with a specific value type.
6919///
6920/// Given
6921/// \code
6922/// _Atomic(int) i;
6923/// _Atomic(float) f;
6924/// \endcode
6925/// atomicType(hasValueType(isInteger()))
6926/// matches "_Atomic(int) i"
6927///
6928/// Usable as: Matcher<AtomicType>
6929AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasValueType, getValue,namespace internal { template <typename T> struct TypeLocMatcherhasValueTypeGetter
{ static TypeLoc (T::*value())() const { return &T::getValueLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherhasValueTypeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<AtomicType>)
>::Func hasValueTypeLoc; namespace internal { template <
typename T> struct TypeMatcherhasValueTypeGetter { static QualType
(T::*value())() const { return &T::getValueType; } }; } extern
const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasValueTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<AtomicType>)>
::Func hasValueType
6930 AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType))namespace internal { template <typename T> struct TypeLocMatcherhasValueTypeGetter
{ static TypeLoc (T::*value())() const { return &T::getValueLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherhasValueTypeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<AtomicType>)
>::Func hasValueTypeLoc; namespace internal { template <
typename T> struct TypeMatcherhasValueTypeGetter { static QualType
(T::*value())() const { return &T::getValueType; } }; } extern
const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasValueTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<AtomicType>)>
::Func hasValueType
;
6931
6932/// Matches types nodes representing C++11 auto types.
6933///
6934/// Given:
6935/// \code
6936/// auto n = 4;
6937/// int v[] = { 2, 3 }
6938/// for (auto i : v) { }
6939/// \endcode
6940/// autoType()
6941/// matches "auto n" and "auto i"
6942extern const AstTypeMatcher<AutoType> autoType;
6943
6944/// Matches types nodes representing C++11 decltype(<expr>) types.
6945///
6946/// Given:
6947/// \code
6948/// short i = 1;
6949/// int j = 42;
6950/// decltype(i + j) result = i + j;
6951/// \endcode
6952/// decltypeType()
6953/// matches "decltype(i + j)"
6954extern const AstTypeMatcher<DecltypeType> decltypeType;
6955
6956/// Matches \c AutoType nodes where the deduced type is a specific type.
6957///
6958/// Note: There is no \c TypeLoc for the deduced type and thus no
6959/// \c getDeducedLoc() matcher.
6960///
6961/// Given
6962/// \code
6963/// auto a = 1;
6964/// auto b = 2.0;
6965/// \endcode
6966/// autoType(hasDeducedType(isInteger()))
6967/// matches "auto a"
6968///
6969/// Usable as: Matcher<AutoType>
6970AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,namespace internal { template <typename T> struct TypeMatcherhasDeducedTypeGetter
{ static QualType (T::*value())() const { return &T::getDeducedType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasDeducedTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<AutoType>)>
::Func hasDeducedType
6971 AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType))namespace internal { template <typename T> struct TypeMatcherhasDeducedTypeGetter
{ static QualType (T::*value())() const { return &T::getDeducedType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasDeducedTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<AutoType>)>
::Func hasDeducedType
;
6972
6973/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
6974///
6975/// Given
6976/// \code
6977/// decltype(1) a = 1;
6978/// decltype(2.0) b = 2.0;
6979/// \endcode
6980/// decltypeType(hasUnderlyingType(isInteger()))
6981/// matches the type of "a"
6982///
6983/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
6984AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,namespace internal { template <typename T> struct TypeMatcherhasUnderlyingTypeGetter
{ static QualType (T::*value())() const { return &T::getUnderlyingType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasUnderlyingTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<DecltypeType, UsingType
>)>::Func hasUnderlyingType
6985 AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,namespace internal { template <typename T> struct TypeMatcherhasUnderlyingTypeGetter
{ static QualType (T::*value())() const { return &T::getUnderlyingType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasUnderlyingTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<DecltypeType, UsingType
>)>::Func hasUnderlyingType
6986 UsingType))namespace internal { template <typename T> struct TypeMatcherhasUnderlyingTypeGetter
{ static QualType (T::*value())() const { return &T::getUnderlyingType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasUnderlyingTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<DecltypeType, UsingType
>)>::Func hasUnderlyingType
;
6987
6988/// Matches \c FunctionType nodes.
6989///
6990/// Given
6991/// \code
6992/// int (*f)(int);
6993/// void g();
6994/// \endcode
6995/// functionType()
6996/// matches "int (*f)(int)" and the type of "g".
6997extern const AstTypeMatcher<FunctionType> functionType;
6998
6999/// Matches \c FunctionProtoType nodes.
7000///
7001/// Given
7002/// \code
7003/// int (*f)(int);
7004/// void g();
7005/// \endcode
7006/// functionProtoType()
7007/// matches "int (*f)(int)" and the type of "g" in C++ mode.
7008/// In C mode, "g" is not matched because it does not contain a prototype.
7009extern const AstTypeMatcher<FunctionProtoType> functionProtoType;
7010
7011/// Matches \c ParenType nodes.
7012///
7013/// Given
7014/// \code
7015/// int (*ptr_to_array)[4];
7016/// int *array_of_ptrs[4];
7017/// \endcode
7018///
7019/// \c varDecl(hasType(pointsTo(parenType()))) matches \c ptr_to_array but not
7020/// \c array_of_ptrs.
7021extern const AstTypeMatcher<ParenType> parenType;
7022
7023/// Matches \c ParenType nodes where the inner type is a specific type.
7024///
7025/// Given
7026/// \code
7027/// int (*ptr_to_array)[4];
7028/// int (*ptr_to_func)(int);
7029/// \endcode
7030///
7031/// \c varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches
7032/// \c ptr_to_func but not \c ptr_to_array.
7033///
7034/// Usable as: Matcher<ParenType>
7035AST_TYPE_TRAVERSE_MATCHER(innerType, getInnerType,namespace internal { template <typename T> struct TypeMatcherinnerTypeGetter
{ static QualType (T::*value())() const { return &T::getInnerType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherinnerTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<ParenType>)>
::Func innerType
7036 AST_POLYMORPHIC_SUPPORTED_TYPES(ParenType))namespace internal { template <typename T> struct TypeMatcherinnerTypeGetter
{ static QualType (T::*value())() const { return &T::getInnerType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherinnerTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<ParenType>)>
::Func innerType
;
7037
7038/// Matches block pointer types, i.e. types syntactically represented as
7039/// "void (^)(int)".
7040///
7041/// The \c pointee is always required to be a \c FunctionType.
7042extern const AstTypeMatcher<BlockPointerType> blockPointerType;
7043
7044/// Matches member pointer types.
7045/// Given
7046/// \code
7047/// struct A { int i; }
7048/// A::* ptr = A::i;
7049/// \endcode
7050/// memberPointerType()
7051/// matches "A::* ptr"
7052extern const AstTypeMatcher<MemberPointerType> memberPointerType;
7053
7054/// Matches pointer types, but does not match Objective-C object pointer
7055/// types.
7056///
7057/// Given
7058/// \code
7059/// int *a;
7060/// int &b = *a;
7061/// int c = 5;
7062///
7063/// @interface Foo
7064/// @end
7065/// Foo *f;
7066/// \endcode
7067/// pointerType()
7068/// matches "int *a", but does not match "Foo *f".
7069extern const AstTypeMatcher<PointerType> pointerType;
7070
7071/// Matches an Objective-C object pointer type, which is different from
7072/// a pointer type, despite being syntactically similar.
7073///
7074/// Given
7075/// \code
7076/// int *a;
7077///
7078/// @interface Foo
7079/// @end
7080/// Foo *f;
7081/// \endcode
7082/// pointerType()
7083/// matches "Foo *f", but does not match "int *a".
7084extern const AstTypeMatcher<ObjCObjectPointerType> objcObjectPointerType;
7085
7086/// Matches both lvalue and rvalue reference types.
7087///
7088/// Given
7089/// \code
7090/// int *a;
7091/// int &b = *a;
7092/// int &&c = 1;
7093/// auto &d = b;
7094/// auto &&e = c;
7095/// auto &&f = 2;
7096/// int g = 5;
7097/// \endcode
7098///
7099/// \c referenceType() matches the types of \c b, \c c, \c d, \c e, and \c f.
7100extern const AstTypeMatcher<ReferenceType> referenceType;
7101
7102/// Matches lvalue reference types.
7103///
7104/// Given:
7105/// \code
7106/// int *a;
7107/// int &b = *a;
7108/// int &&c = 1;
7109/// auto &d = b;
7110/// auto &&e = c;
7111/// auto &&f = 2;
7112/// int g = 5;
7113/// \endcode
7114///
7115/// \c lValueReferenceType() matches the types of \c b, \c d, and \c e. \c e is
7116/// matched since the type is deduced as int& by reference collapsing rules.
7117extern const AstTypeMatcher<LValueReferenceType> lValueReferenceType;
7118
7119/// Matches rvalue reference types.
7120///
7121/// Given:
7122/// \code
7123/// int *a;
7124/// int &b = *a;
7125/// int &&c = 1;
7126/// auto &d = b;
7127/// auto &&e = c;
7128/// auto &&f = 2;
7129/// int g = 5;
7130/// \endcode
7131///
7132/// \c rValueReferenceType() matches the types of \c c and \c f. \c e is not
7133/// matched as it is deduced to int& by reference collapsing rules.
7134extern const AstTypeMatcher<RValueReferenceType> rValueReferenceType;
7135
7136/// Narrows PointerType (and similar) matchers to those where the
7137/// \c pointee matches a given matcher.
7138///
7139/// Given
7140/// \code
7141/// int *a;
7142/// int const *b;
7143/// float const *f;
7144/// \endcode
7145/// pointerType(pointee(isConstQualified(), isInteger()))
7146/// matches "int const *b"
7147///
7148/// Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>,
7149/// Matcher<PointerType>, Matcher<ReferenceType>
7150AST_TYPELOC_TRAVERSE_MATCHER_DECL(namespace internal { template <typename T> struct TypeLocMatcherpointeeGetter
{ static TypeLoc (T::*value())() const { return &T::getPointeeLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointeeLoc; namespace internal { template <typename T>
struct TypeMatcherpointeeGetter { static QualType (T::*value
())() const { return &T::getPointeeType; } }; } extern const
::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointee
7151 pointee, getPointee,namespace internal { template <typename T> struct TypeLocMatcherpointeeGetter
{ static TypeLoc (T::*value())() const { return &T::getPointeeLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointeeLoc; namespace internal { template <typename T>
struct TypeMatcherpointeeGetter { static QualType (T::*value
())() const { return &T::getPointeeType; } }; } extern const
::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointee
7152 AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType,namespace internal { template <typename T> struct TypeLocMatcherpointeeGetter
{ static TypeLoc (T::*value())() const { return &T::getPointeeLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointeeLoc; namespace internal { template <typename T>
struct TypeMatcherpointeeGetter { static QualType (T::*value
())() const { return &T::getPointeeType; } }; } extern const
::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointee
7153 PointerType, ReferenceType))namespace internal { template <typename T> struct TypeLocMatcherpointeeGetter
{ static TypeLoc (T::*value())() const { return &T::getPointeeLoc
; } }; } extern const ::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< TypeLoc, ::clang::ast_matchers::internal:: TypeLocMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeLocTraverseMatcher, void
(::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointeeLoc; namespace internal { template <typename T>
struct TypeMatcherpointeeGetter { static QualType (T::*value
())() const { return &T::getPointeeType; } }; } extern const
::clang::ast_matchers::internal:: TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherpointeeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<BlockPointerType
, MemberPointerType, PointerType, ReferenceType>)>::Func
pointee
;
7154
7155/// Matches typedef types.
7156///
7157/// Given
7158/// \code
7159/// typedef int X;
7160/// \endcode
7161/// typedefType()
7162/// matches "typedef int X"
7163extern const AstTypeMatcher<TypedefType> typedefType;
7164
7165/// Matches enum types.
7166///
7167/// Given
7168/// \code
7169/// enum C { Green };
7170/// enum class S { Red };
7171///
7172/// C c;
7173/// S s;
7174/// \endcode
7175//
7176/// \c enumType() matches the type of the variable declarations of both \c c and
7177/// \c s.
7178extern const AstTypeMatcher<EnumType> enumType;
7179
7180/// Matches template specialization types.
7181///
7182/// Given
7183/// \code
7184/// template <typename T>
7185/// class C { };
7186///
7187/// template class C<int>; // A
7188/// C<char> var; // B
7189/// \endcode
7190///
7191/// \c templateSpecializationType() matches the type of the explicit
7192/// instantiation in \c A and the type of the variable declaration in \c B.
7193extern const AstTypeMatcher<TemplateSpecializationType>
7194 templateSpecializationType;
7195
7196/// Matches C++17 deduced template specialization types, e.g. deduced class
7197/// template types.
7198///
7199/// Given
7200/// \code
7201/// template <typename T>
7202/// class C { public: C(T); };
7203///
7204/// C c(123);
7205/// \endcode
7206/// \c deducedTemplateSpecializationType() matches the type in the declaration
7207/// of the variable \c c.
7208extern const AstTypeMatcher<DeducedTemplateSpecializationType>
7209 deducedTemplateSpecializationType;
7210
7211/// Matches types nodes representing unary type transformations.
7212///
7213/// Given:
7214/// \code
7215/// typedef __underlying_type(T) type;
7216/// \endcode
7217/// unaryTransformType()
7218/// matches "__underlying_type(T)"
7219extern const AstTypeMatcher<UnaryTransformType> unaryTransformType;
7220
7221/// Matches record types (e.g. structs, classes).
7222///
7223/// Given
7224/// \code
7225/// class C {};
7226/// struct S {};
7227///
7228/// C c;
7229/// S s;
7230/// \endcode
7231///
7232/// \c recordType() matches the type of the variable declarations of both \c c
7233/// and \c s.
7234extern const AstTypeMatcher<RecordType> recordType;
7235
7236/// Matches tag types (record and enum types).
7237///
7238/// Given
7239/// \code
7240/// enum E {};
7241/// class C {};
7242///
7243/// E e;
7244/// C c;
7245/// \endcode
7246///
7247/// \c tagType() matches the type of the variable declarations of both \c e
7248/// and \c c.
7249extern const AstTypeMatcher<TagType> tagType;
7250
7251/// Matches types specified with an elaborated type keyword or with a
7252/// qualified name.
7253///
7254/// Given
7255/// \code
7256/// namespace N {
7257/// namespace M {
7258/// class D {};
7259/// }
7260/// }
7261/// class C {};
7262///
7263/// class C c;
7264/// N::M::D d;
7265/// \endcode
7266///
7267/// \c elaboratedType() matches the type of the variable declarations of both
7268/// \c c and \c d.
7269extern const AstTypeMatcher<ElaboratedType> elaboratedType;
7270
7271/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
7272/// matches \c InnerMatcher if the qualifier exists.
7273///
7274/// Given
7275/// \code
7276/// namespace N {
7277/// namespace M {
7278/// class D {};
7279/// }
7280/// }
7281/// N::M::D d;
7282/// \endcode
7283///
7284/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
7285/// matches the type of the variable declaration of \c d.
7286AST_MATCHER_P(ElaboratedType, hasQualifier,namespace internal { class matcher_hasQualifier0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ElaboratedType
> { public: explicit matcher_hasQualifier0Matcher( internal
::Matcher<NestedNameSpecifier> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const ElaboratedType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifier
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ElaboratedType> hasQualifier( internal::Matcher
<NestedNameSpecifier> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasQualifier0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ElaboratedType> ( &
hasQualifier_Type0)(internal::Matcher<NestedNameSpecifier>
const &InnerMatcher); inline bool internal::matcher_hasQualifier0Matcher
::matches( const ElaboratedType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7287 internal::Matcher<NestedNameSpecifier>, InnerMatcher)namespace internal { class matcher_hasQualifier0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ElaboratedType
> { public: explicit matcher_hasQualifier0Matcher( internal
::Matcher<NestedNameSpecifier> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const ElaboratedType
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifier
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<ElaboratedType> hasQualifier( internal::Matcher
<NestedNameSpecifier> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasQualifier0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<ElaboratedType> ( &
hasQualifier_Type0)(internal::Matcher<NestedNameSpecifier>
const &InnerMatcher); inline bool internal::matcher_hasQualifier0Matcher
::matches( const ElaboratedType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7288 if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
7289 return InnerMatcher.matches(*Qualifier, Finder, Builder);
7290
7291 return false;
7292}
7293
7294/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
7295///
7296/// Given
7297/// \code
7298/// namespace N {
7299/// namespace M {
7300/// class D {};
7301/// }
7302/// }
7303/// N::M::D d;
7304/// \endcode
7305///
7306/// \c elaboratedType(namesType(recordType(
7307/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
7308/// declaration of \c d.
7309AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,namespace internal { class matcher_namesType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ElaboratedType
> { public: explicit matcher_namesType0Matcher( internal::
Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ElaboratedType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ElaboratedType
> namesType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_namesType0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<ElaboratedType>
( &namesType_Type0)(internal::Matcher<QualType> const
&InnerMatcher); inline bool internal::matcher_namesType0Matcher
::matches( const ElaboratedType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7310 InnerMatcher)namespace internal { class matcher_namesType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ElaboratedType
> { public: explicit matcher_namesType0Matcher( internal::
Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ElaboratedType &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ElaboratedType
> namesType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_namesType0Matcher(InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<ElaboratedType>
( &namesType_Type0)(internal::Matcher<QualType> const
&InnerMatcher); inline bool internal::matcher_namesType0Matcher
::matches( const ElaboratedType &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7311 return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
7312}
7313
7314/// Matches types specified through a using declaration.
7315///
7316/// Given
7317/// \code
7318/// namespace a { struct S {}; }
7319/// using a::S;
7320/// S s;
7321/// \endcode
7322///
7323/// \c usingType() matches the type of the variable declaration of \c s.
7324extern const AstTypeMatcher<UsingType> usingType;
7325
7326/// Matches types that represent the result of substituting a type for a
7327/// template type parameter.
7328///
7329/// Given
7330/// \code
7331/// template <typename T>
7332/// void F(T t) {
7333/// int i = 1 + t;
7334/// }
7335/// \endcode
7336///
7337/// \c substTemplateTypeParmType() matches the type of 't' but not '1'
7338extern const AstTypeMatcher<SubstTemplateTypeParmType>
7339 substTemplateTypeParmType;
7340
7341/// Matches template type parameter substitutions that have a replacement
7342/// type that matches the provided matcher.
7343///
7344/// Given
7345/// \code
7346/// template <typename T>
7347/// double F(T t);
7348/// int i;
7349/// double j = F(i);
7350/// \endcode
7351///
7352/// \c substTemplateTypeParmType(hasReplacementType(type())) matches int
7353AST_TYPE_TRAVERSE_MATCHER(namespace internal { template <typename T> struct TypeMatcherhasReplacementTypeGetter
{ static QualType (T::*value())() const { return &T::getReplacementType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasReplacementTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<SubstTemplateTypeParmType
>)>::Func hasReplacementType
7354 hasReplacementType, getReplacementType,namespace internal { template <typename T> struct TypeMatcherhasReplacementTypeGetter
{ static QualType (T::*value())() const { return &T::getReplacementType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasReplacementTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<SubstTemplateTypeParmType
>)>::Func hasReplacementType
7355 AST_POLYMORPHIC_SUPPORTED_TYPES(SubstTemplateTypeParmType))namespace internal { template <typename T> struct TypeMatcherhasReplacementTypeGetter
{ static QualType (T::*value())() const { return &T::getReplacementType
; } }; } const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher
< QualType, ::clang::ast_matchers::internal::TypeMatcherhasReplacementTypeGetter
, ::clang::ast_matchers::internal::TypeTraverseMatcher, void(
::clang::ast_matchers::internal::TypeList<SubstTemplateTypeParmType
>)>::Func hasReplacementType
;
7356
7357/// Matches template type parameter types.
7358///
7359/// Example matches T, but not int.
7360/// (matcher = templateTypeParmType())
7361/// \code
7362/// template <typename T> void f(int i);
7363/// \endcode
7364extern const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType;
7365
7366/// Matches injected class name types.
7367///
7368/// Example matches S s, but not S<T> s.
7369/// (matcher = parmVarDecl(hasType(injectedClassNameType())))
7370/// \code
7371/// template <typename T> struct S {
7372/// void f(S s);
7373/// void g(S<T> s);
7374/// };
7375/// \endcode
7376extern const AstTypeMatcher<InjectedClassNameType> injectedClassNameType;
7377
7378/// Matches decayed type
7379/// Example matches i[] in declaration of f.
7380/// (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType())))))
7381/// Example matches i[1].
7382/// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType())))))
7383/// \code
7384/// void f(int i[]) {
7385/// i[1] = 0;
7386/// }
7387/// \endcode
7388extern const AstTypeMatcher<DecayedType> decayedType;
7389
7390/// Matches the decayed type, whoes decayed type matches \c InnerMatcher
7391AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher<QualType>,namespace internal { class matcher_hasDecayedType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DecayedType
> { public: explicit matcher_hasDecayedType0Matcher( internal
::Matcher<QualType> const &AInnerType) : InnerType(
AInnerType) {} bool matches(const DecayedType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerType; }; } inline ::
clang::ast_matchers::internal::Matcher<DecayedType> hasDecayedType
( internal::Matcher<QualType> const &InnerType) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDecayedType0Matcher(InnerType)); } typedef ::clang
::ast_matchers::internal::Matcher<DecayedType> ( &hasDecayedType_Type0
)(internal::Matcher<QualType> const &InnerType); inline
bool internal::matcher_hasDecayedType0Matcher::matches( const
DecayedType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7392 InnerType)namespace internal { class matcher_hasDecayedType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DecayedType
> { public: explicit matcher_hasDecayedType0Matcher( internal
::Matcher<QualType> const &AInnerType) : InnerType(
AInnerType) {} bool matches(const DecayedType &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<QualType> InnerType; }; } inline ::
clang::ast_matchers::internal::Matcher<DecayedType> hasDecayedType
( internal::Matcher<QualType> const &InnerType) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDecayedType0Matcher(InnerType)); } typedef ::clang
::ast_matchers::internal::Matcher<DecayedType> ( &hasDecayedType_Type0
)(internal::Matcher<QualType> const &InnerType); inline
bool internal::matcher_hasDecayedType0Matcher::matches( const
DecayedType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7393 return InnerType.matches(Node.getDecayedType(), Finder, Builder);
7394}
7395
7396/// Matches declarations whose declaration context, interpreted as a
7397/// Decl, matches \c InnerMatcher.
7398///
7399/// Given
7400/// \code
7401/// namespace N {
7402/// namespace M {
7403/// class D {};
7404/// }
7405/// }
7406/// \endcode
7407///
7408/// \c cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the
7409/// declaration of \c class \c D.
7410AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher)namespace internal { class matcher_hasDeclContext0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Decl>
{ public: explicit matcher_hasDeclContext0Matcher( internal::
Matcher<Decl> const &AInnerMatcher) : InnerMatcher(
AInnerMatcher) {} bool matches(const Decl &Node, ::clang::
ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Decl> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<Decl> hasDeclContext(
internal::Matcher<Decl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasDeclContext0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Decl> ( &hasDeclContext_Type0
)(internal::Matcher<Decl> const &InnerMatcher); inline
bool internal::matcher_hasDeclContext0Matcher::matches( const
Decl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7411 const DeclContext *DC = Node.getDeclContext();
7412 if (!DC) return false;
7413 return InnerMatcher.matches(*Decl::castFromDeclContext(DC), Finder, Builder);
7414}
7415
7416/// Matches nested name specifiers.
7417///
7418/// Given
7419/// \code
7420/// namespace ns {
7421/// struct A { static void f(); };
7422/// void A::f() {}
7423/// void g() { A::f(); }
7424/// }
7425/// ns::A a;
7426/// \endcode
7427/// nestedNameSpecifier()
7428/// matches "ns::" and both "A::"
7429extern const internal::VariadicAllOfMatcher<NestedNameSpecifier>
7430 nestedNameSpecifier;
7431
7432/// Same as \c nestedNameSpecifier but matches \c NestedNameSpecifierLoc.
7433extern const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc>
7434 nestedNameSpecifierLoc;
7435
7436/// Matches \c NestedNameSpecifierLocs for which the given inner
7437/// NestedNameSpecifier-matcher matches.
7438AST_MATCHER_FUNCTION_P_OVERLOAD(inline internal::BindableMatcher<NestedNameSpecifierLoc>
loc(internal::Matcher<NestedNameSpecifier> const &
InnerMatcher); typedef internal::BindableMatcher<NestedNameSpecifierLoc
> (&loc_Type1)(internal::Matcher<NestedNameSpecifier
> const &); inline internal::BindableMatcher<NestedNameSpecifierLoc
> loc(internal::Matcher<NestedNameSpecifier> const &
InnerMatcher)
7439 internal::BindableMatcher<NestedNameSpecifierLoc>, loc,inline internal::BindableMatcher<NestedNameSpecifierLoc>
loc(internal::Matcher<NestedNameSpecifier> const &
InnerMatcher); typedef internal::BindableMatcher<NestedNameSpecifierLoc
> (&loc_Type1)(internal::Matcher<NestedNameSpecifier
> const &); inline internal::BindableMatcher<NestedNameSpecifierLoc
> loc(internal::Matcher<NestedNameSpecifier> const &
InnerMatcher)
7440 internal::Matcher<NestedNameSpecifier>, InnerMatcher, 1)inline internal::BindableMatcher<NestedNameSpecifierLoc>
loc(internal::Matcher<NestedNameSpecifier> const &
InnerMatcher); typedef internal::BindableMatcher<NestedNameSpecifierLoc
> (&loc_Type1)(internal::Matcher<NestedNameSpecifier
> const &); inline internal::BindableMatcher<NestedNameSpecifierLoc
> loc(internal::Matcher<NestedNameSpecifier> const &
InnerMatcher)
{
7441 return internal::BindableMatcher<NestedNameSpecifierLoc>(
7442 new internal::LocMatcher<NestedNameSpecifierLoc, NestedNameSpecifier>(
7443 InnerMatcher));
7444}
7445
7446/// Matches nested name specifiers that specify a type matching the
7447/// given \c QualType matcher without qualifiers.
7448///
7449/// Given
7450/// \code
7451/// struct A { struct B { struct C {}; }; };
7452/// A::B::C c;
7453/// \endcode
7454/// nestedNameSpecifier(specifiesType(
7455/// hasDeclaration(cxxRecordDecl(hasName("A")))
7456/// ))
7457/// matches "A::"
7458AST_MATCHER_P(NestedNameSpecifier, specifiesType,namespace internal { class matcher_specifiesType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifier
> { public: explicit matcher_specifiesType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NestedNameSpecifier &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<NestedNameSpecifier
> specifiesType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_specifiesType0Matcher(InnerMatcher));
} typedef ::clang::ast_matchers::internal::Matcher<NestedNameSpecifier
> ( &specifiesType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_specifiesType0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7459 internal::Matcher<QualType>, InnerMatcher)namespace internal { class matcher_specifiesType0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifier
> { public: explicit matcher_specifiesType0Matcher( internal
::Matcher<QualType> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const NestedNameSpecifier &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<QualType> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<NestedNameSpecifier
> specifiesType( internal::Matcher<QualType> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_specifiesType0Matcher(InnerMatcher));
} typedef ::clang::ast_matchers::internal::Matcher<NestedNameSpecifier
> ( &specifiesType_Type0)(internal::Matcher<QualType
> const &InnerMatcher); inline bool internal::matcher_specifiesType0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7460 if (!Node.getAsType())
7461 return false;
7462 return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
7463}
7464
7465/// Matches nested name specifier locs that specify a type matching the
7466/// given \c TypeLoc.
7467///
7468/// Given
7469/// \code
7470/// struct A { struct B { struct C {}; }; };
7471/// A::B::C c;
7472/// \endcode
7473/// nestedNameSpecifierLoc(specifiesTypeLoc(loc(type(
7474/// hasDeclaration(cxxRecordDecl(hasName("A")))))))
7475/// matches "A::"
7476AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,namespace internal { class matcher_specifiesTypeLoc0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NestedNameSpecifierLoc> { public: explicit matcher_specifiesTypeLoc0Matcher
( internal::Matcher<TypeLoc> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifierLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifierLoc> specifiesTypeLoc( internal
::Matcher<TypeLoc> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_specifiesTypeLoc0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<NestedNameSpecifierLoc> ( &specifiesTypeLoc_Type0)
(internal::Matcher<TypeLoc> const &InnerMatcher); inline
bool internal::matcher_specifiesTypeLoc0Matcher::matches( const
NestedNameSpecifierLoc &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7477 internal::Matcher<TypeLoc>, InnerMatcher)namespace internal { class matcher_specifiesTypeLoc0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
NestedNameSpecifierLoc> { public: explicit matcher_specifiesTypeLoc0Matcher
( internal::Matcher<TypeLoc> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifierLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<TypeLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifierLoc> specifiesTypeLoc( internal
::Matcher<TypeLoc> const &InnerMatcher) { return ::
clang::ast_matchers::internal::makeMatcher( new internal::matcher_specifiesTypeLoc0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<NestedNameSpecifierLoc> ( &specifiesTypeLoc_Type0)
(internal::Matcher<TypeLoc> const &InnerMatcher); inline
bool internal::matcher_specifiesTypeLoc0Matcher::matches( const
NestedNameSpecifierLoc &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7478 return Node && Node.getNestedNameSpecifier()->getAsType() &&
7479 InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
7480}
7481
7482/// Matches on the prefix of a \c NestedNameSpecifier.
7483///
7484/// Given
7485/// \code
7486/// struct A { struct B { struct C {}; }; };
7487/// A::B::C c;
7488/// \endcode
7489/// nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and
7490/// matches "A::"
7491AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,namespace internal { class matcher_hasPrefix0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifier
> { public: explicit matcher_hasPrefix0Matcher( internal::
Matcher<NestedNameSpecifier> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifier
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifier
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifier> hasPrefix( internal::Matcher
<NestedNameSpecifier> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasPrefix0Matcher(InnerMatcher)); } typedef ::clang::
ast_matchers::internal::Matcher<NestedNameSpecifier> ( &
hasPrefix_Type0)(internal::Matcher<NestedNameSpecifier>
const &InnerMatcher); inline bool internal::matcher_hasPrefix0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7492 internal::Matcher<NestedNameSpecifier>, InnerMatcher,namespace internal { class matcher_hasPrefix0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifier
> { public: explicit matcher_hasPrefix0Matcher( internal::
Matcher<NestedNameSpecifier> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifier
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifier
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifier> hasPrefix( internal::Matcher
<NestedNameSpecifier> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasPrefix0Matcher(InnerMatcher)); } typedef ::clang::
ast_matchers::internal::Matcher<NestedNameSpecifier> ( &
hasPrefix_Type0)(internal::Matcher<NestedNameSpecifier>
const &InnerMatcher); inline bool internal::matcher_hasPrefix0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7493 0)namespace internal { class matcher_hasPrefix0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifier
> { public: explicit matcher_hasPrefix0Matcher( internal::
Matcher<NestedNameSpecifier> const &AInnerMatcher) :
InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifier
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifier
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifier> hasPrefix( internal::Matcher
<NestedNameSpecifier> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasPrefix0Matcher(InnerMatcher)); } typedef ::clang::
ast_matchers::internal::Matcher<NestedNameSpecifier> ( &
hasPrefix_Type0)(internal::Matcher<NestedNameSpecifier>
const &InnerMatcher); inline bool internal::matcher_hasPrefix0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7494 const NestedNameSpecifier *NextNode = Node.getPrefix();
7495 if (!NextNode)
7496 return false;
7497 return InnerMatcher.matches(*NextNode, Finder, Builder);
7498}
7499
7500/// Matches on the prefix of a \c NestedNameSpecifierLoc.
7501///
7502/// Given
7503/// \code
7504/// struct A { struct B { struct C {}; }; };
7505/// A::B::C c;
7506/// \endcode
7507/// nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A")))))
7508/// matches "A::"
7509AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,namespace internal { class matcher_hasPrefix1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifierLoc
> { public: explicit matcher_hasPrefix1Matcher( internal::
Matcher<NestedNameSpecifierLoc> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifierLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifierLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifierLoc> hasPrefix( internal::
Matcher<NestedNameSpecifierLoc> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasPrefix1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<NestedNameSpecifierLoc>
( &hasPrefix_Type1)(internal::Matcher<NestedNameSpecifierLoc
> const &InnerMatcher); inline bool internal::matcher_hasPrefix1Matcher
::matches( const NestedNameSpecifierLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7510 internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,namespace internal { class matcher_hasPrefix1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifierLoc
> { public: explicit matcher_hasPrefix1Matcher( internal::
Matcher<NestedNameSpecifierLoc> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifierLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifierLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifierLoc> hasPrefix( internal::
Matcher<NestedNameSpecifierLoc> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasPrefix1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<NestedNameSpecifierLoc>
( &hasPrefix_Type1)(internal::Matcher<NestedNameSpecifierLoc
> const &InnerMatcher); inline bool internal::matcher_hasPrefix1Matcher
::matches( const NestedNameSpecifierLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7511 1)namespace internal { class matcher_hasPrefix1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<NestedNameSpecifierLoc
> { public: explicit matcher_hasPrefix1Matcher( internal::
Matcher<NestedNameSpecifierLoc> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifierLoc
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NestedNameSpecifierLoc
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifierLoc> hasPrefix( internal::
Matcher<NestedNameSpecifierLoc> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasPrefix1Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<NestedNameSpecifierLoc>
( &hasPrefix_Type1)(internal::Matcher<NestedNameSpecifierLoc
> const &InnerMatcher); inline bool internal::matcher_hasPrefix1Matcher
::matches( const NestedNameSpecifierLoc &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7512 NestedNameSpecifierLoc NextNode = Node.getPrefix();
7513 if (!NextNode)
7514 return false;
7515 return InnerMatcher.matches(NextNode, Finder, Builder);
7516}
7517
7518/// Matches nested name specifiers that specify a namespace matching the
7519/// given namespace matcher.
7520///
7521/// Given
7522/// \code
7523/// namespace ns { struct A {}; }
7524/// ns::A a;
7525/// \endcode
7526/// nestedNameSpecifier(specifiesNamespace(hasName("ns")))
7527/// matches "ns::"
7528AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,namespace internal { class matcher_specifiesNamespace0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NestedNameSpecifier> { public: explicit matcher_specifiesNamespace0Matcher
( internal::Matcher<NamespaceDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifier
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamespaceDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifier> specifiesNamespace( internal
::Matcher<NamespaceDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_specifiesNamespace0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<NestedNameSpecifier
> ( &specifiesNamespace_Type0)(internal::Matcher<NamespaceDecl
> const &InnerMatcher); inline bool internal::matcher_specifiesNamespace0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7529 internal::Matcher<NamespaceDecl>, InnerMatcher)namespace internal { class matcher_specifiesNamespace0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NestedNameSpecifier> { public: explicit matcher_specifiesNamespace0Matcher
( internal::Matcher<NamespaceDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const NestedNameSpecifier
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<NamespaceDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<NestedNameSpecifier> specifiesNamespace( internal
::Matcher<NamespaceDecl> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_specifiesNamespace0Matcher(InnerMatcher)); } typedef ::
clang::ast_matchers::internal::Matcher<NestedNameSpecifier
> ( &specifiesNamespace_Type0)(internal::Matcher<NamespaceDecl
> const &InnerMatcher); inline bool internal::matcher_specifiesNamespace0Matcher
::matches( const NestedNameSpecifier &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7530 if (!Node.getAsNamespace())
7531 return false;
7532 return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
7533}
7534
7535/// Matches attributes.
7536/// Attributes may be attached with a variety of different syntaxes (including
7537/// keywords, C++11 attributes, GNU ``__attribute``` and MSVC `__declspec``,
7538/// and ``#pragma``s). They may also be implicit.
7539///
7540/// Given
7541/// \code
7542/// struct [[nodiscard]] Foo{};
7543/// void bar(int * __attribute__((nonnull)) );
7544/// __declspec(noinline) void baz();
7545///
7546/// #pragma omp declare simd
7547/// int min();
7548/// \endcode
7549/// attr()
7550/// matches "nodiscard", "nonnull", "noinline", and the whole "#pragma" line.
7551extern const internal::VariadicAllOfMatcher<Attr> attr;
7552
7553/// Overloads for the \c equalsNode matcher.
7554/// FIXME: Implement for other node types.
7555/// @{
7556
7557/// Matches if a node equals another node.
7558///
7559/// \c Decl has pointer identity in the AST.
7560AST_MATCHER_P_OVERLOAD(Decl, equalsNode, const Decl*, Other, 0)namespace internal { class matcher_equalsNode0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Decl>
{ public: explicit matcher_equalsNode0Matcher( const Decl* const
&AOther) : Other(AOther) {} bool matches(const Decl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: const Decl* Other; }; } inline ::clang
::ast_matchers::internal::Matcher<Decl> equalsNode( const
Decl* const &Other) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_equalsNode0Matcher(Other
)); } typedef ::clang::ast_matchers::internal::Matcher<Decl
> ( &equalsNode_Type0)(const Decl* const &Other); inline
bool internal::matcher_equalsNode0Matcher::matches( const Decl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7561 return &Node == Other;
7562}
7563/// Matches if a node equals another node.
7564///
7565/// \c Stmt has pointer identity in the AST.
7566AST_MATCHER_P_OVERLOAD(Stmt, equalsNode, const Stmt*, Other, 1)namespace internal { class matcher_equalsNode1Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Stmt>
{ public: explicit matcher_equalsNode1Matcher( const Stmt* const
&AOther) : Other(AOther) {} bool matches(const Stmt &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: const Stmt* Other; }; } inline ::clang
::ast_matchers::internal::Matcher<Stmt> equalsNode( const
Stmt* const &Other) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_equalsNode1Matcher(Other
)); } typedef ::clang::ast_matchers::internal::Matcher<Stmt
> ( &equalsNode_Type1)(const Stmt* const &Other); inline
bool internal::matcher_equalsNode1Matcher::matches( const Stmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7567 return &Node == Other;
7568}
7569/// Matches if a node equals another node.
7570///
7571/// \c Type has pointer identity in the AST.
7572AST_MATCHER_P_OVERLOAD(Type, equalsNode, const Type*, Other, 2)namespace internal { class matcher_equalsNode2Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Type>
{ public: explicit matcher_equalsNode2Matcher( const Type* const
&AOther) : Other(AOther) {} bool matches(const Type &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: const Type* Other; }; } inline ::clang
::ast_matchers::internal::Matcher<Type> equalsNode( const
Type* const &Other) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_equalsNode2Matcher(Other
)); } typedef ::clang::ast_matchers::internal::Matcher<Type
> ( &equalsNode_Type2)(const Type* const &Other); inline
bool internal::matcher_equalsNode2Matcher::matches( const Type
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7573 return &Node == Other;
7574}
7575
7576/// @}
7577
7578/// Matches each case or default statement belonging to the given switch
7579/// statement. This matcher may produce multiple matches.
7580///
7581/// Given
7582/// \code
7583/// switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } }
7584/// \endcode
7585/// switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s")
7586/// matches four times, with "c" binding each of "case 1:", "case 2:",
7587/// "case 3:" and "case 4:", and "s" respectively binding "switch (1)",
7588/// "switch (1)", "switch (2)" and "switch (2)".
7589AST_MATCHER_P(SwitchStmt, forEachSwitchCase, internal::Matcher<SwitchCase>,namespace internal { class matcher_forEachSwitchCase0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
SwitchStmt> { public: explicit matcher_forEachSwitchCase0Matcher
( internal::Matcher<SwitchCase> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const SwitchStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<SwitchCase
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<SwitchStmt> forEachSwitchCase( internal::Matcher
<SwitchCase> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_forEachSwitchCase0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<SwitchStmt> ( &forEachSwitchCase_Type0)(internal::
Matcher<SwitchCase> const &InnerMatcher); inline bool
internal::matcher_forEachSwitchCase0Matcher::matches( const SwitchStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7590 InnerMatcher)namespace internal { class matcher_forEachSwitchCase0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
SwitchStmt> { public: explicit matcher_forEachSwitchCase0Matcher
( internal::Matcher<SwitchCase> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const SwitchStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<SwitchCase
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<SwitchStmt> forEachSwitchCase( internal::Matcher
<SwitchCase> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_forEachSwitchCase0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<SwitchStmt> ( &forEachSwitchCase_Type0)(internal::
Matcher<SwitchCase> const &InnerMatcher); inline bool
internal::matcher_forEachSwitchCase0Matcher::matches( const SwitchStmt
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7591 BoundNodesTreeBuilder Result;
7592 // FIXME: getSwitchCaseList() does not necessarily guarantee a stable
7593 // iteration order. We should use the more general iterating matchers once
7594 // they are capable of expressing this matcher (for example, it should ignore
7595 // case statements belonging to nested switch statements).
7596 bool Matched = false;
7597 for (const SwitchCase *SC = Node.getSwitchCaseList(); SC;
7598 SC = SC->getNextSwitchCase()) {
7599 BoundNodesTreeBuilder CaseBuilder(*Builder);
7600 bool CaseMatched = InnerMatcher.matches(*SC, Finder, &CaseBuilder);
7601 if (CaseMatched) {
7602 Matched = true;
7603 Result.addMatch(CaseBuilder);
7604 }
7605 }
7606 *Builder = std::move(Result);
7607 return Matched;
7608}
7609
7610/// Matches each constructor initializer in a constructor definition.
7611///
7612/// Given
7613/// \code
7614/// class A { A() : i(42), j(42) {} int i; int j; };
7615/// \endcode
7616/// cxxConstructorDecl(forEachConstructorInitializer(
7617/// forField(decl().bind("x"))
7618/// ))
7619/// will trigger two matches, binding for 'i' and 'j' respectively.
7620AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer,namespace internal { class matcher_forEachConstructorInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_forEachConstructorInitializer0Matcher
( internal::Matcher<CXXCtorInitializer> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXCtorInitializer
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> forEachConstructorInitializer
( internal::Matcher<CXXCtorInitializer> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_forEachConstructorInitializer0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXConstructorDecl
> ( &forEachConstructorInitializer_Type0)(internal::Matcher
<CXXCtorInitializer> const &InnerMatcher); inline bool
internal::matcher_forEachConstructorInitializer0Matcher::matches
( const CXXConstructorDecl &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7621 internal::Matcher<CXXCtorInitializer>, InnerMatcher)namespace internal { class matcher_forEachConstructorInitializer0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_forEachConstructorInitializer0Matcher
( internal::Matcher<CXXCtorInitializer> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<CXXCtorInitializer
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> forEachConstructorInitializer
( internal::Matcher<CXXCtorInitializer> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_forEachConstructorInitializer0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<CXXConstructorDecl
> ( &forEachConstructorInitializer_Type0)(internal::Matcher
<CXXCtorInitializer> const &InnerMatcher); inline bool
internal::matcher_forEachConstructorInitializer0Matcher::matches
( const CXXConstructorDecl &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7622 BoundNodesTreeBuilder Result;
7623 bool Matched = false;
7624 for (const auto *I : Node.inits()) {
7625 if (Finder->isTraversalIgnoringImplicitNodes() && !I->isWritten())
7626 continue;
7627 BoundNodesTreeBuilder InitBuilder(*Builder);
7628 if (InnerMatcher.matches(*I, Finder, &InitBuilder)) {
7629 Matched = true;
7630 Result.addMatch(InitBuilder);
7631 }
7632 }
7633 *Builder = std::move(Result);
7634 return Matched;
7635}
7636
7637/// Matches constructor declarations that are copy constructors.
7638///
7639/// Given
7640/// \code
7641/// struct S {
7642/// S(); // #1
7643/// S(const S &); // #2
7644/// S(S &&); // #3
7645/// };
7646/// \endcode
7647/// cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3.
7648AST_MATCHER(CXXConstructorDecl, isCopyConstructor)namespace internal { class matcher_isCopyConstructorMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_isCopyConstructorMatcher
() = default; bool matches(const CXXConstructorDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> isCopyConstructor() { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isCopyConstructorMatcher()); } inline bool internal::
matcher_isCopyConstructorMatcher::matches( const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7649 return Node.isCopyConstructor();
7650}
7651
7652/// Matches constructor declarations that are move constructors.
7653///
7654/// Given
7655/// \code
7656/// struct S {
7657/// S(); // #1
7658/// S(const S &); // #2
7659/// S(S &&); // #3
7660/// };
7661/// \endcode
7662/// cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2.
7663AST_MATCHER(CXXConstructorDecl, isMoveConstructor)namespace internal { class matcher_isMoveConstructorMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_isMoveConstructorMatcher
() = default; bool matches(const CXXConstructorDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> isMoveConstructor() { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isMoveConstructorMatcher()); } inline bool internal::
matcher_isMoveConstructorMatcher::matches( const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7664 return Node.isMoveConstructor();
7665}
7666
7667/// Matches constructor declarations that are default constructors.
7668///
7669/// Given
7670/// \code
7671/// struct S {
7672/// S(); // #1
7673/// S(const S &); // #2
7674/// S(S &&); // #3
7675/// };
7676/// \endcode
7677/// cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3.
7678AST_MATCHER(CXXConstructorDecl, isDefaultConstructor)namespace internal { class matcher_isDefaultConstructorMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_isDefaultConstructorMatcher
() = default; bool matches(const CXXConstructorDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> isDefaultConstructor() { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_isDefaultConstructorMatcher()); } inline bool internal
::matcher_isDefaultConstructorMatcher::matches( const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7679 return Node.isDefaultConstructor();
7680}
7681
7682/// Matches constructors that delegate to another constructor.
7683///
7684/// Given
7685/// \code
7686/// struct S {
7687/// S(); // #1
7688/// S(int) {} // #2
7689/// S(S &&) : S() {} // #3
7690/// };
7691/// S::S() : S(0) {} // #4
7692/// \endcode
7693/// cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not
7694/// #1 or #2.
7695AST_MATCHER(CXXConstructorDecl, isDelegatingConstructor)namespace internal { class matcher_isDelegatingConstructorMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXConstructorDecl> { public: explicit matcher_isDelegatingConstructorMatcher
() = default; bool matches(const CXXConstructorDecl &Node
, ::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::
clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<CXXConstructorDecl> isDelegatingConstructor()
{ return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_isDelegatingConstructorMatcher()); } inline bool internal
::matcher_isDelegatingConstructorMatcher::matches( const CXXConstructorDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7696 return Node.isDelegatingConstructor();
7697}
7698
7699/// Matches constructor, conversion function, and deduction guide declarations
7700/// that have an explicit specifier if this explicit specifier is resolved to
7701/// true.
7702///
7703/// Given
7704/// \code
7705/// template<bool b>
7706/// struct S {
7707/// S(int); // #1
7708/// explicit S(double); // #2
7709/// operator int(); // #3
7710/// explicit operator bool(); // #4
7711/// explicit(false) S(bool) // # 7
7712/// explicit(true) S(char) // # 8
7713/// explicit(b) S(S) // # 9
7714/// };
7715/// S(int) -> S<true> // #5
7716/// explicit S(double) -> S<false> // #6
7717/// \endcode
7718/// cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
7719/// cxxConversionDecl(isExplicit()) will match #4, but not #3.
7720/// cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
7721AST_POLYMORPHIC_MATCHER(isExplicit, AST_POLYMORPHIC_SUPPORTED_TYPES(namespace internal { template <typename NodeType> class
matcher_isExplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXConstructorDecl
, CXXConversionDecl, CXXDeductionGuideDecl>)> isExplicit
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExplicitMatcher, void(::clang::ast_matchers
::internal::TypeList<CXXConstructorDecl, CXXConversionDecl
, CXXDeductionGuideDecl>)>(); } template <typename NodeType
> bool internal::matcher_isExplicitMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7722 CXXConstructorDecl, CXXConversionDecl,namespace internal { template <typename NodeType> class
matcher_isExplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXConstructorDecl
, CXXConversionDecl, CXXDeductionGuideDecl>)> isExplicit
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExplicitMatcher, void(::clang::ast_matchers
::internal::TypeList<CXXConstructorDecl, CXXConversionDecl
, CXXDeductionGuideDecl>)>(); } template <typename NodeType
> bool internal::matcher_isExplicitMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7723 CXXDeductionGuideDecl))namespace internal { template <typename NodeType> class
matcher_isExplicitMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isExplicitMatcher
, void(::clang::ast_matchers::internal::TypeList<CXXConstructorDecl
, CXXConversionDecl, CXXDeductionGuideDecl>)> isExplicit
() { return ::clang::ast_matchers::internal::PolymorphicMatcher
< internal::matcher_isExplicitMatcher, void(::clang::ast_matchers
::internal::TypeList<CXXConstructorDecl, CXXConversionDecl
, CXXDeductionGuideDecl>)>(); } template <typename NodeType
> bool internal::matcher_isExplicitMatcher<NodeType>
::matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7724 return Node.isExplicit();
7725}
7726
7727/// Matches the expression in an explicit specifier if present in the given
7728/// declaration.
7729///
7730/// Given
7731/// \code
7732/// template<bool b>
7733/// struct S {
7734/// S(int); // #1
7735/// explicit S(double); // #2
7736/// operator int(); // #3
7737/// explicit operator bool(); // #4
7738/// explicit(false) S(bool) // # 7
7739/// explicit(true) S(char) // # 8
7740/// explicit(b) S(S) // # 9
7741/// };
7742/// S(int) -> S<true> // #5
7743/// explicit S(double) -> S<false> // #6
7744/// \endcode
7745/// cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 and #9, but not #1 or #2.
7746/// cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or #4.
7747/// cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not match #5 or #6.
7748AST_MATCHER_P(FunctionDecl, hasExplicitSpecifier, internal::Matcher<Expr>,namespace internal { class matcher_hasExplicitSpecifier0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
FunctionDecl> { public: explicit matcher_hasExplicitSpecifier0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const FunctionDecl &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FunctionDecl
> hasExplicitSpecifier( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasExplicitSpecifier0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FunctionDecl> ( &hasExplicitSpecifier_Type0)(internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasExplicitSpecifier0Matcher::matches( const FunctionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7749 InnerMatcher)namespace internal { class matcher_hasExplicitSpecifier0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
FunctionDecl> { public: explicit matcher_hasExplicitSpecifier0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const FunctionDecl &Node,
::clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<FunctionDecl
> hasExplicitSpecifier( internal::Matcher<Expr> const
&InnerMatcher) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_hasExplicitSpecifier0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<FunctionDecl> ( &hasExplicitSpecifier_Type0)(internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasExplicitSpecifier0Matcher::matches( const FunctionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7750 ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(&Node);
7751 if (!ES.getExpr())
7752 return false;
7753
7754 ASTChildrenNotSpelledInSourceScope RAII(Finder, false);
7755
7756 return InnerMatcher.matches(*ES.getExpr(), Finder, Builder);
7757}
7758
7759/// Matches functions, variables and namespace declarations that are marked with
7760/// the inline keyword.
7761///
7762/// Given
7763/// \code
7764/// inline void f();
7765/// void g();
7766/// namespace n {
7767/// inline namespace m {}
7768/// }
7769/// inline int Foo = 5;
7770/// \endcode
7771/// functionDecl(isInline()) will match ::f().
7772/// namespaceDecl(isInline()) will match n::m.
7773/// varDecl(isInline()) will match Foo;
7774AST_POLYMORPHIC_MATCHER(isInline, AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl,namespace internal { template <typename NodeType> class
matcher_isInlineMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isInlineMatcher
, void(::clang::ast_matchers::internal::TypeList<NamespaceDecl
, FunctionDecl, VarDecl>)> isInline() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isInlineMatcher
, void(::clang::ast_matchers::internal::TypeList<NamespaceDecl
, FunctionDecl, VarDecl>)>(); } template <typename NodeType
> bool internal::matcher_isInlineMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7775 FunctionDecl,namespace internal { template <typename NodeType> class
matcher_isInlineMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isInlineMatcher
, void(::clang::ast_matchers::internal::TypeList<NamespaceDecl
, FunctionDecl, VarDecl>)> isInline() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isInlineMatcher
, void(::clang::ast_matchers::internal::TypeList<NamespaceDecl
, FunctionDecl, VarDecl>)>(); } template <typename NodeType
> bool internal::matcher_isInlineMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7776 VarDecl))namespace internal { template <typename NodeType> class
matcher_isInlineMatcher : public ::clang::ast_matchers::internal
::MatcherInterface<NodeType> { public: bool matches(const
NodeType &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::PolymorphicMatcher< internal::matcher_isInlineMatcher
, void(::clang::ast_matchers::internal::TypeList<NamespaceDecl
, FunctionDecl, VarDecl>)> isInline() { return ::clang::
ast_matchers::internal::PolymorphicMatcher< internal::matcher_isInlineMatcher
, void(::clang::ast_matchers::internal::TypeList<NamespaceDecl
, FunctionDecl, VarDecl>)>(); } template <typename NodeType
> bool internal::matcher_isInlineMatcher<NodeType>::
matches( const NodeType &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7777 // This is required because the spelling of the function used to determine
7778 // whether inline is specified or not differs between the polymorphic types.
7779 if (const auto *FD = dyn_cast<FunctionDecl>(&Node))
7780 return FD->isInlineSpecified();
7781 if (const auto *NSD = dyn_cast<NamespaceDecl>(&Node))
7782 return NSD->isInline();
7783 if (const auto *VD = dyn_cast<VarDecl>(&Node))
7784 return VD->isInline();
7785 llvm_unreachable("Not a valid polymorphic type")::llvm::llvm_unreachable_internal("Not a valid polymorphic type"
, "clang/include/clang/ASTMatchers/ASTMatchers.h", 7785)
;
7786}
7787
7788/// Matches anonymous namespace declarations.
7789///
7790/// Given
7791/// \code
7792/// namespace n {
7793/// namespace {} // #1
7794/// }
7795/// \endcode
7796/// namespaceDecl(isAnonymous()) will match #1 but not ::n.
7797AST_MATCHER(NamespaceDecl, isAnonymous)namespace internal { class matcher_isAnonymousMatcher : public
::clang::ast_matchers::internal::MatcherInterface<NamespaceDecl
> { public: explicit matcher_isAnonymousMatcher() = default
; bool matches(const NamespaceDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<NamespaceDecl>
isAnonymous() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isAnonymousMatcher()); } inline bool internal
::matcher_isAnonymousMatcher::matches( const NamespaceDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
7798 return Node.isAnonymousNamespace();
7799}
7800
7801/// Matches declarations in the namespace `std`, but not in nested namespaces.
7802///
7803/// Given
7804/// \code
7805/// class vector {};
7806/// namespace foo {
7807/// class vector {};
7808/// namespace std {
7809/// class vector {};
7810/// }
7811/// }
7812/// namespace std {
7813/// inline namespace __1 {
7814/// class vector {}; // #1
7815/// namespace experimental {
7816/// class vector {};
7817/// }
7818/// }
7819/// }
7820/// \endcode
7821/// cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
7822AST_MATCHER(Decl, isInStdNamespace)namespace internal { class matcher_isInStdNamespaceMatcher : public
::clang::ast_matchers::internal::MatcherInterface<Decl>
{ public: explicit matcher_isInStdNamespaceMatcher() = default
; bool matches(const Decl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<Decl> isInStdNamespace() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isInStdNamespaceMatcher
()); } inline bool internal::matcher_isInStdNamespaceMatcher::
matches( const Decl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{ return Node.isInStdNamespace(); }
7823
7824/// Matches declarations in an anonymous namespace.
7825///
7826/// Given
7827/// \code
7828/// class vector {};
7829/// namespace foo {
7830/// class vector {};
7831/// namespace {
7832/// class vector {}; // #1
7833/// }
7834/// }
7835/// namespace {
7836/// class vector {}; // #2
7837/// namespace foo {
7838/// class vector{}; // #3
7839/// }
7840/// }
7841/// \endcode
7842/// cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match
7843/// #1, #2 and #3.
7844AST_MATCHER(Decl, isInAnonymousNamespace)namespace internal { class matcher_isInAnonymousNamespaceMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Decl> { public: explicit matcher_isInAnonymousNamespaceMatcher
() = default; bool matches(const Decl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<Decl> isInAnonymousNamespace
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isInAnonymousNamespaceMatcher()); } inline
bool internal::matcher_isInAnonymousNamespaceMatcher::matches
( const Decl &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7845 return Node.isInAnonymousNamespace();
7846}
7847
7848/// If the given case statement does not use the GNU case range
7849/// extension, matches the constant given in the statement.
7850///
7851/// Given
7852/// \code
7853/// switch (1) { case 1: case 1+1: case 3 ... 4: ; }
7854/// \endcode
7855/// caseStmt(hasCaseConstant(integerLiteral()))
7856/// matches "case 1:"
7857AST_MATCHER_P(CaseStmt, hasCaseConstant, internal::Matcher<Expr>,namespace internal { class matcher_hasCaseConstant0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CaseStmt
> { public: explicit matcher_hasCaseConstant0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CaseStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<CaseStmt> hasCaseConstant
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasCaseConstant0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CaseStmt> ( &hasCaseConstant_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasCaseConstant0Matcher::matches( const
CaseStmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7858 InnerMatcher)namespace internal { class matcher_hasCaseConstant0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CaseStmt
> { public: explicit matcher_hasCaseConstant0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CaseStmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<Expr> InnerMatcher; }; } inline ::clang
::ast_matchers::internal::Matcher<CaseStmt> hasCaseConstant
( internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_hasCaseConstant0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CaseStmt> ( &hasCaseConstant_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasCaseConstant0Matcher::matches( const
CaseStmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7859 if (Node.getRHS())
7860 return false;
7861
7862 return InnerMatcher.matches(*Node.getLHS(), Finder, Builder);
7863}
7864
7865/// Matches declaration that has a given attribute.
7866///
7867/// Given
7868/// \code
7869/// __attribute__((device)) void f() { ... }
7870/// \endcode
7871/// decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of
7872/// f. If the matcher is used from clang-query, attr::Kind parameter should be
7873/// passed as a quoted string. e.g., hasAttr("attr::CUDADevice").
7874AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind)namespace internal { class matcher_hasAttr0Matcher : public ::
clang::ast_matchers::internal::MatcherInterface<Decl> {
public: explicit matcher_hasAttr0Matcher( attr::Kind const &
AAttrKind) : AttrKind(AAttrKind) {} bool matches(const Decl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: attr::Kind AttrKind; }; } inline ::
clang::ast_matchers::internal::Matcher<Decl> hasAttr( attr
::Kind const &AttrKind) { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_hasAttr0Matcher(AttrKind
)); } typedef ::clang::ast_matchers::internal::Matcher<Decl
> ( &hasAttr_Type0)(attr::Kind const &AttrKind); inline
bool internal::matcher_hasAttr0Matcher::matches( const Decl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
7875 for (const auto *Attr : Node.attrs()) {
7876 if (Attr->getKind() == AttrKind)
7877 return true;
7878 }
7879 return false;
7880}
7881
7882/// Matches the return value expression of a return statement
7883///
7884/// Given
7885/// \code
7886/// return a + b;
7887/// \endcode
7888/// hasReturnValue(binaryOperator())
7889/// matches 'return a + b'
7890/// with binaryOperator()
7891/// matching 'a + b'
7892AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>,namespace internal { class matcher_hasReturnValue0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ReturnStmt
> { public: explicit matcher_hasReturnValue0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ReturnStmt &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ReturnStmt
> hasReturnValue( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasReturnValue0Matcher(InnerMatcher))
; } typedef ::clang::ast_matchers::internal::Matcher<ReturnStmt
> ( &hasReturnValue_Type0)(internal::Matcher<Expr>
const &InnerMatcher); inline bool internal::matcher_hasReturnValue0Matcher
::matches( const ReturnStmt &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
7893 InnerMatcher)namespace internal { class matcher_hasReturnValue0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<ReturnStmt
> { public: explicit matcher_hasReturnValue0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const ReturnStmt &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<ReturnStmt
> hasReturnValue( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasReturnValue0Matcher(InnerMatcher))
; } typedef ::clang::ast_matchers::internal::Matcher<ReturnStmt
> ( &hasReturnValue_Type0)(internal::Matcher<Expr>
const &InnerMatcher); inline bool internal::matcher_hasReturnValue0Matcher
::matches( const ReturnStmt &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
7894 if (const auto *RetValue = Node.getRetValue())
7895 return InnerMatcher.matches(*RetValue, Finder, Builder);
7896 return false;
7897}
7898
7899/// Matches CUDA kernel call expression.
7900///
7901/// Example matches,
7902/// \code
7903/// kernel<<<i,j>>>();
7904/// \endcode
7905extern const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr>
7906 cudaKernelCallExpr;
7907
7908/// Matches expressions that resolve to a null pointer constant, such as
7909/// GNU's __null, C++11's nullptr, or C's NULL macro.
7910///
7911/// Given:
7912/// \code
7913/// void *v1 = NULL;
7914/// void *v2 = nullptr;
7915/// void *v3 = __null; // GNU extension
7916/// char *cp = (char *)0;
7917/// int *ip = 0;
7918/// int i = 0;
7919/// \endcode
7920/// expr(nullPointerConstant())
7921/// matches the initializer for v1, v2, v3, cp, and ip. Does not match the
7922/// initializer for i.
7923AST_MATCHER_FUNCTION(internal::Matcher<Expr>, nullPointerConstant)inline internal::Matcher<Expr> nullPointerConstant_getInstance
(); inline internal::Matcher<Expr> nullPointerConstant(
) { return ::clang::ast_matchers::internal::MemoizedMatcher<
internal::Matcher<Expr>, nullPointerConstant_getInstance
>::getInstance(); } inline internal::Matcher<Expr> nullPointerConstant_getInstance
()
{
7924 return anyOf(
7925 gnuNullExpr(), cxxNullPtrLiteralExpr(),
7926 integerLiteral(equals(0), hasParent(expr(hasType(pointerType())))));
7927}
7928
7929/// Matches the DecompositionDecl the binding belongs to.
7930///
7931/// For example, in:
7932/// \code
7933/// void foo()
7934/// {
7935/// int arr[3];
7936/// auto &[f, s, t] = arr;
7937///
7938/// f = 42;
7939/// }
7940/// \endcode
7941/// The matcher:
7942/// \code
7943/// bindingDecl(hasName("f"),
7944/// forDecomposition(decompositionDecl())
7945/// \endcode
7946/// matches 'f' in 'auto &[f, s, t]'.
7947AST_MATCHER_P(BindingDecl, forDecomposition, internal::Matcher<ValueDecl>,namespace internal { class matcher_forDecomposition0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
BindingDecl> { public: explicit matcher_forDecomposition0Matcher
( internal::Matcher<ValueDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const BindingDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<ValueDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<BindingDecl> forDecomposition( internal::Matcher
<ValueDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_forDecomposition0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<BindingDecl> ( &forDecomposition_Type0)(internal::
Matcher<ValueDecl> const &InnerMatcher); inline bool
internal::matcher_forDecomposition0Matcher::matches( const BindingDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7948 InnerMatcher)namespace internal { class matcher_forDecomposition0Matcher :
public ::clang::ast_matchers::internal::MatcherInterface<
BindingDecl> { public: explicit matcher_forDecomposition0Matcher
( internal::Matcher<ValueDecl> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const BindingDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: internal::Matcher<ValueDecl
> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<BindingDecl> forDecomposition( internal::Matcher
<ValueDecl> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_forDecomposition0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<BindingDecl> ( &forDecomposition_Type0)(internal::
Matcher<ValueDecl> const &InnerMatcher); inline bool
internal::matcher_forDecomposition0Matcher::matches( const BindingDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7949 if (const ValueDecl *VD = Node.getDecomposedDecl())
7950 return InnerMatcher.matches(*VD, Finder, Builder);
7951 return false;
7952}
7953
7954/// Matches the Nth binding of a DecompositionDecl.
7955///
7956/// For example, in:
7957/// \code
7958/// void foo()
7959/// {
7960/// int arr[3];
7961/// auto &[f, s, t] = arr;
7962///
7963/// f = 42;
7964/// }
7965/// \endcode
7966/// The matcher:
7967/// \code
7968/// decompositionDecl(hasBinding(0,
7969/// bindingDecl(hasName("f").bind("fBinding"))))
7970/// \endcode
7971/// matches the decomposition decl with 'f' bound to "fBinding".
7972AST_MATCHER_P2(DecompositionDecl, hasBinding, unsigned, N,namespace internal { class matcher_hasBinding0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DecompositionDecl
> { public: matcher_hasBinding0Matcher(unsigned const &
AN, internal::Matcher<BindingDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const DecompositionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<BindingDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<DecompositionDecl> hasBinding( unsigned
const &N, internal::Matcher<BindingDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasBinding0Matcher(N, InnerMatcher));
} typedef ::clang::ast_matchers::internal::Matcher<DecompositionDecl
> ( &hasBinding_Type0)(unsigned const &N, internal
::Matcher<BindingDecl> const &InnerMatcher); inline
bool internal::matcher_hasBinding0Matcher::matches( const DecompositionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7973 internal::Matcher<BindingDecl>, InnerMatcher)namespace internal { class matcher_hasBinding0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DecompositionDecl
> { public: matcher_hasBinding0Matcher(unsigned const &
AN, internal::Matcher<BindingDecl> const &AInnerMatcher
) : N(AN), InnerMatcher(AInnerMatcher) {} bool matches(const DecompositionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned N; internal::Matcher
<BindingDecl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<DecompositionDecl> hasBinding( unsigned
const &N, internal::Matcher<BindingDecl> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasBinding0Matcher(N, InnerMatcher));
} typedef ::clang::ast_matchers::internal::Matcher<DecompositionDecl
> ( &hasBinding_Type0)(unsigned const &N, internal
::Matcher<BindingDecl> const &InnerMatcher); inline
bool internal::matcher_hasBinding0Matcher::matches( const DecompositionDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7974 if (Node.bindings().size() <= N)
7975 return false;
7976 return InnerMatcher.matches(*Node.bindings()[N], Finder, Builder);
7977}
7978
7979/// Matches any binding of a DecompositionDecl.
7980///
7981/// For example, in:
7982/// \code
7983/// void foo()
7984/// {
7985/// int arr[3];
7986/// auto &[f, s, t] = arr;
7987///
7988/// f = 42;
7989/// }
7990/// \endcode
7991/// The matcher:
7992/// \code
7993/// decompositionDecl(hasAnyBinding(bindingDecl(hasName("f").bind("fBinding"))))
7994/// \endcode
7995/// matches the decomposition decl with 'f' bound to "fBinding".
7996AST_MATCHER_P(DecompositionDecl, hasAnyBinding, internal::Matcher<BindingDecl>,namespace internal { class matcher_hasAnyBinding0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DecompositionDecl
> { public: explicit matcher_hasAnyBinding0Matcher( internal
::Matcher<BindingDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const DecompositionDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<BindingDecl>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<DecompositionDecl> hasAnyBinding( internal::Matcher<
BindingDecl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasAnyBinding0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<DecompositionDecl> ( &hasAnyBinding_Type0)(internal
::Matcher<BindingDecl> const &InnerMatcher); inline
bool internal::matcher_hasAnyBinding0Matcher::matches( const
DecompositionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
7997 InnerMatcher)namespace internal { class matcher_hasAnyBinding0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<DecompositionDecl
> { public: explicit matcher_hasAnyBinding0Matcher( internal
::Matcher<BindingDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const DecompositionDecl &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<BindingDecl>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<DecompositionDecl> hasAnyBinding( internal::Matcher<
BindingDecl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasAnyBinding0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<DecompositionDecl> ( &hasAnyBinding_Type0)(internal
::Matcher<BindingDecl> const &InnerMatcher); inline
bool internal::matcher_hasAnyBinding0Matcher::matches( const
DecompositionDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
7998 return llvm::any_of(Node.bindings(), [&](const auto *Binding) {
7999 return InnerMatcher.matches(*Binding, Finder, Builder);
8000 });
8001}
8002
8003/// Matches declaration of the function the statement belongs to.
8004///
8005/// Deprecated. Use forCallable() to correctly handle the situation when
8006/// the declaration is not a function (but a block or an Objective-C method).
8007/// forFunction() not only fails to take non-functions into account but also
8008/// may match the wrong declaration in their presence.
8009///
8010/// Given:
8011/// \code
8012/// F& operator=(const F& o) {
8013/// std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });
8014/// return *this;
8015/// }
8016/// \endcode
8017/// returnStmt(forFunction(hasName("operator=")))
8018/// matches 'return *this'
8019/// but does not match 'return v > 0'
8020AST_MATCHER_P(Stmt, forFunction, internal::Matcher<FunctionDecl>,namespace internal { class matcher_forFunction0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Stmt>
{ public: explicit matcher_forFunction0Matcher( internal::Matcher
<FunctionDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Stmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<FunctionDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<Stmt> forFunction
( internal::Matcher<FunctionDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_forFunction0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Stmt> ( &forFunction_Type0
)(internal::Matcher<FunctionDecl> const &InnerMatcher
); inline bool internal::matcher_forFunction0Matcher::matches
( const Stmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
8021 InnerMatcher)namespace internal { class matcher_forFunction0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Stmt>
{ public: explicit matcher_forFunction0Matcher( internal::Matcher
<FunctionDecl> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const Stmt &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; private
: internal::Matcher<FunctionDecl> InnerMatcher; }; } inline
::clang::ast_matchers::internal::Matcher<Stmt> forFunction
( internal::Matcher<FunctionDecl> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_forFunction0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<Stmt> ( &forFunction_Type0
)(internal::Matcher<FunctionDecl> const &InnerMatcher
); inline bool internal::matcher_forFunction0Matcher::matches
( const Stmt &Node, ::clang::ast_matchers::internal::ASTMatchFinder
*Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8022 const auto &Parents = Finder->getASTContext().getParents(Node);
8023
8024 llvm::SmallVector<DynTypedNode, 8> Stack(Parents.begin(), Parents.end());
8025 while (!Stack.empty()) {
8026 const auto &CurNode = Stack.back();
8027 Stack.pop_back();
8028 if (const auto *FuncDeclNode = CurNode.get<FunctionDecl>()) {
8029 if (InnerMatcher.matches(*FuncDeclNode, Finder, Builder)) {
8030 return true;
8031 }
8032 } else if (const auto *LambdaExprNode = CurNode.get<LambdaExpr>()) {
8033 if (InnerMatcher.matches(*LambdaExprNode->getCallOperator(), Finder,
8034 Builder)) {
8035 return true;
8036 }
8037 } else {
8038 llvm::append_range(Stack, Finder->getASTContext().getParents(CurNode));
8039 }
8040 }
8041 return false;
8042}
8043
8044/// Matches declaration of the function, method, or block the statement
8045/// belongs to.
8046///
8047/// Given:
8048/// \code
8049/// F& operator=(const F& o) {
8050/// std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; });
8051/// return *this;
8052/// }
8053/// \endcode
8054/// returnStmt(forCallable(functionDecl(hasName("operator="))))
8055/// matches 'return *this'
8056/// but does not match 'return v > 0'
8057///
8058/// Given:
8059/// \code
8060/// -(void) foo {
8061/// int x = 1;
8062/// dispatch_sync(queue, ^{ int y = 2; });
8063/// }
8064/// \endcode
8065/// declStmt(forCallable(objcMethodDecl()))
8066/// matches 'int x = 1'
8067/// but does not match 'int y = 2'.
8068/// whereas declStmt(forCallable(blockDecl()))
8069/// matches 'int y = 2'
8070/// but does not match 'int x = 1'.
8071AST_MATCHER_P(Stmt, forCallable, internal::Matcher<Decl>, InnerMatcher)namespace internal { class matcher_forCallable0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<Stmt>
{ public: explicit matcher_forCallable0Matcher( internal::Matcher
<Decl> const &AInnerMatcher) : InnerMatcher(AInnerMatcher
) {} bool matches(const Stmt &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: internal
::Matcher<Decl> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<Stmt> forCallable( internal::Matcher
<Decl> const &InnerMatcher) { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_forCallable0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<Stmt> ( &forCallable_Type0)(internal::Matcher<Decl
> const &InnerMatcher); inline bool internal::matcher_forCallable0Matcher
::matches( const Stmt &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8072 const auto &Parents = Finder->getASTContext().getParents(Node);
8073
8074 llvm::SmallVector<DynTypedNode, 8> Stack(Parents.begin(), Parents.end());
8075 while (!Stack.empty()) {
8076 const auto &CurNode = Stack.back();
8077 Stack.pop_back();
8078 if (const auto *FuncDeclNode = CurNode.get<FunctionDecl>()) {
8079 if (InnerMatcher.matches(*FuncDeclNode, Finder, Builder)) {
8080 return true;
8081 }
8082 } else if (const auto *LambdaExprNode = CurNode.get<LambdaExpr>()) {
8083 if (InnerMatcher.matches(*LambdaExprNode->getCallOperator(), Finder,
8084 Builder)) {
8085 return true;
8086 }
8087 } else if (const auto *ObjCMethodDeclNode = CurNode.get<ObjCMethodDecl>()) {
8088 if (InnerMatcher.matches(*ObjCMethodDeclNode, Finder, Builder)) {
8089 return true;
8090 }
8091 } else if (const auto *BlockDeclNode = CurNode.get<BlockDecl>()) {
8092 if (InnerMatcher.matches(*BlockDeclNode, Finder, Builder)) {
8093 return true;
8094 }
8095 } else {
8096 llvm::append_range(Stack, Finder->getASTContext().getParents(CurNode));
8097 }
8098 }
8099 return false;
8100}
8101
8102/// Matches a declaration that has external formal linkage.
8103///
8104/// Example matches only z (matcher = varDecl(hasExternalFormalLinkage()))
8105/// \code
8106/// void f() {
8107/// int x;
8108/// static int y;
8109/// }
8110/// int z;
8111/// \endcode
8112///
8113/// Example matches f() because it has external formal linkage despite being
8114/// unique to the translation unit as though it has internal likage
8115/// (matcher = functionDecl(hasExternalFormalLinkage()))
8116///
8117/// \code
8118/// namespace {
8119/// void f() {}
8120/// }
8121/// \endcode
8122AST_MATCHER(NamedDecl, hasExternalFormalLinkage)namespace internal { class matcher_hasExternalFormalLinkageMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
NamedDecl> { public: explicit matcher_hasExternalFormalLinkageMatcher
() = default; bool matches(const NamedDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<NamedDecl
> hasExternalFormalLinkage() { return ::clang::ast_matchers
::internal::makeMatcher( new internal::matcher_hasExternalFormalLinkageMatcher
()); } inline bool internal::matcher_hasExternalFormalLinkageMatcher
::matches( const NamedDecl &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8123 return Node.hasExternalFormalLinkage();
8124}
8125
8126/// Matches a declaration that has default arguments.
8127///
8128/// Example matches y (matcher = parmVarDecl(hasDefaultArgument()))
8129/// \code
8130/// void x(int val) {}
8131/// void y(int val = 0) {}
8132/// \endcode
8133///
8134/// Deprecated. Use hasInitializer() instead to be able to
8135/// match on the contents of the default argument. For example:
8136///
8137/// \code
8138/// void x(int val = 7) {}
8139/// void y(int val = 42) {}
8140/// \endcode
8141/// parmVarDecl(hasInitializer(integerLiteral(equals(42))))
8142/// matches the parameter of y
8143///
8144/// A matcher such as
8145/// parmVarDecl(hasInitializer(anything()))
8146/// is equivalent to parmVarDecl(hasDefaultArgument()).
8147AST_MATCHER(ParmVarDecl, hasDefaultArgument)namespace internal { class matcher_hasDefaultArgumentMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
ParmVarDecl> { public: explicit matcher_hasDefaultArgumentMatcher
() = default; bool matches(const ParmVarDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<ParmVarDecl
> hasDefaultArgument() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_hasDefaultArgumentMatcher
()); } inline bool internal::matcher_hasDefaultArgumentMatcher
::matches( const ParmVarDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8148 return Node.hasDefaultArg();
8149}
8150
8151/// Matches array new expressions.
8152///
8153/// Given:
8154/// \code
8155/// MyClass *p1 = new MyClass[10];
8156/// \endcode
8157/// cxxNewExpr(isArray())
8158/// matches the expression 'new MyClass[10]'.
8159AST_MATCHER(CXXNewExpr, isArray)namespace internal { class matcher_isArrayMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<CXXNewExpr
> { public: explicit matcher_isArrayMatcher() = default; bool
matches(const CXXNewExpr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<CXXNewExpr> isArray() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isArrayMatcher
()); } inline bool internal::matcher_isArrayMatcher::matches(
const CXXNewExpr &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8160 return Node.isArray();
8161}
8162
8163/// Matches placement new expression arguments.
8164///
8165/// Given:
8166/// \code
8167/// MyClass *p1 = new (Storage, 16) MyClass();
8168/// \endcode
8169/// cxxNewExpr(hasPlacementArg(1, integerLiteral(equals(16))))
8170/// matches the expression 'new (Storage, 16) MyClass()'.
8171AST_MATCHER_P2(CXXNewExpr, hasPlacementArg, unsigned, Index,namespace internal { class matcher_hasPlacementArg0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXNewExpr
> { public: matcher_hasPlacementArg0Matcher(unsigned const
&AIndex, internal::Matcher<Expr> const &AInnerMatcher
) : Index(AIndex), InnerMatcher(AInnerMatcher) {} bool matches
(const CXXNewExpr &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned Index; internal::
Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<CXXNewExpr> hasPlacementArg( unsigned
const &Index, internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasPlacementArg0Matcher(Index, InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<CXXNewExpr> (
&hasPlacementArg_Type0)(unsigned const &Index, internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasPlacementArg0Matcher::matches( const CXXNewExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
8172 internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasPlacementArg0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXNewExpr
> { public: matcher_hasPlacementArg0Matcher(unsigned const
&AIndex, internal::Matcher<Expr> const &AInnerMatcher
) : Index(AIndex), InnerMatcher(AInnerMatcher) {} bool matches
(const CXXNewExpr &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; private: unsigned Index; internal::
Matcher<Expr> InnerMatcher; }; } inline ::clang::ast_matchers
::internal::Matcher<CXXNewExpr> hasPlacementArg( unsigned
const &Index, internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasPlacementArg0Matcher(Index, InnerMatcher)); } typedef
::clang::ast_matchers::internal::Matcher<CXXNewExpr> (
&hasPlacementArg_Type0)(unsigned const &Index, internal
::Matcher<Expr> const &InnerMatcher); inline bool internal
::matcher_hasPlacementArg0Matcher::matches( const CXXNewExpr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
8173 return Node.getNumPlacementArgs() > Index &&
8174 InnerMatcher.matches(*Node.getPlacementArg(Index), Finder, Builder);
8175}
8176
8177/// Matches any placement new expression arguments.
8178///
8179/// Given:
8180/// \code
8181/// MyClass *p1 = new (Storage) MyClass();
8182/// \endcode
8183/// cxxNewExpr(hasAnyPlacementArg(anything()))
8184/// matches the expression 'new (Storage, 16) MyClass()'.
8185AST_MATCHER_P(CXXNewExpr, hasAnyPlacementArg, internal::Matcher<Expr>,namespace internal { class matcher_hasAnyPlacementArg0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXNewExpr> { public: explicit matcher_hasAnyPlacementArg0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXNewExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXNewExpr
> hasAnyPlacementArg( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasAnyPlacementArg0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<CXXNewExpr
> ( &hasAnyPlacementArg_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasAnyPlacementArg0Matcher
::matches( const CXXNewExpr &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
8186 InnerMatcher)namespace internal { class matcher_hasAnyPlacementArg0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
CXXNewExpr> { public: explicit matcher_hasAnyPlacementArg0Matcher
( internal::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXNewExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXNewExpr
> hasAnyPlacementArg( internal::Matcher<Expr> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasAnyPlacementArg0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<CXXNewExpr
> ( &hasAnyPlacementArg_Type0)(internal::Matcher<Expr
> const &InnerMatcher); inline bool internal::matcher_hasAnyPlacementArg0Matcher
::matches( const CXXNewExpr &Node, ::clang::ast_matchers::
internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8187 return llvm::any_of(Node.placement_arguments(), [&](const Expr *Arg) {
8188 return InnerMatcher.matches(*Arg, Finder, Builder);
8189 });
8190}
8191
8192/// Matches array new expressions with a given array size.
8193///
8194/// Given:
8195/// \code
8196/// MyClass *p1 = new MyClass[10];
8197/// \endcode
8198/// cxxNewExpr(hasArraySize(integerLiteral(equals(10))))
8199/// matches the expression 'new MyClass[10]'.
8200AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_hasArraySize0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXNewExpr
> { public: explicit matcher_hasArraySize0Matcher( internal
::Matcher<Expr> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const CXXNewExpr &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; private: internal::Matcher<Expr> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<CXXNewExpr
> hasArraySize( internal::Matcher<Expr> const &InnerMatcher
) { return ::clang::ast_matchers::internal::makeMatcher( new internal
::matcher_hasArraySize0Matcher(InnerMatcher)); } typedef ::clang
::ast_matchers::internal::Matcher<CXXNewExpr> ( &hasArraySize_Type0
)(internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_hasArraySize0Matcher::matches( const CXXNewExpr
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8201 return Node.isArray() && *Node.getArraySize() &&
8202 InnerMatcher.matches(**Node.getArraySize(), Finder, Builder);
8203}
8204
8205/// Matches a class declaration that is defined.
8206///
8207/// Example matches x (matcher = cxxRecordDecl(hasDefinition()))
8208/// \code
8209/// class x {};
8210/// class y;
8211/// \endcode
8212AST_MATCHER(CXXRecordDecl, hasDefinition)namespace internal { class matcher_hasDefinitionMatcher : public
::clang::ast_matchers::internal::MatcherInterface<CXXRecordDecl
> { public: explicit matcher_hasDefinitionMatcher() = default
; bool matches(const CXXRecordDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<CXXRecordDecl>
hasDefinition() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasDefinitionMatcher()); } inline bool
internal::matcher_hasDefinitionMatcher::matches( const CXXRecordDecl
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8213 return Node.hasDefinition();
8214}
8215
8216/// Matches C++11 scoped enum declaration.
8217///
8218/// Example matches Y (matcher = enumDecl(isScoped()))
8219/// \code
8220/// enum X {};
8221/// enum class Y {};
8222/// \endcode
8223AST_MATCHER(EnumDecl, isScoped)namespace internal { class matcher_isScopedMatcher : public ::
clang::ast_matchers::internal::MatcherInterface<EnumDecl>
{ public: explicit matcher_isScopedMatcher() = default; bool
matches(const EnumDecl &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const override; }; } inline ::clang::ast_matchers::
internal::Matcher<EnumDecl> isScoped() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isScopedMatcher
()); } inline bool internal::matcher_isScopedMatcher::matches
( const EnumDecl &Node, ::clang::ast_matchers::internal::
ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8224 return Node.isScoped();
8225}
8226
8227/// Matches a function declared with a trailing return type.
8228///
8229/// Example matches Y (matcher = functionDecl(hasTrailingReturn()))
8230/// \code
8231/// int X() {}
8232/// auto Y() -> int {}
8233/// \endcode
8234AST_MATCHER(FunctionDecl, hasTrailingReturn)namespace internal { class matcher_hasTrailingReturnMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
FunctionDecl> { public: explicit matcher_hasTrailingReturnMatcher
() = default; bool matches(const FunctionDecl &Node, ::clang
::ast_matchers::internal::ASTMatchFinder *Finder, ::clang::ast_matchers
::internal::BoundNodesTreeBuilder *Builder) const override; }
; } inline ::clang::ast_matchers::internal::Matcher<FunctionDecl
> hasTrailingReturn() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_hasTrailingReturnMatcher
()); } inline bool internal::matcher_hasTrailingReturnMatcher
::matches( const FunctionDecl &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8235 if (const auto *F = Node.getType()->getAs<FunctionProtoType>())
8236 return F->hasTrailingReturn();
8237 return false;
8238}
8239
8240/// Matches expressions that match InnerMatcher that are possibly wrapped in an
8241/// elidable constructor and other corresponding bookkeeping nodes.
8242///
8243/// In C++17, elidable copy constructors are no longer being generated in the
8244/// AST as it is not permitted by the standard. They are, however, part of the
8245/// AST in C++14 and earlier. So, a matcher must abstract over these differences
8246/// to work in all language modes. This matcher skips elidable constructor-call
8247/// AST nodes, `ExprWithCleanups` nodes wrapping elidable constructor-calls and
8248/// various implicit nodes inside the constructor calls, all of which will not
8249/// appear in the C++17 AST.
8250///
8251/// Given
8252///
8253/// \code
8254/// struct H {};
8255/// H G();
8256/// void f() {
8257/// H D = G();
8258/// }
8259/// \endcode
8260///
8261/// ``varDecl(hasInitializer(ignoringElidableConstructorCall(callExpr())))``
8262/// matches ``H D = G()`` in C++11 through C++17 (and beyond).
8263AST_MATCHER_P(Expr, ignoringElidableConstructorCall,namespace internal { class matcher_ignoringElidableConstructorCall0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringElidableConstructorCall0Matcher
( ast_matchers::internal::Matcher<Expr> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const Expr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: ast_matchers::internal::Matcher<
Expr> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<Expr> ignoringElidableConstructorCall( ast_matchers
::internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringElidableConstructorCall0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<Expr
> ( &ignoringElidableConstructorCall_Type0)(ast_matchers
::internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringElidableConstructorCall0Matcher
::matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
8264 ast_matchers::internal::Matcher<Expr>, InnerMatcher)namespace internal { class matcher_ignoringElidableConstructorCall0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
Expr> { public: explicit matcher_ignoringElidableConstructorCall0Matcher
( ast_matchers::internal::Matcher<Expr> const &AInnerMatcher
) : InnerMatcher(AInnerMatcher) {} bool matches(const Expr &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: ast_matchers::internal::Matcher<
Expr> InnerMatcher; }; } inline ::clang::ast_matchers::internal
::Matcher<Expr> ignoringElidableConstructorCall( ast_matchers
::internal::Matcher<Expr> const &InnerMatcher) { return
::clang::ast_matchers::internal::makeMatcher( new internal::
matcher_ignoringElidableConstructorCall0Matcher(InnerMatcher)
); } typedef ::clang::ast_matchers::internal::Matcher<Expr
> ( &ignoringElidableConstructorCall_Type0)(ast_matchers
::internal::Matcher<Expr> const &InnerMatcher); inline
bool internal::matcher_ignoringElidableConstructorCall0Matcher
::matches( const Expr &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8265 // E tracks the node that we are examining.
8266 const Expr *E = &Node;
8267 // If present, remove an outer `ExprWithCleanups` corresponding to the
8268 // underlying `CXXConstructExpr`. This check won't cover all cases of added
8269 // `ExprWithCleanups` corresponding to `CXXConstructExpr` nodes (because the
8270 // EWC is placed on the outermost node of the expression, which this may not
8271 // be), but, it still improves the coverage of this matcher.
8272 if (const auto *CleanupsExpr = dyn_cast<ExprWithCleanups>(&Node))
8273 E = CleanupsExpr->getSubExpr();
8274 if (const auto *CtorExpr = dyn_cast<CXXConstructExpr>(E)) {
8275 if (CtorExpr->isElidable()) {
8276 if (const auto *MaterializeTemp =
8277 dyn_cast<MaterializeTemporaryExpr>(CtorExpr->getArg(0))) {
8278 return InnerMatcher.matches(*MaterializeTemp->getSubExpr(), Finder,
8279 Builder);
8280 }
8281 }
8282 }
8283 return InnerMatcher.matches(Node, Finder, Builder);
8284}
8285
8286//----------------------------------------------------------------------------//
8287// OpenMP handling.
8288//----------------------------------------------------------------------------//
8289
8290/// Matches any ``#pragma omp`` executable directive.
8291///
8292/// Given
8293///
8294/// \code
8295/// #pragma omp parallel
8296/// #pragma omp parallel default(none)
8297/// #pragma omp taskyield
8298/// \endcode
8299///
8300/// ``ompExecutableDirective()`` matches ``omp parallel``,
8301/// ``omp parallel default(none)`` and ``omp taskyield``.
8302extern const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective>
8303 ompExecutableDirective;
8304
8305/// Matches standalone OpenMP directives,
8306/// i.e., directives that can't have a structured block.
8307///
8308/// Given
8309///
8310/// \code
8311/// #pragma omp parallel
8312/// {}
8313/// #pragma omp taskyield
8314/// \endcode
8315///
8316/// ``ompExecutableDirective(isStandaloneDirective()))`` matches
8317/// ``omp taskyield``.
8318AST_MATCHER(OMPExecutableDirective, isStandaloneDirective)namespace internal { class matcher_isStandaloneDirectiveMatcher
: public ::clang::ast_matchers::internal::MatcherInterface<
OMPExecutableDirective> { public: explicit matcher_isStandaloneDirectiveMatcher
() = default; bool matches(const OMPExecutableDirective &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; }; } inline ::clang::ast_matchers::internal
::Matcher<OMPExecutableDirective> isStandaloneDirective
() { return ::clang::ast_matchers::internal::makeMatcher( new
internal::matcher_isStandaloneDirectiveMatcher()); } inline bool
internal::matcher_isStandaloneDirectiveMatcher::matches( const
OMPExecutableDirective &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8319 return Node.isStandaloneDirective();
8320}
8321
8322/// Matches the structured-block of the OpenMP executable directive
8323///
8324/// Prerequisite: the executable directive must not be standalone directive.
8325/// If it is, it will never match.
8326///
8327/// Given
8328///
8329/// \code
8330/// #pragma omp parallel
8331/// ;
8332/// #pragma omp parallel
8333/// {}
8334/// \endcode
8335///
8336/// ``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;``
8337AST_MATCHER_P(OMPExecutableDirective, hasStructuredBlock,namespace internal { class matcher_hasStructuredBlock0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
OMPExecutableDirective> { public: explicit matcher_hasStructuredBlock0Matcher
( internal::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const OMPExecutableDirective &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Stmt> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<OMPExecutableDirective
> hasStructuredBlock( internal::Matcher<Stmt> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasStructuredBlock0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<OMPExecutableDirective
> ( &hasStructuredBlock_Type0)(internal::Matcher<Stmt
> const &InnerMatcher); inline bool internal::matcher_hasStructuredBlock0Matcher
::matches( const OMPExecutableDirective &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
8338 internal::Matcher<Stmt>, InnerMatcher)namespace internal { class matcher_hasStructuredBlock0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
OMPExecutableDirective> { public: explicit matcher_hasStructuredBlock0Matcher
( internal::Matcher<Stmt> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const OMPExecutableDirective &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<Stmt> InnerMatcher
; }; } inline ::clang::ast_matchers::internal::Matcher<OMPExecutableDirective
> hasStructuredBlock( internal::Matcher<Stmt> const &
InnerMatcher) { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_hasStructuredBlock0Matcher(InnerMatcher
)); } typedef ::clang::ast_matchers::internal::Matcher<OMPExecutableDirective
> ( &hasStructuredBlock_Type0)(internal::Matcher<Stmt
> const &InnerMatcher); inline bool internal::matcher_hasStructuredBlock0Matcher
::matches( const OMPExecutableDirective &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8339 if (Node.isStandaloneDirective())
8340 return false; // Standalone directives have no structured blocks.
8341 return InnerMatcher.matches(*Node.getStructuredBlock(), Finder, Builder);
8342}
8343
8344/// Matches any clause in an OpenMP directive.
8345///
8346/// Given
8347///
8348/// \code
8349/// #pragma omp parallel
8350/// #pragma omp parallel default(none)
8351/// \endcode
8352///
8353/// ``ompExecutableDirective(hasAnyClause(anything()))`` matches
8354/// ``omp parallel default(none)``.
8355AST_MATCHER_P(OMPExecutableDirective, hasAnyClause,namespace internal { class matcher_hasAnyClause0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<OMPExecutableDirective
> { public: explicit matcher_hasAnyClause0Matcher( internal
::Matcher<OMPClause> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const OMPExecutableDirective &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<OMPClause>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<OMPExecutableDirective> hasAnyClause( internal::Matcher
<OMPClause> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasAnyClause0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<OMPExecutableDirective> ( &hasAnyClause_Type0)(internal
::Matcher<OMPClause> const &InnerMatcher); inline bool
internal::matcher_hasAnyClause0Matcher::matches( const OMPExecutableDirective
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
8356 internal::Matcher<OMPClause>, InnerMatcher)namespace internal { class matcher_hasAnyClause0Matcher : public
::clang::ast_matchers::internal::MatcherInterface<OMPExecutableDirective
> { public: explicit matcher_hasAnyClause0Matcher( internal
::Matcher<OMPClause> const &AInnerMatcher) : InnerMatcher
(AInnerMatcher) {} bool matches(const OMPExecutableDirective &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const override; private: internal::Matcher<OMPClause>
InnerMatcher; }; } inline ::clang::ast_matchers::internal::Matcher
<OMPExecutableDirective> hasAnyClause( internal::Matcher
<OMPClause> const &InnerMatcher) { return ::clang::
ast_matchers::internal::makeMatcher( new internal::matcher_hasAnyClause0Matcher
(InnerMatcher)); } typedef ::clang::ast_matchers::internal::Matcher
<OMPExecutableDirective> ( &hasAnyClause_Type0)(internal
::Matcher<OMPClause> const &InnerMatcher); inline bool
internal::matcher_hasAnyClause0Matcher::matches( const OMPExecutableDirective
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8357 ArrayRef<OMPClause *> Clauses = Node.clauses();
8358 return matchesFirstInPointerRange(InnerMatcher, Clauses.begin(),
8359 Clauses.end(), Finder,
8360 Builder) != Clauses.end();
8361}
8362
8363/// Matches OpenMP ``default`` clause.
8364///
8365/// Given
8366///
8367/// \code
8368/// #pragma omp parallel default(none)
8369/// #pragma omp parallel default(shared)
8370/// #pragma omp parallel default(private)
8371/// #pragma omp parallel default(firstprivate)
8372/// #pragma omp parallel
8373/// \endcode
8374///
8375/// ``ompDefaultClause()`` matches ``default(none)``, ``default(shared)``,
8376/// `` default(private)`` and ``default(firstprivate)``
8377extern const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause>
8378 ompDefaultClause;
8379
8380/// Matches if the OpenMP ``default`` clause has ``none`` kind specified.
8381///
8382/// Given
8383///
8384/// \code
8385/// #pragma omp parallel
8386/// #pragma omp parallel default(none)
8387/// #pragma omp parallel default(shared)
8388/// #pragma omp parallel default(private)
8389/// #pragma omp parallel default(firstprivate)
8390/// \endcode
8391///
8392/// ``ompDefaultClause(isNoneKind())`` matches only ``default(none)``.
8393AST_MATCHER(OMPDefaultClause, isNoneKind)namespace internal { class matcher_isNoneKindMatcher : public
::clang::ast_matchers::internal::MatcherInterface<OMPDefaultClause
> { public: explicit matcher_isNoneKindMatcher() = default
; bool matches(const OMPDefaultClause &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<OMPDefaultClause
> isNoneKind() { return ::clang::ast_matchers::internal::makeMatcher
( new internal::matcher_isNoneKindMatcher()); } inline bool internal
::matcher_isNoneKindMatcher::matches( const OMPDefaultClause &
Node, ::clang::ast_matchers::internal::ASTMatchFinder *Finder
, ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder
) const
{
8394 return Node.getDefaultKind() == llvm::omp::OMP_DEFAULT_none;
8395}
8396
8397/// Matches if the OpenMP ``default`` clause has ``shared`` kind specified.
8398///
8399/// Given
8400///
8401/// \code
8402/// #pragma omp parallel
8403/// #pragma omp parallel default(none)
8404/// #pragma omp parallel default(shared)
8405/// #pragma omp parallel default(private)
8406/// #pragma omp parallel default(firstprivate)
8407/// \endcode
8408///
8409/// ``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``.
8410AST_MATCHER(OMPDefaultClause, isSharedKind)namespace internal { class matcher_isSharedKindMatcher : public
::clang::ast_matchers::internal::MatcherInterface<OMPDefaultClause
> { public: explicit matcher_isSharedKindMatcher() = default
; bool matches(const OMPDefaultClause &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<OMPDefaultClause
> isSharedKind() { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_isSharedKindMatcher()); } inline
bool internal::matcher_isSharedKindMatcher::matches( const OMPDefaultClause
&Node, ::clang::ast_matchers::internal::ASTMatchFinder *
Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8411 return Node.getDefaultKind() == llvm::omp::OMP_DEFAULT_shared;
8412}
8413
8414/// Matches if the OpenMP ``default`` clause has ``private`` kind
8415/// specified.
8416///
8417/// Given
8418///
8419/// \code
8420/// #pragma omp parallel
8421/// #pragma omp parallel default(none)
8422/// #pragma omp parallel default(shared)
8423/// #pragma omp parallel default(private)
8424/// #pragma omp parallel default(firstprivate)
8425/// \endcode
8426///
8427/// ``ompDefaultClause(isPrivateKind())`` matches only
8428/// ``default(private)``.
8429AST_MATCHER(OMPDefaultClause, isPrivateKind)namespace internal { class matcher_isPrivateKindMatcher : public
::clang::ast_matchers::internal::MatcherInterface<OMPDefaultClause
> { public: explicit matcher_isPrivateKindMatcher() = default
; bool matches(const OMPDefaultClause &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; }; } inline
::clang::ast_matchers::internal::Matcher<OMPDefaultClause
> isPrivateKind() { return ::clang::ast_matchers::internal
::makeMatcher( new internal::matcher_isPrivateKindMatcher());
} inline bool internal::matcher_isPrivateKindMatcher::matches
( const OMPDefaultClause &Node, ::clang::ast_matchers::internal
::ASTMatchFinder *Finder, ::clang::ast_matchers::internal::BoundNodesTreeBuilder
*Builder) const
{
8430 return Node.getDefaultKind() == llvm::omp::OMP_DEFAULT_private;
8431}
8432
8433/// Matches if the OpenMP ``default`` clause has ``firstprivate`` kind
8434/// specified.
8435///
8436/// Given
8437///
8438/// \code
8439/// #pragma omp parallel
8440/// #pragma omp parallel default(none)
8441/// #pragma omp parallel default(shared)
8442/// #pragma omp parallel default(private)
8443/// #pragma omp parallel default(firstprivate)
8444/// \endcode
8445///
8446/// ``ompDefaultClause(isFirstPrivateKind())`` matches only
8447/// ``default(firstprivate)``.
8448AST_MATCHER(OMPDefaultClause, isFirstPrivateKind)namespace internal { class matcher_isFirstPrivateKindMatcher :
public ::clang::ast_matchers::internal::MatcherInterface<
OMPDefaultClause> { public: explicit matcher_isFirstPrivateKindMatcher
() = default; bool matches(const OMPDefaultClause &Node, ::
clang::ast_matchers::internal::ASTMatchFinder *Finder, ::clang
::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
override; }; } inline ::clang::ast_matchers::internal::Matcher
<OMPDefaultClause> isFirstPrivateKind() { return ::clang
::ast_matchers::internal::makeMatcher( new internal::matcher_isFirstPrivateKindMatcher
()); } inline bool internal::matcher_isFirstPrivateKindMatcher
::matches( const OMPDefaultClause &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8449 return Node.getDefaultKind() == llvm::omp::OMP_DEFAULT_firstprivate;
8450}
8451
8452/// Matches if the OpenMP directive is allowed to contain the specified OpenMP
8453/// clause kind.
8454///
8455/// Given
8456///
8457/// \code
8458/// #pragma omp parallel
8459/// #pragma omp parallel for
8460/// #pragma omp for
8461/// \endcode
8462///
8463/// `ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches
8464/// ``omp parallel`` and ``omp parallel for``.
8465///
8466/// If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter
8467/// should be passed as a quoted string. e.g.,
8468/// ``isAllowedToContainClauseKind("OMPC_default").``
8469AST_MATCHER_P(OMPExecutableDirective, isAllowedToContainClauseKind,namespace internal { class matcher_isAllowedToContainClauseKind0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
OMPExecutableDirective> { public: explicit matcher_isAllowedToContainClauseKind0Matcher
( OpenMPClauseKind const &ACKind) : CKind(ACKind) {} bool
matches(const OMPExecutableDirective &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: OpenMPClauseKind
CKind; }; } inline ::clang::ast_matchers::internal::Matcher<
OMPExecutableDirective> isAllowedToContainClauseKind( OpenMPClauseKind
const &CKind) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_isAllowedToContainClauseKind0Matcher
(CKind)); } typedef ::clang::ast_matchers::internal::Matcher<
OMPExecutableDirective> ( &isAllowedToContainClauseKind_Type0
)(OpenMPClauseKind const &CKind); inline bool internal::matcher_isAllowedToContainClauseKind0Matcher
::matches( const OMPExecutableDirective &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
8470 OpenMPClauseKind, CKind)namespace internal { class matcher_isAllowedToContainClauseKind0Matcher
: public ::clang::ast_matchers::internal::MatcherInterface<
OMPExecutableDirective> { public: explicit matcher_isAllowedToContainClauseKind0Matcher
( OpenMPClauseKind const &ACKind) : CKind(ACKind) {} bool
matches(const OMPExecutableDirective &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const override; private: OpenMPClauseKind
CKind; }; } inline ::clang::ast_matchers::internal::Matcher<
OMPExecutableDirective> isAllowedToContainClauseKind( OpenMPClauseKind
const &CKind) { return ::clang::ast_matchers::internal::
makeMatcher( new internal::matcher_isAllowedToContainClauseKind0Matcher
(CKind)); } typedef ::clang::ast_matchers::internal::Matcher<
OMPExecutableDirective> ( &isAllowedToContainClauseKind_Type0
)(OpenMPClauseKind const &CKind); inline bool internal::matcher_isAllowedToContainClauseKind0Matcher
::matches( const OMPExecutableDirective &Node, ::clang::ast_matchers
::internal::ASTMatchFinder *Finder, ::clang::ast_matchers::internal
::BoundNodesTreeBuilder *Builder) const
{
8471 return llvm::omp::isAllowedClauseForDirective(
8472 Node.getDirectiveKind(), CKind,
8473 Finder->getASTContext().getLangOpts().OpenMP);
8474}
8475
8476//----------------------------------------------------------------------------//
8477// End OpenMP handling.
8478//----------------------------------------------------------------------------//
8479
8480} // namespace ast_matchers
8481} // namespace clang
8482
8483#endif // LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H

/build/source/clang/include/clang/ASTMatchers/ASTMatchersInternal.h

1//===- ASTMatchersInternal.h - Structural query framework -------*- C++ -*-===//
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// Implements the base layer of the matcher framework.
10//
11// Matchers are methods that return a Matcher<T> which provides a method
12// Matches(...) which is a predicate on an AST node. The Matches method's
13// parameters define the context of the match, which allows matchers to recurse
14// or store the current node as bound to a specific string, so that it can be
15// retrieved later.
16//
17// In general, matchers have two parts:
18// 1. A function Matcher<T> MatcherName(<arguments>) which returns a Matcher<T>
19// based on the arguments and optionally on template type deduction based
20// on the arguments. Matcher<T>s form an implicit reverse hierarchy
21// to clang's AST class hierarchy, meaning that you can use a Matcher<Base>
22// everywhere a Matcher<Derived> is required.
23// 2. An implementation of a class derived from MatcherInterface<T>.
24//
25// The matcher functions are defined in ASTMatchers.h. To make it possible
26// to implement both the matcher function and the implementation of the matcher
27// interface in one place, ASTMatcherMacros.h defines macros that allow
28// implementing a matcher in a single place.
29//
30// This file contains the base classes needed to construct the actual matchers.
31//
32//===----------------------------------------------------------------------===//
33
34#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSINTERNAL_H
35#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSINTERNAL_H
36
37#include "clang/AST/ASTTypeTraits.h"
38#include "clang/AST/Decl.h"
39#include "clang/AST/DeclCXX.h"
40#include "clang/AST/DeclFriend.h"
41#include "clang/AST/DeclTemplate.h"
42#include "clang/AST/Expr.h"
43#include "clang/AST/ExprCXX.h"
44#include "clang/AST/ExprObjC.h"
45#include "clang/AST/NestedNameSpecifier.h"
46#include "clang/AST/Stmt.h"
47#include "clang/AST/TemplateName.h"
48#include "clang/AST/Type.h"
49#include "clang/AST/TypeLoc.h"
50#include "clang/Basic/LLVM.h"
51#include "clang/Basic/OperatorKinds.h"
52#include "llvm/ADT/APFloat.h"
53#include "llvm/ADT/ArrayRef.h"
54#include "llvm/ADT/IntrusiveRefCntPtr.h"
55#include "llvm/ADT/STLExtras.h"
56#include "llvm/ADT/SmallVector.h"
57#include "llvm/ADT/StringRef.h"
58#include "llvm/ADT/iterator.h"
59#include "llvm/Support/Casting.h"
60#include "llvm/Support/ManagedStatic.h"
61#include "llvm/Support/Regex.h"
62#include <algorithm>
63#include <cassert>
64#include <cstddef>
65#include <cstdint>
66#include <map>
67#include <memory>
68#include <optional>
69#include <string>
70#include <tuple>
71#include <type_traits>
72#include <utility>
73#include <vector>
74
75namespace clang {
76
77class ASTContext;
78
79namespace ast_matchers {
80
81class BoundNodes;
82
83namespace internal {
84
85/// A type-list implementation.
86///
87/// A "linked list" of types, accessible by using the ::head and ::tail
88/// typedefs.
89template <typename... Ts> struct TypeList {}; // Empty sentinel type list.
90
91template <typename T1, typename... Ts> struct TypeList<T1, Ts...> {
92 /// The first type on the list.
93 using head = T1;
94
95 /// A sublist with the tail. ie everything but the head.
96 ///
97 /// This type is used to do recursion. TypeList<>/EmptyTypeList indicates the
98 /// end of the list.
99 using tail = TypeList<Ts...>;
100};
101
102/// The empty type list.
103using EmptyTypeList = TypeList<>;
104
105/// Helper meta-function to determine if some type \c T is present or
106/// a parent type in the list.
107template <typename AnyTypeList, typename T> struct TypeListContainsSuperOf {
108 static const bool value =
109 std::is_base_of<typename AnyTypeList::head, T>::value ||
110 TypeListContainsSuperOf<typename AnyTypeList::tail, T>::value;
111};
112template <typename T> struct TypeListContainsSuperOf<EmptyTypeList, T> {
113 static const bool value = false;
114};
115
116/// Variadic function object.
117///
118/// Most of the functions below that use VariadicFunction could be implemented
119/// using plain C++11 variadic functions, but the function object allows us to
120/// capture it on the dynamic matcher registry.
121template <typename ResultT, typename ArgT,
122 ResultT (*Func)(ArrayRef<const ArgT *>)>
123struct VariadicFunction {
124 ResultT operator()() const { return Func(std::nullopt); }
125
126 template <typename... ArgsT>
127 ResultT operator()(const ArgT &Arg1, const ArgsT &... Args) const {
128 return Execute(Arg1, static_cast<const ArgT &>(Args)...);
129 }
130
131 // We also allow calls with an already created array, in case the caller
132 // already had it.
133 ResultT operator()(ArrayRef<ArgT> Args) const {
134 return Func(llvm::to_vector<8>(llvm::make_pointer_range(Args)));
135 }
136
137private:
138 // Trampoline function to allow for implicit conversions to take place
139 // before we make the array.
140 template <typename... ArgsT> ResultT Execute(const ArgsT &... Args) const {
141 const ArgT *const ArgsArray[] = {&Args...};
142 return Func(ArrayRef<const ArgT *>(ArgsArray, sizeof...(ArgsT)));
143 }
144};
145
146/// Unifies obtaining the underlying type of a regular node through
147/// `getType` and a TypedefNameDecl node through `getUnderlyingType`.
148inline QualType getUnderlyingType(const Expr &Node) { return Node.getType(); }
149
150inline QualType getUnderlyingType(const ValueDecl &Node) {
151 return Node.getType();
152}
153inline QualType getUnderlyingType(const TypedefNameDecl &Node) {
154 return Node.getUnderlyingType();
155}
156inline QualType getUnderlyingType(const FriendDecl &Node) {
157 if (const TypeSourceInfo *TSI = Node.getFriendType())
158 return TSI->getType();
159 return QualType();
160}
161inline QualType getUnderlyingType(const CXXBaseSpecifier &Node) {
162 return Node.getType();
163}
164
165/// Unifies obtaining a `TypeSourceInfo` from different node types.
166template <typename T,
167 std::enable_if_t<TypeListContainsSuperOf<
168 TypeList<CXXBaseSpecifier, CXXCtorInitializer,
169 CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr,
170 CompoundLiteralExpr, DeclaratorDecl, ObjCPropertyDecl,
171 TemplateArgumentLoc, TypedefNameDecl>,
172 T>::value> * = nullptr>
173inline TypeSourceInfo *GetTypeSourceInfo(const T &Node) {
174 return Node.getTypeSourceInfo();
175}
176template <typename T,
177 std::enable_if_t<TypeListContainsSuperOf<
178 TypeList<CXXFunctionalCastExpr, ExplicitCastExpr>, T>::value> * =
179 nullptr>
180inline TypeSourceInfo *GetTypeSourceInfo(const T &Node) {
181 return Node.getTypeInfoAsWritten();
182}
183inline TypeSourceInfo *GetTypeSourceInfo(const BlockDecl &Node) {
184 return Node.getSignatureAsWritten();
185}
186inline TypeSourceInfo *GetTypeSourceInfo(const CXXNewExpr &Node) {
187 return Node.getAllocatedTypeSourceInfo();
188}
189inline TypeSourceInfo *
190GetTypeSourceInfo(const ClassTemplateSpecializationDecl &Node) {
191 return Node.getTypeAsWritten();
192}
193
194/// Unifies obtaining the FunctionProtoType pointer from both
195/// FunctionProtoType and FunctionDecl nodes..
196inline const FunctionProtoType *
197getFunctionProtoType(const FunctionProtoType &Node) {
198 return &Node;
199}
200
201inline const FunctionProtoType *getFunctionProtoType(const FunctionDecl &Node) {
202 return Node.getType()->getAs<FunctionProtoType>();
203}
204
205/// Unifies obtaining the access specifier from Decl and CXXBaseSpecifier nodes.
206inline clang::AccessSpecifier getAccessSpecifier(const Decl &Node) {
207 return Node.getAccess();
208}
209
210inline clang::AccessSpecifier getAccessSpecifier(const CXXBaseSpecifier &Node) {
211 return Node.getAccessSpecifier();
212}
213
214/// Internal version of BoundNodes. Holds all the bound nodes.
215class BoundNodesMap {
216public:
217 /// Adds \c Node to the map with key \c ID.
218 ///
219 /// The node's base type should be in NodeBaseType or it will be unaccessible.
220 void addNode(StringRef ID, const DynTypedNode &DynNode) {
221 NodeMap[std::string(ID)] = DynNode;
222 }
223
224 /// Returns the AST node bound to \c ID.
225 ///
226 /// Returns NULL if there was no node bound to \c ID or if there is a node but
227 /// it cannot be converted to the specified type.
228 template <typename T>
229 const T *getNodeAs(StringRef ID) const {
230 IDToNodeMap::const_iterator It = NodeMap.find(ID);
231 if (It == NodeMap.end()) {
4
Taking false branch
19
Taking true branch
26
Taking true branch
34
Taking false branch
232 return nullptr;
20
Returning null pointer, which participates in a condition later
27
Returning null pointer, which participates in a condition later
233 }
234 return It->second.get<T>();
5
Calling 'DynTypedNode::get'
12
Returning from 'DynTypedNode::get'
13
Returning null pointer, which participates in a condition later
35
Calling 'DynTypedNode::get'
42
Returning from 'DynTypedNode::get'
43
Returning pointer, which participates in a condition later
235 }
236
237 DynTypedNode getNode(StringRef ID) const {
238 IDToNodeMap::const_iterator It = NodeMap.find(ID);
239 if (It == NodeMap.end()) {
240 return DynTypedNode();
241 }
242 return It->second;
243 }
244
245 /// Imposes an order on BoundNodesMaps.
246 bool operator<(const BoundNodesMap &Other) const {
247 return NodeMap < Other.NodeMap;
248 }
249
250 /// A map from IDs to the bound nodes.
251 ///
252 /// Note that we're using std::map here, as for memoization:
253 /// - we need a comparison operator
254 /// - we need an assignment operator
255 using IDToNodeMap = std::map<std::string, DynTypedNode, std::less<>>;
256
257 const IDToNodeMap &getMap() const {
258 return NodeMap;
259 }
260
261 /// Returns \c true if this \c BoundNodesMap can be compared, i.e. all
262 /// stored nodes have memoization data.
263 bool isComparable() const {
264 for (const auto &IDAndNode : NodeMap) {
265 if (!IDAndNode.second.getMemoizationData())
266 return false;
267 }
268 return true;
269 }
270
271private:
272 IDToNodeMap NodeMap;
273};
274
275/// Creates BoundNodesTree objects.
276///
277/// The tree builder is used during the matching process to insert the bound
278/// nodes from the Id matcher.
279class BoundNodesTreeBuilder {
280public:
281 /// A visitor interface to visit all BoundNodes results for a
282 /// BoundNodesTree.
283 class Visitor {
284 public:
285 virtual ~Visitor() = default;
286
287 /// Called multiple times during a single call to VisitMatches(...).
288 ///
289 /// 'BoundNodesView' contains the bound nodes for a single match.
290 virtual void visitMatch(const BoundNodes& BoundNodesView) = 0;
291 };
292
293 /// Add a binding from an id to a node.
294 void setBinding(StringRef Id, const DynTypedNode &DynNode) {
295 if (Bindings.empty())
296 Bindings.emplace_back();
297 for (BoundNodesMap &Binding : Bindings)
298 Binding.addNode(Id, DynNode);
299 }
300
301 /// Adds a branch in the tree.
302 void addMatch(const BoundNodesTreeBuilder &Bindings);
303
304 /// Visits all matches that this BoundNodesTree represents.
305 ///
306 /// The ownership of 'ResultVisitor' remains at the caller.
307 void visitMatches(Visitor* ResultVisitor);
308
309 template <typename ExcludePredicate>
310 bool removeBindings(const ExcludePredicate &Predicate) {
311 llvm::erase_if(Bindings, Predicate);
312 return !Bindings.empty();
313 }
314
315 /// Imposes an order on BoundNodesTreeBuilders.
316 bool operator<(const BoundNodesTreeBuilder &Other) const {
317 return Bindings < Other.Bindings;
318 }
319
320 /// Returns \c true if this \c BoundNodesTreeBuilder can be compared,
321 /// i.e. all stored node maps have memoization data.
322 bool isComparable() const {
323 for (const BoundNodesMap &NodesMap : Bindings) {
324 if (!NodesMap.isComparable())
325 return false;
326 }
327 return true;
328 }
329
330private:
331 SmallVector<BoundNodesMap, 1> Bindings;
332};
333
334class ASTMatchFinder;
335
336/// Generic interface for all matchers.
337///
338/// Used by the implementation of Matcher<T> and DynTypedMatcher.
339/// In general, implement MatcherInterface<T> or SingleNodeMatcherInterface<T>
340/// instead.
341class DynMatcherInterface
342 : public llvm::ThreadSafeRefCountedBase<DynMatcherInterface> {
343public:
344 virtual ~DynMatcherInterface() = default;
345
346 /// Returns true if \p DynNode can be matched.
347 ///
348 /// May bind \p DynNode to an ID via \p Builder, or recurse into
349 /// the AST via \p Finder.
350 virtual bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
351 BoundNodesTreeBuilder *Builder) const = 0;
352
353 virtual std::optional<clang::TraversalKind> TraversalKind() const {
354 return std::nullopt;
355 }
356};
357
358/// Generic interface for matchers on an AST node of type T.
359///
360/// Implement this if your matcher may need to inspect the children or
361/// descendants of the node or bind matched nodes to names. If you are
362/// writing a simple matcher that only inspects properties of the
363/// current node and doesn't care about its children or descendants,
364/// implement SingleNodeMatcherInterface instead.
365template <typename T>
366class MatcherInterface : public DynMatcherInterface {
367public:
368 /// Returns true if 'Node' can be matched.
369 ///
370 /// May bind 'Node' to an ID via 'Builder', or recurse into
371 /// the AST via 'Finder'.
372 virtual bool matches(const T &Node,
373 ASTMatchFinder *Finder,
374 BoundNodesTreeBuilder *Builder) const = 0;
375
376 bool dynMatches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
377 BoundNodesTreeBuilder *Builder) const override {
378 return matches(DynNode.getUnchecked<T>(), Finder, Builder);
379 }
380};
381
382/// Interface for matchers that only evaluate properties on a single
383/// node.
384template <typename T>
385class SingleNodeMatcherInterface : public MatcherInterface<T> {
386public:
387 /// Returns true if the matcher matches the provided node.
388 ///
389 /// A subclass must implement this instead of Matches().
390 virtual bool matchesNode(const T &Node) const = 0;
391
392private:
393 /// Implements MatcherInterface::Matches.
394 bool matches(const T &Node,
395 ASTMatchFinder * /* Finder */,
396 BoundNodesTreeBuilder * /* Builder */) const override {
397 return matchesNode(Node);
398 }
399};
400
401template <typename> class Matcher;
402
403/// Matcher that works on a \c DynTypedNode.
404///
405/// It is constructed from a \c Matcher<T> object and redirects most calls to
406/// underlying matcher.
407/// It checks whether the \c DynTypedNode is convertible into the type of the
408/// underlying matcher and then do the actual match on the actual node, or
409/// return false if it is not convertible.
410class DynTypedMatcher {
411public:
412 /// Takes ownership of the provided implementation pointer.
413 template <typename T>
414 DynTypedMatcher(MatcherInterface<T> *Implementation)
415 : SupportedKind(ASTNodeKind::getFromNodeKind<T>()),
416 RestrictKind(SupportedKind), Implementation(Implementation) {}
417
418 /// Construct from a variadic function.
419 enum VariadicOperator {
420 /// Matches nodes for which all provided matchers match.
421 VO_AllOf,
422
423 /// Matches nodes for which at least one of the provided matchers
424 /// matches.
425 VO_AnyOf,
426
427 /// Matches nodes for which at least one of the provided matchers
428 /// matches, but doesn't stop at the first match.
429 VO_EachOf,
430
431 /// Matches any node but executes all inner matchers to find result
432 /// bindings.
433 VO_Optionally,
434
435 /// Matches nodes that do not match the provided matcher.
436 ///
437 /// Uses the variadic matcher interface, but fails if
438 /// InnerMatchers.size() != 1.
439 VO_UnaryNot
440 };
441
442 static DynTypedMatcher
443 constructVariadic(VariadicOperator Op, ASTNodeKind SupportedKind,
444 std::vector<DynTypedMatcher> InnerMatchers);
445
446 static DynTypedMatcher
447 constructRestrictedWrapper(const DynTypedMatcher &InnerMatcher,
448 ASTNodeKind RestrictKind);
449
450 /// Get a "true" matcher for \p NodeKind.
451 ///
452 /// It only checks that the node is of the right kind.
453 static DynTypedMatcher trueMatcher(ASTNodeKind NodeKind);
454
455 void setAllowBind(bool AB) { AllowBind = AB; }
456
457 /// Check whether this matcher could ever match a node of kind \p Kind.
458 /// \return \c false if this matcher will never match such a node. Otherwise,
459 /// return \c true.
460 bool canMatchNodesOfKind(ASTNodeKind Kind) const;
461
462 /// Return a matcher that points to the same implementation, but
463 /// restricts the node types for \p Kind.
464 DynTypedMatcher dynCastTo(const ASTNodeKind Kind) const;
465
466 /// Return a matcher that points to the same implementation, but sets the
467 /// traversal kind.
468 ///
469 /// If the traversal kind is already set, then \c TK overrides it.
470 DynTypedMatcher withTraversalKind(TraversalKind TK);
471
472 /// Returns true if the matcher matches the given \c DynNode.
473 bool matches(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
474 BoundNodesTreeBuilder *Builder) const;
475
476 /// Same as matches(), but skips the kind check.
477 ///
478 /// It is faster, but the caller must ensure the node is valid for the
479 /// kind of this matcher.
480 bool matchesNoKindCheck(const DynTypedNode &DynNode, ASTMatchFinder *Finder,
481 BoundNodesTreeBuilder *Builder) const;
482
483 /// Bind the specified \p ID to the matcher.
484 /// \return A new matcher with the \p ID bound to it if this matcher supports
485 /// binding. Otherwise, returns an empty \c std::optional<>.
486 std::optional<DynTypedMatcher> tryBind(StringRef ID) const;
487
488 /// Returns a unique \p ID for the matcher.
489 ///
490 /// Casting a Matcher<T> to Matcher<U> creates a matcher that has the
491 /// same \c Implementation pointer, but different \c RestrictKind. We need to
492 /// include both in the ID to make it unique.
493 ///
494 /// \c MatcherIDType supports operator< and provides strict weak ordering.
495 using MatcherIDType = std::pair<ASTNodeKind, uint64_t>;
496 MatcherIDType getID() const {
497 /// FIXME: Document the requirements this imposes on matcher
498 /// implementations (no new() implementation_ during a Matches()).
499 return std::make_pair(RestrictKind,
500 reinterpret_cast<uint64_t>(Implementation.get()));
501 }
502
503 /// Returns the type this matcher works on.
504 ///
505 /// \c matches() will always return false unless the node passed is of this
506 /// or a derived type.
507 ASTNodeKind getSupportedKind() const { return SupportedKind; }
508
509 /// Returns \c true if the passed \c DynTypedMatcher can be converted
510 /// to a \c Matcher<T>.
511 ///
512 /// This method verifies that the underlying matcher in \c Other can process
513 /// nodes of types T.
514 template <typename T> bool canConvertTo() const {
515 return canConvertTo(ASTNodeKind::getFromNodeKind<T>());
516 }
517 bool canConvertTo(ASTNodeKind To) const;
518
519 /// Construct a \c Matcher<T> interface around the dynamic matcher.
520 ///
521 /// This method asserts that \c canConvertTo() is \c true. Callers
522 /// should call \c canConvertTo() first to make sure that \c this is
523 /// compatible with T.
524 template <typename T> Matcher<T> convertTo() const {
525 assert(canConvertTo<T>())(static_cast <bool> (canConvertTo<T>()) ? void (0
) : __assert_fail ("canConvertTo<T>()", "clang/include/clang/ASTMatchers/ASTMatchersInternal.h"
, 525, __extension__ __PRETTY_FUNCTION__))
;
526 return unconditionalConvertTo<T>();
527 }
528
529 /// Same as \c convertTo(), but does not check that the underlying
530 /// matcher can handle a value of T.
531 ///
532 /// If it is not compatible, then this matcher will never match anything.
533 template <typename T> Matcher<T> unconditionalConvertTo() const;
534
535 /// Returns the \c TraversalKind respected by calls to `match()`, if any.
536 ///
537 /// Most matchers will not have a traversal kind set, instead relying on the
538 /// surrounding context. For those, \c std::nullopt is returned.
539 std::optional<clang::TraversalKind> getTraversalKind() const {
540 return Implementation->TraversalKind();
541 }
542
543private:
544 DynTypedMatcher(ASTNodeKind SupportedKind, ASTNodeKind RestrictKind,
545 IntrusiveRefCntPtr<DynMatcherInterface> Implementation)
546 : SupportedKind(SupportedKind), RestrictKind(RestrictKind),
547 Implementation(std::move(Implementation)) {}
548
549 bool AllowBind = false;
550 ASTNodeKind SupportedKind;
551
552 /// A potentially stricter node kind.
553 ///
554 /// It allows to perform implicit and dynamic cast of matchers without
555 /// needing to change \c Implementation.
556 ASTNodeKind RestrictKind;
557 IntrusiveRefCntPtr<DynMatcherInterface> Implementation;
558};
559
560/// Wrapper of a MatcherInterface<T> *that allows copying.
561///
562/// A Matcher<Base> can be used anywhere a Matcher<Derived> is
563/// required. This establishes an is-a relationship which is reverse
564/// to the AST hierarchy. In other words, Matcher<T> is contravariant
565/// with respect to T. The relationship is built via a type conversion
566/// operator rather than a type hierarchy to be able to templatize the
567/// type hierarchy instead of spelling it out.
568template <typename T>
569class Matcher {
570public:
571 /// Takes ownership of the provided implementation pointer.
572 explicit Matcher(MatcherInterface<T> *Implementation)
573 : Implementation(Implementation) {}
574
575 /// Implicitly converts \c Other to a Matcher<T>.
576 ///
577 /// Requires \c T to be derived from \c From.
578 template <typename From>
579 Matcher(const Matcher<From> &Other,
580 std::enable_if_t<std::is_base_of<From, T>::value &&
581 !std::is_same<From, T>::value> * = nullptr)
582 : Implementation(restrictMatcher(Other.Implementation)) {
583 assert(Implementation.getSupportedKind().isSame((static_cast <bool> (Implementation.getSupportedKind().
isSame( ASTNodeKind::getFromNodeKind<T>())) ? void (0) :
__assert_fail ("Implementation.getSupportedKind().isSame( ASTNodeKind::getFromNodeKind<T>())"
, "clang/include/clang/ASTMatchers/ASTMatchersInternal.h", 584
, __extension__ __PRETTY_FUNCTION__))
584 ASTNodeKind::getFromNodeKind<T>()))(static_cast <bool> (Implementation.getSupportedKind().
isSame( ASTNodeKind::getFromNodeKind<T>())) ? void (0) :
__assert_fail ("Implementation.getSupportedKind().isSame( ASTNodeKind::getFromNodeKind<T>())"
, "clang/include/clang/ASTMatchers/ASTMatchersInternal.h", 584
, __extension__ __PRETTY_FUNCTION__))
;
585 }
586
587 /// Implicitly converts \c Matcher<Type> to \c Matcher<QualType>.
588 ///
589 /// The resulting matcher is not strict, i.e. ignores qualifiers.
590 template <typename TypeT>
591 Matcher(const Matcher<TypeT> &Other,
592 std::enable_if_t<std::is_same<T, QualType>::value &&
593 std::is_same<TypeT, Type>::value> * = nullptr)
594 : Implementation(new TypeToQualType<TypeT>(Other)) {}
595
596 /// Convert \c this into a \c Matcher<T> by applying dyn_cast<> to the
597 /// argument.
598 /// \c To must be a base class of \c T.
599 template <typename To> Matcher<To> dynCastTo() const & {
600 static_assert(std::is_base_of<To, T>::value, "Invalid dynCast call.");
601 return Matcher<To>(Implementation);
602 }
603
604 template <typename To> Matcher<To> dynCastTo() && {
605 static_assert(std::is_base_of<To, T>::value, "Invalid dynCast call.");
606 return Matcher<To>(std::move(Implementation));
607 }
608
609 /// Forwards the call to the underlying MatcherInterface<T> pointer.
610 bool matches(const T &Node,
611 ASTMatchFinder *Finder,
612 BoundNodesTreeBuilder *Builder) const {
613 return Implementation.matches(DynTypedNode::create(Node), Finder, Builder);
614 }
615
616 /// Returns an ID that uniquely identifies the matcher.
617 DynTypedMatcher::MatcherIDType getID() const {
618 return Implementation.getID();
619 }
620
621 /// Extract the dynamic matcher.
622 ///
623 /// The returned matcher keeps the same restrictions as \c this and remembers
624 /// that it is meant to support nodes of type \c T.
625 operator DynTypedMatcher() const & { return Implementation; }
626
627 operator DynTypedMatcher() && { return std::move(Implementation); }
628
629 /// Allows the conversion of a \c Matcher<Type> to a \c
630 /// Matcher<QualType>.
631 ///
632 /// Depending on the constructor argument, the matcher is either strict, i.e.
633 /// does only matches in the absence of qualifiers, or not, i.e. simply
634 /// ignores any qualifiers.
635 template <typename TypeT>
636 class TypeToQualType : public MatcherInterface<QualType> {
637 const DynTypedMatcher InnerMatcher;
638
639 public:
640 TypeToQualType(const Matcher<TypeT> &InnerMatcher)
641 : InnerMatcher(InnerMatcher) {}
642
643 bool matches(const QualType &Node, ASTMatchFinder *Finder,
644 BoundNodesTreeBuilder *Builder) const override {
645 if (Node.isNull())
646 return false;
647 return this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder,
648 Builder);
649 }
650
651 std::optional<clang::TraversalKind> TraversalKind() const override {
652 return this->InnerMatcher.getTraversalKind();
653 }
654 };
655
656private:
657 // For Matcher<T> <=> Matcher<U> conversions.
658 template <typename U> friend class Matcher;
659
660 // For DynTypedMatcher::unconditionalConvertTo<T>.
661 friend class DynTypedMatcher;
662
663 static DynTypedMatcher restrictMatcher(const DynTypedMatcher &Other) {
664 return Other.dynCastTo(ASTNodeKind::getFromNodeKind<T>());
665 }
666
667 explicit Matcher(const DynTypedMatcher &Implementation)
668 : Implementation(restrictMatcher(Implementation)) {
669 assert(this->Implementation.getSupportedKind().isSame((static_cast <bool> (this->Implementation.getSupportedKind
().isSame( ASTNodeKind::getFromNodeKind<T>())) ? void (
0) : __assert_fail ("this->Implementation.getSupportedKind().isSame( ASTNodeKind::getFromNodeKind<T>())"
, "clang/include/clang/ASTMatchers/ASTMatchersInternal.h", 670
, __extension__ __PRETTY_FUNCTION__))
670 ASTNodeKind::getFromNodeKind<T>()))(static_cast <bool> (this->Implementation.getSupportedKind
().isSame( ASTNodeKind::getFromNodeKind<T>())) ? void (
0) : __assert_fail ("this->Implementation.getSupportedKind().isSame( ASTNodeKind::getFromNodeKind<T>())"
, "clang/include/clang/ASTMatchers/ASTMatchersInternal.h", 670
, __extension__ __PRETTY_FUNCTION__))
;
671 }
672
673 DynTypedMatcher Implementation;
674}; // class Matcher
675
676/// A convenient helper for creating a Matcher<T> without specifying
677/// the template type argument.
678template <typename T>
679inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) {
680 return Matcher<T>(Implementation);
681}
682
683/// Interface that allows matchers to traverse the AST.
684/// FIXME: Find a better name.
685///
686/// This provides three entry methods for each base node type in the AST:
687/// - \c matchesChildOf:
688/// Matches a matcher on every child node of the given node. Returns true
689/// if at least one child node could be matched.
690/// - \c matchesDescendantOf:
691/// Matches a matcher on all descendant nodes of the given node. Returns true
692/// if at least one descendant matched.
693/// - \c matchesAncestorOf:
694/// Matches a matcher on all ancestors of the given node. Returns true if
695/// at least one ancestor matched.
696///
697/// FIXME: Currently we only allow Stmt and Decl nodes to start a traversal.
698/// In the future, we want to implement this for all nodes for which it makes
699/// sense. In the case of matchesAncestorOf, we'll want to implement it for
700/// all nodes, as all nodes have ancestors.
701class ASTMatchFinder {
702public:
703 /// Defines how bindings are processed on recursive matches.
704 enum BindKind {
705 /// Stop at the first match and only bind the first match.
706 BK_First,
707
708 /// Create results for all combinations of bindings that match.
709 BK_All
710 };
711
712 /// Defines which ancestors are considered for a match.
713 enum AncestorMatchMode {
714 /// All ancestors.
715 AMM_All,
716
717 /// Direct parent only.
718 AMM_ParentOnly
719 };
720
721 virtual ~ASTMatchFinder() = default;
722
723 /// Returns true if the given C++ class is directly or indirectly derived
724 /// from a base type matching \c base.
725 ///
726 /// A class is not considered to be derived from itself.
727 virtual bool classIsDerivedFrom(const CXXRecordDecl *Declaration,
728 const Matcher<NamedDecl> &Base,
729 BoundNodesTreeBuilder *Builder,
730 bool Directly) = 0;
731
732 /// Returns true if the given Objective-C class is directly or indirectly
733 /// derived from a base class matching \c base.
734 ///
735 /// A class is not considered to be derived from itself.
736 virtual bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration,
737 const Matcher<NamedDecl> &Base,
738 BoundNodesTreeBuilder *Builder,
739 bool Directly) = 0;
740
741 template <typename T>
742 bool matchesChildOf(const T &Node, const DynTypedMatcher &Matcher,
743 BoundNodesTreeBuilder *Builder, BindKind Bind) {
744 static_assert(std::is_base_of<Decl, T>::value ||
745 std::is_base_of<Stmt, T>::value ||
746 std::is_base_of<NestedNameSpecifier, T>::value ||
747 std::is_base_of<NestedNameSpecifierLoc, T>::value ||
748 std::is_base_of<TypeLoc, T>::value ||
749 std::is_base_of<QualType, T>::value ||
750 std::is_base_of<Attr, T>::value,
751 "unsupported type for recursive matching");
752 return matchesChildOf(DynTypedNode::create(Node), getASTContext(), Matcher,
753 Builder, Bind);
754 }
755
756 template <typename T>
757 bool matchesDescendantOf(const T &Node, const DynTypedMatcher &Matcher,
758 BoundNodesTreeBuilder *Builder, BindKind Bind) {
759 static_assert(std::is_base_of<Decl, T>::value ||
760 std::is_base_of<Stmt, T>::value ||
761 std::is_base_of<NestedNameSpecifier, T>::value ||
762 std::is_base_of<NestedNameSpecifierLoc, T>::value ||
763 std::is_base_of<TypeLoc, T>::value ||
764 std::is_base_of<QualType, T>::value ||
765 std::is_base_of<Attr, T>::value,
766 "unsupported type for recursive matching");
767 return matchesDescendantOf(DynTypedNode::create(Node), getASTContext(),
768 Matcher, Builder, Bind);
769 }
770
771 // FIXME: Implement support for BindKind.
772 template <typename T>
773 bool matchesAncestorOf(const T &Node, const DynTypedMatcher &Matcher,
774 BoundNodesTreeBuilder *Builder,
775 AncestorMatchMode MatchMode) {
776 static_assert(std::is_base_of<Decl, T>::value ||
777 std::is_base_of<NestedNameSpecifierLoc, T>::value ||
778 std::is_base_of<Stmt, T>::value ||
779 std::is_base_of<TypeLoc, T>::value ||
780 std::is_base_of<Attr, T>::value,
781 "type not allowed for recursive matching");
782 return matchesAncestorOf(DynTypedNode::create(Node), getASTContext(),
783 Matcher, Builder, MatchMode);
784 }
785
786 virtual ASTContext &getASTContext() const = 0;
787
788 virtual bool IsMatchingInASTNodeNotSpelledInSource() const = 0;
789
790 virtual bool IsMatchingInASTNodeNotAsIs() const = 0;
791
792 bool isTraversalIgnoringImplicitNodes() const;
793
794protected:
795 virtual bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
796 const DynTypedMatcher &Matcher,
797 BoundNodesTreeBuilder *Builder,
798 BindKind Bind) = 0;
799
800 virtual bool matchesDescendantOf(const DynTypedNode &Node, ASTContext &Ctx,
801 const DynTypedMatcher &Matcher,
802 BoundNodesTreeBuilder *Builder,
803 BindKind Bind) = 0;
804
805 virtual bool matchesAncestorOf(const DynTypedNode &Node, ASTContext &Ctx,
806 const DynTypedMatcher &Matcher,
807 BoundNodesTreeBuilder *Builder,
808 AncestorMatchMode MatchMode) = 0;
809private:
810 friend struct ASTChildrenNotSpelledInSourceScope;
811 virtual bool isMatchingChildrenNotSpelledInSource() const = 0;
812 virtual void setMatchingChildrenNotSpelledInSource(bool Set) = 0;
813};
814
815struct ASTChildrenNotSpelledInSourceScope {
816 ASTChildrenNotSpelledInSourceScope(ASTMatchFinder *V, bool B)
817 : MV(V), MB(V->isMatchingChildrenNotSpelledInSource()) {
818 V->setMatchingChildrenNotSpelledInSource(B);
819 }
820 ~ASTChildrenNotSpelledInSourceScope() {
821 MV->setMatchingChildrenNotSpelledInSource(MB);
822 }
823
824private:
825 ASTMatchFinder *MV;
826 bool MB;
827};
828
829/// Specialization of the conversion functions for QualType.
830///
831/// This specialization provides the Matcher<Type>->Matcher<QualType>
832/// conversion that the static API does.
833template <>
834inline Matcher<QualType> DynTypedMatcher::convertTo<QualType>() const {
835 assert(canConvertTo<QualType>())(static_cast <bool> (canConvertTo<QualType>()) ? void
(0) : __assert_fail ("canConvertTo<QualType>()", "clang/include/clang/ASTMatchers/ASTMatchersInternal.h"
, 835, __extension__ __PRETTY_FUNCTION__))
;
836 const ASTNodeKind SourceKind = getSupportedKind();
837 if (SourceKind.isSame(ASTNodeKind::getFromNodeKind<Type>())) {
838 // We support implicit conversion from Matcher<Type> to Matcher<QualType>
839 return unconditionalConvertTo<Type>();
840 }
841 return unconditionalConvertTo<QualType>();
842}
843
844/// Finds the first node in a range that matches the given matcher.
845template <typename MatcherT, typename IteratorT>
846IteratorT matchesFirstInRange(const MatcherT &Matcher, IteratorT Start,
847 IteratorT End, ASTMatchFinder *Finder,
848 BoundNodesTreeBuilder *Builder) {
849 for (IteratorT I = Start; I != End; ++I) {
850 BoundNodesTreeBuilder Result(*Builder);
851 if (Matcher.matches(*I, Finder, &Result)) {
852 *Builder = std::move(Result);
853 return I;
854 }
855 }
856 return End;
857}
858
859/// Finds the first node in a pointer range that matches the given
860/// matcher.
861template <typename MatcherT, typename IteratorT>
862IteratorT matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start,
863 IteratorT End, ASTMatchFinder *Finder,
864 BoundNodesTreeBuilder *Builder) {
865 for (IteratorT I = Start; I != End; ++I) {
866 BoundNodesTreeBuilder Result(*Builder);
867 if (Matcher.matches(**I, Finder, &Result)) {
868 *Builder = std::move(Result);
869 return I;
870 }
871 }
872 return End;
873}
874
875template <typename T, std::enable_if_t<!std::is_base_of<FunctionDecl, T>::value>
876 * = nullptr>
877inline bool isDefaultedHelper(const T *) {
878 return false;
879}
880inline bool isDefaultedHelper(const FunctionDecl *FD) {
881 return FD->isDefaulted();
882}
883
884// Metafunction to determine if type T has a member called getDecl.
885template <typename Ty>
886class has_getDecl {
887 using yes = char[1];
888 using no = char[2];
889
890 template <typename Inner>
891 static yes& test(Inner *I, decltype(I->getDecl()) * = nullptr);
892
893 template <typename>
894 static no& test(...);
895
896public:
897 static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes);
898};
899
900/// Matches overloaded operators with a specific name.
901///
902/// The type argument ArgT is not used by this matcher but is used by
903/// PolymorphicMatcher and should be StringRef.
904template <typename T, typename ArgT>
905class HasOverloadedOperatorNameMatcher : public SingleNodeMatcherInterface<T> {
906 static_assert(std::is_same<T, CXXOperatorCallExpr>::value ||
907 std::is_base_of<FunctionDecl, T>::value,
908 "unsupported class for matcher");
909 static_assert(std::is_same<ArgT, std::vector<std::string>>::value,
910 "argument type must be std::vector<std::string>");
911
912public:
913 explicit HasOverloadedOperatorNameMatcher(std::vector<std::string> Names)
914 : SingleNodeMatcherInterface<T>(), Names(std::move(Names)) {}
915
916 bool matchesNode(const T &Node) const override {
917 return matchesSpecialized(Node);
918 }
919
920private:
921
922 /// CXXOperatorCallExpr exist only for calls to overloaded operators
923 /// so this function returns true if the call is to an operator of the given
924 /// name.
925 bool matchesSpecialized(const CXXOperatorCallExpr &Node) const {
926 return llvm::is_contained(Names, getOperatorSpelling(Node.getOperator()));
927 }
928
929 /// Returns true only if CXXMethodDecl represents an overloaded
930 /// operator and has the given operator name.
931 bool matchesSpecialized(const FunctionDecl &Node) const {
932 return Node.isOverloadedOperator() &&
933 llvm::is_contained(
934 Names, getOperatorSpelling(Node.getOverloadedOperator()));
935 }
936
937 std::vector<std::string> Names;
938};
939
940/// Matches named declarations with a specific name.
941///
942/// See \c hasName() and \c hasAnyName() in ASTMatchers.h for details.
943class HasNameMatcher : public SingleNodeMatcherInterface<NamedDecl> {
944 public:
945 explicit HasNameMatcher(std::vector<std::string> Names);
946
947 bool matchesNode(const NamedDecl &Node) const override;
948
949private:
950 /// Unqualified match routine.
951 ///
952 /// It is much faster than the full match, but it only works for unqualified
953 /// matches.
954 bool matchesNodeUnqualified(const NamedDecl &Node) const;
955
956 /// Full match routine
957 ///
958 /// Fast implementation for the simple case of a named declaration at
959 /// namespace or RecordDecl scope.
960 /// It is slower than matchesNodeUnqualified, but faster than
961 /// matchesNodeFullSlow.
962 bool matchesNodeFullFast(const NamedDecl &Node) const;
963
964 /// Full match routine
965 ///
966 /// It generates the fully qualified name of the declaration (which is
967 /// expensive) before trying to match.
968 /// It is slower but simple and works on all cases.
969 bool matchesNodeFullSlow(const NamedDecl &Node) const;
970
971 bool UseUnqualifiedMatch;
972 std::vector<std::string> Names;
973};
974
975/// Trampoline function to use VariadicFunction<> to construct a
976/// HasNameMatcher.
977Matcher<NamedDecl> hasAnyNameFunc(ArrayRef<const StringRef *> NameRefs);
978
979/// Trampoline function to use VariadicFunction<> to construct a
980/// hasAnySelector matcher.
981Matcher<ObjCMessageExpr> hasAnySelectorFunc(
982 ArrayRef<const StringRef *> NameRefs);
983
984/// Matches declarations for QualType and CallExpr.
985///
986/// Type argument DeclMatcherT is required by PolymorphicMatcher but
987/// not actually used.
988template <typename T, typename DeclMatcherT>
989class HasDeclarationMatcher : public MatcherInterface<T> {
990 static_assert(std::is_same<DeclMatcherT, Matcher<Decl>>::value,
991 "instantiated with wrong types");
992
993 DynTypedMatcher InnerMatcher;
994
995public:
996 explicit HasDeclarationMatcher(const Matcher<Decl> &InnerMatcher)
997 : InnerMatcher(InnerMatcher) {}
998
999 bool matches(const T &Node, ASTMatchFinder *Finder,
1000 BoundNodesTreeBuilder *Builder) const override {
1001 return matchesSpecialized(Node, Finder, Builder);
1002 }
1003
1004private:
1005 /// Forwards to matching on the underlying type of the QualType.
1006 bool matchesSpecialized(const QualType &Node, ASTMatchFinder *Finder,
1007 BoundNodesTreeBuilder *Builder) const {
1008 if (Node.isNull())
1009 return false;
1010
1011 return matchesSpecialized(*Node, Finder, Builder);
1012 }
1013
1014 /// Finds the best declaration for a type and returns whether the inner
1015 /// matcher matches on it.
1016 bool matchesSpecialized(const Type &Node, ASTMatchFinder *Finder,
1017 BoundNodesTreeBuilder *Builder) const {
1018 // DeducedType does not have declarations of its own, so
1019 // match the deduced type instead.
1020 if (const auto *S = dyn_cast<DeducedType>(&Node)) {
1021 QualType DT = S->getDeducedType();
1022 return !DT.isNull() ? matchesSpecialized(*DT, Finder, Builder) : false;
1023 }
1024
1025 // First, for any types that have a declaration, extract the declaration and
1026 // match on it.
1027 if (const auto *S = dyn_cast<TagType>(&Node)) {
1028 return matchesDecl(S->getDecl(), Finder, Builder);
1029 }
1030 if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
1031 return matchesDecl(S->getDecl(), Finder, Builder);
1032 }
1033 if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
1034 return matchesDecl(S->getDecl(), Finder, Builder);
1035 }
1036 if (const auto *S = dyn_cast<TypedefType>(&Node)) {
1037 return matchesDecl(S->getDecl(), Finder, Builder);
1038 }
1039 if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
1040 return matchesDecl(S->getDecl(), Finder, Builder);
1041 }
1042 if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
1043 return matchesDecl(S->getInterface(), Finder, Builder);
1044 }
1045
1046 // A SubstTemplateTypeParmType exists solely to mark a type substitution
1047 // on the instantiated template. As users usually want to match the
1048 // template parameter on the uninitialized template, we can always desugar
1049 // one level without loss of expressivness.
1050 // For example, given:
1051 // template<typename T> struct X { T t; } class A {}; X<A> a;
1052 // The following matcher will match, which otherwise would not:
1053 // fieldDecl(hasType(pointerType())).
1054 if (const auto *S = dyn_cast<SubstTemplateTypeParmType>(&Node)) {
1055 return matchesSpecialized(S->getReplacementType(), Finder, Builder);
1056 }
1057
1058 // For template specialization types, we want to match the template
1059 // declaration, as long as the type is still dependent, and otherwise the
1060 // declaration of the instantiated tag type.
1061 if (const auto *S = dyn_cast<TemplateSpecializationType>(&Node)) {
1062 if (!S->isTypeAlias() && S->isSugared()) {
1063 // If the template is non-dependent, we want to match the instantiated
1064 // tag type.
1065 // For example, given:
1066 // template<typename T> struct X {}; X<int> a;
1067 // The following matcher will match, which otherwise would not:
1068 // templateSpecializationType(hasDeclaration(cxxRecordDecl())).
1069 return matchesSpecialized(*S->desugar(), Finder, Builder);
1070 }
1071 // If the template is dependent or an alias, match the template
1072 // declaration.
1073 return matchesDecl(S->getTemplateName().getAsTemplateDecl(), Finder,
1074 Builder);
1075 }
1076
1077 // FIXME: We desugar elaborated types. This makes the assumption that users
1078 // do never want to match on whether a type is elaborated - there are
1079 // arguments for both sides; for now, continue desugaring.
1080 if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
1081 return matchesSpecialized(S->desugar(), Finder, Builder);
1082 }
1083 // Similarly types found via using declarations.
1084 // These are *usually* meaningless sugar, and this matches the historical
1085 // behavior prior to the introduction of UsingType.
1086 if (const auto *S = dyn_cast<UsingType>(&Node)) {
1087 return matchesSpecialized(S->desugar(), Finder, Builder);
1088 }
1089 return false;
1090 }
1091
1092 /// Extracts the Decl the DeclRefExpr references and returns whether
1093 /// the inner matcher matches on it.
1094 bool matchesSpecialized(const DeclRefExpr &Node, ASTMatchFinder *Finder,
1095 BoundNodesTreeBuilder *Builder) const {
1096 return matchesDecl(Node.getDecl(), Finder, Builder);
1097 }
1098
1099 /// Extracts the Decl of the callee of a CallExpr and returns whether
1100 /// the inner matcher matches on it.
1101 bool matchesSpecialized(const CallExpr &Node, ASTMatchFinder *Finder,
1102 BoundNodesTreeBuilder *Builder) const {
1103 return matchesDecl(Node.getCalleeDecl(), Finder, Builder);
1104 }
1105
1106 /// Extracts the Decl of the constructor call and returns whether the
1107 /// inner matcher matches on it.
1108 bool matchesSpecialized(const CXXConstructExpr &Node,
1109 ASTMatchFinder *Finder,
1110 BoundNodesTreeBuilder *Builder) const {
1111 return matchesDecl(Node.getConstructor(), Finder, Builder);
1112 }
1113
1114 bool matchesSpecialized(const ObjCIvarRefExpr &Node,
1115 ASTMatchFinder *Finder,
1116 BoundNodesTreeBuilder *Builder) const {
1117 return matchesDecl(Node.getDecl(), Finder, Builder);
1118 }
1119
1120 /// Extracts the operator new of the new call and returns whether the
1121 /// inner matcher matches on it.
1122 bool matchesSpecialized(const CXXNewExpr &Node,
1123 ASTMatchFinder *Finder,
1124 BoundNodesTreeBuilder *Builder) const {
1125 return matchesDecl(Node.getOperatorNew(), Finder, Builder);
1126 }
1127
1128 /// Extracts the \c ValueDecl a \c MemberExpr refers to and returns
1129 /// whether the inner matcher matches on it.
1130 bool matchesSpecialized(const MemberExpr &Node,
1131 ASTMatchFinder *Finder,
1132 BoundNodesTreeBuilder *Builder) const {
1133 return matchesDecl(Node.getMemberDecl(), Finder, Builder);
1134 }
1135
1136 /// Extracts the \c LabelDecl a \c AddrLabelExpr refers to and returns
1137 /// whether the inner matcher matches on it.
1138 bool matchesSpecialized(const AddrLabelExpr &Node,
1139 ASTMatchFinder *Finder,
1140 BoundNodesTreeBuilder *Builder) const {
1141 return matchesDecl(Node.getLabel(), Finder, Builder);
1142 }
1143
1144 /// Extracts the declaration of a LabelStmt and returns whether the
1145 /// inner matcher matches on it.
1146 bool matchesSpecialized(const LabelStmt &Node, ASTMatchFinder *Finder,
1147 BoundNodesTreeBuilder *Builder) const {
1148 return matchesDecl(Node.getDecl(), Finder, Builder);
1149 }
1150
1151 /// Returns whether the inner matcher \c Node. Returns false if \c Node
1152 /// is \c NULL.
1153 bool matchesDecl(const Decl *Node, ASTMatchFinder *Finder,
1154 BoundNodesTreeBuilder *Builder) const {
1155 return Node != nullptr &&
1156 !(Finder->isTraversalIgnoringImplicitNodes() &&
1157 Node->isImplicit()) &&
1158 this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder,
1159 Builder);
1160 }
1161};
1162
1163/// IsBaseType<T>::value is true if T is a "base" type in the AST
1164/// node class hierarchies.
1165template <typename T>
1166struct IsBaseType {
1167 static const bool value =
1168 std::is_same<T, Decl>::value || std::is_same<T, Stmt>::value ||
1169 std::is_same<T, QualType>::value || std::is_same<T, Type>::value ||
1170 std::is_same<T, TypeLoc>::value ||
1171 std::is_same<T, NestedNameSpecifier>::value ||
1172 std::is_same<T, NestedNameSpecifierLoc>::value ||
1173 std::is_same<T, CXXCtorInitializer>::value ||
1174 std::is_same<T, TemplateArgumentLoc>::value ||
1175 std::is_same<T, Attr>::value;
1176};
1177template <typename T>
1178const bool IsBaseType<T>::value;
1179
1180/// A "type list" that contains all types.
1181///
1182/// Useful for matchers like \c anything and \c unless.
1183using AllNodeBaseTypes =
1184 TypeList<Decl, Stmt, NestedNameSpecifier, NestedNameSpecifierLoc, QualType,
1185 Type, TypeLoc, CXXCtorInitializer, Attr>;
1186
1187/// Helper meta-function to extract the argument out of a function of
1188/// type void(Arg).
1189///
1190/// See AST_POLYMORPHIC_SUPPORTED_TYPES for details.
1191template <class T> struct ExtractFunctionArgMeta;
1192template <class T> struct ExtractFunctionArgMeta<void(T)> {
1193 using type = T;
1194};
1195
1196template <class T, class Tuple, std::size_t... I>
1197constexpr T *new_from_tuple_impl(Tuple &&t, std::index_sequence<I...>) {
1198 return new T(std::get<I>(std::forward<Tuple>(t))...);
1199}
1200
1201template <class T, class Tuple> constexpr T *new_from_tuple(Tuple &&t) {
1202 return new_from_tuple_impl<T>(
1203 std::forward<Tuple>(t),
1204 std::make_index_sequence<
1205 std::tuple_size<std::remove_reference_t<Tuple>>::value>{});
1206}
1207
1208/// Default type lists for ArgumentAdaptingMatcher matchers.
1209using AdaptativeDefaultFromTypes = AllNodeBaseTypes;
1210using AdaptativeDefaultToTypes =
1211 TypeList<Decl, Stmt, NestedNameSpecifier, NestedNameSpecifierLoc, TypeLoc,
1212 QualType, Attr>;
1213
1214/// All types that are supported by HasDeclarationMatcher above.
1215using HasDeclarationSupportedTypes =
1216 TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
1217 ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
1218 MemberExpr, QualType, RecordType, TagType,
1219 TemplateSpecializationType, TemplateTypeParmType, TypedefType,
1220 UnresolvedUsingType, ObjCIvarRefExpr>;
1221
1222/// A Matcher that allows binding the node it matches to an id.
1223///
1224/// BindableMatcher provides a \a bind() method that allows binding the
1225/// matched node to an id if the match was successful.
1226template <typename T> class BindableMatcher : public Matcher<T> {
1227public:
1228 explicit BindableMatcher(const Matcher<T> &M) : Matcher<T>(M) {}
1229 explicit BindableMatcher(MatcherInterface<T> *Implementation)
1230 : Matcher<T>(Implementation) {}
1231
1232 /// Returns a matcher that will bind the matched node on a match.
1233 ///
1234 /// The returned matcher is equivalent to this matcher, but will
1235 /// bind the matched node on a match.
1236 Matcher<T> bind(StringRef ID) const {
1237 return DynTypedMatcher(*this)
1238 .tryBind(ID)
1239 ->template unconditionalConvertTo<T>();
1240 }
1241
1242 /// Same as Matcher<T>'s conversion operator, but enables binding on
1243 /// the returned matcher.
1244 operator DynTypedMatcher() const {
1245 DynTypedMatcher Result = static_cast<const Matcher<T> &>(*this);
1246 Result.setAllowBind(true);
1247 return Result;
1248 }
1249};
1250
1251/// Matches any instance of the given NodeType.
1252///
1253/// This is useful when a matcher syntactically requires a child matcher,
1254/// but the context doesn't care. See for example: anything().
1255class TrueMatcher {
1256public:
1257 using ReturnTypes = AllNodeBaseTypes;
1258
1259 template <typename T> operator Matcher<T>() const {
1260 return DynTypedMatcher::trueMatcher(ASTNodeKind::getFromNodeKind<T>())
1261 .template unconditionalConvertTo<T>();
1262 }
1263};
1264
1265/// Creates a Matcher<T> that matches if all inner matchers match.
1266template <typename T>
1267BindableMatcher<T>
1268makeAllOfComposite(ArrayRef<const Matcher<T> *> InnerMatchers) {
1269 // For the size() == 0 case, we return a "true" matcher.
1270 if (InnerMatchers.empty()) {
1271 return BindableMatcher<T>(TrueMatcher());
1272 }
1273 // For the size() == 1 case, we simply return that one matcher.
1274 // No need to wrap it in a variadic operation.
1275 if (InnerMatchers.size() == 1) {
1276 return BindableMatcher<T>(*InnerMatchers[0]);
1277 }
1278
1279 using PI = llvm::pointee_iterator<const Matcher<T> *const *>;
1280
1281 std::vector<DynTypedMatcher> DynMatchers(PI(InnerMatchers.begin()),
1282 PI(InnerMatchers.end()));
1283 return BindableMatcher<T>(
1284 DynTypedMatcher::constructVariadic(DynTypedMatcher::VO_AllOf,
1285 ASTNodeKind::getFromNodeKind<T>(),
1286 std::move(DynMatchers))
1287 .template unconditionalConvertTo<T>());
1288}
1289
1290/// Creates a Matcher<T> that matches if
1291/// T is dyn_cast'able into InnerT and all inner matchers match.
1292///
1293/// Returns BindableMatcher, as matchers that use dyn_cast have
1294/// the same object both to match on and to run submatchers on,
1295/// so there is no ambiguity with what gets bound.
1296template <typename T, typename InnerT>
1297BindableMatcher<T>
1298makeDynCastAllOfComposite(ArrayRef<const Matcher<InnerT> *> InnerMatchers) {
1299 return BindableMatcher<T>(
1300 makeAllOfComposite(InnerMatchers).template dynCastTo<T>());
1301}
1302
1303/// A VariadicDynCastAllOfMatcher<SourceT, TargetT> object is a
1304/// variadic functor that takes a number of Matcher<TargetT> and returns a
1305/// Matcher<SourceT> that matches TargetT nodes that are matched by all of the
1306/// given matchers, if SourceT can be dynamically casted into TargetT.
1307///
1308/// For example:
1309/// const VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> record;
1310/// Creates a functor record(...) that creates a Matcher<Decl> given
1311/// a variable number of arguments of type Matcher<CXXRecordDecl>.
1312/// The returned matcher matches if the given Decl can by dynamically
1313/// casted to CXXRecordDecl and all given matchers match.
1314template <typename SourceT, typename TargetT>
1315class VariadicDynCastAllOfMatcher
1316 : public VariadicFunction<BindableMatcher<SourceT>, Matcher<TargetT>,
1317 makeDynCastAllOfComposite<SourceT, TargetT>> {
1318public:
1319 VariadicDynCastAllOfMatcher() {}
1320};
1321
1322/// A \c VariadicAllOfMatcher<T> object is a variadic functor that takes
1323/// a number of \c Matcher<T> and returns a \c Matcher<T> that matches \c T
1324/// nodes that are matched by all of the given matchers.
1325///
1326/// For example:
1327/// const VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier;
1328/// Creates a functor nestedNameSpecifier(...) that creates a
1329/// \c Matcher<NestedNameSpecifier> given a variable number of arguments of type
1330/// \c Matcher<NestedNameSpecifier>.
1331/// The returned matcher matches if all given matchers match.
1332template <typename T>
1333class VariadicAllOfMatcher
1334 : public VariadicFunction<BindableMatcher<T>, Matcher<T>,
1335 makeAllOfComposite<T>> {
1336public:
1337 VariadicAllOfMatcher() {}
1338};
1339
1340/// VariadicOperatorMatcher related types.
1341/// @{
1342
1343/// Polymorphic matcher object that uses a \c
1344/// DynTypedMatcher::VariadicOperator operator.
1345///
1346/// Input matchers can have any type (including other polymorphic matcher
1347/// types), and the actual Matcher<T> is generated on demand with an implicit
1348/// conversion operator.
1349template <typename... Ps> class VariadicOperatorMatcher {
1350public:
1351 VariadicOperatorMatcher(DynTypedMatcher::VariadicOperator Op, Ps &&... Params)
1352 : Op(Op), Params(std::forward<Ps>(Params)...) {}
1353
1354 template <typename T> operator Matcher<T>() const & {
1355 return DynTypedMatcher::constructVariadic(
1356 Op, ASTNodeKind::getFromNodeKind<T>(),
1357 getMatchers<T>(std::index_sequence_for<Ps...>()))
1358 .template unconditionalConvertTo<T>();
1359 }
1360
1361 template <typename T> operator Matcher<T>() && {
1362 return DynTypedMatcher::constructVariadic(
1363 Op, ASTNodeKind::getFromNodeKind<T>(),
1364 getMatchers<T>(std::index_sequence_for<Ps...>()))
1365 .template unconditionalConvertTo<T>();
1366 }
1367
1368private:
1369 // Helper method to unpack the tuple into a vector.
1370 template <typename T, std::size_t... Is>
1371 std::vector<DynTypedMatcher> getMatchers(std::index_sequence<Is...>) const & {
1372 return {Matcher<T>(std::get<Is>(Params))...};
1373 }
1374
1375 template <typename T, std::size_t... Is>
1376 std::vector<DynTypedMatcher> getMatchers(std::index_sequence<Is...>) && {
1377 return {Matcher<T>(std::get<Is>(std::move(Params)))...};
1378 }
1379
1380 const DynTypedMatcher::VariadicOperator Op;
1381 std::tuple<Ps...> Params;
1382};
1383
1384/// Overloaded function object to generate VariadicOperatorMatcher
1385/// objects from arbitrary matchers.
1386template <unsigned MinCount, unsigned MaxCount>
1387struct VariadicOperatorMatcherFunc {
1388 DynTypedMatcher::VariadicOperator Op;
1389
1390 template <typename... Ms>
1391 VariadicOperatorMatcher<Ms...> operator()(Ms &&... Ps) const {
1392 static_assert(MinCount <= sizeof...(Ms) && sizeof...(Ms) <= MaxCount,
1393 "invalid number of parameters for variadic matcher");
1394 return VariadicOperatorMatcher<Ms...>(Op, std::forward<Ms>(Ps)...);
1395 }
1396};
1397
1398template <typename T, bool IsBaseOf, typename Head, typename Tail>
1399struct GetCladeImpl {
1400 using Type = Head;
1401};
1402template <typename T, typename Head, typename Tail>
1403struct GetCladeImpl<T, false, Head, Tail>
1404 : GetCladeImpl<T, std::is_base_of<typename Tail::head, T>::value,
1405 typename Tail::head, typename Tail::tail> {};
1406
1407template <typename T, typename... U>
1408struct GetClade : GetCladeImpl<T, false, T, AllNodeBaseTypes> {};
1409
1410template <typename CladeType, typename... MatcherTypes>
1411struct MapAnyOfMatcherImpl {
1412
1413 template <typename... InnerMatchers>
1414 BindableMatcher<CladeType>
1415 operator()(InnerMatchers &&... InnerMatcher) const {
1416 return VariadicAllOfMatcher<CladeType>()(std::apply(
1417 internal::VariadicOperatorMatcherFunc<
1418 0, std::numeric_limits<unsigned>::max()>{
1419 internal::DynTypedMatcher::VO_AnyOf},
1420 std::apply(
1421 [&](auto... Matcher) {
1422 return std::make_tuple(Matcher(InnerMatcher...)...);
1423 },
1424 std::tuple<
1425 VariadicDynCastAllOfMatcher<CladeType, MatcherTypes>...>())));
1426 }
1427};
1428
1429template <typename... MatcherTypes>
1430using MapAnyOfMatcher =
1431 MapAnyOfMatcherImpl<typename GetClade<MatcherTypes...>::Type,
1432 MatcherTypes...>;
1433
1434template <typename... MatcherTypes> struct MapAnyOfHelper {
1435 using CladeType = typename GetClade<MatcherTypes...>::Type;
1436
1437 MapAnyOfMatcher<MatcherTypes...> with;
1438
1439 operator BindableMatcher<CladeType>() const { return with(); }
1440
1441 Matcher<CladeType> bind(StringRef ID) const { return with().bind(ID); }
1442};
1443
1444template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
1445 typename T, typename ToTypes>
1446class ArgumentAdaptingMatcherFuncAdaptor {
1447public:
1448 explicit ArgumentAdaptingMatcherFuncAdaptor(const Matcher<T> &InnerMatcher)
1449 : InnerMatcher(InnerMatcher) {}
1450
1451 using ReturnTypes = ToTypes;
1452
1453 template <typename To> operator Matcher<To>() const & {
1454 return Matcher<To>(new ArgumentAdapterT<To, T>(InnerMatcher));
1455 }
1456
1457 template <typename To> operator Matcher<To>() && {
1458 return Matcher<To>(new ArgumentAdapterT<To, T>(std::move(InnerMatcher)));
1459 }
1460
1461private:
1462 Matcher<T> InnerMatcher;
1463};
1464
1465/// Converts a \c Matcher<T> to a matcher of desired type \c To by
1466/// "adapting" a \c To into a \c T.
1467///
1468/// The \c ArgumentAdapterT argument specifies how the adaptation is done.
1469///
1470/// For example:
1471/// \c ArgumentAdaptingMatcher<HasMatcher, T>(InnerMatcher);
1472/// Given that \c InnerMatcher is of type \c Matcher<T>, this returns a matcher
1473/// that is convertible into any matcher of type \c To by constructing
1474/// \c HasMatcher<To, T>(InnerMatcher).
1475///
1476/// If a matcher does not need knowledge about the inner type, prefer to use
1477/// PolymorphicMatcher.
1478template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
1479 typename FromTypes = AdaptativeDefaultFromTypes,
1480 typename ToTypes = AdaptativeDefaultToTypes>
1481struct ArgumentAdaptingMatcherFunc {
1482 template <typename T>
1483 static ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>
1484 create(const Matcher<T> &InnerMatcher) {
1485 return ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>(
1486 InnerMatcher);
1487 }
1488
1489 template <typename T>
1490 ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>
1491 operator()(const Matcher<T> &InnerMatcher) const {
1492 return create(InnerMatcher);
1493 }
1494
1495 template <typename... T>
1496 ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT,
1497 typename GetClade<T...>::Type, ToTypes>
1498 operator()(const MapAnyOfHelper<T...> &InnerMatcher) const {
1499 return create(InnerMatcher.with());
1500 }
1501};
1502
1503template <typename T> class TraversalMatcher : public MatcherInterface<T> {
1504 DynTypedMatcher InnerMatcher;
1505 clang::TraversalKind Traversal;
1506
1507public:
1508 explicit TraversalMatcher(clang::TraversalKind TK,
1509 const Matcher<T> &InnerMatcher)
1510 : InnerMatcher(InnerMatcher), Traversal(TK) {}
1511
1512 bool matches(const T &Node, ASTMatchFinder *Finder,
1513 BoundNodesTreeBuilder *Builder) const override {
1514 return this->InnerMatcher.matches(DynTypedNode::create(Node), Finder,
1515 Builder);
1516 }
1517
1518 std::optional<clang::TraversalKind> TraversalKind() const override {
1519 if (auto NestedKind = this->InnerMatcher.getTraversalKind())
1520 return NestedKind;
1521 return Traversal;
1522 }
1523};
1524
1525template <typename MatcherType> class TraversalWrapper {
1526public:
1527 TraversalWrapper(TraversalKind TK, const MatcherType &InnerMatcher)
1528 : TK(TK), InnerMatcher(InnerMatcher) {}
1529
1530 template <typename T> operator Matcher<T>() const & {
1531 return internal::DynTypedMatcher::constructRestrictedWrapper(
1532 new internal::TraversalMatcher<T>(TK, InnerMatcher),
1533 ASTNodeKind::getFromNodeKind<T>())
1534 .template unconditionalConvertTo<T>();
1535 }
1536
1537 template <typename T> operator Matcher<T>() && {
1538 return internal::DynTypedMatcher::constructRestrictedWrapper(
1539 new internal::TraversalMatcher<T>(TK, std::move(InnerMatcher)),
1540 ASTNodeKind::getFromNodeKind<T>())
1541 .template unconditionalConvertTo<T>();
1542 }
1543
1544private:
1545 TraversalKind TK;
1546 MatcherType InnerMatcher;
1547};
1548
1549/// A PolymorphicMatcher<MatcherT, P1, ..., PN> object can be
1550/// created from N parameters p1, ..., pN (of type P1, ..., PN) and
1551/// used as a Matcher<T> where a MatcherT<T, P1, ..., PN>(p1, ..., pN)
1552/// can be constructed.
1553///
1554/// For example:
1555/// - PolymorphicMatcher<IsDefinitionMatcher>()
1556/// creates an object that can be used as a Matcher<T> for any type T
1557/// where an IsDefinitionMatcher<T>() can be constructed.
1558/// - PolymorphicMatcher<ValueEqualsMatcher, int>(42)
1559/// creates an object that can be used as a Matcher<T> for any type T
1560/// where a ValueEqualsMatcher<T, int>(42) can be constructed.
1561template <template <typename T, typename... Params> class MatcherT,
1562 typename ReturnTypesF, typename... ParamTypes>
1563class PolymorphicMatcher {
1564public:
1565 PolymorphicMatcher(const ParamTypes &... Params) : Params(Params...) {}
1566
1567 using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
1568
1569 template <typename T> operator Matcher<T>() const & {
1570 static_assert(TypeListContainsSuperOf<ReturnTypes, T>::value,
1571 "right polymorphic conversion");
1572 return Matcher<T>(new_from_tuple<MatcherT<T, ParamTypes...>>(Params));
1573 }
1574
1575 template <typename T> operator Matcher<T>() && {
1576 static_assert(TypeListContainsSuperOf<ReturnTypes, T>::value,
1577 "right polymorphic conversion");
1578 return Matcher<T>(
1579 new_from_tuple<MatcherT<T, ParamTypes...>>(std::move(Params)));
1580 }
1581
1582private:
1583 std::tuple<ParamTypes...> Params;
1584};
1585
1586/// Matches nodes of type T that have child nodes of type ChildT for
1587/// which a specified child matcher matches.
1588///
1589/// ChildT must be an AST base type.
1590template <typename T, typename ChildT>
1591class HasMatcher : public MatcherInterface<T> {
1592 DynTypedMatcher InnerMatcher;
1593
1594public:
1595 explicit HasMatcher(const Matcher<ChildT> &InnerMatcher)
1596 : InnerMatcher(InnerMatcher) {}
1597
1598 bool matches(const T &Node, ASTMatchFinder *Finder,
1599 BoundNodesTreeBuilder *Builder) const override {
1600 return Finder->matchesChildOf(Node, this->InnerMatcher, Builder,
1601 ASTMatchFinder::BK_First);
1602 }
1603};
1604
1605/// Matches nodes of type T that have child nodes of type ChildT for
1606/// which a specified child matcher matches. ChildT must be an AST base
1607/// type.
1608/// As opposed to the HasMatcher, the ForEachMatcher will produce a match
1609/// for each child that matches.
1610template <typename T, typename ChildT>
1611class ForEachMatcher : public MatcherInterface<T> {
1612 static_assert(IsBaseType<ChildT>::value,
1613 "for each only accepts base type matcher");
1614
1615 DynTypedMatcher InnerMatcher;
1616
1617public:
1618 explicit ForEachMatcher(const Matcher<ChildT> &InnerMatcher)
1619 : InnerMatcher(InnerMatcher) {}
1620
1621 bool matches(const T &Node, ASTMatchFinder *Finder,
1622 BoundNodesTreeBuilder *Builder) const override {
1623 return Finder->matchesChildOf(
1624 Node, this->InnerMatcher, Builder,
1625 ASTMatchFinder::BK_All);
1626 }
1627};
1628
1629/// @}
1630
1631template <typename T>
1632inline Matcher<T> DynTypedMatcher::unconditionalConvertTo() const {
1633 return Matcher<T>(*this);
1634}
1635
1636/// Matches nodes of type T that have at least one descendant node of
1637/// type DescendantT for which the given inner matcher matches.
1638///
1639/// DescendantT must be an AST base type.
1640template <typename T, typename DescendantT>
1641class HasDescendantMatcher : public MatcherInterface<T> {
1642 static_assert(IsBaseType<DescendantT>::value,
1643 "has descendant only accepts base type matcher");
1644
1645 DynTypedMatcher DescendantMatcher;
1646
1647public:
1648 explicit HasDescendantMatcher(const Matcher<DescendantT> &DescendantMatcher)
1649 : DescendantMatcher(DescendantMatcher) {}
1650
1651 bool matches(const T &Node, ASTMatchFinder *Finder,
1652 BoundNodesTreeBuilder *Builder) const override {
1653 return Finder->matchesDescendantOf(Node, this->DescendantMatcher, Builder,
1654 ASTMatchFinder::BK_First);
1655 }
1656};
1657
1658/// Matches nodes of type \c T that have a parent node of type \c ParentT
1659/// for which the given inner matcher matches.
1660///
1661/// \c ParentT must be an AST base type.
1662template <typename T, typename ParentT>
1663class HasParentMatcher : public MatcherInterface<T> {
1664 static_assert(IsBaseType<ParentT>::value,
1665 "has parent only accepts base type matcher");
1666
1667 DynTypedMatcher ParentMatcher;
1668
1669public:
1670 explicit HasParentMatcher(const Matcher<ParentT> &ParentMatcher)
1671 : ParentMatcher(ParentMatcher) {}
1672
1673 bool matches(const T &Node, ASTMatchFinder *Finder,
1674 BoundNodesTreeBuilder *Builder) const override {
1675 return Finder->matchesAncestorOf(Node, this->ParentMatcher, Builder,
1676 ASTMatchFinder::AMM_ParentOnly);
1677 }
1678};
1679
1680/// Matches nodes of type \c T that have at least one ancestor node of
1681/// type \c AncestorT for which the given inner matcher matches.
1682///
1683/// \c AncestorT must be an AST base type.
1684template <typename T, typename AncestorT>
1685class HasAncestorMatcher : public MatcherInterface<T> {
1686 static_assert(IsBaseType<AncestorT>::value,
1687 "has ancestor only accepts base type matcher");
1688
1689 DynTypedMatcher AncestorMatcher;
1690
1691public:
1692 explicit HasAncestorMatcher(const Matcher<AncestorT> &AncestorMatcher)
1693 : AncestorMatcher(AncestorMatcher) {}
1694
1695 bool matches(const T &Node, ASTMatchFinder *Finder,
1696 BoundNodesTreeBuilder *Builder) const override {
1697 return Finder->matchesAncestorOf(Node, this->AncestorMatcher, Builder,
1698 ASTMatchFinder::AMM_All);
1699 }
1700};
1701
1702/// Matches nodes of type T that have at least one descendant node of
1703/// type DescendantT for which the given inner matcher matches.
1704///
1705/// DescendantT must be an AST base type.
1706/// As opposed to HasDescendantMatcher, ForEachDescendantMatcher will match
1707/// for each descendant node that matches instead of only for the first.
1708template <typename T, typename DescendantT>
1709class ForEachDescendantMatcher : public MatcherInterface<T> {
1710 static_assert(IsBaseType<DescendantT>::value,
1711 "for each descendant only accepts base type matcher");
1712
1713 DynTypedMatcher DescendantMatcher;
1714
1715public:
1716 explicit ForEachDescendantMatcher(
1717 const Matcher<DescendantT> &DescendantMatcher)
1718 : DescendantMatcher(DescendantMatcher) {}
1719
1720 bool matches(const T &Node, ASTMatchFinder *Finder,
1721 BoundNodesTreeBuilder *Builder) const override {
1722 return Finder->matchesDescendantOf(Node, this->DescendantMatcher, Builder,
1723 ASTMatchFinder::BK_All);
1724 }
1725};
1726
1727/// Matches on nodes that have a getValue() method if getValue() equals
1728/// the value the ValueEqualsMatcher was constructed with.
1729template <typename T, typename ValueT>
1730class ValueEqualsMatcher : public SingleNodeMatcherInterface<T> {
1731 static_assert(std::is_base_of<CharacterLiteral, T>::value ||
1732 std::is_base_of<CXXBoolLiteralExpr, T>::value ||
1733 std::is_base_of<FloatingLiteral, T>::value ||
1734 std::is_base_of<IntegerLiteral, T>::value,
1735 "the node must have a getValue method");
1736
1737public:
1738 explicit ValueEqualsMatcher(const ValueT &ExpectedValue)
1739 : ExpectedValue(ExpectedValue) {}
1740
1741 bool matchesNode(const T &Node) const override {
1742 return Node.getValue() == ExpectedValue;
1743 }
1744
1745private:
1746 ValueT ExpectedValue;
1747};
1748
1749/// Template specializations to easily write matchers for floating point
1750/// literals.
1751template <>
1752inline bool ValueEqualsMatcher<FloatingLiteral, double>::matchesNode(
1753 const FloatingLiteral &Node) const {
1754 if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
1755 return Node.getValue().convertToFloat() == ExpectedValue;
1756 if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
1757 return Node.getValue().convertToDouble() == ExpectedValue;
1758 return false;
1759}
1760template <>
1761inline bool ValueEqualsMatcher<FloatingLiteral, float>::matchesNode(
1762 const FloatingLiteral &Node) const {
1763 if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
1764 return Node.getValue().convertToFloat() == ExpectedValue;
1765 if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
1766 return Node.getValue().convertToDouble() == ExpectedValue;
1767 return false;
1768}
1769template <>
1770inline bool ValueEqualsMatcher<FloatingLiteral, llvm::APFloat>::matchesNode(
1771 const FloatingLiteral &Node) const {
1772 return ExpectedValue.compare(Node.getValue()) == llvm::APFloat::cmpEqual;
1773}
1774
1775/// Matches nodes of type \c TLoc for which the inner
1776/// \c Matcher<T> matches.
1777template <typename TLoc, typename T>
1778class LocMatcher : public MatcherInterface<TLoc> {
1779 DynTypedMatcher InnerMatcher;
1780
1781public:
1782 explicit LocMatcher(const Matcher<T> &InnerMatcher)
1783 : InnerMatcher(InnerMatcher) {}
1784
1785 bool matches(const TLoc &Node, ASTMatchFinder *Finder,
1786 BoundNodesTreeBuilder *Builder) const override {
1787 if (!Node)
1788 return false;
1789 return this->InnerMatcher.matches(extract(Node), Finder, Builder);
1790 }
1791
1792private:
1793 static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
1794 return DynTypedNode::create(*Loc.getNestedNameSpecifier());
1795 }
1796};
1797
1798/// Matches \c TypeLocs based on an inner matcher matching a certain
1799/// \c QualType.
1800///
1801/// Used to implement the \c loc() matcher.
1802class TypeLocTypeMatcher : public MatcherInterface<TypeLoc> {
1803 DynTypedMatcher InnerMatcher;
1804
1805public:
1806 explicit TypeLocTypeMatcher(const Matcher<QualType> &InnerMatcher)
1807 : InnerMatcher(InnerMatcher) {}
1808
1809 bool matches(const TypeLoc &Node, ASTMatchFinder *Finder,
1810 BoundNodesTreeBuilder *Builder) const override {
1811 if (!Node)
1812 return false;
1813 return this->InnerMatcher.matches(DynTypedNode::create(Node.getType()),
1814 Finder, Builder);
1815 }
1816};
1817
1818/// Matches nodes of type \c T for which the inner matcher matches on a
1819/// another node of type \c T that can be reached using a given traverse
1820/// function.
1821template <typename T> class TypeTraverseMatcher : public MatcherInterface<T> {
1822 DynTypedMatcher InnerMatcher;
1823
1824public:
1825 explicit TypeTraverseMatcher(const Matcher<QualType> &InnerMatcher,
1826 QualType (T::*TraverseFunction)() const)
1827 : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {}
1828
1829 bool matches(const T &Node, ASTMatchFinder *Finder,
1830 BoundNodesTreeBuilder *Builder) const override {
1831 QualType NextNode = (Node.*TraverseFunction)();
1832 if (NextNode.isNull())
1833 return false;
1834 return this->InnerMatcher.matches(DynTypedNode::create(NextNode), Finder,
1835 Builder);
1836 }
1837
1838private:
1839 QualType (T::*TraverseFunction)() const;
1840};
1841
1842/// Matches nodes of type \c T in a ..Loc hierarchy, for which the inner
1843/// matcher matches on a another node of type \c T that can be reached using a
1844/// given traverse function.
1845template <typename T>
1846class TypeLocTraverseMatcher : public MatcherInterface<T> {
1847 DynTypedMatcher InnerMatcher;
1848
1849public:
1850 explicit TypeLocTraverseMatcher(const Matcher<TypeLoc> &InnerMatcher,
1851 TypeLoc (T::*TraverseFunction)() const)
1852 : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {}
1853
1854 bool matches(const T &Node, ASTMatchFinder *Finder,
1855 BoundNodesTreeBuilder *Builder) const override {
1856 TypeLoc NextNode = (Node.*TraverseFunction)();
1857 if (!NextNode)
1858 return false;
1859 return this->InnerMatcher.matches(DynTypedNode::create(NextNode), Finder,
1860 Builder);
1861 }
1862
1863private:
1864 TypeLoc (T::*TraverseFunction)() const;
1865};
1866
1867/// Converts a \c Matcher<InnerT> to a \c Matcher<OuterT>, where
1868/// \c OuterT is any type that is supported by \c Getter.
1869///
1870/// \code Getter<OuterT>::value() \endcode returns a
1871/// \code InnerTBase (OuterT::*)() \endcode, which is used to adapt a \c OuterT
1872/// object into a \c InnerT
1873template <typename InnerTBase,
1874 template <typename OuterT> class Getter,
1875 template <typename OuterT> class MatcherImpl,
1876 typename ReturnTypesF>
1877class TypeTraversePolymorphicMatcher {
1878private:
1879 using Self = TypeTraversePolymorphicMatcher<InnerTBase, Getter, MatcherImpl,
1880 ReturnTypesF>;
1881
1882 static Self create(ArrayRef<const Matcher<InnerTBase> *> InnerMatchers);
1883
1884public:
1885 using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
1886
1887 explicit TypeTraversePolymorphicMatcher(
1888 ArrayRef<const Matcher<InnerTBase> *> InnerMatchers)
1889 : InnerMatcher(makeAllOfComposite(InnerMatchers)) {}
1890
1891 template <typename OuterT> operator Matcher<OuterT>() const {
1892 return Matcher<OuterT>(
1893 new MatcherImpl<OuterT>(InnerMatcher, Getter<OuterT>::value()));
1894 }
1895
1896 struct Func
1897 : public VariadicFunction<Self, Matcher<InnerTBase>, &Self::create> {
1898 Func() {}
1899 };
1900
1901private:
1902 Matcher<InnerTBase> InnerMatcher;
1903};
1904
1905/// A simple memoizer of T(*)() functions.
1906///
1907/// It will call the passed 'Func' template parameter at most once.
1908/// Used to support AST_MATCHER_FUNCTION() macro.
1909template <typename Matcher, Matcher (*Func)()> class MemoizedMatcher {
1910 struct Wrapper {
1911 Wrapper() : M(Func()) {}
1912
1913 Matcher M;
1914 };
1915
1916public:
1917 static const Matcher &getInstance() {
1918 static llvm::ManagedStatic<Wrapper> Instance;
1919 return Instance->M;
1920 }
1921};
1922
1923// Define the create() method out of line to silence a GCC warning about
1924// the struct "Func" having greater visibility than its base, which comes from
1925// using the flag -fvisibility-inlines-hidden.
1926template <typename InnerTBase, template <typename OuterT> class Getter,
1927 template <typename OuterT> class MatcherImpl, typename ReturnTypesF>
1928TypeTraversePolymorphicMatcher<InnerTBase, Getter, MatcherImpl, ReturnTypesF>
1929TypeTraversePolymorphicMatcher<
1930 InnerTBase, Getter, MatcherImpl,
1931 ReturnTypesF>::create(ArrayRef<const Matcher<InnerTBase> *> InnerMatchers) {
1932 return Self(InnerMatchers);
1933}
1934
1935// FIXME: unify ClassTemplateSpecializationDecl and TemplateSpecializationType's
1936// APIs for accessing the template argument list.
1937inline ArrayRef<TemplateArgument>
1938getTemplateSpecializationArgs(const ClassTemplateSpecializationDecl &D) {
1939 return D.getTemplateArgs().asArray();
1940}
1941
1942inline ArrayRef<TemplateArgument>
1943getTemplateSpecializationArgs(const TemplateSpecializationType &T) {
1944 return T.template_arguments();
1945}
1946
1947inline ArrayRef<TemplateArgument>
1948getTemplateSpecializationArgs(const FunctionDecl &FD) {
1949 if (const auto* TemplateArgs = FD.getTemplateSpecializationArgs())
1950 return TemplateArgs->asArray();
1951 return ArrayRef<TemplateArgument>();
1952}
1953
1954struct NotEqualsBoundNodePredicate {
1955 bool operator()(const internal::BoundNodesMap &Nodes) const {
1956 return Nodes.getNode(ID) != Node;
1957 }
1958
1959 std::string ID;
1960 DynTypedNode Node;
1961};
1962
1963template <typename Ty, typename Enable = void> struct GetBodyMatcher {
1964 static const Stmt *get(const Ty &Node) { return Node.getBody(); }
1965};
1966
1967template <typename Ty>
1968struct GetBodyMatcher<
1969 Ty, std::enable_if_t<std::is_base_of<FunctionDecl, Ty>::value>> {
1970 static const Stmt *get(const Ty &Node) {
1971 return Node.doesThisDeclarationHaveABody() ? Node.getBody() : nullptr;
1972 }
1973};
1974
1975template <typename NodeType>
1976inline std::optional<BinaryOperatorKind>
1977equivalentBinaryOperator(const NodeType &Node) {
1978 return Node.getOpcode();
1979}
1980
1981template <>
1982inline std::optional<BinaryOperatorKind>
1983equivalentBinaryOperator<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) {
1984 if (Node.getNumArgs() != 2)
1985 return std::nullopt;
1986 switch (Node.getOperator()) {
1987 default:
1988 return std::nullopt;
1989 case OO_ArrowStar:
1990 return BO_PtrMemI;
1991 case OO_Star:
1992 return BO_Mul;
1993 case OO_Slash:
1994 return BO_Div;
1995 case OO_Percent:
1996 return BO_Rem;
1997 case OO_Plus:
1998 return BO_Add;
1999 case OO_Minus:
2000 return BO_Sub;
2001 case OO_LessLess:
2002 return BO_Shl;
2003 case OO_GreaterGreater:
2004 return BO_Shr;
2005 case OO_Spaceship:
2006 return BO_Cmp;
2007 case OO_Less:
2008 return BO_LT;
2009 case OO_Greater:
2010 return BO_GT;
2011 case OO_LessEqual:
2012 return BO_LE;
2013 case OO_GreaterEqual:
2014 return BO_GE;
2015 case OO_EqualEqual:
2016 return BO_EQ;
2017 case OO_ExclaimEqual:
2018 return BO_NE;
2019 case OO_Amp:
2020 return BO_And;
2021 case OO_Caret:
2022 return BO_Xor;
2023 case OO_Pipe:
2024 return BO_Or;
2025 case OO_AmpAmp:
2026 return BO_LAnd;
2027 case OO_PipePipe:
2028 return BO_LOr;
2029 case OO_Equal:
2030 return BO_Assign;
2031 case OO_StarEqual:
2032 return BO_MulAssign;
2033 case OO_SlashEqual:
2034 return BO_DivAssign;
2035 case OO_PercentEqual:
2036 return BO_RemAssign;
2037 case OO_PlusEqual:
2038 return BO_AddAssign;
2039 case OO_MinusEqual:
2040 return BO_SubAssign;
2041 case OO_LessLessEqual:
2042 return BO_ShlAssign;
2043 case OO_GreaterGreaterEqual:
2044 return BO_ShrAssign;
2045 case OO_AmpEqual:
2046 return BO_AndAssign;
2047 case OO_CaretEqual:
2048 return BO_XorAssign;
2049 case OO_PipeEqual:
2050 return BO_OrAssign;
2051 case OO_Comma:
2052 return BO_Comma;
2053 }
2054}
2055
2056template <typename NodeType>
2057inline std::optional<UnaryOperatorKind>
2058equivalentUnaryOperator(const NodeType &Node) {
2059 return Node.getOpcode();
2060}
2061
2062template <>
2063inline std::optional<UnaryOperatorKind>
2064equivalentUnaryOperator<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) {
2065 if (Node.getNumArgs() != 1 && Node.getOperator() != OO_PlusPlus &&
2066 Node.getOperator() != OO_MinusMinus)
2067 return std::nullopt;
2068 switch (Node.getOperator()) {
2069 default:
2070 return std::nullopt;
2071 case OO_Plus:
2072 return UO_Plus;
2073 case OO_Minus:
2074 return UO_Minus;
2075 case OO_Amp:
2076 return UO_AddrOf;
2077 case OO_Star:
2078 return UO_Deref;
2079 case OO_Tilde:
2080 return UO_Not;
2081 case OO_Exclaim:
2082 return UO_LNot;
2083 case OO_PlusPlus: {
2084 const auto *FD = Node.getDirectCallee();
2085 if (!FD)
2086 return std::nullopt;
2087 return FD->getNumParams() > 0 ? UO_PostInc : UO_PreInc;
2088 }
2089 case OO_MinusMinus: {
2090 const auto *FD = Node.getDirectCallee();
2091 if (!FD)
2092 return std::nullopt;
2093 return FD->getNumParams() > 0 ? UO_PostDec : UO_PreDec;
2094 }
2095 case OO_Coawait:
2096 return UO_Coawait;
2097 }
2098}
2099
2100template <typename NodeType> inline const Expr *getLHS(const NodeType &Node) {
2101 return Node.getLHS();
2102}
2103template <>
2104inline const Expr *
2105getLHS<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) {
2106 if (!internal::equivalentBinaryOperator(Node))
2107 return nullptr;
2108 return Node.getArg(0);
2109}
2110template <typename NodeType> inline const Expr *getRHS(const NodeType &Node) {
2111 return Node.getRHS();
2112}
2113template <>
2114inline const Expr *
2115getRHS<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) {
2116 if (!internal::equivalentBinaryOperator(Node))
2117 return nullptr;
2118 return Node.getArg(1);
2119}
2120template <typename NodeType>
2121inline const Expr *getSubExpr(const NodeType &Node) {
2122 return Node.getSubExpr();
2123}
2124template <>
2125inline const Expr *
2126getSubExpr<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) {
2127 if (!internal::equivalentUnaryOperator(Node))
2128 return nullptr;
2129 return Node.getArg(0);
2130}
2131
2132template <typename Ty>
2133struct HasSizeMatcher {
2134 static bool hasSize(const Ty &Node, unsigned int N) {
2135 return Node.getSize() == N;
2136 }
2137};
2138
2139template <>
2140inline bool HasSizeMatcher<StringLiteral>::hasSize(
2141 const StringLiteral &Node, unsigned int N) {
2142 return Node.getLength() == N;
2143}
2144
2145template <typename Ty>
2146struct GetSourceExpressionMatcher {
2147 static const Expr *get(const Ty &Node) {
2148 return Node.getSubExpr();
2149 }
2150};
2151
2152template <>
2153inline const Expr *GetSourceExpressionMatcher<OpaqueValueExpr>::get(
2154 const OpaqueValueExpr &Node) {
2155 return Node.getSourceExpr();
2156}
2157
2158template <typename Ty>
2159struct CompoundStmtMatcher {
2160 static const CompoundStmt *get(const Ty &Node) {
2161 return &Node;
2162 }
2163};
2164
2165template <>
2166inline const CompoundStmt *
2167CompoundStmtMatcher<StmtExpr>::get(const StmtExpr &Node) {
2168 return Node.getSubStmt();
2169}
2170
2171/// If \p Loc is (transitively) expanded from macro \p MacroName, returns the
2172/// location (in the chain of expansions) at which \p MacroName was
2173/// expanded. Since the macro may have been expanded inside a series of
2174/// expansions, that location may itself be a MacroID.
2175std::optional<SourceLocation> getExpansionLocOfMacro(StringRef MacroName,
2176 SourceLocation Loc,
2177 const ASTContext &Context);
2178
2179inline std::optional<StringRef> getOpName(const UnaryOperator &Node) {
2180 return Node.getOpcodeStr(Node.getOpcode());
2181}
2182inline std::optional<StringRef> getOpName(const BinaryOperator &Node) {
2183 return Node.getOpcodeStr();
2184}
2185inline StringRef getOpName(const CXXRewrittenBinaryOperator &Node) {
2186 return Node.getOpcodeStr();
2187}
2188inline std::optional<StringRef> getOpName(const CXXOperatorCallExpr &Node) {
2189 auto optBinaryOpcode = equivalentBinaryOperator(Node);
2190 if (!optBinaryOpcode) {
2191 auto optUnaryOpcode = equivalentUnaryOperator(Node);
2192 if (!optUnaryOpcode)
2193 return std::nullopt;
2194 return UnaryOperator::getOpcodeStr(*optUnaryOpcode);
2195 }
2196 return BinaryOperator::getOpcodeStr(*optBinaryOpcode);
2197}
2198
2199/// Matches overloaded operators with a specific name.
2200///
2201/// The type argument ArgT is not used by this matcher but is used by
2202/// PolymorphicMatcher and should be std::vector<std::string>>.
2203template <typename T, typename ArgT = std::vector<std::string>>
2204class HasAnyOperatorNameMatcher : public SingleNodeMatcherInterface<T> {
2205 static_assert(std::is_same<T, BinaryOperator>::value ||
2206 std::is_same<T, CXXOperatorCallExpr>::value ||
2207 std::is_same<T, CXXRewrittenBinaryOperator>::value ||
2208 std::is_same<T, UnaryOperator>::value,
2209 "Matcher only supports `BinaryOperator`, `UnaryOperator`, "
2210 "`CXXOperatorCallExpr` and `CXXRewrittenBinaryOperator`");
2211 static_assert(std::is_same<ArgT, std::vector<std::string>>::value,
2212 "Matcher ArgT must be std::vector<std::string>");
2213
2214public:
2215 explicit HasAnyOperatorNameMatcher(std::vector<std::string> Names)
2216 : SingleNodeMatcherInterface<T>(), Names(std::move(Names)) {}
2217
2218 bool matchesNode(const T &Node) const override {
2219 std::optional<StringRef> OptOpName = getOpName(Node);
2220 return OptOpName && llvm::is_contained(Names, *OptOpName);
2221 }
2222
2223private:
2224 static std::optional<StringRef> getOpName(const UnaryOperator &Node) {
2225 return Node.getOpcodeStr(Node.getOpcode());
2226 }
2227 static std::optional<StringRef> getOpName(const BinaryOperator &Node) {
2228 return Node.getOpcodeStr();
2229 }
2230 static StringRef getOpName(const CXXRewrittenBinaryOperator &Node) {
2231 return Node.getOpcodeStr();
2232 }
2233 static std::optional<StringRef> getOpName(const CXXOperatorCallExpr &Node) {
2234 auto optBinaryOpcode = equivalentBinaryOperator(Node);
2235 if (!optBinaryOpcode) {
2236 auto optUnaryOpcode = equivalentUnaryOperator(Node);
2237 if (!optUnaryOpcode)
2238 return std::nullopt;
2239 return UnaryOperator::getOpcodeStr(*optUnaryOpcode);
2240 }
2241 return BinaryOperator::getOpcodeStr(*optBinaryOpcode);
2242 }
2243
2244 std::vector<std::string> Names;
2245};
2246
2247using HasOpNameMatcher =
2248 PolymorphicMatcher<HasAnyOperatorNameMatcher,
2249 void(
2250 TypeList<BinaryOperator, CXXOperatorCallExpr,
2251 CXXRewrittenBinaryOperator, UnaryOperator>),
2252 std::vector<std::string>>;
2253
2254HasOpNameMatcher hasAnyOperatorNameFunc(ArrayRef<const StringRef *> NameRefs);
2255
2256using HasOverloadOpNameMatcher =
2257 PolymorphicMatcher<HasOverloadedOperatorNameMatcher,
2258 void(TypeList<CXXOperatorCallExpr, FunctionDecl>),
2259 std::vector<std::string>>;
2260
2261HasOverloadOpNameMatcher
2262hasAnyOverloadedOperatorNameFunc(ArrayRef<const StringRef *> NameRefs);
2263
2264/// Returns true if \p Node has a base specifier matching \p BaseSpec.
2265///
2266/// A class is not considered to be derived from itself.
2267bool matchesAnyBase(const CXXRecordDecl &Node,
2268 const Matcher<CXXBaseSpecifier> &BaseSpecMatcher,
2269 ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder);
2270
2271std::shared_ptr<llvm::Regex> createAndVerifyRegex(StringRef Regex,
2272 llvm::Regex::RegexFlags Flags,
2273 StringRef MatcherID);
2274
2275inline bool
2276MatchTemplateArgLocAt(const DeclRefExpr &Node, unsigned int Index,
2277 internal::Matcher<TemplateArgumentLoc> InnerMatcher,
2278 internal::ASTMatchFinder *Finder,
2279 internal::BoundNodesTreeBuilder *Builder) {
2280 llvm::ArrayRef<TemplateArgumentLoc> ArgLocs = Node.template_arguments();
2281 return Index < ArgLocs.size() &&
2282 InnerMatcher.matches(ArgLocs[Index], Finder, Builder);
2283}
2284
2285inline bool
2286MatchTemplateArgLocAt(const TemplateSpecializationTypeLoc &Node,
2287 unsigned int Index,
2288 internal::Matcher<TemplateArgumentLoc> InnerMatcher,
2289 internal::ASTMatchFinder *Finder,
2290 internal::BoundNodesTreeBuilder *Builder) {
2291 return !Node.isNull() && Index < Node.getNumArgs() &&
2292 InnerMatcher.matches(Node.getArgLoc(Index), Finder, Builder);
2293}
2294
2295} // namespace internal
2296
2297} // namespace ast_matchers
2298
2299} // namespace clang
2300
2301#endif // LLVM_CLANG_ASTMATCHERS_ASTMATCHERSINTERNAL_H

/build/source/clang/include/clang/AST/ASTTypeTraits.h

1//===--- ASTTypeTraits.h ----------------------------------------*- C++ -*-===//
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// Provides a dynamic type identifier and a dynamically typed node container
10// that can be used to store an AST base node at runtime in the same storage in
11// a type safe way.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_ASTTYPETRAITS_H
16#define LLVM_CLANG_AST_ASTTYPETRAITS_H
17
18#include "clang/AST/ASTFwd.h"
19#include "clang/AST/DeclCXX.h"
20#include "clang/AST/LambdaCapture.h"
21#include "clang/AST/NestedNameSpecifier.h"
22#include "clang/AST/TemplateBase.h"
23#include "clang/AST/TypeLoc.h"
24#include "clang/Basic/LLVM.h"
25#include "llvm/ADT/DenseMapInfo.h"
26#include "llvm/Support/AlignOf.h"
27
28namespace llvm {
29class raw_ostream;
30} // namespace llvm
31
32namespace clang {
33
34struct PrintingPolicy;
35
36/// Defines how we descend a level in the AST when we pass
37/// through expressions.
38enum TraversalKind {
39 /// Will traverse all child nodes.
40 TK_AsIs,
41
42 /// Ignore AST nodes not written in the source
43 TK_IgnoreUnlessSpelledInSource
44};
45
46/// Kind identifier.
47///
48/// It can be constructed from any node kind and allows for runtime type
49/// hierarchy checks.
50/// Use getFromNodeKind<T>() to construct them.
51class ASTNodeKind {
52public:
53 /// Empty identifier. It matches nothing.
54 constexpr ASTNodeKind() : KindId(NKI_None) {}
55
56 /// Construct an identifier for T.
57 template <class T> static constexpr ASTNodeKind getFromNodeKind() {
58 return ASTNodeKind(KindToKindId<T>::Id);
59 }
60
61 /// \{
62 /// Construct an identifier for the dynamic type of the node
63 static ASTNodeKind getFromNode(const Decl &D);
64 static ASTNodeKind getFromNode(const Stmt &S);
65 static ASTNodeKind getFromNode(const Type &T);
66 static ASTNodeKind getFromNode(const TypeLoc &T);
67 static ASTNodeKind getFromNode(const LambdaCapture &L);
68 static ASTNodeKind getFromNode(const OMPClause &C);
69 static ASTNodeKind getFromNode(const Attr &A);
70 /// \}
71
72 /// Returns \c true if \c this and \c Other represent the same kind.
73 constexpr bool isSame(ASTNodeKind Other) const {
74 return KindId != NKI_None && KindId == Other.KindId;
75 }
76
77 /// Returns \c true only for the default \c ASTNodeKind()
78 constexpr bool isNone() const { return KindId == NKI_None; }
79
80 /// Returns \c true if \c this is a base kind of (or same as) \c Other.
81 bool isBaseOf(ASTNodeKind Other) const;
82
83 /// Returns \c true if \c this is a base kind of (or same as) \c Other.
84 /// \param Distance If non-null, used to return the distance between \c this
85 /// and \c Other in the class hierarchy.
86 bool isBaseOf(ASTNodeKind Other, unsigned *Distance) const;
87
88 /// String representation of the kind.
89 StringRef asStringRef() const;
90
91 /// Strict weak ordering for ASTNodeKind.
92 constexpr bool operator<(const ASTNodeKind &Other) const {
93 return KindId < Other.KindId;
94 }
95
96 /// Return the most derived type between \p Kind1 and \p Kind2.
97 ///
98 /// Return ASTNodeKind() if they are not related.
99 static ASTNodeKind getMostDerivedType(ASTNodeKind Kind1, ASTNodeKind Kind2);
100
101 /// Return the most derived common ancestor between Kind1 and Kind2.
102 ///
103 /// Return ASTNodeKind() if they are not related.
104 static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1,
105 ASTNodeKind Kind2);
106
107 ASTNodeKind getCladeKind() const;
108
109 /// Hooks for using ASTNodeKind as a key in a DenseMap.
110 struct DenseMapInfo {
111 // ASTNodeKind() is a good empty key because it is represented as a 0.
112 static inline ASTNodeKind getEmptyKey() { return ASTNodeKind(); }
113 // NKI_NumberOfKinds is not a valid value, so it is good for a
114 // tombstone key.
115 static inline ASTNodeKind getTombstoneKey() {
116 return ASTNodeKind(NKI_NumberOfKinds);
117 }
118 static unsigned getHashValue(const ASTNodeKind &Val) { return Val.KindId; }
119 static bool isEqual(const ASTNodeKind &LHS, const ASTNodeKind &RHS) {
120 return LHS.KindId == RHS.KindId;
121 }
122 };
123
124 /// Check if the given ASTNodeKind identifies a type that offers pointer
125 /// identity. This is useful for the fast path in DynTypedNode.
126 constexpr bool hasPointerIdentity() const {
127 return KindId > NKI_LastKindWithoutPointerIdentity;
128 }
129
130private:
131 /// Kind ids.
132 ///
133 /// Includes all possible base and derived kinds.
134 enum NodeKindId {
135 NKI_None,
136 NKI_TemplateArgument,
137 NKI_TemplateArgumentLoc,
138 NKI_LambdaCapture,
139 NKI_TemplateName,
140 NKI_NestedNameSpecifierLoc,
141 NKI_QualType,
142#define TYPELOC(CLASS, PARENT) NKI_##CLASS##TypeLoc,
143#include "clang/AST/TypeLocNodes.def"
144 NKI_TypeLoc,
145 NKI_LastKindWithoutPointerIdentity = NKI_TypeLoc,
146 NKI_CXXBaseSpecifier,
147 NKI_CXXCtorInitializer,
148 NKI_NestedNameSpecifier,
149 NKI_Decl,
150#define DECL(DERIVED, BASE) NKI_##DERIVED##Decl,
151#include "clang/AST/DeclNodes.inc"
152 NKI_Stmt,
153#define STMT(DERIVED, BASE) NKI_##DERIVED,
154#include "clang/AST/StmtNodes.inc"
155 NKI_Type,
156#define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
157#include "clang/AST/TypeNodes.inc"
158 NKI_OMPClause,
159#define GEN_CLANG_CLAUSE_CLASS
160#define CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
161#include "llvm/Frontend/OpenMP/OMP.inc"
162 NKI_Attr,
163#define ATTR(A) NKI_##A##Attr,
164#include "clang/Basic/AttrList.inc"
165 NKI_ObjCProtocolLoc,
166 NKI_NumberOfKinds
167 };
168
169 /// Use getFromNodeKind<T>() to construct the kind.
170 constexpr ASTNodeKind(NodeKindId KindId) : KindId(KindId) {}
171
172 /// Returns \c true if \c Base is a base kind of (or same as) \c
173 /// Derived.
174 static bool isBaseOf(NodeKindId Base, NodeKindId Derived);
175
176 /// Returns \c true if \c Base is a base kind of (or same as) \c
177 /// Derived.
178 /// \param Distance If non-null, used to return the distance between \c Base
179 /// and \c Derived in the class hierarchy.
180 static bool isBaseOf(NodeKindId Base, NodeKindId Derived, unsigned *Distance);
181
182 /// Helper meta-function to convert a kind T to its enum value.
183 ///
184 /// This struct is specialized below for all known kinds.
185 template <class T> struct KindToKindId {
186 static const NodeKindId Id = NKI_None;
187 };
188 template <class T>
189 struct KindToKindId<const T> : KindToKindId<T> {};
190
191 /// Per kind info.
192 struct KindInfo {
193 /// The id of the parent kind, or None if it has no parent.
194 NodeKindId ParentId;
195 /// Name of the kind.
196 const char *Name;
197 };
198 static const KindInfo AllKindInfo[NKI_NumberOfKinds];
199
200 NodeKindId KindId;
201};
202
203#define KIND_TO_KIND_ID(Class) \
204 template <> struct ASTNodeKind::KindToKindId<Class> { \
205 static const NodeKindId Id = NKI_##Class; \
206 };
207KIND_TO_KIND_ID(CXXCtorInitializer)
208KIND_TO_KIND_ID(TemplateArgument)
209KIND_TO_KIND_ID(TemplateArgumentLoc)
210KIND_TO_KIND_ID(LambdaCapture)
211KIND_TO_KIND_ID(TemplateName)
212KIND_TO_KIND_ID(NestedNameSpecifier)
213KIND_TO_KIND_ID(NestedNameSpecifierLoc)
214KIND_TO_KIND_ID(QualType)
215#define TYPELOC(CLASS, PARENT) KIND_TO_KIND_ID(CLASS##TypeLoc)
216#include "clang/AST/TypeLocNodes.def"
217KIND_TO_KIND_ID(TypeLoc)
218KIND_TO_KIND_ID(Decl)
219KIND_TO_KIND_ID(Stmt)
220KIND_TO_KIND_ID(Type)
221KIND_TO_KIND_ID(OMPClause)
222KIND_TO_KIND_ID(Attr)
223KIND_TO_KIND_ID(ObjCProtocolLoc)
224KIND_TO_KIND_ID(CXXBaseSpecifier)
225#define DECL(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Decl)
226#include "clang/AST/DeclNodes.inc"
227#define STMT(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED)
228#include "clang/AST/StmtNodes.inc"
229#define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
230#include "clang/AST/TypeNodes.inc"
231#define GEN_CLANG_CLAUSE_CLASS
232#define CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
233#include "llvm/Frontend/OpenMP/OMP.inc"
234#define ATTR(A) KIND_TO_KIND_ID(A##Attr)
235#include "clang/Basic/AttrList.inc"
236#undef KIND_TO_KIND_ID
237
238inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) {
239 OS << K.asStringRef();
240 return OS;
241}
242
243/// A dynamically typed AST node container.
244///
245/// Stores an AST node in a type safe way. This allows writing code that
246/// works with different kinds of AST nodes, despite the fact that they don't
247/// have a common base class.
248///
249/// Use \c create(Node) to create a \c DynTypedNode from an AST node,
250/// and \c get<T>() to retrieve the node as type T if the types match.
251///
252/// See \c ASTNodeKind for which node base types are currently supported;
253/// You can create DynTypedNodes for all nodes in the inheritance hierarchy of
254/// the supported base types.
255class DynTypedNode {
256public:
257 /// Creates a \c DynTypedNode from \c Node.
258 template <typename T>
259 static DynTypedNode create(const T &Node) {
260 return BaseConverter<T>::create(Node);
261 }
262
263 /// Retrieve the stored node as type \c T.
264 ///
265 /// Returns NULL if the stored node does not have a type that is
266 /// convertible to \c T.
267 ///
268 /// For types that have identity via their pointer in the AST
269 /// (like \c Stmt, \c Decl, \c Type and \c NestedNameSpecifier) the returned
270 /// pointer points to the referenced AST node.
271 /// For other types (like \c QualType) the value is stored directly
272 /// in the \c DynTypedNode, and the returned pointer points at
273 /// the storage inside DynTypedNode. For those nodes, do not
274 /// use the pointer outside the scope of the DynTypedNode.
275 template <typename T> const T *get() const {
276 return BaseConverter<T>::get(NodeKind, &Storage);
6
Calling 'DynCastPtrConverter::get'
10
Returning from 'DynCastPtrConverter::get'
11
Returning null pointer, which participates in a condition later
36
Calling 'DynCastPtrConverter::get'
40
Returning from 'DynCastPtrConverter::get'
41
Returning pointer, which participates in a condition later
277 }
278
279 /// Retrieve the stored node as type \c T.
280 ///
281 /// Similar to \c get(), but asserts that the type is what we are expecting.
282 template <typename T>
283 const T &getUnchecked() const {
284 return BaseConverter<T>::getUnchecked(NodeKind, &Storage);
285 }
286
287 ASTNodeKind getNodeKind() const { return NodeKind; }
288
289 /// Returns a pointer that identifies the stored AST node.
290 ///
291 /// Note that this is not supported by all AST nodes. For AST nodes
292 /// that don't have a pointer-defined identity inside the AST, this
293 /// method returns NULL.
294 const void *getMemoizationData() const {
295 return NodeKind.hasPointerIdentity()
296 ? *reinterpret_cast<void *const *>(&Storage)
297 : nullptr;
298 }
299
300 /// Prints the node to the given output stream.
301 void print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const;
302
303 /// Dumps the node to the given output stream.
304 void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
305
306 /// For nodes which represent textual entities in the source code,
307 /// return their SourceRange. For all other nodes, return SourceRange().
308 SourceRange getSourceRange() const;
309
310 /// @{
311 /// Imposes an order on \c DynTypedNode.
312 ///
313 /// Supports comparison of nodes that support memoization.
314 /// FIXME: Implement comparison for other node types (currently
315 /// only Stmt, Decl, Type and NestedNameSpecifier return memoization data).
316 bool operator<(const DynTypedNode &Other) const {
317 if (!NodeKind.isSame(Other.NodeKind))
318 return NodeKind < Other.NodeKind;
319
320 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
321 return getUnchecked<QualType>().getAsOpaquePtr() <
322 Other.getUnchecked<QualType>().getAsOpaquePtr();
323
324 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(NodeKind)) {
325 auto TLA = getUnchecked<TypeLoc>();
326 auto TLB = Other.getUnchecked<TypeLoc>();
327 return std::make_pair(TLA.getType().getAsOpaquePtr(),
328 TLA.getOpaqueData()) <
329 std::make_pair(TLB.getType().getAsOpaquePtr(),
330 TLB.getOpaqueData());
331 }
332
333 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
334 NodeKind)) {
335 auto NNSLA = getUnchecked<NestedNameSpecifierLoc>();
336 auto NNSLB = Other.getUnchecked<NestedNameSpecifierLoc>();
337 return std::make_pair(NNSLA.getNestedNameSpecifier(),
338 NNSLA.getOpaqueData()) <
339 std::make_pair(NNSLB.getNestedNameSpecifier(),
340 NNSLB.getOpaqueData());
341 }
342
343 assert(getMemoizationData() && Other.getMemoizationData())(static_cast <bool> (getMemoizationData() && Other
.getMemoizationData()) ? void (0) : __assert_fail ("getMemoizationData() && Other.getMemoizationData()"
, "clang/include/clang/AST/ASTTypeTraits.h", 343, __extension__
__PRETTY_FUNCTION__))
;
344 return getMemoizationData() < Other.getMemoizationData();
345 }
346 bool operator==(const DynTypedNode &Other) const {
347 // DynTypedNode::create() stores the exact kind of the node in NodeKind.
348 // If they contain the same node, their NodeKind must be the same.
349 if (!NodeKind.isSame(Other.NodeKind))
350 return false;
351
352 // FIXME: Implement for other types.
353 if (ASTNodeKind::getFromNodeKind<QualType>().isSame(NodeKind))
354 return getUnchecked<QualType>() == Other.getUnchecked<QualType>();
355
356 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(NodeKind))
357 return getUnchecked<TypeLoc>() == Other.getUnchecked<TypeLoc>();
358
359 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(NodeKind))
360 return getUnchecked<NestedNameSpecifierLoc>() ==
361 Other.getUnchecked<NestedNameSpecifierLoc>();
362
363 assert(getMemoizationData() && Other.getMemoizationData())(static_cast <bool> (getMemoizationData() && Other
.getMemoizationData()) ? void (0) : __assert_fail ("getMemoizationData() && Other.getMemoizationData()"
, "clang/include/clang/AST/ASTTypeTraits.h", 363, __extension__
__PRETTY_FUNCTION__))
;
364 return getMemoizationData() == Other.getMemoizationData();
365 }
366 bool operator!=(const DynTypedNode &Other) const {
367 return !operator==(Other);
368 }
369 /// @}
370
371 /// Hooks for using DynTypedNode as a key in a DenseMap.
372 struct DenseMapInfo {
373 static inline DynTypedNode getEmptyKey() {
374 DynTypedNode Node;
375 Node.NodeKind = ASTNodeKind::DenseMapInfo::getEmptyKey();
376 return Node;
377 }
378 static inline DynTypedNode getTombstoneKey() {
379 DynTypedNode Node;
380 Node.NodeKind = ASTNodeKind::DenseMapInfo::getTombstoneKey();
381 return Node;
382 }
383 static unsigned getHashValue(const DynTypedNode &Val) {
384 // FIXME: Add hashing support for the remaining types.
385 if (ASTNodeKind::getFromNodeKind<TypeLoc>().isBaseOf(Val.NodeKind)) {
386 auto TL = Val.getUnchecked<TypeLoc>();
387 return llvm::hash_combine(TL.getType().getAsOpaquePtr(),
388 TL.getOpaqueData());
389 }
390
391 if (ASTNodeKind::getFromNodeKind<NestedNameSpecifierLoc>().isSame(
392 Val.NodeKind)) {
393 auto NNSL = Val.getUnchecked<NestedNameSpecifierLoc>();
394 return llvm::hash_combine(NNSL.getNestedNameSpecifier(),
395 NNSL.getOpaqueData());
396 }
397
398 assert(Val.getMemoizationData())(static_cast <bool> (Val.getMemoizationData()) ? void (
0) : __assert_fail ("Val.getMemoizationData()", "clang/include/clang/AST/ASTTypeTraits.h"
, 398, __extension__ __PRETTY_FUNCTION__))
;
399 return llvm::hash_value(Val.getMemoizationData());
400 }
401 static bool isEqual(const DynTypedNode &LHS, const DynTypedNode &RHS) {
402 auto Empty = ASTNodeKind::DenseMapInfo::getEmptyKey();
403 auto TombStone = ASTNodeKind::DenseMapInfo::getTombstoneKey();
404 return (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, Empty) &&
405 ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, Empty)) ||
406 (ASTNodeKind::DenseMapInfo::isEqual(LHS.NodeKind, TombStone) &&
407 ASTNodeKind::DenseMapInfo::isEqual(RHS.NodeKind, TombStone)) ||
408 LHS == RHS;
409 }
410 };
411
412private:
413 /// Takes care of converting from and to \c T.
414 template <typename T, typename EnablerT = void> struct BaseConverter;
415
416 /// Converter that uses dyn_cast<T> from a stored BaseT*.
417 template <typename T, typename BaseT> struct DynCastPtrConverter {
418 static const T *get(ASTNodeKind NodeKind, const void *Storage) {
419 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
7
Assuming the condition is false
8
Taking false branch
37
Assuming the condition is true
38
Taking true branch
420 return &getUnchecked(NodeKind, Storage);
39
Returning pointer, which participates in a condition later
421 return nullptr;
9
Returning null pointer, which participates in a condition later
422 }
423 static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
424 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))(static_cast <bool> (ASTNodeKind::getFromNodeKind<T>
().isBaseOf(NodeKind)) ? void (0) : __assert_fail ("ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind)"
, "clang/include/clang/AST/ASTTypeTraits.h", 424, __extension__
__PRETTY_FUNCTION__))
;
425 return *cast<T>(static_cast<const BaseT *>(
426 *reinterpret_cast<const void *const *>(Storage)));
427 }
428 static DynTypedNode create(const BaseT &Node) {
429 DynTypedNode Result;
430 Result.NodeKind = ASTNodeKind::getFromNode(Node);
431 new (&Result.Storage) const void *(&Node);
432 return Result;
433 }
434 };
435
436 /// Converter that stores T* (by pointer).
437 template <typename T> struct PtrConverter {
438 static const T *get(ASTNodeKind NodeKind, const void *Storage) {
439 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
440 return &getUnchecked(NodeKind, Storage);
441 return nullptr;
442 }
443 static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
444 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))(static_cast <bool> (ASTNodeKind::getFromNodeKind<T>
().isSame(NodeKind)) ? void (0) : __assert_fail ("ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind)"
, "clang/include/clang/AST/ASTTypeTraits.h", 444, __extension__
__PRETTY_FUNCTION__))
;
445 return *static_cast<const T *>(
446 *reinterpret_cast<const void *const *>(Storage));
447 }
448 static DynTypedNode create(const T &Node) {
449 DynTypedNode Result;
450 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
451 new (&Result.Storage) const void *(&Node);
452 return Result;
453 }
454 };
455
456 /// Converter that stores T (by value).
457 template <typename T> struct ValueConverter {
458 static const T *get(ASTNodeKind NodeKind, const void *Storage) {
459 if (ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))
460 return reinterpret_cast<const T *>(Storage);
461 return nullptr;
462 }
463 static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
464 assert(ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind))(static_cast <bool> (ASTNodeKind::getFromNodeKind<T>
().isSame(NodeKind)) ? void (0) : __assert_fail ("ASTNodeKind::getFromNodeKind<T>().isSame(NodeKind)"
, "clang/include/clang/AST/ASTTypeTraits.h", 464, __extension__
__PRETTY_FUNCTION__))
;
465 return *reinterpret_cast<const T *>(Storage);
466 }
467 static DynTypedNode create(const T &Node) {
468 DynTypedNode Result;
469 Result.NodeKind = ASTNodeKind::getFromNodeKind<T>();
470 new (&Result.Storage) T(Node);
471 return Result;
472 }
473 };
474
475 /// Converter that stores nodes by value. It must be possible to dynamically
476 /// cast the stored node within a type hierarchy without breaking (especially
477 /// through slicing).
478 template <typename T, typename BaseT,
479 typename = std::enable_if_t<(sizeof(T) == sizeof(BaseT))>>
480 struct DynCastValueConverter {
481 static const T *get(ASTNodeKind NodeKind, const void *Storage) {
482 if (ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))
483 return &getUnchecked(NodeKind, Storage);
484 return nullptr;
485 }
486 static const T &getUnchecked(ASTNodeKind NodeKind, const void *Storage) {
487 assert(ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind))(static_cast <bool> (ASTNodeKind::getFromNodeKind<T>
().isBaseOf(NodeKind)) ? void (0) : __assert_fail ("ASTNodeKind::getFromNodeKind<T>().isBaseOf(NodeKind)"
, "clang/include/clang/AST/ASTTypeTraits.h", 487, __extension__
__PRETTY_FUNCTION__))
;
488 return *static_cast<const T *>(reinterpret_cast<const BaseT *>(Storage));
489 }
490 static DynTypedNode create(const T &Node) {
491 DynTypedNode Result;
492 Result.NodeKind = ASTNodeKind::getFromNode(Node);
493 new (&Result.Storage) T(Node);
494 return Result;
495 }
496 };
497
498 ASTNodeKind NodeKind;
499
500 /// Stores the data of the node.
501 ///
502 /// Note that we can store \c Decls, \c Stmts, \c Types,
503 /// \c NestedNameSpecifiers and \c CXXCtorInitializer by pointer as they are
504 /// guaranteed to be unique pointers pointing to dedicated storage in the AST.
505 /// \c QualTypes, \c NestedNameSpecifierLocs, \c TypeLocs,
506 /// \c TemplateArguments and \c TemplateArgumentLocs on the other hand do not
507 /// have storage or unique pointers and thus need to be stored by value.
508 llvm::AlignedCharArrayUnion<const void *, TemplateArgument,
509 TemplateArgumentLoc, NestedNameSpecifierLoc,
510 QualType, TypeLoc, ObjCProtocolLoc>
511 Storage;
512};
513
514template <typename T>
515struct DynTypedNode::BaseConverter<
516 T, std::enable_if_t<std::is_base_of<Decl, T>::value>>
517 : public DynCastPtrConverter<T, Decl> {};
518
519template <typename T>
520struct DynTypedNode::BaseConverter<
521 T, std::enable_if_t<std::is_base_of<Stmt, T>::value>>
522 : public DynCastPtrConverter<T, Stmt> {};
523
524template <typename T>
525struct DynTypedNode::BaseConverter<
526 T, std::enable_if_t<std::is_base_of<Type, T>::value>>
527 : public DynCastPtrConverter<T, Type> {};
528
529template <typename T>
530struct DynTypedNode::BaseConverter<
531 T, std::enable_if_t<std::is_base_of<OMPClause, T>::value>>
532 : public DynCastPtrConverter<T, OMPClause> {};
533
534template <typename T>
535struct DynTypedNode::BaseConverter<
536 T, std::enable_if_t<std::is_base_of<Attr, T>::value>>
537 : public DynCastPtrConverter<T, Attr> {};
538
539template <>
540struct DynTypedNode::BaseConverter<
541 NestedNameSpecifier, void> : public PtrConverter<NestedNameSpecifier> {};
542
543template <>
544struct DynTypedNode::BaseConverter<
545 CXXCtorInitializer, void> : public PtrConverter<CXXCtorInitializer> {};
546
547template <>
548struct DynTypedNode::BaseConverter<
549 TemplateArgument, void> : public ValueConverter<TemplateArgument> {};
550
551template <>
552struct DynTypedNode::BaseConverter<TemplateArgumentLoc, void>
553 : public ValueConverter<TemplateArgumentLoc> {};
554
555template <>
556struct DynTypedNode::BaseConverter<LambdaCapture, void>
557 : public ValueConverter<LambdaCapture> {};
558
559template <>
560struct DynTypedNode::BaseConverter<
561 TemplateName, void> : public ValueConverter<TemplateName> {};
562
563template <>
564struct DynTypedNode::BaseConverter<
565 NestedNameSpecifierLoc,
566 void> : public ValueConverter<NestedNameSpecifierLoc> {};
567
568template <>
569struct DynTypedNode::BaseConverter<QualType,
570 void> : public ValueConverter<QualType> {};
571
572template <typename T>
573struct DynTypedNode::BaseConverter<
574 T, std::enable_if_t<std::is_base_of<TypeLoc, T>::value>>
575 : public DynCastValueConverter<T, TypeLoc> {};
576
577template <>
578struct DynTypedNode::BaseConverter<CXXBaseSpecifier, void>
579 : public PtrConverter<CXXBaseSpecifier> {};
580
581template <>
582struct DynTypedNode::BaseConverter<ObjCProtocolLoc, void>
583 : public ValueConverter<ObjCProtocolLoc> {};
584
585// The only operation we allow on unsupported types is \c get.
586// This allows to conveniently use \c DynTypedNode when having an arbitrary
587// AST node that is not supported, but prevents misuse - a user cannot create
588// a DynTypedNode from arbitrary types.
589template <typename T, typename EnablerT> struct DynTypedNode::BaseConverter {
590 static const T *get(ASTNodeKind NodeKind, const char Storage[]) {
591 return NULL__null;
592 }
593};
594
595} // end namespace clang
596
597namespace llvm {
598
599template <>
600struct DenseMapInfo<clang::ASTNodeKind> : clang::ASTNodeKind::DenseMapInfo {};
601
602template <>
603struct DenseMapInfo<clang::DynTypedNode> : clang::DynTypedNode::DenseMapInfo {};
604
605} // end namespace llvm
606
607#endif

/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h

1// Components for manipulating sequences of characters -*- C++ -*-
2
3// Copyright (C) 1997-2020 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file bits/basic_string.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{string}
28 */
29
30//
31// ISO C++ 14882: 21 Strings library
32//
33
34#ifndef _BASIC_STRING_H1
35#define _BASIC_STRING_H1 1
36
37#pragma GCC system_header
38
39#include <ext/atomicity.h>
40#include <ext/alloc_traits.h>
41#include <debug/debug.h>
42
43#if __cplusplus201703L >= 201103L
44#include <initializer_list>
45#endif
46
47#if __cplusplus201703L >= 201703L
48# include <string_view>
49#endif
50
51
52namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
53{
54_GLIBCXX_BEGIN_NAMESPACE_VERSION
55
56#if _GLIBCXX_USE_CXX11_ABI1
57_GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 {
58 /**
59 * @class basic_string basic_string.h <string>
60 * @brief Managing sequences of characters and character-like objects.
61 *
62 * @ingroup strings
63 * @ingroup sequences
64 *
65 * @tparam _CharT Type of character
66 * @tparam _Traits Traits for character type, defaults to
67 * char_traits<_CharT>.
68 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
69 *
70 * Meets the requirements of a <a href="tables.html#65">container</a>, a
71 * <a href="tables.html#66">reversible container</a>, and a
72 * <a href="tables.html#67">sequence</a>. Of the
73 * <a href="tables.html#68">optional sequence requirements</a>, only
74 * @c push_back, @c at, and @c %array access are supported.
75 */
76 template<typename _CharT, typename _Traits, typename _Alloc>
77 class basic_string
78 {
79 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
80 rebind<_CharT>::other _Char_alloc_type;
81 typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits;
82
83 // Types:
84 public:
85 typedef _Traits traits_type;
86 typedef typename _Traits::char_type value_type;
87 typedef _Char_alloc_type allocator_type;
88 typedef typename _Alloc_traits::size_type size_type;
89 typedef typename _Alloc_traits::difference_type difference_type;
90 typedef typename _Alloc_traits::reference reference;
91 typedef typename _Alloc_traits::const_reference const_reference;
92 typedef typename _Alloc_traits::pointer pointer;
93 typedef typename _Alloc_traits::const_pointer const_pointer;
94 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
95 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
96 const_iterator;
97 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
98 typedef std::reverse_iterator<iterator> reverse_iterator;
99
100 /// Value returned by various member functions when they fail.
101 static const size_type npos = static_cast<size_type>(-1);
102
103 protected:
104 // type used for positions in insert, erase etc.
105#if __cplusplus201703L < 201103L
106 typedef iterator __const_iterator;
107#else
108 typedef const_iterator __const_iterator;
109#endif
110
111 private:
112#if __cplusplus201703L >= 201703L
113 // A helper type for avoiding boiler-plate.
114 typedef basic_string_view<_CharT, _Traits> __sv_type;
115
116 template<typename _Tp, typename _Res>
117 using _If_sv = enable_if_t<
118 __and_<is_convertible<const _Tp&, __sv_type>,
119 __not_<is_convertible<const _Tp*, const basic_string*>>,
120 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
121 _Res>;
122
123 // Allows an implicit conversion to __sv_type.
124 static __sv_type
125 _S_to_string_view(__sv_type __svt) noexcept
126 { return __svt; }
127
128 // Wraps a string_view by explicit conversion and thus
129 // allows to add an internal constructor that does not
130 // participate in overload resolution when a string_view
131 // is provided.
132 struct __sv_wrapper
133 {
134 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
135 __sv_type _M_sv;
136 };
137
138 /**
139 * @brief Only internally used: Construct string from a string view
140 * wrapper.
141 * @param __svw string view wrapper.
142 * @param __a Allocator to use.
143 */
144 explicit
145 basic_string(__sv_wrapper __svw, const _Alloc& __a)
146 : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { }
147#endif
148
149 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
150 struct _Alloc_hider : allocator_type // TODO check __is_final
151 {
152#if __cplusplus201703L < 201103L
153 _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
154 : allocator_type(__a), _M_p(__dat) { }
155#else
156 _Alloc_hider(pointer __dat, const _Alloc& __a)
157 : allocator_type(__a), _M_p(__dat) { }
158
159 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
160 : allocator_type(std::move(__a)), _M_p(__dat) { }
161#endif
162
163 pointer _M_p; // The actual data.
164 };
165
166 _Alloc_hider _M_dataplus;
167 size_type _M_string_length;
168
169 enum { _S_local_capacity = 15 / sizeof(_CharT) };
170
171 union
172 {
173 _CharT _M_local_buf[_S_local_capacity + 1];
174 size_type _M_allocated_capacity;
175 };
176
177 void
178 _M_data(pointer __p)
179 { _M_dataplus._M_p = __p; }
180
181 void
182 _M_length(size_type __length)
183 { _M_string_length = __length; }
184
185 pointer
186 _M_data() const
187 { return _M_dataplus._M_p; }
188
189 pointer
190 _M_local_data()
191 {
192#if __cplusplus201703L >= 201103L
193 return std::pointer_traits<pointer>::pointer_to(*_M_local_buf);
194#else
195 return pointer(_M_local_buf);
196#endif
197 }
198
199 const_pointer
200 _M_local_data() const
201 {
202#if __cplusplus201703L >= 201103L
203 return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf);
204#else
205 return const_pointer(_M_local_buf);
206#endif
207 }
208
209 void
210 _M_capacity(size_type __capacity)
211 { _M_allocated_capacity = __capacity; }
212
213 void
214 _M_set_length(size_type __n)
215 {
216 _M_length(__n);
217 traits_type::assign(_M_data()[__n], _CharT());
218 }
219
220 bool
221 _M_is_local() const
222 { return _M_data() == _M_local_data(); }
223
224 // Create & Destroy
225 pointer
226 _M_create(size_type&, size_type);
227
228 void
229 _M_dispose()
230 {
231 if (!_M_is_local())
232 _M_destroy(_M_allocated_capacity);
233 }
234
235 void
236 _M_destroy(size_type __size) throw()
237 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
238
239 // _M_construct_aux is used to implement the 21.3.1 para 15 which
240 // requires special behaviour if _InIterator is an integral type
241 template<typename _InIterator>
242 void
243 _M_construct_aux(_InIterator __beg, _InIterator __end,
244 std::__false_type)
245 {
246 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
247 _M_construct(__beg, __end, _Tag());
248 }
249
250 // _GLIBCXX_RESOLVE_LIB_DEFECTS
251 // 438. Ambiguity in the "do the right thing" clause
252 template<typename _Integer>
253 void
254 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
255 { _M_construct_aux_2(static_cast<size_type>(__beg), __end); }
256
257 void
258 _M_construct_aux_2(size_type __req, _CharT __c)
259 { _M_construct(__req, __c); }
260
261 template<typename _InIterator>
262 void
263 _M_construct(_InIterator __beg, _InIterator __end)
264 {
265 typedef typename std::__is_integer<_InIterator>::__type _Integral;
266 _M_construct_aux(__beg, __end, _Integral());
267 }
268
269 // For Input Iterators, used in istreambuf_iterators, etc.
270 template<typename _InIterator>
271 void
272 _M_construct(_InIterator __beg, _InIterator __end,
273 std::input_iterator_tag);
274
275 // For forward_iterators up to random_access_iterators, used for
276 // string::iterator, _CharT*, etc.
277 template<typename _FwdIterator>
278 void
279 _M_construct(_FwdIterator __beg, _FwdIterator __end,
280 std::forward_iterator_tag);
281
282 void
283 _M_construct(size_type __req, _CharT __c);
284
285 allocator_type&
286 _M_get_allocator()
287 { return _M_dataplus; }
288
289 const allocator_type&
290 _M_get_allocator() const
291 { return _M_dataplus; }
292
293 private:
294
295#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
296 // The explicit instantiations in misc-inst.cc require this due to
297 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063
298 template<typename _Tp, bool _Requires =
299 !__are_same<_Tp, _CharT*>::__value
300 && !__are_same<_Tp, const _CharT*>::__value
301 && !__are_same<_Tp, iterator>::__value
302 && !__are_same<_Tp, const_iterator>::__value>
303 struct __enable_if_not_native_iterator
304 { typedef basic_string& __type; };
305 template<typename _Tp>
306 struct __enable_if_not_native_iterator<_Tp, false> { };
307#endif
308
309 size_type
310 _M_check(size_type __pos, const char* __s) const
311 {
312 if (__pos > this->size())
313 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "("%s: __pos (which is %zu) > " "this->size() (which is %zu)"
)
314 "this->size() (which is %zu)")("%s: __pos (which is %zu) > " "this->size() (which is %zu)"
)
,
315 __s, __pos, this->size());
316 return __pos;
317 }
318
319 void
320 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
321 {
322 if (this->max_size() - (this->size() - __n1) < __n2)
323 __throw_length_error(__N(__s)(__s));
324 }
325
326
327 // NB: _M_limit doesn't check for a bad __pos value.
328 size_type
329 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPTnoexcept
330 {
331 const bool __testoff = __off < this->size() - __pos;
332 return __testoff ? __off : this->size() - __pos;
333 }
334
335 // True if _Rep and source do not overlap.
336 bool
337 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept
338 {
339 return (less<const _CharT*>()(__s, _M_data())
340 || less<const _CharT*>()(_M_data() + this->size(), __s));
341 }
342
343 // When __n = 1 way faster than the general multichar
344 // traits_type::copy/move/assign.
345 static void
346 _S_copy(_CharT* __d, const _CharT* __s, size_type __n)
347 {
348 if (__n == 1)
349 traits_type::assign(*__d, *__s);
350 else
351 traits_type::copy(__d, __s, __n);
352 }
353
354 static void
355 _S_move(_CharT* __d, const _CharT* __s, size_type __n)
356 {
357 if (__n == 1)
358 traits_type::assign(*__d, *__s);
359 else
360 traits_type::move(__d, __s, __n);
361 }
362
363 static void
364 _S_assign(_CharT* __d, size_type __n, _CharT __c)
365 {
366 if (__n == 1)
367 traits_type::assign(*__d, __c);
368 else
369 traits_type::assign(__d, __n, __c);
370 }
371
372 // _S_copy_chars is a separate template to permit specialization
373 // to optimize for the common case of pointers as iterators.
374 template<class _Iterator>
375 static void
376 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
377 {
378 for (; __k1 != __k2; ++__k1, (void)++__p)
379 traits_type::assign(*__p, *__k1); // These types are off.
380 }
381
382 static void
383 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPTnoexcept
384 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
385
386 static void
387 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
388 _GLIBCXX_NOEXCEPTnoexcept
389 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
390
391 static void
392 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPTnoexcept
393 { _S_copy(__p, __k1, __k2 - __k1); }
394
395 static void
396 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
397 _GLIBCXX_NOEXCEPTnoexcept
398 { _S_copy(__p, __k1, __k2 - __k1); }
399
400 static int
401 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPTnoexcept
402 {
403 const difference_type __d = difference_type(__n1 - __n2);
404
405 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
406 return __gnu_cxx::__numeric_traits<int>::__max;
407 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
408 return __gnu_cxx::__numeric_traits<int>::__min;
409 else
410 return int(__d);
411 }
412
413 void
414 _M_assign(const basic_string&);
415
416 void
417 _M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
418 size_type __len2);
419
420 void
421 _M_erase(size_type __pos, size_type __n);
422
423 public:
424 // Construct/copy/destroy:
425 // NB: We overload ctors in some cases instead of using default
426 // arguments, per 17.4.4.4 para. 2 item 2.
427
428 /**
429 * @brief Default constructor creates an empty string.
430 */
431 basic_string()
432 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)noexcept(is_nothrow_default_constructible<_Alloc>::value
)
433 : _M_dataplus(_M_local_data())
434 { _M_set_length(0); }
435
436 /**
437 * @brief Construct an empty string using allocator @a a.
438 */
439 explicit
440 basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPTnoexcept
441 : _M_dataplus(_M_local_data(), __a)
442 { _M_set_length(0); }
443
444 /**
445 * @brief Construct string with copy of value of @a __str.
446 * @param __str Source string.
447 */
448 basic_string(const basic_string& __str)
449 : _M_dataplus(_M_local_data(),
450 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
451 { _M_construct(__str._M_data(), __str._M_data() + __str.length()); }
452
453 // _GLIBCXX_RESOLVE_LIB_DEFECTS
454 // 2583. no way to supply an allocator for basic_string(str, pos)
455 /**
456 * @brief Construct string as copy of a substring.
457 * @param __str Source string.
458 * @param __pos Index of first character to copy from.
459 * @param __a Allocator to use.
460 */
461 basic_string(const basic_string& __str, size_type __pos,
462 const _Alloc& __a = _Alloc())
463 : _M_dataplus(_M_local_data(), __a)
464 {
465 const _CharT* __start = __str._M_data()
466 + __str._M_check(__pos, "basic_string::basic_string");
467 _M_construct(__start, __start + __str._M_limit(__pos, npos));
468 }
469
470 /**
471 * @brief Construct string as copy of a substring.
472 * @param __str Source string.
473 * @param __pos Index of first character to copy from.
474 * @param __n Number of characters to copy.
475 */
476 basic_string(const basic_string& __str, size_type __pos,
477 size_type __n)
478 : _M_dataplus(_M_local_data())
479 {
480 const _CharT* __start = __str._M_data()
481 + __str._M_check(__pos, "basic_string::basic_string");
482 _M_construct(__start, __start + __str._M_limit(__pos, __n));
483 }
484
485 /**
486 * @brief Construct string as copy of a substring.
487 * @param __str Source string.
488 * @param __pos Index of first character to copy from.
489 * @param __n Number of characters to copy.
490 * @param __a Allocator to use.
491 */
492 basic_string(const basic_string& __str, size_type __pos,
493 size_type __n, const _Alloc& __a)
494 : _M_dataplus(_M_local_data(), __a)
495 {
496 const _CharT* __start
497 = __str._M_data() + __str._M_check(__pos, "string::string");
498 _M_construct(__start, __start + __str._M_limit(__pos, __n));
499 }
500
501 /**
502 * @brief Construct string initialized by a character %array.
503 * @param __s Source character %array.
504 * @param __n Number of characters to copy.
505 * @param __a Allocator to use (default is default allocator).
506 *
507 * NB: @a __s must have at least @a __n characters, &apos;\\0&apos;
508 * has no special meaning.
509 */
510 basic_string(const _CharT* __s, size_type __n,
511 const _Alloc& __a = _Alloc())
512 : _M_dataplus(_M_local_data(), __a)
513 { _M_construct(__s, __s + __n); }
514
515 /**
516 * @brief Construct string as copy of a C string.
517 * @param __s Source C string.
518 * @param __a Allocator to use (default is default allocator).
519 */
520#if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
521 // _GLIBCXX_RESOLVE_LIB_DEFECTS
522 // 3076. basic_string CTAD ambiguity
523 template<typename = _RequireAllocator<_Alloc>>
524#endif
525 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
526 : _M_dataplus(_M_local_data(), __a)
527 { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); }
528
529 /**
530 * @brief Construct string as multiple characters.
531 * @param __n Number of characters.
532 * @param __c Character to use.
533 * @param __a Allocator to use (default is default allocator).
534 */
535#if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
536 // _GLIBCXX_RESOLVE_LIB_DEFECTS
537 // 3076. basic_string CTAD ambiguity
538 template<typename = _RequireAllocator<_Alloc>>
539#endif
540 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
541 : _M_dataplus(_M_local_data(), __a)
542 { _M_construct(__n, __c); }
543
544#if __cplusplus201703L >= 201103L
545 /**
546 * @brief Move construct string.
547 * @param __str Source string.
548 *
549 * The newly-created string contains the exact contents of @a __str.
550 * @a __str is a valid, but unspecified string.
551 **/
552 basic_string(basic_string&& __str) noexcept
553 : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
554 {
555 if (__str._M_is_local())
556 {
557 traits_type::copy(_M_local_buf, __str._M_local_buf,
558 _S_local_capacity + 1);
559 }
560 else
561 {
562 _M_data(__str._M_data());
563 _M_capacity(__str._M_allocated_capacity);
564 }
565
566 // Must use _M_length() here not _M_set_length() because
567 // basic_stringbuf relies on writing into unallocated capacity so
568 // we mess up the contents if we put a '\0' in the string.
569 _M_length(__str.length());
570 __str._M_data(__str._M_local_data());
571 __str._M_set_length(0);
572 }
573
574 /**
575 * @brief Construct string from an initializer %list.
576 * @param __l std::initializer_list of characters.
577 * @param __a Allocator to use (default is default allocator).
578 */
579 basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
580 : _M_dataplus(_M_local_data(), __a)
581 { _M_construct(__l.begin(), __l.end()); }
582
583 basic_string(const basic_string& __str, const _Alloc& __a)
584 : _M_dataplus(_M_local_data(), __a)
585 { _M_construct(__str.begin(), __str.end()); }
586
587 basic_string(basic_string&& __str, const _Alloc& __a)
588 noexcept(_Alloc_traits::_S_always_equal())
589 : _M_dataplus(_M_local_data(), __a)
590 {
591 if (__str._M_is_local())
592 {
593 traits_type::copy(_M_local_buf, __str._M_local_buf,
594 _S_local_capacity + 1);
595 _M_length(__str.length());
596 __str._M_set_length(0);
597 }
598 else if (_Alloc_traits::_S_always_equal()
599 || __str.get_allocator() == __a)
600 {
601 _M_data(__str._M_data());
602 _M_length(__str.length());
603 _M_capacity(__str._M_allocated_capacity);
604 __str._M_data(__str._M_local_buf);
605 __str._M_set_length(0);
606 }
607 else
608 _M_construct(__str.begin(), __str.end());
609 }
610
611#endif // C++11
612
613 /**
614 * @brief Construct string as copy of a range.
615 * @param __beg Start of range.
616 * @param __end End of range.
617 * @param __a Allocator to use (default is default allocator).
618 */
619#if __cplusplus201703L >= 201103L
620 template<typename _InputIterator,
621 typename = std::_RequireInputIter<_InputIterator>>
622#else
623 template<typename _InputIterator>
624#endif
625 basic_string(_InputIterator __beg, _InputIterator __end,
626 const _Alloc& __a = _Alloc())
627 : _M_dataplus(_M_local_data(), __a)
628 { _M_construct(__beg, __end); }
629
630#if __cplusplus201703L >= 201703L
631 /**
632 * @brief Construct string from a substring of a string_view.
633 * @param __t Source object convertible to string view.
634 * @param __pos The index of the first character to copy from __t.
635 * @param __n The number of characters to copy from __t.
636 * @param __a Allocator to use.
637 */
638 template<typename _Tp, typename = _If_sv<_Tp, void>>
639 basic_string(const _Tp& __t, size_type __pos, size_type __n,
640 const _Alloc& __a = _Alloc())
641 : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
642
643 /**
644 * @brief Construct string from a string_view.
645 * @param __t Source object convertible to string view.
646 * @param __a Allocator to use (default is default allocator).
647 */
648 template<typename _Tp, typename = _If_sv<_Tp, void>>
649 explicit
650 basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
651 : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
652#endif // C++17
653
654 /**
655 * @brief Destroy the string instance.
656 */
657 ~basic_string()
658 { _M_dispose(); }
659
660 /**
661 * @brief Assign the value of @a str to this string.
662 * @param __str Source string.
663 */
664 basic_string&
665 operator=(const basic_string& __str)
666 {
667 return this->assign(__str);
668 }
669
670 /**
671 * @brief Copy contents of @a s into this string.
672 * @param __s Source null-terminated string.
673 */
674 basic_string&
675 operator=(const _CharT* __s)
676 { return this->assign(__s); }
677
678 /**
679 * @brief Set value to string of length 1.
680 * @param __c Source character.
681 *
682 * Assigning to a character makes this string length 1 and
683 * (*this)[0] == @a c.
684 */
685 basic_string&
686 operator=(_CharT __c)
687 {
688 this->assign(1, __c);
689 return *this;
690 }
691
692#if __cplusplus201703L >= 201103L
693 /**
694 * @brief Move assign the value of @a str to this string.
695 * @param __str Source string.
696 *
697 * The contents of @a str are moved into this string (without copying).
698 * @a str is a valid, but unspecified string.
699 **/
700 // _GLIBCXX_RESOLVE_LIB_DEFECTS
701 // 2063. Contradictory requirements for string move assignment
702 basic_string&
703 operator=(basic_string&& __str)
704 noexcept(_Alloc_traits::_S_nothrow_move())
705 {
706 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
707 && !_Alloc_traits::_S_always_equal()
708 && _M_get_allocator() != __str._M_get_allocator())
709 {
710 // Destroy existing storage before replacing allocator.
711 _M_destroy(_M_allocated_capacity);
712 _M_data(_M_local_data());
713 _M_set_length(0);
714 }
715 // Replace allocator if POCMA is true.
716 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
717
718 if (__str._M_is_local())
719 {
720 // We've always got room for a short string, just copy it.
721 if (__str.size())
722 this->_S_copy(_M_data(), __str._M_data(), __str.size());
723 _M_set_length(__str.size());
724 }
725 else if (_Alloc_traits::_S_propagate_on_move_assign()
726 || _Alloc_traits::_S_always_equal()
727 || _M_get_allocator() == __str._M_get_allocator())
728 {
729 // Just move the allocated pointer, our allocator can free it.
730 pointer __data = nullptr;
731 size_type __capacity;
732 if (!_M_is_local())
733 {
734 if (_Alloc_traits::_S_always_equal())
735 {
736 // __str can reuse our existing storage.
737 __data = _M_data();
738 __capacity = _M_allocated_capacity;
739 }
740 else // __str can't use it, so free it.
741 _M_destroy(_M_allocated_capacity);
742 }
743
744 _M_data(__str._M_data());
745 _M_length(__str.length());
746 _M_capacity(__str._M_allocated_capacity);
747 if (__data)
748 {
749 __str._M_data(__data);
750 __str._M_capacity(__capacity);
751 }
752 else
753 __str._M_data(__str._M_local_buf);
754 }
755 else // Need to do a deep copy
756 assign(__str);
757 __str.clear();
758 return *this;
759 }
760
761 /**
762 * @brief Set value to string constructed from initializer %list.
763 * @param __l std::initializer_list.
764 */
765 basic_string&
766 operator=(initializer_list<_CharT> __l)
767 {
768 this->assign(__l.begin(), __l.size());
769 return *this;
770 }
771#endif // C++11
772
773#if __cplusplus201703L >= 201703L
774 /**
775 * @brief Set value to string constructed from a string_view.
776 * @param __svt An object convertible to string_view.
777 */
778 template<typename _Tp>
779 _If_sv<_Tp, basic_string&>
780 operator=(const _Tp& __svt)
781 { return this->assign(__svt); }
782
783 /**
784 * @brief Convert to a string_view.
785 * @return A string_view.
786 */
787 operator __sv_type() const noexcept
788 { return __sv_type(data(), size()); }
789#endif // C++17
790
791 // Iterators:
792 /**
793 * Returns a read/write iterator that points to the first character in
794 * the %string.
795 */
796 iterator
797 begin() _GLIBCXX_NOEXCEPTnoexcept
798 { return iterator(_M_data()); }
799
800 /**
801 * Returns a read-only (constant) iterator that points to the first
802 * character in the %string.
803 */
804 const_iterator
805 begin() const _GLIBCXX_NOEXCEPTnoexcept
806 { return const_iterator(_M_data()); }
807
808 /**
809 * Returns a read/write iterator that points one past the last
810 * character in the %string.
811 */
812 iterator
813 end() _GLIBCXX_NOEXCEPTnoexcept
814 { return iterator(_M_data() + this->size()); }
815
816 /**
817 * Returns a read-only (constant) iterator that points one past the
818 * last character in the %string.
819 */
820 const_iterator
821 end() const _GLIBCXX_NOEXCEPTnoexcept
822 { return const_iterator(_M_data() + this->size()); }
823
824 /**
825 * Returns a read/write reverse iterator that points to the last
826 * character in the %string. Iteration is done in reverse element
827 * order.
828 */
829 reverse_iterator
830 rbegin() _GLIBCXX_NOEXCEPTnoexcept
831 { return reverse_iterator(this->end()); }
832
833 /**
834 * Returns a read-only (constant) reverse iterator that points
835 * to the last character in the %string. Iteration is done in
836 * reverse element order.
837 */
838 const_reverse_iterator
839 rbegin() const _GLIBCXX_NOEXCEPTnoexcept
840 { return const_reverse_iterator(this->end()); }
841
842 /**
843 * Returns a read/write reverse iterator that points to one before the
844 * first character in the %string. Iteration is done in reverse
845 * element order.
846 */
847 reverse_iterator
848 rend() _GLIBCXX_NOEXCEPTnoexcept
849 { return reverse_iterator(this->begin()); }
850
851 /**
852 * Returns a read-only (constant) reverse iterator that points
853 * to one before the first character in the %string. Iteration
854 * is done in reverse element order.
855 */
856 const_reverse_iterator
857 rend() const _GLIBCXX_NOEXCEPTnoexcept
858 { return const_reverse_iterator(this->begin()); }
859
860#if __cplusplus201703L >= 201103L
861 /**
862 * Returns a read-only (constant) iterator that points to the first
863 * character in the %string.
864 */
865 const_iterator
866 cbegin() const noexcept
867 { return const_iterator(this->_M_data()); }
868
869 /**
870 * Returns a read-only (constant) iterator that points one past the
871 * last character in the %string.
872 */
873 const_iterator
874 cend() const noexcept
875 { return const_iterator(this->_M_data() + this->size()); }
876
877 /**
878 * Returns a read-only (constant) reverse iterator that points
879 * to the last character in the %string. Iteration is done in
880 * reverse element order.
881 */
882 const_reverse_iterator
883 crbegin() const noexcept
884 { return const_reverse_iterator(this->end()); }
885
886 /**
887 * Returns a read-only (constant) reverse iterator that points
888 * to one before the first character in the %string. Iteration
889 * is done in reverse element order.
890 */
891 const_reverse_iterator
892 crend() const noexcept
893 { return const_reverse_iterator(this->begin()); }
894#endif
895
896 public:
897 // Capacity:
898 /// Returns the number of characters in the string, not including any
899 /// null-termination.
900 size_type
901 size() const _GLIBCXX_NOEXCEPTnoexcept
902 { return _M_string_length; }
903
904 /// Returns the number of characters in the string, not including any
905 /// null-termination.
906 size_type
907 length() const _GLIBCXX_NOEXCEPTnoexcept
908 { return _M_string_length; }
909
910 /// Returns the size() of the largest possible %string.
911 size_type
912 max_size() const _GLIBCXX_NOEXCEPTnoexcept
913 { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
914
915 /**
916 * @brief Resizes the %string to the specified number of characters.
917 * @param __n Number of characters the %string should contain.
918 * @param __c Character to fill any new elements.
919 *
920 * This function will %resize the %string to the specified
921 * number of characters. If the number is smaller than the
922 * %string's current size the %string is truncated, otherwise
923 * the %string is extended and new elements are %set to @a __c.
924 */
925 void
926 resize(size_type __n, _CharT __c);
927
928 /**
929 * @brief Resizes the %string to the specified number of characters.
930 * @param __n Number of characters the %string should contain.
931 *
932 * This function will resize the %string to the specified length. If
933 * the new size is smaller than the %string's current size the %string
934 * is truncated, otherwise the %string is extended and new characters
935 * are default-constructed. For basic types such as char, this means
936 * setting them to 0.
937 */
938 void
939 resize(size_type __n)
940 { this->resize(__n, _CharT()); }
941
942#if __cplusplus201703L >= 201103L
943 /// A non-binding request to reduce capacity() to size().
944 void
945 shrink_to_fit() noexcept
946 {
947#if __cpp_exceptions
948 if (capacity() > size())
949 {
950 try
951 { reserve(0); }
952 catch(...)
953 { }
954 }
955#endif
956 }
957#endif
958
959 /**
960 * Returns the total number of characters that the %string can hold
961 * before needing to allocate more memory.
962 */
963 size_type
964 capacity() const _GLIBCXX_NOEXCEPTnoexcept
965 {
966 return _M_is_local() ? size_type(_S_local_capacity)
967 : _M_allocated_capacity;
968 }
969
970 /**
971 * @brief Attempt to preallocate enough memory for specified number of
972 * characters.
973 * @param __res_arg Number of characters required.
974 * @throw std::length_error If @a __res_arg exceeds @c max_size().
975 *
976 * This function attempts to reserve enough memory for the
977 * %string to hold the specified number of characters. If the
978 * number requested is more than max_size(), length_error is
979 * thrown.
980 *
981 * The advantage of this function is that if optimal code is a
982 * necessity and the user can determine the string length that will be
983 * required, the user can reserve the memory in %advance, and thus
984 * prevent a possible reallocation of memory and copying of %string
985 * data.
986 */
987 void
988 reserve(size_type __res_arg = 0);
989
990 /**
991 * Erases the string, making it empty.
992 */
993 void
994 clear() _GLIBCXX_NOEXCEPTnoexcept
995 { _M_set_length(0); }
996
997 /**
998 * Returns true if the %string is empty. Equivalent to
999 * <code>*this == ""</code>.
1000 */
1001 _GLIBCXX_NODISCARD[[__nodiscard__]] bool
1002 empty() const _GLIBCXX_NOEXCEPTnoexcept
1003 { return this->size() == 0; }
1004
1005 // Element access:
1006 /**
1007 * @brief Subscript access to the data contained in the %string.
1008 * @param __pos The index of the character to access.
1009 * @return Read-only (constant) reference to the character.
1010 *
1011 * This operator allows for easy, array-style, data access.
1012 * Note that data access with this operator is unchecked and
1013 * out_of_range lookups are not defined. (For checked lookups
1014 * see at().)
1015 */
1016 const_reference
1017 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPTnoexcept
1018 {
1019 __glibcxx_assert(__pos <= size())do { if (! (__pos <= size())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1019, __PRETTY_FUNCTION__, "__pos <= size()"); } while (
false)
;
1020 return _M_data()[__pos];
1021 }
1022
1023 /**
1024 * @brief Subscript access to the data contained in the %string.
1025 * @param __pos The index of the character to access.
1026 * @return Read/write reference to the character.
1027 *
1028 * This operator allows for easy, array-style, data access.
1029 * Note that data access with this operator is unchecked and
1030 * out_of_range lookups are not defined. (For checked lookups
1031 * see at().)
1032 */
1033 reference
1034 operator[](size_type __pos)
1035 {
1036 // Allow pos == size() both in C++98 mode, as v3 extension,
1037 // and in C++11 mode.
1038 __glibcxx_assert(__pos <= size())do { if (! (__pos <= size())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1038, __PRETTY_FUNCTION__, "__pos <= size()"); } while (
false)
;
1039 // In pedantic mode be strict in C++98 mode.
1040 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size());
1041 return _M_data()[__pos];
1042 }
1043
1044 /**
1045 * @brief Provides access to the data contained in the %string.
1046 * @param __n The index of the character to access.
1047 * @return Read-only (const) reference to the character.
1048 * @throw std::out_of_range If @a n is an invalid index.
1049 *
1050 * This function provides for safer data access. The parameter is
1051 * first checked that it is in the range of the string. The function
1052 * throws out_of_range if the check fails.
1053 */
1054 const_reference
1055 at(size_type __n) const
1056 {
1057 if (__n >= this->size())
1058 __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1059 "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1060 "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
,
1061 __n, this->size());
1062 return _M_data()[__n];
1063 }
1064
1065 /**
1066 * @brief Provides access to the data contained in the %string.
1067 * @param __n The index of the character to access.
1068 * @return Read/write reference to the character.
1069 * @throw std::out_of_range If @a n is an invalid index.
1070 *
1071 * This function provides for safer data access. The parameter is
1072 * first checked that it is in the range of the string. The function
1073 * throws out_of_range if the check fails.
1074 */
1075 reference
1076 at(size_type __n)
1077 {
1078 if (__n >= size())
1079 __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1080 "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1081 "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
,
1082 __n, this->size());
1083 return _M_data()[__n];
1084 }
1085
1086#if __cplusplus201703L >= 201103L
1087 /**
1088 * Returns a read/write reference to the data at the first
1089 * element of the %string.
1090 */
1091 reference
1092 front() noexcept
1093 {
1094 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1094, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1095 return operator[](0);
1096 }
1097
1098 /**
1099 * Returns a read-only (constant) reference to the data at the first
1100 * element of the %string.
1101 */
1102 const_reference
1103 front() const noexcept
1104 {
1105 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1105, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1106 return operator[](0);
1107 }
1108
1109 /**
1110 * Returns a read/write reference to the data at the last
1111 * element of the %string.
1112 */
1113 reference
1114 back() noexcept
1115 {
1116 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1116, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1117 return operator[](this->size() - 1);
1118 }
1119
1120 /**
1121 * Returns a read-only (constant) reference to the data at the
1122 * last element of the %string.
1123 */
1124 const_reference
1125 back() const noexcept
1126 {
1127 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1127, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1128 return operator[](this->size() - 1);
1129 }
1130#endif
1131
1132 // Modifiers:
1133 /**
1134 * @brief Append a string to this string.
1135 * @param __str The string to append.
1136 * @return Reference to this string.
1137 */
1138 basic_string&
1139 operator+=(const basic_string& __str)
1140 { return this->append(__str); }
1141
1142 /**
1143 * @brief Append a C string.
1144 * @param __s The C string to append.
1145 * @return Reference to this string.
1146 */
1147 basic_string&
1148 operator+=(const _CharT* __s)
1149 { return this->append(__s); }
1150
1151 /**
1152 * @brief Append a character.
1153 * @param __c The character to append.
1154 * @return Reference to this string.
1155 */
1156 basic_string&
1157 operator+=(_CharT __c)
1158 {
1159 this->push_back(__c);
1160 return *this;
1161 }
1162
1163#if __cplusplus201703L >= 201103L
1164 /**
1165 * @brief Append an initializer_list of characters.
1166 * @param __l The initializer_list of characters to be appended.
1167 * @return Reference to this string.
1168 */
1169 basic_string&
1170 operator+=(initializer_list<_CharT> __l)
1171 { return this->append(__l.begin(), __l.size()); }
1172#endif // C++11
1173
1174#if __cplusplus201703L >= 201703L
1175 /**
1176 * @brief Append a string_view.
1177 * @param __svt An object convertible to string_view to be appended.
1178 * @return Reference to this string.
1179 */
1180 template<typename _Tp>
1181 _If_sv<_Tp, basic_string&>
1182 operator+=(const _Tp& __svt)
1183 { return this->append(__svt); }
1184#endif // C++17
1185
1186 /**
1187 * @brief Append a string to this string.
1188 * @param __str The string to append.
1189 * @return Reference to this string.
1190 */
1191 basic_string&
1192 append(const basic_string& __str)
1193 { return _M_append(__str._M_data(), __str.size()); }
1194
1195 /**
1196 * @brief Append a substring.
1197 * @param __str The string to append.
1198 * @param __pos Index of the first character of str to append.
1199 * @param __n The number of characters to append.
1200 * @return Reference to this string.
1201 * @throw std::out_of_range if @a __pos is not a valid index.
1202 *
1203 * This function appends @a __n characters from @a __str
1204 * starting at @a __pos to this string. If @a __n is is larger
1205 * than the number of available characters in @a __str, the
1206 * remainder of @a __str is appended.
1207 */
1208 basic_string&
1209 append(const basic_string& __str, size_type __pos, size_type __n = npos)
1210 { return _M_append(__str._M_data()
1211 + __str._M_check(__pos, "basic_string::append"),
1212 __str._M_limit(__pos, __n)); }
1213
1214 /**
1215 * @brief Append a C substring.
1216 * @param __s The C string to append.
1217 * @param __n The number of characters to append.
1218 * @return Reference to this string.
1219 */
1220 basic_string&
1221 append(const _CharT* __s, size_type __n)
1222 {
1223 __glibcxx_requires_string_len(__s, __n);
1224 _M_check_length(size_type(0), __n, "basic_string::append");
1225 return _M_append(__s, __n);
1226 }
1227
1228 /**
1229 * @brief Append a C string.
1230 * @param __s The C string to append.
1231 * @return Reference to this string.
1232 */
1233 basic_string&
1234 append(const _CharT* __s)
1235 {
1236 __glibcxx_requires_string(__s);
1237 const size_type __n = traits_type::length(__s);
1238 _M_check_length(size_type(0), __n, "basic_string::append");
1239 return _M_append(__s, __n);
1240 }
1241
1242 /**
1243 * @brief Append multiple characters.
1244 * @param __n The number of characters to append.
1245 * @param __c The character to use.
1246 * @return Reference to this string.
1247 *
1248 * Appends __n copies of __c to this string.
1249 */
1250 basic_string&
1251 append(size_type __n, _CharT __c)
1252 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
1253
1254#if __cplusplus201703L >= 201103L
1255 /**
1256 * @brief Append an initializer_list of characters.
1257 * @param __l The initializer_list of characters to append.
1258 * @return Reference to this string.
1259 */
1260 basic_string&
1261 append(initializer_list<_CharT> __l)
1262 { return this->append(__l.begin(), __l.size()); }
1263#endif // C++11
1264
1265 /**
1266 * @brief Append a range of characters.
1267 * @param __first Iterator referencing the first character to append.
1268 * @param __last Iterator marking the end of the range.
1269 * @return Reference to this string.
1270 *
1271 * Appends characters in the range [__first,__last) to this string.
1272 */
1273#if __cplusplus201703L >= 201103L
1274 template<class _InputIterator,
1275 typename = std::_RequireInputIter<_InputIterator>>
1276#else
1277 template<class _InputIterator>
1278#endif
1279 basic_string&
1280 append(_InputIterator __first, _InputIterator __last)
1281 { return this->replace(end(), end(), __first, __last); }
1282
1283#if __cplusplus201703L >= 201703L
1284 /**
1285 * @brief Append a string_view.
1286 * @param __svt An object convertible to string_view to be appended.
1287 * @return Reference to this string.
1288 */
1289 template<typename _Tp>
1290 _If_sv<_Tp, basic_string&>
1291 append(const _Tp& __svt)
1292 {
1293 __sv_type __sv = __svt;
1294 return this->append(__sv.data(), __sv.size());
1295 }
1296
1297 /**
1298 * @brief Append a range of characters from a string_view.
1299 * @param __svt An object convertible to string_view to be appended from.
1300 * @param __pos The position in the string_view to append from.
1301 * @param __n The number of characters to append from the string_view.
1302 * @return Reference to this string.
1303 */
1304 template<typename _Tp>
1305 _If_sv<_Tp, basic_string&>
1306 append(const _Tp& __svt, size_type __pos, size_type __n = npos)
1307 {
1308 __sv_type __sv = __svt;
1309 return _M_append(__sv.data()
1310 + std::__sv_check(__sv.size(), __pos, "basic_string::append"),
1311 std::__sv_limit(__sv.size(), __pos, __n));
1312 }
1313#endif // C++17
1314
1315 /**
1316 * @brief Append a single character.
1317 * @param __c Character to append.
1318 */
1319 void
1320 push_back(_CharT __c)
1321 {
1322 const size_type __size = this->size();
1323 if (__size + 1 > this->capacity())
1324 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1325 traits_type::assign(this->_M_data()[__size], __c);
1326 this->_M_set_length(__size + 1);
1327 }
1328
1329 /**
1330 * @brief Set value to contents of another string.
1331 * @param __str Source string to use.
1332 * @return Reference to this string.
1333 */
1334 basic_string&
1335 assign(const basic_string& __str)
1336 {
1337#if __cplusplus201703L >= 201103L
1338 if (_Alloc_traits::_S_propagate_on_copy_assign())
1339 {
1340 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1341 && _M_get_allocator() != __str._M_get_allocator())
1342 {
1343 // Propagating allocator cannot free existing storage so must
1344 // deallocate it before replacing current allocator.
1345 if (__str.size() <= _S_local_capacity)
1346 {
1347 _M_destroy(_M_allocated_capacity);
1348 _M_data(_M_local_data());
1349 _M_set_length(0);
1350 }
1351 else
1352 {
1353 const auto __len = __str.size();
1354 auto __alloc = __str._M_get_allocator();
1355 // If this allocation throws there are no effects:
1356 auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1);
1357 _M_destroy(_M_allocated_capacity);
1358 _M_data(__ptr);
1359 _M_capacity(__len);
1360 _M_set_length(__len);
1361 }
1362 }
1363 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1364 }
1365#endif
1366 this->_M_assign(__str);
1367 return *this;
1368 }
1369
1370#if __cplusplus201703L >= 201103L
1371 /**
1372 * @brief Set value to contents of another string.
1373 * @param __str Source string to use.
1374 * @return Reference to this string.
1375 *
1376 * This function sets this string to the exact contents of @a __str.
1377 * @a __str is a valid, but unspecified string.
1378 */
1379 basic_string&
1380 assign(basic_string&& __str)
1381 noexcept(_Alloc_traits::_S_nothrow_move())
1382 {
1383 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1384 // 2063. Contradictory requirements for string move assignment
1385 return *this = std::move(__str);
1386 }
1387#endif // C++11
1388
1389 /**
1390 * @brief Set value to a substring of a string.
1391 * @param __str The string to use.
1392 * @param __pos Index of the first character of str.
1393 * @param __n Number of characters to use.
1394 * @return Reference to this string.
1395 * @throw std::out_of_range if @a pos is not a valid index.
1396 *
1397 * This function sets this string to the substring of @a __str
1398 * consisting of @a __n characters at @a __pos. If @a __n is
1399 * is larger than the number of available characters in @a
1400 * __str, the remainder of @a __str is used.
1401 */
1402 basic_string&
1403 assign(const basic_string& __str, size_type __pos, size_type __n = npos)
1404 { return _M_replace(size_type(0), this->size(), __str._M_data()
1405 + __str._M_check(__pos, "basic_string::assign"),
1406 __str._M_limit(__pos, __n)); }
1407
1408 /**
1409 * @brief Set value to a C substring.
1410 * @param __s The C string to use.
1411 * @param __n Number of characters to use.
1412 * @return Reference to this string.
1413 *
1414 * This function sets the value of this string to the first @a __n
1415 * characters of @a __s. If @a __n is is larger than the number of
1416 * available characters in @a __s, the remainder of @a __s is used.
1417 */
1418 basic_string&
1419 assign(const _CharT* __s, size_type __n)
1420 {
1421 __glibcxx_requires_string_len(__s, __n);
1422 return _M_replace(size_type(0), this->size(), __s, __n);
1423 }
1424
1425 /**
1426 * @brief Set value to contents of a C string.
1427 * @param __s The C string to use.
1428 * @return Reference to this string.
1429 *
1430 * This function sets the value of this string to the value of @a __s.
1431 * The data is copied, so there is no dependence on @a __s once the
1432 * function returns.
1433 */
1434 basic_string&
1435 assign(const _CharT* __s)
1436 {
1437 __glibcxx_requires_string(__s);
1438 return _M_replace(size_type(0), this->size(), __s,
1439 traits_type::length(__s));
1440 }
1441
1442 /**
1443 * @brief Set value to multiple characters.
1444 * @param __n Length of the resulting string.
1445 * @param __c The character to use.
1446 * @return Reference to this string.
1447 *
1448 * This function sets the value of this string to @a __n copies of
1449 * character @a __c.
1450 */
1451 basic_string&
1452 assign(size_type __n, _CharT __c)
1453 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
1454
1455 /**
1456 * @brief Set value to a range of characters.
1457 * @param __first Iterator referencing the first character to append.
1458 * @param __last Iterator marking the end of the range.
1459 * @return Reference to this string.
1460 *
1461 * Sets value of string to characters in the range [__first,__last).
1462 */
1463#if __cplusplus201703L >= 201103L
1464 template<class _InputIterator,
1465 typename = std::_RequireInputIter<_InputIterator>>
1466#else
1467 template<class _InputIterator>
1468#endif
1469 basic_string&
1470 assign(_InputIterator __first, _InputIterator __last)
1471 { return this->replace(begin(), end(), __first, __last); }
1472
1473#if __cplusplus201703L >= 201103L
1474 /**
1475 * @brief Set value to an initializer_list of characters.
1476 * @param __l The initializer_list of characters to assign.
1477 * @return Reference to this string.
1478 */
1479 basic_string&
1480 assign(initializer_list<_CharT> __l)
1481 { return this->assign(__l.begin(), __l.size()); }
1482#endif // C++11
1483
1484#if __cplusplus201703L >= 201703L
1485 /**
1486 * @brief Set value from a string_view.
1487 * @param __svt The source object convertible to string_view.
1488 * @return Reference to this string.
1489 */
1490 template<typename _Tp>
1491 _If_sv<_Tp, basic_string&>
1492 assign(const _Tp& __svt)
1493 {
1494 __sv_type __sv = __svt;
1495 return this->assign(__sv.data(), __sv.size());
1496 }
1497
1498 /**
1499 * @brief Set value from a range of characters in a string_view.
1500 * @param __svt The source object convertible to string_view.
1501 * @param __pos The position in the string_view to assign from.
1502 * @param __n The number of characters to assign.
1503 * @return Reference to this string.
1504 */
1505 template<typename _Tp>
1506 _If_sv<_Tp, basic_string&>
1507 assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
1508 {
1509 __sv_type __sv = __svt;
1510 return _M_replace(size_type(0), this->size(),
1511 __sv.data()
1512 + std::__sv_check(__sv.size(), __pos, "basic_string::assign"),
1513 std::__sv_limit(__sv.size(), __pos, __n));
1514 }
1515#endif // C++17
1516
1517#if __cplusplus201703L >= 201103L
1518 /**
1519 * @brief Insert multiple characters.
1520 * @param __p Const_iterator referencing location in string to
1521 * insert at.
1522 * @param __n Number of characters to insert
1523 * @param __c The character to insert.
1524 * @return Iterator referencing the first inserted char.
1525 * @throw std::length_error If new length exceeds @c max_size().
1526 *
1527 * Inserts @a __n copies of character @a __c starting at the
1528 * position referenced by iterator @a __p. If adding
1529 * characters causes the length to exceed max_size(),
1530 * length_error is thrown. The value of the string doesn't
1531 * change if an error is thrown.
1532 */
1533 iterator
1534 insert(const_iterator __p, size_type __n, _CharT __c)
1535 {
1536 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1537 const size_type __pos = __p - begin();
1538 this->replace(__p, __p, __n, __c);
1539 return iterator(this->_M_data() + __pos);
1540 }
1541#else
1542 /**
1543 * @brief Insert multiple characters.
1544 * @param __p Iterator referencing location in string to insert at.
1545 * @param __n Number of characters to insert
1546 * @param __c The character to insert.
1547 * @throw std::length_error If new length exceeds @c max_size().
1548 *
1549 * Inserts @a __n copies of character @a __c starting at the
1550 * position referenced by iterator @a __p. If adding
1551 * characters causes the length to exceed max_size(),
1552 * length_error is thrown. The value of the string doesn't
1553 * change if an error is thrown.
1554 */
1555 void
1556 insert(iterator __p, size_type __n, _CharT __c)
1557 { this->replace(__p, __p, __n, __c); }
1558#endif
1559
1560#if __cplusplus201703L >= 201103L
1561 /**
1562 * @brief Insert a range of characters.
1563 * @param __p Const_iterator referencing location in string to
1564 * insert at.
1565 * @param __beg Start of range.
1566 * @param __end End of range.
1567 * @return Iterator referencing the first inserted char.
1568 * @throw std::length_error If new length exceeds @c max_size().
1569 *
1570 * Inserts characters in range [beg,end). If adding characters
1571 * causes the length to exceed max_size(), length_error is
1572 * thrown. The value of the string doesn't change if an error
1573 * is thrown.
1574 */
1575 template<class _InputIterator,
1576 typename = std::_RequireInputIter<_InputIterator>>
1577 iterator
1578 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
1579 {
1580 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1581 const size_type __pos = __p - begin();
1582 this->replace(__p, __p, __beg, __end);
1583 return iterator(this->_M_data() + __pos);
1584 }
1585#else
1586 /**
1587 * @brief Insert a range of characters.
1588 * @param __p Iterator referencing location in string to insert at.
1589 * @param __beg Start of range.
1590 * @param __end End of range.
1591 * @throw std::length_error If new length exceeds @c max_size().
1592 *
1593 * Inserts characters in range [__beg,__end). If adding
1594 * characters causes the length to exceed max_size(),
1595 * length_error is thrown. The value of the string doesn't
1596 * change if an error is thrown.
1597 */
1598 template<class _InputIterator>
1599 void
1600 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
1601 { this->replace(__p, __p, __beg, __end); }
1602#endif
1603
1604#if __cplusplus201703L >= 201103L
1605 /**
1606 * @brief Insert an initializer_list of characters.
1607 * @param __p Iterator referencing location in string to insert at.
1608 * @param __l The initializer_list of characters to insert.
1609 * @throw std::length_error If new length exceeds @c max_size().
1610 */
1611 iterator
1612 insert(const_iterator __p, initializer_list<_CharT> __l)
1613 { return this->insert(__p, __l.begin(), __l.end()); }
1614
1615#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
1616 // See PR libstdc++/83328
1617 void
1618 insert(iterator __p, initializer_list<_CharT> __l)
1619 {
1620 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1621 this->insert(__p - begin(), __l.begin(), __l.size());
1622 }
1623#endif
1624#endif // C++11
1625
1626 /**
1627 * @brief Insert value of a string.
1628 * @param __pos1 Position in string to insert at.
1629 * @param __str The string to insert.
1630 * @return Reference to this string.
1631 * @throw std::length_error If new length exceeds @c max_size().
1632 *
1633 * Inserts value of @a __str starting at @a __pos1. If adding
1634 * characters causes the length to exceed max_size(),
1635 * length_error is thrown. The value of the string doesn't
1636 * change if an error is thrown.
1637 */
1638 basic_string&
1639 insert(size_type __pos1, const basic_string& __str)
1640 { return this->replace(__pos1, size_type(0),
1641 __str._M_data(), __str.size()); }
1642
1643 /**
1644 * @brief Insert a substring.
1645 * @param __pos1 Position in string to insert at.
1646 * @param __str The string to insert.
1647 * @param __pos2 Start of characters in str to insert.
1648 * @param __n Number of characters to insert.
1649 * @return Reference to this string.
1650 * @throw std::length_error If new length exceeds @c max_size().
1651 * @throw std::out_of_range If @a pos1 > size() or
1652 * @a __pos2 > @a str.size().
1653 *
1654 * Starting at @a pos1, insert @a __n character of @a __str
1655 * beginning with @a __pos2. If adding characters causes the
1656 * length to exceed max_size(), length_error is thrown. If @a
1657 * __pos1 is beyond the end of this string or @a __pos2 is
1658 * beyond the end of @a __str, out_of_range is thrown. The
1659 * value of the string doesn't change if an error is thrown.
1660 */
1661 basic_string&
1662 insert(size_type __pos1, const basic_string& __str,
1663 size_type __pos2, size_type __n = npos)
1664 { return this->replace(__pos1, size_type(0), __str._M_data()
1665 + __str._M_check(__pos2, "basic_string::insert"),
1666 __str._M_limit(__pos2, __n)); }
1667
1668 /**
1669 * @brief Insert a C substring.
1670 * @param __pos Position in string to insert at.
1671 * @param __s The C string to insert.
1672 * @param __n The number of characters to insert.
1673 * @return Reference to this string.
1674 * @throw std::length_error If new length exceeds @c max_size().
1675 * @throw std::out_of_range If @a __pos is beyond the end of this
1676 * string.
1677 *
1678 * Inserts the first @a __n characters of @a __s starting at @a
1679 * __pos. If adding characters causes the length to exceed
1680 * max_size(), length_error is thrown. If @a __pos is beyond
1681 * end(), out_of_range is thrown. The value of the string
1682 * doesn't change if an error is thrown.
1683 */
1684 basic_string&
1685 insert(size_type __pos, const _CharT* __s, size_type __n)
1686 { return this->replace(__pos, size_type(0), __s, __n); }
1687
1688 /**
1689 * @brief Insert a C string.
1690 * @param __pos Position in string to insert at.
1691 * @param __s The C string to insert.
1692 * @return Reference to this string.
1693 * @throw std::length_error If new length exceeds @c max_size().
1694 * @throw std::out_of_range If @a pos is beyond the end of this
1695 * string.
1696 *
1697 * Inserts the first @a n characters of @a __s starting at @a __pos. If
1698 * adding characters causes the length to exceed max_size(),
1699 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
1700 * thrown. The value of the string doesn't change if an error is
1701 * thrown.
1702 */
1703 basic_string&
1704 insert(size_type __pos, const _CharT* __s)
1705 {
1706 __glibcxx_requires_string(__s);
1707 return this->replace(__pos, size_type(0), __s,
1708 traits_type::length(__s));
1709 }
1710
1711 /**
1712 * @brief Insert multiple characters.
1713 * @param __pos Index in string to insert at.
1714 * @param __n Number of characters to insert
1715 * @param __c The character to insert.
1716 * @return Reference to this string.
1717 * @throw std::length_error If new length exceeds @c max_size().
1718 * @throw std::out_of_range If @a __pos is beyond the end of this
1719 * string.
1720 *
1721 * Inserts @a __n copies of character @a __c starting at index
1722 * @a __pos. If adding characters causes the length to exceed
1723 * max_size(), length_error is thrown. If @a __pos > length(),
1724 * out_of_range is thrown. The value of the string doesn't
1725 * change if an error is thrown.
1726 */
1727 basic_string&
1728 insert(size_type __pos, size_type __n, _CharT __c)
1729 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
1730 size_type(0), __n, __c); }
1731
1732 /**
1733 * @brief Insert one character.
1734 * @param __p Iterator referencing position in string to insert at.
1735 * @param __c The character to insert.
1736 * @return Iterator referencing newly inserted char.
1737 * @throw std::length_error If new length exceeds @c max_size().
1738 *
1739 * Inserts character @a __c at position referenced by @a __p.
1740 * If adding character causes the length to exceed max_size(),
1741 * length_error is thrown. If @a __p is beyond end of string,
1742 * out_of_range is thrown. The value of the string doesn't
1743 * change if an error is thrown.
1744 */
1745 iterator
1746 insert(__const_iterator __p, _CharT __c)
1747 {
1748 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
1749 const size_type __pos = __p - begin();
1750 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
1751 return iterator(_M_data() + __pos);
1752 }
1753
1754#if __cplusplus201703L >= 201703L
1755 /**
1756 * @brief Insert a string_view.
1757 * @param __pos Position in string to insert at.
1758 * @param __svt The object convertible to string_view to insert.
1759 * @return Reference to this string.
1760 */
1761 template<typename _Tp>
1762 _If_sv<_Tp, basic_string&>
1763 insert(size_type __pos, const _Tp& __svt)
1764 {
1765 __sv_type __sv = __svt;
1766 return this->insert(__pos, __sv.data(), __sv.size());
1767 }
1768
1769 /**
1770 * @brief Insert a string_view.
1771 * @param __pos1 Position in string to insert at.
1772 * @param __svt The object convertible to string_view to insert from.
1773 * @param __pos2 Start of characters in str to insert.
1774 * @param __n The number of characters to insert.
1775 * @return Reference to this string.
1776 */
1777 template<typename _Tp>
1778 _If_sv<_Tp, basic_string&>
1779 insert(size_type __pos1, const _Tp& __svt,
1780 size_type __pos2, size_type __n = npos)
1781 {
1782 __sv_type __sv = __svt;
1783 return this->replace(__pos1, size_type(0),
1784 __sv.data()
1785 + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"),
1786 std::__sv_limit(__sv.size(), __pos2, __n));
1787 }
1788#endif // C++17
1789
1790 /**
1791 * @brief Remove characters.
1792 * @param __pos Index of first character to remove (default 0).
1793 * @param __n Number of characters to remove (default remainder).
1794 * @return Reference to this string.
1795 * @throw std::out_of_range If @a pos is beyond the end of this
1796 * string.
1797 *
1798 * Removes @a __n characters from this string starting at @a
1799 * __pos. The length of the string is reduced by @a __n. If
1800 * there are < @a __n characters to remove, the remainder of
1801 * the string is truncated. If @a __p is beyond end of string,
1802 * out_of_range is thrown. The value of the string doesn't
1803 * change if an error is thrown.
1804 */
1805 basic_string&
1806 erase(size_type __pos = 0, size_type __n = npos)
1807 {
1808 _M_check(__pos, "basic_string::erase");
1809 if (__n == npos)
1810 this->_M_set_length(__pos);
1811 else if (__n != 0)
1812 this->_M_erase(__pos, _M_limit(__pos, __n));
1813 return *this;
1814 }
1815
1816 /**
1817 * @brief Remove one character.
1818 * @param __position Iterator referencing the character to remove.
1819 * @return iterator referencing same location after removal.
1820 *
1821 * Removes the character at @a __position from this string. The value
1822 * of the string doesn't change if an error is thrown.
1823 */
1824 iterator
1825 erase(__const_iterator __position)
1826 {
1827 _GLIBCXX_DEBUG_PEDASSERT(__position >= begin()
1828 && __position < end());
1829 const size_type __pos = __position - begin();
1830 this->_M_erase(__pos, size_type(1));
1831 return iterator(_M_data() + __pos);
1832 }
1833
1834 /**
1835 * @brief Remove a range of characters.
1836 * @param __first Iterator referencing the first character to remove.
1837 * @param __last Iterator referencing the end of the range.
1838 * @return Iterator referencing location of first after removal.
1839 *
1840 * Removes the characters in the range [first,last) from this string.
1841 * The value of the string doesn't change if an error is thrown.
1842 */
1843 iterator
1844 erase(__const_iterator __first, __const_iterator __last)
1845 {
1846 _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last
1847 && __last <= end());
1848 const size_type __pos = __first - begin();
1849 if (__last == end())
1850 this->_M_set_length(__pos);
1851 else
1852 this->_M_erase(__pos, __last - __first);
1853 return iterator(this->_M_data() + __pos);
1854 }
1855
1856#if __cplusplus201703L >= 201103L
1857 /**
1858 * @brief Remove the last character.
1859 *
1860 * The string must be non-empty.
1861 */
1862 void
1863 pop_back() noexcept
1864 {
1865 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 1865, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1866 _M_erase(size() - 1, 1);
1867 }
1868#endif // C++11
1869
1870 /**
1871 * @brief Replace characters with value from another string.
1872 * @param __pos Index of first character to replace.
1873 * @param __n Number of characters to be replaced.
1874 * @param __str String to insert.
1875 * @return Reference to this string.
1876 * @throw std::out_of_range If @a pos is beyond the end of this
1877 * string.
1878 * @throw std::length_error If new length exceeds @c max_size().
1879 *
1880 * Removes the characters in the range [__pos,__pos+__n) from
1881 * this string. In place, the value of @a __str is inserted.
1882 * If @a __pos is beyond end of string, out_of_range is thrown.
1883 * If the length of the result exceeds max_size(), length_error
1884 * is thrown. The value of the string doesn't change if an
1885 * error is thrown.
1886 */
1887 basic_string&
1888 replace(size_type __pos, size_type __n, const basic_string& __str)
1889 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
1890
1891 /**
1892 * @brief Replace characters with value from another string.
1893 * @param __pos1 Index of first character to replace.
1894 * @param __n1 Number of characters to be replaced.
1895 * @param __str String to insert.
1896 * @param __pos2 Index of first character of str to use.
1897 * @param __n2 Number of characters from str to use.
1898 * @return Reference to this string.
1899 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
1900 * __str.size().
1901 * @throw std::length_error If new length exceeds @c max_size().
1902 *
1903 * Removes the characters in the range [__pos1,__pos1 + n) from this
1904 * string. In place, the value of @a __str is inserted. If @a __pos is
1905 * beyond end of string, out_of_range is thrown. If the length of the
1906 * result exceeds max_size(), length_error is thrown. The value of the
1907 * string doesn't change if an error is thrown.
1908 */
1909 basic_string&
1910 replace(size_type __pos1, size_type __n1, const basic_string& __str,
1911 size_type __pos2, size_type __n2 = npos)
1912 { return this->replace(__pos1, __n1, __str._M_data()
1913 + __str._M_check(__pos2, "basic_string::replace"),
1914 __str._M_limit(__pos2, __n2)); }
1915
1916 /**
1917 * @brief Replace characters with value of a C substring.
1918 * @param __pos Index of first character to replace.
1919 * @param __n1 Number of characters to be replaced.
1920 * @param __s C string to insert.
1921 * @param __n2 Number of characters from @a s to use.
1922 * @return Reference to this string.
1923 * @throw std::out_of_range If @a pos1 > size().
1924 * @throw std::length_error If new length exceeds @c max_size().
1925 *
1926 * Removes the characters in the range [__pos,__pos + __n1)
1927 * from this string. In place, the first @a __n2 characters of
1928 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
1929 * @a __pos is beyond end of string, out_of_range is thrown. If
1930 * the length of result exceeds max_size(), length_error is
1931 * thrown. The value of the string doesn't change if an error
1932 * is thrown.
1933 */
1934 basic_string&
1935 replace(size_type __pos, size_type __n1, const _CharT* __s,
1936 size_type __n2)
1937 {
1938 __glibcxx_requires_string_len(__s, __n2);
1939 return _M_replace(_M_check(__pos, "basic_string::replace"),
1940 _M_limit(__pos, __n1), __s, __n2);
1941 }
1942
1943 /**
1944 * @brief Replace characters with value of a C string.
1945 * @param __pos Index of first character to replace.
1946 * @param __n1 Number of characters to be replaced.
1947 * @param __s C string to insert.
1948 * @return Reference to this string.
1949 * @throw std::out_of_range If @a pos > size().
1950 * @throw std::length_error If new length exceeds @c max_size().
1951 *
1952 * Removes the characters in the range [__pos,__pos + __n1)
1953 * from this string. In place, the characters of @a __s are
1954 * inserted. If @a __pos is beyond end of string, out_of_range
1955 * is thrown. If the length of result exceeds max_size(),
1956 * length_error is thrown. The value of the string doesn't
1957 * change if an error is thrown.
1958 */
1959 basic_string&
1960 replace(size_type __pos, size_type __n1, const _CharT* __s)
1961 {
1962 __glibcxx_requires_string(__s);
1963 return this->replace(__pos, __n1, __s, traits_type::length(__s));
1964 }
1965
1966 /**
1967 * @brief Replace characters with multiple characters.
1968 * @param __pos Index of first character to replace.
1969 * @param __n1 Number of characters to be replaced.
1970 * @param __n2 Number of characters to insert.
1971 * @param __c Character to insert.
1972 * @return Reference to this string.
1973 * @throw std::out_of_range If @a __pos > size().
1974 * @throw std::length_error If new length exceeds @c max_size().
1975 *
1976 * Removes the characters in the range [pos,pos + n1) from this
1977 * string. In place, @a __n2 copies of @a __c are inserted.
1978 * If @a __pos is beyond end of string, out_of_range is thrown.
1979 * If the length of result exceeds max_size(), length_error is
1980 * thrown. The value of the string doesn't change if an error
1981 * is thrown.
1982 */
1983 basic_string&
1984 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
1985 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
1986 _M_limit(__pos, __n1), __n2, __c); }
1987
1988 /**
1989 * @brief Replace range of characters with string.
1990 * @param __i1 Iterator referencing start of range to replace.
1991 * @param __i2 Iterator referencing end of range to replace.
1992 * @param __str String value to insert.
1993 * @return Reference to this string.
1994 * @throw std::length_error If new length exceeds @c max_size().
1995 *
1996 * Removes the characters in the range [__i1,__i2). In place,
1997 * the value of @a __str is inserted. If the length of result
1998 * exceeds max_size(), length_error is thrown. The value of
1999 * the string doesn't change if an error is thrown.
2000 */
2001 basic_string&
2002 replace(__const_iterator __i1, __const_iterator __i2,
2003 const basic_string& __str)
2004 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
2005
2006 /**
2007 * @brief Replace range of characters with C substring.
2008 * @param __i1 Iterator referencing start of range to replace.
2009 * @param __i2 Iterator referencing end of range to replace.
2010 * @param __s C string value to insert.
2011 * @param __n Number of characters from s to insert.
2012 * @return Reference to this string.
2013 * @throw std::length_error If new length exceeds @c max_size().
2014 *
2015 * Removes the characters in the range [__i1,__i2). In place,
2016 * the first @a __n characters of @a __s are inserted. If the
2017 * length of result exceeds max_size(), length_error is thrown.
2018 * The value of the string doesn't change if an error is
2019 * thrown.
2020 */
2021 basic_string&
2022 replace(__const_iterator __i1, __const_iterator __i2,
2023 const _CharT* __s, size_type __n)
2024 {
2025 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2026 && __i2 <= end());
2027 return this->replace(__i1 - begin(), __i2 - __i1, __s, __n);
2028 }
2029
2030 /**
2031 * @brief Replace range of characters with C string.
2032 * @param __i1 Iterator referencing start of range to replace.
2033 * @param __i2 Iterator referencing end of range to replace.
2034 * @param __s C string value to insert.
2035 * @return Reference to this string.
2036 * @throw std::length_error If new length exceeds @c max_size().
2037 *
2038 * Removes the characters in the range [__i1,__i2). In place,
2039 * the characters of @a __s are inserted. If the length of
2040 * result exceeds max_size(), length_error is thrown. The
2041 * value of the string doesn't change if an error is thrown.
2042 */
2043 basic_string&
2044 replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s)
2045 {
2046 __glibcxx_requires_string(__s);
2047 return this->replace(__i1, __i2, __s, traits_type::length(__s));
2048 }
2049
2050 /**
2051 * @brief Replace range of characters with multiple characters
2052 * @param __i1 Iterator referencing start of range to replace.
2053 * @param __i2 Iterator referencing end of range to replace.
2054 * @param __n Number of characters to insert.
2055 * @param __c Character to insert.
2056 * @return Reference to this string.
2057 * @throw std::length_error If new length exceeds @c max_size().
2058 *
2059 * Removes the characters in the range [__i1,__i2). In place,
2060 * @a __n copies of @a __c are inserted. If the length of
2061 * result exceeds max_size(), length_error is thrown. The
2062 * value of the string doesn't change if an error is thrown.
2063 */
2064 basic_string&
2065 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2066 _CharT __c)
2067 {
2068 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2069 && __i2 <= end());
2070 return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c);
2071 }
2072
2073 /**
2074 * @brief Replace range of characters with range.
2075 * @param __i1 Iterator referencing start of range to replace.
2076 * @param __i2 Iterator referencing end of range to replace.
2077 * @param __k1 Iterator referencing start of range to insert.
2078 * @param __k2 Iterator referencing end of range to insert.
2079 * @return Reference to this string.
2080 * @throw std::length_error If new length exceeds @c max_size().
2081 *
2082 * Removes the characters in the range [__i1,__i2). In place,
2083 * characters in the range [__k1,__k2) are inserted. If the
2084 * length of result exceeds max_size(), length_error is thrown.
2085 * The value of the string doesn't change if an error is
2086 * thrown.
2087 */
2088#if __cplusplus201703L >= 201103L
2089 template<class _InputIterator,
2090 typename = std::_RequireInputIter<_InputIterator>>
2091 basic_string&
2092 replace(const_iterator __i1, const_iterator __i2,
2093 _InputIterator __k1, _InputIterator __k2)
2094 {
2095 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2096 && __i2 <= end());
2097 __glibcxx_requires_valid_range(__k1, __k2);
2098 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2099 std::__false_type());
2100 }
2101#else
2102 template<class _InputIterator>
2103#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2104 typename __enable_if_not_native_iterator<_InputIterator>::__type
2105#else
2106 basic_string&
2107#endif
2108 replace(iterator __i1, iterator __i2,
2109 _InputIterator __k1, _InputIterator __k2)
2110 {
2111 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2112 && __i2 <= end());
2113 __glibcxx_requires_valid_range(__k1, __k2);
2114 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2115 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2116 }
2117#endif
2118
2119 // Specializations for the common case of pointer and iterator:
2120 // useful to avoid the overhead of temporary buffering in _M_replace.
2121 basic_string&
2122 replace(__const_iterator __i1, __const_iterator __i2,
2123 _CharT* __k1, _CharT* __k2)
2124 {
2125 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2126 && __i2 <= end());
2127 __glibcxx_requires_valid_range(__k1, __k2);
2128 return this->replace(__i1 - begin(), __i2 - __i1,
2129 __k1, __k2 - __k1);
2130 }
2131
2132 basic_string&
2133 replace(__const_iterator __i1, __const_iterator __i2,
2134 const _CharT* __k1, const _CharT* __k2)
2135 {
2136 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2137 && __i2 <= end());
2138 __glibcxx_requires_valid_range(__k1, __k2);
2139 return this->replace(__i1 - begin(), __i2 - __i1,
2140 __k1, __k2 - __k1);
2141 }
2142
2143 basic_string&
2144 replace(__const_iterator __i1, __const_iterator __i2,
2145 iterator __k1, iterator __k2)
2146 {
2147 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2148 && __i2 <= end());
2149 __glibcxx_requires_valid_range(__k1, __k2);
2150 return this->replace(__i1 - begin(), __i2 - __i1,
2151 __k1.base(), __k2 - __k1);
2152 }
2153
2154 basic_string&
2155 replace(__const_iterator __i1, __const_iterator __i2,
2156 const_iterator __k1, const_iterator __k2)
2157 {
2158 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2159 && __i2 <= end());
2160 __glibcxx_requires_valid_range(__k1, __k2);
2161 return this->replace(__i1 - begin(), __i2 - __i1,
2162 __k1.base(), __k2 - __k1);
2163 }
2164
2165#if __cplusplus201703L >= 201103L
2166 /**
2167 * @brief Replace range of characters with initializer_list.
2168 * @param __i1 Iterator referencing start of range to replace.
2169 * @param __i2 Iterator referencing end of range to replace.
2170 * @param __l The initializer_list of characters to insert.
2171 * @return Reference to this string.
2172 * @throw std::length_error If new length exceeds @c max_size().
2173 *
2174 * Removes the characters in the range [__i1,__i2). In place,
2175 * characters in the range [__k1,__k2) are inserted. If the
2176 * length of result exceeds max_size(), length_error is thrown.
2177 * The value of the string doesn't change if an error is
2178 * thrown.
2179 */
2180 basic_string& replace(const_iterator __i1, const_iterator __i2,
2181 initializer_list<_CharT> __l)
2182 { return this->replace(__i1, __i2, __l.begin(), __l.size()); }
2183#endif // C++11
2184
2185#if __cplusplus201703L >= 201703L
2186 /**
2187 * @brief Replace range of characters with string_view.
2188 * @param __pos The position to replace at.
2189 * @param __n The number of characters to replace.
2190 * @param __svt The object convertible to string_view to insert.
2191 * @return Reference to this string.
2192 */
2193 template<typename _Tp>
2194 _If_sv<_Tp, basic_string&>
2195 replace(size_type __pos, size_type __n, const _Tp& __svt)
2196 {
2197 __sv_type __sv = __svt;
2198 return this->replace(__pos, __n, __sv.data(), __sv.size());
2199 }
2200
2201 /**
2202 * @brief Replace range of characters with string_view.
2203 * @param __pos1 The position to replace at.
2204 * @param __n1 The number of characters to replace.
2205 * @param __svt The object convertible to string_view to insert from.
2206 * @param __pos2 The position in the string_view to insert from.
2207 * @param __n2 The number of characters to insert.
2208 * @return Reference to this string.
2209 */
2210 template<typename _Tp>
2211 _If_sv<_Tp, basic_string&>
2212 replace(size_type __pos1, size_type __n1, const _Tp& __svt,
2213 size_type __pos2, size_type __n2 = npos)
2214 {
2215 __sv_type __sv = __svt;
2216 return this->replace(__pos1, __n1,
2217 __sv.data()
2218 + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"),
2219 std::__sv_limit(__sv.size(), __pos2, __n2));
2220 }
2221
2222 /**
2223 * @brief Replace range of characters with string_view.
2224 * @param __i1 An iterator referencing the start position
2225 to replace at.
2226 * @param __i2 An iterator referencing the end position
2227 for the replace.
2228 * @param __svt The object convertible to string_view to insert from.
2229 * @return Reference to this string.
2230 */
2231 template<typename _Tp>
2232 _If_sv<_Tp, basic_string&>
2233 replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt)
2234 {
2235 __sv_type __sv = __svt;
2236 return this->replace(__i1 - begin(), __i2 - __i1, __sv);
2237 }
2238#endif // C++17
2239
2240 private:
2241 template<class _Integer>
2242 basic_string&
2243 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2244 _Integer __n, _Integer __val, __true_type)
2245 { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); }
2246
2247 template<class _InputIterator>
2248 basic_string&
2249 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2250 _InputIterator __k1, _InputIterator __k2,
2251 __false_type);
2252
2253 basic_string&
2254 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2255 _CharT __c);
2256
2257 basic_string&
2258 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
2259 const size_type __len2);
2260
2261 basic_string&
2262 _M_append(const _CharT* __s, size_type __n);
2263
2264 public:
2265
2266 /**
2267 * @brief Copy substring into C string.
2268 * @param __s C string to copy value into.
2269 * @param __n Number of characters to copy.
2270 * @param __pos Index of first character to copy.
2271 * @return Number of characters actually copied
2272 * @throw std::out_of_range If __pos > size().
2273 *
2274 * Copies up to @a __n characters starting at @a __pos into the
2275 * C string @a __s. If @a __pos is %greater than size(),
2276 * out_of_range is thrown.
2277 */
2278 size_type
2279 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
2280
2281 /**
2282 * @brief Swap contents with another string.
2283 * @param __s String to swap with.
2284 *
2285 * Exchanges the contents of this string with that of @a __s in constant
2286 * time.
2287 */
2288 void
2289 swap(basic_string& __s) _GLIBCXX_NOEXCEPTnoexcept;
2290
2291 // String operations:
2292 /**
2293 * @brief Return const pointer to null-terminated contents.
2294 *
2295 * This is a handle to internal data. Do not modify or dire things may
2296 * happen.
2297 */
2298 const _CharT*
2299 c_str() const _GLIBCXX_NOEXCEPTnoexcept
2300 { return _M_data(); }
2301
2302 /**
2303 * @brief Return const pointer to contents.
2304 *
2305 * This is a pointer to internal data. It is undefined to modify
2306 * the contents through the returned pointer. To get a pointer that
2307 * allows modifying the contents use @c &str[0] instead,
2308 * (or in C++17 the non-const @c str.data() overload).
2309 */
2310 const _CharT*
2311 data() const _GLIBCXX_NOEXCEPTnoexcept
2312 { return _M_data(); }
2313
2314#if __cplusplus201703L >= 201703L
2315 /**
2316 * @brief Return non-const pointer to contents.
2317 *
2318 * This is a pointer to the character sequence held by the string.
2319 * Modifying the characters in the sequence is allowed.
2320 */
2321 _CharT*
2322 data() noexcept
2323 { return _M_data(); }
2324#endif
2325
2326 /**
2327 * @brief Return copy of allocator used to construct this string.
2328 */
2329 allocator_type
2330 get_allocator() const _GLIBCXX_NOEXCEPTnoexcept
2331 { return _M_get_allocator(); }
2332
2333 /**
2334 * @brief Find position of a C substring.
2335 * @param __s C string to locate.
2336 * @param __pos Index of character to search from.
2337 * @param __n Number of characters from @a s to search for.
2338 * @return Index of start of first occurrence.
2339 *
2340 * Starting from @a __pos, searches forward for the first @a
2341 * __n characters in @a __s within this string. If found,
2342 * returns the index where it begins. If not found, returns
2343 * npos.
2344 */
2345 size_type
2346 find(const _CharT* __s, size_type __pos, size_type __n) const
2347 _GLIBCXX_NOEXCEPTnoexcept;
2348
2349 /**
2350 * @brief Find position of a string.
2351 * @param __str String to locate.
2352 * @param __pos Index of character to search from (default 0).
2353 * @return Index of start of first occurrence.
2354 *
2355 * Starting from @a __pos, searches forward for value of @a __str within
2356 * this string. If found, returns the index where it begins. If not
2357 * found, returns npos.
2358 */
2359 size_type
2360 find(const basic_string& __str, size_type __pos = 0) const
2361 _GLIBCXX_NOEXCEPTnoexcept
2362 { return this->find(__str.data(), __pos, __str.size()); }
2363
2364#if __cplusplus201703L >= 201703L
2365 /**
2366 * @brief Find position of a string_view.
2367 * @param __svt The object convertible to string_view to locate.
2368 * @param __pos Index of character to search from (default 0).
2369 * @return Index of start of first occurrence.
2370 */
2371 template<typename _Tp>
2372 _If_sv<_Tp, size_type>
2373 find(const _Tp& __svt, size_type __pos = 0) const
2374 noexcept(is_same<_Tp, __sv_type>::value)
2375 {
2376 __sv_type __sv = __svt;
2377 return this->find(__sv.data(), __pos, __sv.size());
2378 }
2379#endif // C++17
2380
2381 /**
2382 * @brief Find position of a C string.
2383 * @param __s C string to locate.
2384 * @param __pos Index of character to search from (default 0).
2385 * @return Index of start of first occurrence.
2386 *
2387 * Starting from @a __pos, searches forward for the value of @a
2388 * __s within this string. If found, returns the index where
2389 * it begins. If not found, returns npos.
2390 */
2391 size_type
2392 find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept
2393 {
2394 __glibcxx_requires_string(__s);
2395 return this->find(__s, __pos, traits_type::length(__s));
2396 }
2397
2398 /**
2399 * @brief Find position of a character.
2400 * @param __c Character to locate.
2401 * @param __pos Index of character to search from (default 0).
2402 * @return Index of first occurrence.
2403 *
2404 * Starting from @a __pos, searches forward for @a __c within
2405 * this string. If found, returns the index where it was
2406 * found. If not found, returns npos.
2407 */
2408 size_type
2409 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept;
2410
2411 /**
2412 * @brief Find last position of a string.
2413 * @param __str String to locate.
2414 * @param __pos Index of character to search back from (default end).
2415 * @return Index of start of last occurrence.
2416 *
2417 * Starting from @a __pos, searches backward for value of @a
2418 * __str within this string. If found, returns the index where
2419 * it begins. If not found, returns npos.
2420 */
2421 size_type
2422 rfind(const basic_string& __str, size_type __pos = npos) const
2423 _GLIBCXX_NOEXCEPTnoexcept
2424 { return this->rfind(__str.data(), __pos, __str.size()); }
2425
2426#if __cplusplus201703L >= 201703L
2427 /**
2428 * @brief Find last position of a string_view.
2429 * @param __svt The object convertible to string_view to locate.
2430 * @param __pos Index of character to search back from (default end).
2431 * @return Index of start of last occurrence.
2432 */
2433 template<typename _Tp>
2434 _If_sv<_Tp, size_type>
2435 rfind(const _Tp& __svt, size_type __pos = npos) const
2436 noexcept(is_same<_Tp, __sv_type>::value)
2437 {
2438 __sv_type __sv = __svt;
2439 return this->rfind(__sv.data(), __pos, __sv.size());
2440 }
2441#endif // C++17
2442
2443 /**
2444 * @brief Find last position of a C substring.
2445 * @param __s C string to locate.
2446 * @param __pos Index of character to search back from.
2447 * @param __n Number of characters from s to search for.
2448 * @return Index of start of last occurrence.
2449 *
2450 * Starting from @a __pos, searches backward for the first @a
2451 * __n characters in @a __s within this string. If found,
2452 * returns the index where it begins. If not found, returns
2453 * npos.
2454 */
2455 size_type
2456 rfind(const _CharT* __s, size_type __pos, size_type __n) const
2457 _GLIBCXX_NOEXCEPTnoexcept;
2458
2459 /**
2460 * @brief Find last position of a C string.
2461 * @param __s C string to locate.
2462 * @param __pos Index of character to start search at (default end).
2463 * @return Index of start of last occurrence.
2464 *
2465 * Starting from @a __pos, searches backward for the value of
2466 * @a __s within this string. If found, returns the index
2467 * where it begins. If not found, returns npos.
2468 */
2469 size_type
2470 rfind(const _CharT* __s, size_type __pos = npos) const
2471 {
2472 __glibcxx_requires_string(__s);
2473 return this->rfind(__s, __pos, traits_type::length(__s));
2474 }
2475
2476 /**
2477 * @brief Find last position of a character.
2478 * @param __c Character to locate.
2479 * @param __pos Index of character to search back from (default end).
2480 * @return Index of last occurrence.
2481 *
2482 * Starting from @a __pos, searches backward for @a __c within
2483 * this string. If found, returns the index where it was
2484 * found. If not found, returns npos.
2485 */
2486 size_type
2487 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept;
2488
2489 /**
2490 * @brief Find position of a character of string.
2491 * @param __str String containing characters to locate.
2492 * @param __pos Index of character to search from (default 0).
2493 * @return Index of first occurrence.
2494 *
2495 * Starting from @a __pos, searches forward for one of the
2496 * characters of @a __str within this string. If found,
2497 * returns the index where it was found. If not found, returns
2498 * npos.
2499 */
2500 size_type
2501 find_first_of(const basic_string& __str, size_type __pos = 0) const
2502 _GLIBCXX_NOEXCEPTnoexcept
2503 { return this->find_first_of(__str.data(), __pos, __str.size()); }
2504
2505#if __cplusplus201703L >= 201703L
2506 /**
2507 * @brief Find position of a character of a string_view.
2508 * @param __svt An object convertible to string_view containing
2509 * characters to locate.
2510 * @param __pos Index of character to search from (default 0).
2511 * @return Index of first occurrence.
2512 */
2513 template<typename _Tp>
2514 _If_sv<_Tp, size_type>
2515 find_first_of(const _Tp& __svt, size_type __pos = 0) const
2516 noexcept(is_same<_Tp, __sv_type>::value)
2517 {
2518 __sv_type __sv = __svt;
2519 return this->find_first_of(__sv.data(), __pos, __sv.size());
2520 }
2521#endif // C++17
2522
2523 /**
2524 * @brief Find position of a character of C substring.
2525 * @param __s String containing characters to locate.
2526 * @param __pos Index of character to search from.
2527 * @param __n Number of characters from s to search for.
2528 * @return Index of first occurrence.
2529 *
2530 * Starting from @a __pos, searches forward for one of the
2531 * first @a __n characters of @a __s within this string. If
2532 * found, returns the index where it was found. If not found,
2533 * returns npos.
2534 */
2535 size_type
2536 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
2537 _GLIBCXX_NOEXCEPTnoexcept;
2538
2539 /**
2540 * @brief Find position of a character of C string.
2541 * @param __s String containing characters to locate.
2542 * @param __pos Index of character to search from (default 0).
2543 * @return Index of first occurrence.
2544 *
2545 * Starting from @a __pos, searches forward for one of the
2546 * characters of @a __s within this string. If found, returns
2547 * the index where it was found. If not found, returns npos.
2548 */
2549 size_type
2550 find_first_of(const _CharT* __s, size_type __pos = 0) const
2551 _GLIBCXX_NOEXCEPTnoexcept
2552 {
2553 __glibcxx_requires_string(__s);
2554 return this->find_first_of(__s, __pos, traits_type::length(__s));
2555 }
2556
2557 /**
2558 * @brief Find position of a character.
2559 * @param __c Character to locate.
2560 * @param __pos Index of character to search from (default 0).
2561 * @return Index of first occurrence.
2562 *
2563 * Starting from @a __pos, searches forward for the character
2564 * @a __c within this string. If found, returns the index
2565 * where it was found. If not found, returns npos.
2566 *
2567 * Note: equivalent to find(__c, __pos).
2568 */
2569 size_type
2570 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept
2571 { return this->find(__c, __pos); }
2572
2573 /**
2574 * @brief Find last position of a character of string.
2575 * @param __str String containing characters to locate.
2576 * @param __pos Index of character to search back from (default end).
2577 * @return Index of last occurrence.
2578 *
2579 * Starting from @a __pos, searches backward for one of the
2580 * characters of @a __str within this string. If found,
2581 * returns the index where it was found. If not found, returns
2582 * npos.
2583 */
2584 size_type
2585 find_last_of(const basic_string& __str, size_type __pos = npos) const
2586 _GLIBCXX_NOEXCEPTnoexcept
2587 { return this->find_last_of(__str.data(), __pos, __str.size()); }
2588
2589#if __cplusplus201703L >= 201703L
2590 /**
2591 * @brief Find last position of a character of string.
2592 * @param __svt An object convertible to string_view containing
2593 * characters to locate.
2594 * @param __pos Index of character to search back from (default end).
2595 * @return Index of last occurrence.
2596 */
2597 template<typename _Tp>
2598 _If_sv<_Tp, size_type>
2599 find_last_of(const _Tp& __svt, size_type __pos = npos) const
2600 noexcept(is_same<_Tp, __sv_type>::value)
2601 {
2602 __sv_type __sv = __svt;
2603 return this->find_last_of(__sv.data(), __pos, __sv.size());
2604 }
2605#endif // C++17
2606
2607 /**
2608 * @brief Find last position of a character of C substring.
2609 * @param __s C string containing characters to locate.
2610 * @param __pos Index of character to search back from.
2611 * @param __n Number of characters from s to search for.
2612 * @return Index of last occurrence.
2613 *
2614 * Starting from @a __pos, searches backward for one of the
2615 * first @a __n characters of @a __s within this string. If
2616 * found, returns the index where it was found. If not found,
2617 * returns npos.
2618 */
2619 size_type
2620 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
2621 _GLIBCXX_NOEXCEPTnoexcept;
2622
2623 /**
2624 * @brief Find last position of a character of C string.
2625 * @param __s C string containing characters to locate.
2626 * @param __pos Index of character to search back from (default end).
2627 * @return Index of last occurrence.
2628 *
2629 * Starting from @a __pos, searches backward for one of the
2630 * characters of @a __s within this string. If found, returns
2631 * the index where it was found. If not found, returns npos.
2632 */
2633 size_type
2634 find_last_of(const _CharT* __s, size_type __pos = npos) const
2635 _GLIBCXX_NOEXCEPTnoexcept
2636 {
2637 __glibcxx_requires_string(__s);
2638 return this->find_last_of(__s, __pos, traits_type::length(__s));
2639 }
2640
2641 /**
2642 * @brief Find last position of a character.
2643 * @param __c Character to locate.
2644 * @param __pos Index of character to search back from (default end).
2645 * @return Index of last occurrence.
2646 *
2647 * Starting from @a __pos, searches backward for @a __c within
2648 * this string. If found, returns the index where it was
2649 * found. If not found, returns npos.
2650 *
2651 * Note: equivalent to rfind(__c, __pos).
2652 */
2653 size_type
2654 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept
2655 { return this->rfind(__c, __pos); }
2656
2657 /**
2658 * @brief Find position of a character not in string.
2659 * @param __str String containing characters to avoid.
2660 * @param __pos Index of character to search from (default 0).
2661 * @return Index of first occurrence.
2662 *
2663 * Starting from @a __pos, searches forward for a character not contained
2664 * in @a __str within this string. If found, returns the index where it
2665 * was found. If not found, returns npos.
2666 */
2667 size_type
2668 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
2669 _GLIBCXX_NOEXCEPTnoexcept
2670 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
2671
2672#if __cplusplus201703L >= 201703L
2673 /**
2674 * @brief Find position of a character not in a string_view.
2675 * @param __svt A object convertible to string_view containing
2676 * characters to avoid.
2677 * @param __pos Index of character to search from (default 0).
2678 * @return Index of first occurrence.
2679 */
2680 template<typename _Tp>
2681 _If_sv<_Tp, size_type>
2682 find_first_not_of(const _Tp& __svt, size_type __pos = 0) const
2683 noexcept(is_same<_Tp, __sv_type>::value)
2684 {
2685 __sv_type __sv = __svt;
2686 return this->find_first_not_of(__sv.data(), __pos, __sv.size());
2687 }
2688#endif // C++17
2689
2690 /**
2691 * @brief Find position of a character not in C substring.
2692 * @param __s C string containing characters to avoid.
2693 * @param __pos Index of character to search from.
2694 * @param __n Number of characters from __s to consider.
2695 * @return Index of first occurrence.
2696 *
2697 * Starting from @a __pos, searches forward for a character not
2698 * contained in the first @a __n characters of @a __s within
2699 * this string. If found, returns the index where it was
2700 * found. If not found, returns npos.
2701 */
2702 size_type
2703 find_first_not_of(const _CharT* __s, size_type __pos,
2704 size_type __n) const _GLIBCXX_NOEXCEPTnoexcept;
2705
2706 /**
2707 * @brief Find position of a character not in C string.
2708 * @param __s C string containing characters to avoid.
2709 * @param __pos Index of character to search from (default 0).
2710 * @return Index of first occurrence.
2711 *
2712 * Starting from @a __pos, searches forward for a character not
2713 * contained in @a __s within this string. If found, returns
2714 * the index where it was found. If not found, returns npos.
2715 */
2716 size_type
2717 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
2718 _GLIBCXX_NOEXCEPTnoexcept
2719 {
2720 __glibcxx_requires_string(__s);
2721 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
2722 }
2723
2724 /**
2725 * @brief Find position of a different character.
2726 * @param __c Character to avoid.
2727 * @param __pos Index of character to search from (default 0).
2728 * @return Index of first occurrence.
2729 *
2730 * Starting from @a __pos, searches forward for a character
2731 * other than @a __c within this string. If found, returns the
2732 * index where it was found. If not found, returns npos.
2733 */
2734 size_type
2735 find_first_not_of(_CharT __c, size_type __pos = 0) const
2736 _GLIBCXX_NOEXCEPTnoexcept;
2737
2738 /**
2739 * @brief Find last position of a character not in string.
2740 * @param __str String containing characters to avoid.
2741 * @param __pos Index of character to search back from (default end).
2742 * @return Index of last occurrence.
2743 *
2744 * Starting from @a __pos, searches backward for a character
2745 * not contained in @a __str within this string. If found,
2746 * returns the index where it was found. If not found, returns
2747 * npos.
2748 */
2749 size_type
2750 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
2751 _GLIBCXX_NOEXCEPTnoexcept
2752 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
2753
2754#if __cplusplus201703L >= 201703L
2755 /**
2756 * @brief Find last position of a character not in a string_view.
2757 * @param __svt An object convertible to string_view containing
2758 * characters to avoid.
2759 * @param __pos Index of character to search back from (default end).
2760 * @return Index of last occurrence.
2761 */
2762 template<typename _Tp>
2763 _If_sv<_Tp, size_type>
2764 find_last_not_of(const _Tp& __svt, size_type __pos = npos) const
2765 noexcept(is_same<_Tp, __sv_type>::value)
2766 {
2767 __sv_type __sv = __svt;
2768 return this->find_last_not_of(__sv.data(), __pos, __sv.size());
2769 }
2770#endif // C++17
2771
2772 /**
2773 * @brief Find last position of a character not in C substring.
2774 * @param __s C string containing characters to avoid.
2775 * @param __pos Index of character to search back from.
2776 * @param __n Number of characters from s to consider.
2777 * @return Index of last occurrence.
2778 *
2779 * Starting from @a __pos, searches backward for a character not
2780 * contained in the first @a __n characters of @a __s within this string.
2781 * If found, returns the index where it was found. If not found,
2782 * returns npos.
2783 */
2784 size_type
2785 find_last_not_of(const _CharT* __s, size_type __pos,
2786 size_type __n) const _GLIBCXX_NOEXCEPTnoexcept;
2787 /**
2788 * @brief Find last position of a character not in C string.
2789 * @param __s C string containing characters to avoid.
2790 * @param __pos Index of character to search back from (default end).
2791 * @return Index of last occurrence.
2792 *
2793 * Starting from @a __pos, searches backward for a character
2794 * not contained in @a __s within this string. If found,
2795 * returns the index where it was found. If not found, returns
2796 * npos.
2797 */
2798 size_type
2799 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
2800 _GLIBCXX_NOEXCEPTnoexcept
2801 {
2802 __glibcxx_requires_string(__s);
2803 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
2804 }
2805
2806 /**
2807 * @brief Find last position of a different character.
2808 * @param __c Character to avoid.
2809 * @param __pos Index of character to search back from (default end).
2810 * @return Index of last occurrence.
2811 *
2812 * Starting from @a __pos, searches backward for a character other than
2813 * @a __c within this string. If found, returns the index where it was
2814 * found. If not found, returns npos.
2815 */
2816 size_type
2817 find_last_not_of(_CharT __c, size_type __pos = npos) const
2818 _GLIBCXX_NOEXCEPTnoexcept;
2819
2820 /**
2821 * @brief Get a substring.
2822 * @param __pos Index of first character (default 0).
2823 * @param __n Number of characters in substring (default remainder).
2824 * @return The new string.
2825 * @throw std::out_of_range If __pos > size().
2826 *
2827 * Construct and return a new string using the @a __n
2828 * characters starting at @a __pos. If the string is too
2829 * short, use the remainder of the characters. If @a __pos is
2830 * beyond the end of the string, out_of_range is thrown.
2831 */
2832 basic_string
2833 substr(size_type __pos = 0, size_type __n = npos) const
2834 { return basic_string(*this,
2835 _M_check(__pos, "basic_string::substr"), __n); }
2836
2837 /**
2838 * @brief Compare to a string.
2839 * @param __str String to compare against.
2840 * @return Integer < 0, 0, or > 0.
2841 *
2842 * Returns an integer < 0 if this string is ordered before @a
2843 * __str, 0 if their values are equivalent, or > 0 if this
2844 * string is ordered after @a __str. Determines the effective
2845 * length rlen of the strings to compare as the smallest of
2846 * size() and str.size(). The function then compares the two
2847 * strings by calling traits::compare(data(), str.data(),rlen).
2848 * If the result of the comparison is nonzero returns it,
2849 * otherwise the shorter one is ordered first.
2850 */
2851 int
2852 compare(const basic_string& __str) const
2853 {
2854 const size_type __size = this->size();
2855 const size_type __osize = __str.size();
2856 const size_type __len = std::min(__size, __osize);
2857
2858 int __r = traits_type::compare(_M_data(), __str.data(), __len);
2859 if (!__r)
2860 __r = _S_compare(__size, __osize);
2861 return __r;
2862 }
2863
2864#if __cplusplus201703L >= 201703L
2865 /**
2866 * @brief Compare to a string_view.
2867 * @param __svt An object convertible to string_view to compare against.
2868 * @return Integer < 0, 0, or > 0.
2869 */
2870 template<typename _Tp>
2871 _If_sv<_Tp, int>
2872 compare(const _Tp& __svt) const
2873 noexcept(is_same<_Tp, __sv_type>::value)
2874 {
2875 __sv_type __sv = __svt;
2876 const size_type __size = this->size();
2877 const size_type __osize = __sv.size();
2878 const size_type __len = std::min(__size, __osize);
2879
2880 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
2881 if (!__r)
2882 __r = _S_compare(__size, __osize);
2883 return __r;
2884 }
2885
2886 /**
2887 * @brief Compare to a string_view.
2888 * @param __pos A position in the string to start comparing from.
2889 * @param __n The number of characters to compare.
2890 * @param __svt An object convertible to string_view to compare
2891 * against.
2892 * @return Integer < 0, 0, or > 0.
2893 */
2894 template<typename _Tp>
2895 _If_sv<_Tp, int>
2896 compare(size_type __pos, size_type __n, const _Tp& __svt) const
2897 noexcept(is_same<_Tp, __sv_type>::value)
2898 {
2899 __sv_type __sv = __svt;
2900 return __sv_type(*this).substr(__pos, __n).compare(__sv);
2901 }
2902
2903 /**
2904 * @brief Compare to a string_view.
2905 * @param __pos1 A position in the string to start comparing from.
2906 * @param __n1 The number of characters to compare.
2907 * @param __svt An object convertible to string_view to compare
2908 * against.
2909 * @param __pos2 A position in the string_view to start comparing from.
2910 * @param __n2 The number of characters to compare.
2911 * @return Integer < 0, 0, or > 0.
2912 */
2913 template<typename _Tp>
2914 _If_sv<_Tp, int>
2915 compare(size_type __pos1, size_type __n1, const _Tp& __svt,
2916 size_type __pos2, size_type __n2 = npos) const
2917 noexcept(is_same<_Tp, __sv_type>::value)
2918 {
2919 __sv_type __sv = __svt;
2920 return __sv_type(*this)
2921 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
2922 }
2923#endif // C++17
2924
2925 /**
2926 * @brief Compare substring to a string.
2927 * @param __pos Index of first character of substring.
2928 * @param __n Number of characters in substring.
2929 * @param __str String to compare against.
2930 * @return Integer < 0, 0, or > 0.
2931 *
2932 * Form the substring of this string from the @a __n characters
2933 * starting at @a __pos. Returns an integer < 0 if the
2934 * substring is ordered before @a __str, 0 if their values are
2935 * equivalent, or > 0 if the substring is ordered after @a
2936 * __str. Determines the effective length rlen of the strings
2937 * to compare as the smallest of the length of the substring
2938 * and @a __str.size(). The function then compares the two
2939 * strings by calling
2940 * traits::compare(substring.data(),str.data(),rlen). If the
2941 * result of the comparison is nonzero returns it, otherwise
2942 * the shorter one is ordered first.
2943 */
2944 int
2945 compare(size_type __pos, size_type __n, const basic_string& __str) const;
2946
2947 /**
2948 * @brief Compare substring to a substring.
2949 * @param __pos1 Index of first character of substring.
2950 * @param __n1 Number of characters in substring.
2951 * @param __str String to compare against.
2952 * @param __pos2 Index of first character of substring of str.
2953 * @param __n2 Number of characters in substring of str.
2954 * @return Integer < 0, 0, or > 0.
2955 *
2956 * Form the substring of this string from the @a __n1
2957 * characters starting at @a __pos1. Form the substring of @a
2958 * __str from the @a __n2 characters starting at @a __pos2.
2959 * Returns an integer < 0 if this substring is ordered before
2960 * the substring of @a __str, 0 if their values are equivalent,
2961 * or > 0 if this substring is ordered after the substring of
2962 * @a __str. Determines the effective length rlen of the
2963 * strings to compare as the smallest of the lengths of the
2964 * substrings. The function then compares the two strings by
2965 * calling
2966 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
2967 * If the result of the comparison is nonzero returns it,
2968 * otherwise the shorter one is ordered first.
2969 */
2970 int
2971 compare(size_type __pos1, size_type __n1, const basic_string& __str,
2972 size_type __pos2, size_type __n2 = npos) const;
2973
2974 /**
2975 * @brief Compare to a C string.
2976 * @param __s C string to compare against.
2977 * @return Integer < 0, 0, or > 0.
2978 *
2979 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
2980 * their values are equivalent, or > 0 if this string is ordered after
2981 * @a __s. Determines the effective length rlen of the strings to
2982 * compare as the smallest of size() and the length of a string
2983 * constructed from @a __s. The function then compares the two strings
2984 * by calling traits::compare(data(),s,rlen). If the result of the
2985 * comparison is nonzero returns it, otherwise the shorter one is
2986 * ordered first.
2987 */
2988 int
2989 compare(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept;
2990
2991 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2992 // 5 String::compare specification questionable
2993 /**
2994 * @brief Compare substring to a C string.
2995 * @param __pos Index of first character of substring.
2996 * @param __n1 Number of characters in substring.
2997 * @param __s C string to compare against.
2998 * @return Integer < 0, 0, or > 0.
2999 *
3000 * Form the substring of this string from the @a __n1
3001 * characters starting at @a pos. Returns an integer < 0 if
3002 * the substring is ordered before @a __s, 0 if their values
3003 * are equivalent, or > 0 if the substring is ordered after @a
3004 * __s. Determines the effective length rlen of the strings to
3005 * compare as the smallest of the length of the substring and
3006 * the length of a string constructed from @a __s. The
3007 * function then compares the two string by calling
3008 * traits::compare(substring.data(),__s,rlen). If the result of
3009 * the comparison is nonzero returns it, otherwise the shorter
3010 * one is ordered first.
3011 */
3012 int
3013 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
3014
3015 /**
3016 * @brief Compare substring against a character %array.
3017 * @param __pos Index of first character of substring.
3018 * @param __n1 Number of characters in substring.
3019 * @param __s character %array to compare against.
3020 * @param __n2 Number of characters of s.
3021 * @return Integer < 0, 0, or > 0.
3022 *
3023 * Form the substring of this string from the @a __n1
3024 * characters starting at @a __pos. Form a string from the
3025 * first @a __n2 characters of @a __s. Returns an integer < 0
3026 * if this substring is ordered before the string from @a __s,
3027 * 0 if their values are equivalent, or > 0 if this substring
3028 * is ordered after the string from @a __s. Determines the
3029 * effective length rlen of the strings to compare as the
3030 * smallest of the length of the substring and @a __n2. The
3031 * function then compares the two strings by calling
3032 * traits::compare(substring.data(),s,rlen). If the result of
3033 * the comparison is nonzero returns it, otherwise the shorter
3034 * one is ordered first.
3035 *
3036 * NB: s must have at least n2 characters, &apos;\\0&apos; has
3037 * no special meaning.
3038 */
3039 int
3040 compare(size_type __pos, size_type __n1, const _CharT* __s,
3041 size_type __n2) const;
3042
3043#if __cplusplus201703L > 201703L
3044 bool
3045 starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
3046 { return __sv_type(this->data(), this->size()).starts_with(__x); }
3047
3048 bool
3049 starts_with(_CharT __x) const noexcept
3050 { return __sv_type(this->data(), this->size()).starts_with(__x); }
3051
3052 bool
3053 starts_with(const _CharT* __x) const noexcept
3054 { return __sv_type(this->data(), this->size()).starts_with(__x); }
3055
3056 bool
3057 ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
3058 { return __sv_type(this->data(), this->size()).ends_with(__x); }
3059
3060 bool
3061 ends_with(_CharT __x) const noexcept
3062 { return __sv_type(this->data(), this->size()).ends_with(__x); }
3063
3064 bool
3065 ends_with(const _CharT* __x) const noexcept
3066 { return __sv_type(this->data(), this->size()).ends_with(__x); }
3067#endif // C++20
3068
3069 // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
3070 template<typename, typename, typename> friend class basic_stringbuf;
3071 };
3072_GLIBCXX_END_NAMESPACE_CXX11}
3073#else // !_GLIBCXX_USE_CXX11_ABI
3074 // Reference-counted COW string implentation
3075
3076 /**
3077 * @class basic_string basic_string.h <string>
3078 * @brief Managing sequences of characters and character-like objects.
3079 *
3080 * @ingroup strings
3081 * @ingroup sequences
3082 *
3083 * @tparam _CharT Type of character
3084 * @tparam _Traits Traits for character type, defaults to
3085 * char_traits<_CharT>.
3086 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
3087 *
3088 * Meets the requirements of a <a href="tables.html#65">container</a>, a
3089 * <a href="tables.html#66">reversible container</a>, and a
3090 * <a href="tables.html#67">sequence</a>. Of the
3091 * <a href="tables.html#68">optional sequence requirements</a>, only
3092 * @c push_back, @c at, and @c %array access are supported.
3093 *
3094 * @doctodo
3095 *
3096 *
3097 * Documentation? What's that?
3098 * Nathan Myers <ncm@cantrip.org>.
3099 *
3100 * A string looks like this:
3101 *
3102 * @code
3103 * [_Rep]
3104 * _M_length
3105 * [basic_string<char_type>] _M_capacity
3106 * _M_dataplus _M_refcount
3107 * _M_p ----------------> unnamed array of char_type
3108 * @endcode
3109 *
3110 * Where the _M_p points to the first character in the string, and
3111 * you cast it to a pointer-to-_Rep and subtract 1 to get a
3112 * pointer to the header.
3113 *
3114 * This approach has the enormous advantage that a string object
3115 * requires only one allocation. All the ugliness is confined
3116 * within a single %pair of inline functions, which each compile to
3117 * a single @a add instruction: _Rep::_M_data(), and
3118 * string::_M_rep(); and the allocation function which gets a
3119 * block of raw bytes and with room enough and constructs a _Rep
3120 * object at the front.
3121 *
3122 * The reason you want _M_data pointing to the character %array and
3123 * not the _Rep is so that the debugger can see the string
3124 * contents. (Probably we should add a non-inline member to get
3125 * the _Rep for the debugger to use, so users can check the actual
3126 * string length.)
3127 *
3128 * Note that the _Rep object is a POD so that you can have a
3129 * static <em>empty string</em> _Rep object already @a constructed before
3130 * static constructors have run. The reference-count encoding is
3131 * chosen so that a 0 indicates one reference, so you never try to
3132 * destroy the empty-string _Rep object.
3133 *
3134 * All but the last paragraph is considered pretty conventional
3135 * for a C++ string implementation.
3136 */
3137 // 21.3 Template class basic_string
3138 template<typename _CharT, typename _Traits, typename _Alloc>
3139 class basic_string
3140 {
3141 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
3142 rebind<_CharT>::other _CharT_alloc_type;
3143 typedef __gnu_cxx::__alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
3144
3145 // Types:
3146 public:
3147 typedef _Traits traits_type;
3148 typedef typename _Traits::char_type value_type;
3149 typedef _Alloc allocator_type;
3150 typedef typename _CharT_alloc_type::size_type size_type;
3151 typedef typename _CharT_alloc_type::difference_type difference_type;
3152#if __cplusplus201703L < 201103L
3153 typedef typename _CharT_alloc_type::reference reference;
3154 typedef typename _CharT_alloc_type::const_reference const_reference;
3155#else
3156 typedef value_type& reference;
3157 typedef const value_type& const_reference;
3158#endif
3159 typedef typename _CharT_alloc_traits::pointer pointer;
3160 typedef typename _CharT_alloc_traits::const_pointer const_pointer;
3161 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
3162 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
3163 const_iterator;
3164 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
3165 typedef std::reverse_iterator<iterator> reverse_iterator;
3166
3167 protected:
3168 // type used for positions in insert, erase etc.
3169 typedef iterator __const_iterator;
3170
3171 private:
3172 // _Rep: string representation
3173 // Invariants:
3174 // 1. String really contains _M_length + 1 characters: due to 21.3.4
3175 // must be kept null-terminated.
3176 // 2. _M_capacity >= _M_length
3177 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
3178 // 3. _M_refcount has three states:
3179 // -1: leaked, one reference, no ref-copies allowed, non-const.
3180 // 0: one reference, non-const.
3181 // n>0: n + 1 references, operations require a lock, const.
3182 // 4. All fields==0 is an empty string, given the extra storage
3183 // beyond-the-end for a null terminator; thus, the shared
3184 // empty string representation needs no constructor.
3185
3186 struct _Rep_base
3187 {
3188 size_type _M_length;
3189 size_type _M_capacity;
3190 _Atomic_word _M_refcount;
3191 };
3192
3193 struct _Rep : _Rep_base
3194 {
3195 // Types:
3196 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
3197 rebind<char>::other _Raw_bytes_alloc;
3198
3199 // (Public) Data members:
3200
3201 // The maximum number of individual char_type elements of an
3202 // individual string is determined by _S_max_size. This is the
3203 // value that will be returned by max_size(). (Whereas npos
3204 // is the maximum number of bytes the allocator can allocate.)
3205 // If one was to divvy up the theoretical largest size string,
3206 // with a terminating character and m _CharT elements, it'd
3207 // look like this:
3208 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
3209 // Solving for m:
3210 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1
3211 // In addition, this implementation quarters this amount.
3212 static const size_type _S_max_size;
3213 static const _CharT _S_terminal;
3214
3215 // The following storage is init'd to 0 by the linker, resulting
3216 // (carefully) in an empty string with one reference.
3217 static size_type _S_empty_rep_storage[];
3218
3219 static _Rep&
3220 _S_empty_rep() _GLIBCXX_NOEXCEPTnoexcept
3221 {
3222 // NB: Mild hack to avoid strict-aliasing warnings. Note that
3223 // _S_empty_rep_storage is never modified and the punning should
3224 // be reasonably safe in this case.
3225 void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
3226 return *reinterpret_cast<_Rep*>(__p);
3227 }
3228
3229 bool
3230 _M_is_leaked() const _GLIBCXX_NOEXCEPTnoexcept
3231 {
3232#if defined(__GTHREADS1)
3233 // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
3234 // so we need to use an atomic load. However, _M_is_leaked
3235 // predicate does not change concurrently (i.e. the string is either
3236 // leaked or not), so a relaxed load is enough.
3237 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED0) < 0;
3238#else
3239 return this->_M_refcount < 0;
3240#endif
3241 }
3242
3243 bool
3244 _M_is_shared() const _GLIBCXX_NOEXCEPTnoexcept
3245 {
3246#if defined(__GTHREADS1)
3247 // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose,
3248 // so we need to use an atomic load. Another thread can drop last
3249 // but one reference concurrently with this check, so we need this
3250 // load to be acquire to synchronize with release fetch_and_add in
3251 // _M_dispose.
3252 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE2) > 0;
3253#else
3254 return this->_M_refcount > 0;
3255#endif
3256 }
3257
3258 void
3259 _M_set_leaked() _GLIBCXX_NOEXCEPTnoexcept
3260 { this->_M_refcount = -1; }
3261
3262 void
3263 _M_set_sharable() _GLIBCXX_NOEXCEPTnoexcept
3264 { this->_M_refcount = 0; }
3265
3266 void
3267 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPTnoexcept
3268 {
3269#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3270 if (__builtin_expect(this != &_S_empty_rep(), false))
3271#endif
3272 {
3273 this->_M_set_sharable(); // One reference.
3274 this->_M_length = __n;
3275 traits_type::assign(this->_M_refdata()[__n], _S_terminal);
3276 // grrr. (per 21.3.4)
3277 // You cannot leave those LWG people alone for a second.
3278 }
3279 }
3280
3281 _CharT*
3282 _M_refdata() throw()
3283 { return reinterpret_cast<_CharT*>(this + 1); }
3284
3285 _CharT*
3286 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2)
3287 {
3288 return (!_M_is_leaked() && __alloc1 == __alloc2)
3289 ? _M_refcopy() : _M_clone(__alloc1);
3290 }
3291
3292 // Create & Destroy
3293 static _Rep*
3294 _S_create(size_type, size_type, const _Alloc&);
3295
3296 void
3297 _M_dispose(const _Alloc& __a) _GLIBCXX_NOEXCEPTnoexcept
3298 {
3299#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3300 if (__builtin_expect(this != &_S_empty_rep(), false))
3301#endif
3302 {
3303 // Be race-detector-friendly. For more info see bits/c++config.
3304 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount);
3305 // Decrement of _M_refcount is acq_rel, because:
3306 // - all but last decrements need to release to synchronize with
3307 // the last decrement that will delete the object.
3308 // - the last decrement needs to acquire to synchronize with
3309 // all the previous decrements.
3310 // - last but one decrement needs to release to synchronize with
3311 // the acquire load in _M_is_shared that will conclude that
3312 // the object is not shared anymore.
3313 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
3314 -1) <= 0)
3315 {
3316 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount);
3317 _M_destroy(__a);
3318 }
3319 }
3320 } // XXX MT
3321
3322 void
3323 _M_destroy(const _Alloc&) throw();
3324
3325 _CharT*
3326 _M_refcopy() throw()
3327 {
3328#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3329 if (__builtin_expect(this != &_S_empty_rep(), false))
3330#endif
3331 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
3332 return _M_refdata();
3333 } // XXX MT
3334
3335 _CharT*
3336 _M_clone(const _Alloc&, size_type __res = 0);
3337 };
3338
3339 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
3340 struct _Alloc_hider : _Alloc
3341 {
3342 _Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPTnoexcept
3343 : _Alloc(__a), _M_p(__dat) { }
3344
3345 _CharT* _M_p; // The actual data.
3346 };
3347
3348 public:
3349 // Data Members (public):
3350 // NB: This is an unsigned type, and thus represents the maximum
3351 // size that the allocator can hold.
3352 /// Value returned by various member functions when they fail.
3353 static const size_type npos = static_cast<size_type>(-1);
3354
3355 private:
3356 // Data Members (private):
3357 mutable _Alloc_hider _M_dataplus;
3358
3359 _CharT*
3360 _M_data() const _GLIBCXX_NOEXCEPTnoexcept
3361 { return _M_dataplus._M_p; }
3362
3363 _CharT*
3364 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPTnoexcept
3365 { return (_M_dataplus._M_p = __p); }
3366
3367 _Rep*
3368 _M_rep() const _GLIBCXX_NOEXCEPTnoexcept
3369 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
3370
3371 // For the internal use we have functions similar to `begin'/`end'
3372 // but they do not call _M_leak.
3373 iterator
3374 _M_ibegin() const _GLIBCXX_NOEXCEPTnoexcept
3375 { return iterator(_M_data()); }
3376
3377 iterator
3378 _M_iend() const _GLIBCXX_NOEXCEPTnoexcept
3379 { return iterator(_M_data() + this->size()); }
3380
3381 void
3382 _M_leak() // for use in begin() & non-const op[]
3383 {
3384 if (!_M_rep()->_M_is_leaked())
3385 _M_leak_hard();
3386 }
3387
3388 size_type
3389 _M_check(size_type __pos, const char* __s) const
3390 {
3391 if (__pos > this->size())
3392 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "("%s: __pos (which is %zu) > " "this->size() (which is %zu)"
)
3393 "this->size() (which is %zu)")("%s: __pos (which is %zu) > " "this->size() (which is %zu)"
)
,
3394 __s, __pos, this->size());
3395 return __pos;
3396 }
3397
3398 void
3399 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
3400 {
3401 if (this->max_size() - (this->size() - __n1) < __n2)
3402 __throw_length_error(__N(__s)(__s));
3403 }
3404
3405 // NB: _M_limit doesn't check for a bad __pos value.
3406 size_type
3407 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPTnoexcept
3408 {
3409 const bool __testoff = __off < this->size() - __pos;
3410 return __testoff ? __off : this->size() - __pos;
3411 }
3412
3413 // True if _Rep and source do not overlap.
3414 bool
3415 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept
3416 {
3417 return (less<const _CharT*>()(__s, _M_data())
3418 || less<const _CharT*>()(_M_data() + this->size(), __s));
3419 }
3420
3421 // When __n = 1 way faster than the general multichar
3422 // traits_type::copy/move/assign.
3423 static void
3424 _M_copy(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPTnoexcept
3425 {
3426 if (__n == 1)
3427 traits_type::assign(*__d, *__s);
3428 else
3429 traits_type::copy(__d, __s, __n);
3430 }
3431
3432 static void
3433 _M_move(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPTnoexcept
3434 {
3435 if (__n == 1)
3436 traits_type::assign(*__d, *__s);
3437 else
3438 traits_type::move(__d, __s, __n);
3439 }
3440
3441 static void
3442 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPTnoexcept
3443 {
3444 if (__n == 1)
3445 traits_type::assign(*__d, __c);
3446 else
3447 traits_type::assign(__d, __n, __c);
3448 }
3449
3450 // _S_copy_chars is a separate template to permit specialization
3451 // to optimize for the common case of pointers as iterators.
3452 template<class _Iterator>
3453 static void
3454 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
3455 {
3456 for (; __k1 != __k2; ++__k1, (void)++__p)
3457 traits_type::assign(*__p, *__k1); // These types are off.
3458 }
3459
3460 static void
3461 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPTnoexcept
3462 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3463
3464 static void
3465 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
3466 _GLIBCXX_NOEXCEPTnoexcept
3467 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
3468
3469 static void
3470 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPTnoexcept
3471 { _M_copy(__p, __k1, __k2 - __k1); }
3472
3473 static void
3474 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
3475 _GLIBCXX_NOEXCEPTnoexcept
3476 { _M_copy(__p, __k1, __k2 - __k1); }
3477
3478 static int
3479 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPTnoexcept
3480 {
3481 const difference_type __d = difference_type(__n1 - __n2);
3482
3483 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
3484 return __gnu_cxx::__numeric_traits<int>::__max;
3485 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
3486 return __gnu_cxx::__numeric_traits<int>::__min;
3487 else
3488 return int(__d);
3489 }
3490
3491 void
3492 _M_mutate(size_type __pos, size_type __len1, size_type __len2);
3493
3494 void
3495 _M_leak_hard();
3496
3497 static _Rep&
3498 _S_empty_rep() _GLIBCXX_NOEXCEPTnoexcept
3499 { return _Rep::_S_empty_rep(); }
3500
3501#if __cplusplus201703L >= 201703L
3502 // A helper type for avoiding boiler-plate.
3503 typedef basic_string_view<_CharT, _Traits> __sv_type;
3504
3505 template<typename _Tp, typename _Res>
3506 using _If_sv = enable_if_t<
3507 __and_<is_convertible<const _Tp&, __sv_type>,
3508 __not_<is_convertible<const _Tp*, const basic_string*>>,
3509 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
3510 _Res>;
3511
3512 // Allows an implicit conversion to __sv_type.
3513 static __sv_type
3514 _S_to_string_view(__sv_type __svt) noexcept
3515 { return __svt; }
3516
3517 // Wraps a string_view by explicit conversion and thus
3518 // allows to add an internal constructor that does not
3519 // participate in overload resolution when a string_view
3520 // is provided.
3521 struct __sv_wrapper
3522 {
3523 explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
3524 __sv_type _M_sv;
3525 };
3526
3527 /**
3528 * @brief Only internally used: Construct string from a string view
3529 * wrapper.
3530 * @param __svw string view wrapper.
3531 * @param __a Allocator to use.
3532 */
3533 explicit
3534 basic_string(__sv_wrapper __svw, const _Alloc& __a)
3535 : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { }
3536#endif
3537
3538 public:
3539 // Construct/copy/destroy:
3540 // NB: We overload ctors in some cases instead of using default
3541 // arguments, per 17.4.4.4 para. 2 item 2.
3542
3543 /**
3544 * @brief Default constructor creates an empty string.
3545 */
3546 basic_string()
3547#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3548 _GLIBCXX_NOEXCEPTnoexcept
3549 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc())
3550#else
3551 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc())
3552#endif
3553 { }
3554
3555 /**
3556 * @brief Construct an empty string using allocator @a a.
3557 */
3558 explicit
3559 basic_string(const _Alloc& __a);
3560
3561 // NB: per LWG issue 42, semantics different from IS:
3562 /**
3563 * @brief Construct string with copy of value of @a str.
3564 * @param __str Source string.
3565 */
3566 basic_string(const basic_string& __str);
3567
3568 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3569 // 2583. no way to supply an allocator for basic_string(str, pos)
3570 /**
3571 * @brief Construct string as copy of a substring.
3572 * @param __str Source string.
3573 * @param __pos Index of first character to copy from.
3574 * @param __a Allocator to use.
3575 */
3576 basic_string(const basic_string& __str, size_type __pos,
3577 const _Alloc& __a = _Alloc());
3578
3579 /**
3580 * @brief Construct string as copy of a substring.
3581 * @param __str Source string.
3582 * @param __pos Index of first character to copy from.
3583 * @param __n Number of characters to copy.
3584 */
3585 basic_string(const basic_string& __str, size_type __pos,
3586 size_type __n);
3587 /**
3588 * @brief Construct string as copy of a substring.
3589 * @param __str Source string.
3590 * @param __pos Index of first character to copy from.
3591 * @param __n Number of characters to copy.
3592 * @param __a Allocator to use.
3593 */
3594 basic_string(const basic_string& __str, size_type __pos,
3595 size_type __n, const _Alloc& __a);
3596
3597 /**
3598 * @brief Construct string initialized by a character %array.
3599 * @param __s Source character %array.
3600 * @param __n Number of characters to copy.
3601 * @param __a Allocator to use (default is default allocator).
3602 *
3603 * NB: @a __s must have at least @a __n characters, &apos;\\0&apos;
3604 * has no special meaning.
3605 */
3606 basic_string(const _CharT* __s, size_type __n,
3607 const _Alloc& __a = _Alloc());
3608
3609 /**
3610 * @brief Construct string as copy of a C string.
3611 * @param __s Source C string.
3612 * @param __a Allocator to use (default is default allocator).
3613 */
3614#if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
3615 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3616 // 3076. basic_string CTAD ambiguity
3617 template<typename = _RequireAllocator<_Alloc>>
3618#endif
3619 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
3620 : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) :
3621 __s + npos, __a), __a)
3622 { }
3623
3624 /**
3625 * @brief Construct string as multiple characters.
3626 * @param __n Number of characters.
3627 * @param __c Character to use.
3628 * @param __a Allocator to use (default is default allocator).
3629 */
3630 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc());
3631
3632#if __cplusplus201703L >= 201103L
3633 /**
3634 * @brief Move construct string.
3635 * @param __str Source string.
3636 *
3637 * The newly-created string contains the exact contents of @a __str.
3638 * @a __str is a valid, but unspecified string.
3639 **/
3640 basic_string(basic_string&& __str)
3641#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3642 noexcept // FIXME C++11: should always be noexcept.
3643#endif
3644 : _M_dataplus(std::move(__str._M_dataplus))
3645 {
3646#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3647 __str._M_data(_S_empty_rep()._M_refdata());
3648#else
3649 __str._M_data(_S_construct(size_type(), _CharT(), get_allocator()));
3650#endif
3651 }
3652
3653 /**
3654 * @brief Construct string from an initializer %list.
3655 * @param __l std::initializer_list of characters.
3656 * @param __a Allocator to use (default is default allocator).
3657 */
3658 basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc());
3659
3660 basic_string(const basic_string& __str, const _Alloc& __a)
3661 : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.get_allocator()), __a)
3662 { }
3663
3664 basic_string(basic_string&& __str, const _Alloc& __a)
3665 : _M_dataplus(__str._M_data(), __a)
3666 {
3667 if (__a == __str.get_allocator())
3668 {
3669#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
3670 __str._M_data(_S_empty_rep()._M_refdata());
3671#else
3672 __str._M_data(_S_construct(size_type(), _CharT(), __a));
3673#endif
3674 }
3675 else
3676 _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a);
3677 }
3678#endif // C++11
3679
3680 /**
3681 * @brief Construct string as copy of a range.
3682 * @param __beg Start of range.
3683 * @param __end End of range.
3684 * @param __a Allocator to use (default is default allocator).
3685 */
3686 template<class _InputIterator>
3687 basic_string(_InputIterator __beg, _InputIterator __end,
3688 const _Alloc& __a = _Alloc());
3689
3690#if __cplusplus201703L >= 201703L
3691 /**
3692 * @brief Construct string from a substring of a string_view.
3693 * @param __t Source object convertible to string view.
3694 * @param __pos The index of the first character to copy from __t.
3695 * @param __n The number of characters to copy from __t.
3696 * @param __a Allocator to use.
3697 */
3698 template<typename _Tp, typename = _If_sv<_Tp, void>>
3699 basic_string(const _Tp& __t, size_type __pos, size_type __n,
3700 const _Alloc& __a = _Alloc())
3701 : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
3702
3703 /**
3704 * @brief Construct string from a string_view.
3705 * @param __t Source object convertible to string view.
3706 * @param __a Allocator to use (default is default allocator).
3707 */
3708 template<typename _Tp, typename = _If_sv<_Tp, void>>
3709 explicit
3710 basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
3711 : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
3712#endif // C++17
3713
3714 /**
3715 * @brief Destroy the string instance.
3716 */
3717 ~basic_string() _GLIBCXX_NOEXCEPTnoexcept
3718 { _M_rep()->_M_dispose(this->get_allocator()); }
3719
3720 /**
3721 * @brief Assign the value of @a str to this string.
3722 * @param __str Source string.
3723 */
3724 basic_string&
3725 operator=(const basic_string& __str)
3726 { return this->assign(__str); }
3727
3728 /**
3729 * @brief Copy contents of @a s into this string.
3730 * @param __s Source null-terminated string.
3731 */
3732 basic_string&
3733 operator=(const _CharT* __s)
3734 { return this->assign(__s); }
3735
3736 /**
3737 * @brief Set value to string of length 1.
3738 * @param __c Source character.
3739 *
3740 * Assigning to a character makes this string length 1 and
3741 * (*this)[0] == @a c.
3742 */
3743 basic_string&
3744 operator=(_CharT __c)
3745 {
3746 this->assign(1, __c);
3747 return *this;
3748 }
3749
3750#if __cplusplus201703L >= 201103L
3751 /**
3752 * @brief Move assign the value of @a str to this string.
3753 * @param __str Source string.
3754 *
3755 * The contents of @a str are moved into this string (without copying).
3756 * @a str is a valid, but unspecified string.
3757 **/
3758 basic_string&
3759 operator=(basic_string&& __str)
3760 _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value)noexcept(allocator_traits<_Alloc>::is_always_equal::value
)
3761 {
3762 // NB: DR 1204.
3763 this->swap(__str);
3764 return *this;
3765 }
3766
3767 /**
3768 * @brief Set value to string constructed from initializer %list.
3769 * @param __l std::initializer_list.
3770 */
3771 basic_string&
3772 operator=(initializer_list<_CharT> __l)
3773 {
3774 this->assign(__l.begin(), __l.size());
3775 return *this;
3776 }
3777#endif // C++11
3778
3779#if __cplusplus201703L >= 201703L
3780 /**
3781 * @brief Set value to string constructed from a string_view.
3782 * @param __svt An object convertible to string_view.
3783 */
3784 template<typename _Tp>
3785 _If_sv<_Tp, basic_string&>
3786 operator=(const _Tp& __svt)
3787 { return this->assign(__svt); }
3788
3789 /**
3790 * @brief Convert to a string_view.
3791 * @return A string_view.
3792 */
3793 operator __sv_type() const noexcept
3794 { return __sv_type(data(), size()); }
3795#endif // C++17
3796
3797 // Iterators:
3798 /**
3799 * Returns a read/write iterator that points to the first character in
3800 * the %string. Unshares the string.
3801 */
3802 iterator
3803 begin() // FIXME C++11: should be noexcept.
3804 {
3805 _M_leak();
3806 return iterator(_M_data());
3807 }
3808
3809 /**
3810 * Returns a read-only (constant) iterator that points to the first
3811 * character in the %string.
3812 */
3813 const_iterator
3814 begin() const _GLIBCXX_NOEXCEPTnoexcept
3815 { return const_iterator(_M_data()); }
3816
3817 /**
3818 * Returns a read/write iterator that points one past the last
3819 * character in the %string. Unshares the string.
3820 */
3821 iterator
3822 end() // FIXME C++11: should be noexcept.
3823 {
3824 _M_leak();
3825 return iterator(_M_data() + this->size());
3826 }
3827
3828 /**
3829 * Returns a read-only (constant) iterator that points one past the
3830 * last character in the %string.
3831 */
3832 const_iterator
3833 end() const _GLIBCXX_NOEXCEPTnoexcept
3834 { return const_iterator(_M_data() + this->size()); }
3835
3836 /**
3837 * Returns a read/write reverse iterator that points to the last
3838 * character in the %string. Iteration is done in reverse element
3839 * order. Unshares the string.
3840 */
3841 reverse_iterator
3842 rbegin() // FIXME C++11: should be noexcept.
3843 { return reverse_iterator(this->end()); }
3844
3845 /**
3846 * Returns a read-only (constant) reverse iterator that points
3847 * to the last character in the %string. Iteration is done in
3848 * reverse element order.
3849 */
3850 const_reverse_iterator
3851 rbegin() const _GLIBCXX_NOEXCEPTnoexcept
3852 { return const_reverse_iterator(this->end()); }
3853
3854 /**
3855 * Returns a read/write reverse iterator that points to one before the
3856 * first character in the %string. Iteration is done in reverse
3857 * element order. Unshares the string.
3858 */
3859 reverse_iterator
3860 rend() // FIXME C++11: should be noexcept.
3861 { return reverse_iterator(this->begin()); }
3862
3863 /**
3864 * Returns a read-only (constant) reverse iterator that points
3865 * to one before the first character in the %string. Iteration
3866 * is done in reverse element order.
3867 */
3868 const_reverse_iterator
3869 rend() const _GLIBCXX_NOEXCEPTnoexcept
3870 { return const_reverse_iterator(this->begin()); }
3871
3872#if __cplusplus201703L >= 201103L
3873 /**
3874 * Returns a read-only (constant) iterator that points to the first
3875 * character in the %string.
3876 */
3877 const_iterator
3878 cbegin() const noexcept
3879 { return const_iterator(this->_M_data()); }
3880
3881 /**
3882 * Returns a read-only (constant) iterator that points one past the
3883 * last character in the %string.
3884 */
3885 const_iterator
3886 cend() const noexcept
3887 { return const_iterator(this->_M_data() + this->size()); }
3888
3889 /**
3890 * Returns a read-only (constant) reverse iterator that points
3891 * to the last character in the %string. Iteration is done in
3892 * reverse element order.
3893 */
3894 const_reverse_iterator
3895 crbegin() const noexcept
3896 { return const_reverse_iterator(this->end()); }
3897
3898 /**
3899 * Returns a read-only (constant) reverse iterator that points
3900 * to one before the first character in the %string. Iteration
3901 * is done in reverse element order.
3902 */
3903 const_reverse_iterator
3904 crend() const noexcept
3905 { return const_reverse_iterator(this->begin()); }
3906#endif
3907
3908 public:
3909 // Capacity:
3910 /// Returns the number of characters in the string, not including any
3911 /// null-termination.
3912 size_type
3913 size() const _GLIBCXX_NOEXCEPTnoexcept
3914 { return _M_rep()->_M_length; }
3915
3916 /// Returns the number of characters in the string, not including any
3917 /// null-termination.
3918 size_type
3919 length() const _GLIBCXX_NOEXCEPTnoexcept
3920 { return _M_rep()->_M_length; }
3921
3922 /// Returns the size() of the largest possible %string.
3923 size_type
3924 max_size() const _GLIBCXX_NOEXCEPTnoexcept
3925 { return _Rep::_S_max_size; }
3926
3927 /**
3928 * @brief Resizes the %string to the specified number of characters.
3929 * @param __n Number of characters the %string should contain.
3930 * @param __c Character to fill any new elements.
3931 *
3932 * This function will %resize the %string to the specified
3933 * number of characters. If the number is smaller than the
3934 * %string's current size the %string is truncated, otherwise
3935 * the %string is extended and new elements are %set to @a __c.
3936 */
3937 void
3938 resize(size_type __n, _CharT __c);
3939
3940 /**
3941 * @brief Resizes the %string to the specified number of characters.
3942 * @param __n Number of characters the %string should contain.
3943 *
3944 * This function will resize the %string to the specified length. If
3945 * the new size is smaller than the %string's current size the %string
3946 * is truncated, otherwise the %string is extended and new characters
3947 * are default-constructed. For basic types such as char, this means
3948 * setting them to 0.
3949 */
3950 void
3951 resize(size_type __n)
3952 { this->resize(__n, _CharT()); }
3953
3954#if __cplusplus201703L >= 201103L
3955 /// A non-binding request to reduce capacity() to size().
3956 void
3957 shrink_to_fit() _GLIBCXX_NOEXCEPTnoexcept
3958 {
3959#if __cpp_exceptions
3960 if (capacity() > size())
3961 {
3962 try
3963 { reserve(0); }
3964 catch(...)
3965 { }
3966 }
3967#endif
3968 }
3969#endif
3970
3971 /**
3972 * Returns the total number of characters that the %string can hold
3973 * before needing to allocate more memory.
3974 */
3975 size_type
3976 capacity() const _GLIBCXX_NOEXCEPTnoexcept
3977 { return _M_rep()->_M_capacity; }
3978
3979 /**
3980 * @brief Attempt to preallocate enough memory for specified number of
3981 * characters.
3982 * @param __res_arg Number of characters required.
3983 * @throw std::length_error If @a __res_arg exceeds @c max_size().
3984 *
3985 * This function attempts to reserve enough memory for the
3986 * %string to hold the specified number of characters. If the
3987 * number requested is more than max_size(), length_error is
3988 * thrown.
3989 *
3990 * The advantage of this function is that if optimal code is a
3991 * necessity and the user can determine the string length that will be
3992 * required, the user can reserve the memory in %advance, and thus
3993 * prevent a possible reallocation of memory and copying of %string
3994 * data.
3995 */
3996 void
3997 reserve(size_type __res_arg = 0);
3998
3999 /**
4000 * Erases the string, making it empty.
4001 */
4002#if _GLIBCXX_FULLY_DYNAMIC_STRING0 == 0
4003 void
4004 clear() _GLIBCXX_NOEXCEPTnoexcept
4005 {
4006 if (_M_rep()->_M_is_shared())
4007 {
4008 _M_rep()->_M_dispose(this->get_allocator());
4009 _M_data(_S_empty_rep()._M_refdata());
4010 }
4011 else
4012 _M_rep()->_M_set_length_and_sharable(0);
4013 }
4014#else
4015 // PR 56166: this should not throw.
4016 void
4017 clear()
4018 { _M_mutate(0, this->size(), 0); }
4019#endif
4020
4021 /**
4022 * Returns true if the %string is empty. Equivalent to
4023 * <code>*this == ""</code>.
4024 */
4025 _GLIBCXX_NODISCARD[[__nodiscard__]] bool
4026 empty() const _GLIBCXX_NOEXCEPTnoexcept
4027 { return this->size() == 0; }
4028
4029 // Element access:
4030 /**
4031 * @brief Subscript access to the data contained in the %string.
4032 * @param __pos The index of the character to access.
4033 * @return Read-only (constant) reference to the character.
4034 *
4035 * This operator allows for easy, array-style, data access.
4036 * Note that data access with this operator is unchecked and
4037 * out_of_range lookups are not defined. (For checked lookups
4038 * see at().)
4039 */
4040 const_reference
4041 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPTnoexcept
4042 {
4043 __glibcxx_assert(__pos <= size())do { if (! (__pos <= size())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4043, __PRETTY_FUNCTION__, "__pos <= size()"); } while (
false)
;
4044 return _M_data()[__pos];
4045 }
4046
4047 /**
4048 * @brief Subscript access to the data contained in the %string.
4049 * @param __pos The index of the character to access.
4050 * @return Read/write reference to the character.
4051 *
4052 * This operator allows for easy, array-style, data access.
4053 * Note that data access with this operator is unchecked and
4054 * out_of_range lookups are not defined. (For checked lookups
4055 * see at().) Unshares the string.
4056 */
4057 reference
4058 operator[](size_type __pos)
4059 {
4060 // Allow pos == size() both in C++98 mode, as v3 extension,
4061 // and in C++11 mode.
4062 __glibcxx_assert(__pos <= size())do { if (! (__pos <= size())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4062, __PRETTY_FUNCTION__, "__pos <= size()"); } while (
false)
;
4063 // In pedantic mode be strict in C++98 mode.
4064 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size());
4065 _M_leak();
4066 return _M_data()[__pos];
4067 }
4068
4069 /**
4070 * @brief Provides access to the data contained in the %string.
4071 * @param __n The index of the character to access.
4072 * @return Read-only (const) reference to the character.
4073 * @throw std::out_of_range If @a n is an invalid index.
4074 *
4075 * This function provides for safer data access. The parameter is
4076 * first checked that it is in the range of the string. The function
4077 * throws out_of_range if the check fails.
4078 */
4079 const_reference
4080 at(size_type __n) const
4081 {
4082 if (__n >= this->size())
4083 __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
4084 "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
4085 "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
,
4086 __n, this->size());
4087 return _M_data()[__n];
4088 }
4089
4090 /**
4091 * @brief Provides access to the data contained in the %string.
4092 * @param __n The index of the character to access.
4093 * @return Read/write reference to the character.
4094 * @throw std::out_of_range If @a n is an invalid index.
4095 *
4096 * This function provides for safer data access. The parameter is
4097 * first checked that it is in the range of the string. The function
4098 * throws out_of_range if the check fails. Success results in
4099 * unsharing the string.
4100 */
4101 reference
4102 at(size_type __n)
4103 {
4104 if (__n >= size())
4105 __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
4106 "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
4107 "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
,
4108 __n, this->size());
4109 _M_leak();
4110 return _M_data()[__n];
4111 }
4112
4113#if __cplusplus201703L >= 201103L
4114 /**
4115 * Returns a read/write reference to the data at the first
4116 * element of the %string.
4117 */
4118 reference
4119 front()
4120 {
4121 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4121, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
4122 return operator[](0);
4123 }
4124
4125 /**
4126 * Returns a read-only (constant) reference to the data at the first
4127 * element of the %string.
4128 */
4129 const_reference
4130 front() const noexcept
4131 {
4132 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4132, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
4133 return operator[](0);
4134 }
4135
4136 /**
4137 * Returns a read/write reference to the data at the last
4138 * element of the %string.
4139 */
4140 reference
4141 back()
4142 {
4143 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4143, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
4144 return operator[](this->size() - 1);
4145 }
4146
4147 /**
4148 * Returns a read-only (constant) reference to the data at the
4149 * last element of the %string.
4150 */
4151 const_reference
4152 back() const noexcept
4153 {
4154 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4154, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
4155 return operator[](this->size() - 1);
4156 }
4157#endif
4158
4159 // Modifiers:
4160 /**
4161 * @brief Append a string to this string.
4162 * @param __str The string to append.
4163 * @return Reference to this string.
4164 */
4165 basic_string&
4166 operator+=(const basic_string& __str)
4167 { return this->append(__str); }
4168
4169 /**
4170 * @brief Append a C string.
4171 * @param __s The C string to append.
4172 * @return Reference to this string.
4173 */
4174 basic_string&
4175 operator+=(const _CharT* __s)
4176 { return this->append(__s); }
4177
4178 /**
4179 * @brief Append a character.
4180 * @param __c The character to append.
4181 * @return Reference to this string.
4182 */
4183 basic_string&
4184 operator+=(_CharT __c)
4185 {
4186 this->push_back(__c);
4187 return *this;
4188 }
4189
4190#if __cplusplus201703L >= 201103L
4191 /**
4192 * @brief Append an initializer_list of characters.
4193 * @param __l The initializer_list of characters to be appended.
4194 * @return Reference to this string.
4195 */
4196 basic_string&
4197 operator+=(initializer_list<_CharT> __l)
4198 { return this->append(__l.begin(), __l.size()); }
4199#endif // C++11
4200
4201#if __cplusplus201703L >= 201703L
4202 /**
4203 * @brief Append a string_view.
4204 * @param __svt The object convertible to string_view to be appended.
4205 * @return Reference to this string.
4206 */
4207 template<typename _Tp>
4208 _If_sv<_Tp, basic_string&>
4209 operator+=(const _Tp& __svt)
4210 { return this->append(__svt); }
4211#endif // C++17
4212
4213 /**
4214 * @brief Append a string to this string.
4215 * @param __str The string to append.
4216 * @return Reference to this string.
4217 */
4218 basic_string&
4219 append(const basic_string& __str);
4220
4221 /**
4222 * @brief Append a substring.
4223 * @param __str The string to append.
4224 * @param __pos Index of the first character of str to append.
4225 * @param __n The number of characters to append.
4226 * @return Reference to this string.
4227 * @throw std::out_of_range if @a __pos is not a valid index.
4228 *
4229 * This function appends @a __n characters from @a __str
4230 * starting at @a __pos to this string. If @a __n is is larger
4231 * than the number of available characters in @a __str, the
4232 * remainder of @a __str is appended.
4233 */
4234 basic_string&
4235 append(const basic_string& __str, size_type __pos, size_type __n = npos);
4236
4237 /**
4238 * @brief Append a C substring.
4239 * @param __s The C string to append.
4240 * @param __n The number of characters to append.
4241 * @return Reference to this string.
4242 */
4243 basic_string&
4244 append(const _CharT* __s, size_type __n);
4245
4246 /**
4247 * @brief Append a C string.
4248 * @param __s The C string to append.
4249 * @return Reference to this string.
4250 */
4251 basic_string&
4252 append(const _CharT* __s)
4253 {
4254 __glibcxx_requires_string(__s);
4255 return this->append(__s, traits_type::length(__s));
4256 }
4257
4258 /**
4259 * @brief Append multiple characters.
4260 * @param __n The number of characters to append.
4261 * @param __c The character to use.
4262 * @return Reference to this string.
4263 *
4264 * Appends __n copies of __c to this string.
4265 */
4266 basic_string&
4267 append(size_type __n, _CharT __c);
4268
4269#if __cplusplus201703L >= 201103L
4270 /**
4271 * @brief Append an initializer_list of characters.
4272 * @param __l The initializer_list of characters to append.
4273 * @return Reference to this string.
4274 */
4275 basic_string&
4276 append(initializer_list<_CharT> __l)
4277 { return this->append(__l.begin(), __l.size()); }
4278#endif // C++11
4279
4280 /**
4281 * @brief Append a range of characters.
4282 * @param __first Iterator referencing the first character to append.
4283 * @param __last Iterator marking the end of the range.
4284 * @return Reference to this string.
4285 *
4286 * Appends characters in the range [__first,__last) to this string.
4287 */
4288 template<class _InputIterator>
4289 basic_string&
4290 append(_InputIterator __first, _InputIterator __last)
4291 { return this->replace(_M_iend(), _M_iend(), __first, __last); }
4292
4293#if __cplusplus201703L >= 201703L
4294 /**
4295 * @brief Append a string_view.
4296 * @param __svt The object convertible to string_view to be appended.
4297 * @return Reference to this string.
4298 */
4299 template<typename _Tp>
4300 _If_sv<_Tp, basic_string&>
4301 append(const _Tp& __svt)
4302 {
4303 __sv_type __sv = __svt;
4304 return this->append(__sv.data(), __sv.size());
4305 }
4306
4307 /**
4308 * @brief Append a range of characters from a string_view.
4309 * @param __svt The object convertible to string_view to be appended
4310 * from.
4311 * @param __pos The position in the string_view to append from.
4312 * @param __n The number of characters to append from the string_view.
4313 * @return Reference to this string.
4314 */
4315 template<typename _Tp>
4316 _If_sv<_Tp, basic_string&>
4317 append(const _Tp& __svt, size_type __pos, size_type __n = npos)
4318 {
4319 __sv_type __sv = __svt;
4320 return append(__sv.data()
4321 + std::__sv_check(__sv.size(), __pos, "basic_string::append"),
4322 std::__sv_limit(__sv.size(), __pos, __n));
4323 }
4324#endif // C++17
4325
4326 /**
4327 * @brief Append a single character.
4328 * @param __c Character to append.
4329 */
4330 void
4331 push_back(_CharT __c)
4332 {
4333 const size_type __len = 1 + this->size();
4334 if (__len > this->capacity() || _M_rep()->_M_is_shared())
4335 this->reserve(__len);
4336 traits_type::assign(_M_data()[this->size()], __c);
4337 _M_rep()->_M_set_length_and_sharable(__len);
4338 }
4339
4340 /**
4341 * @brief Set value to contents of another string.
4342 * @param __str Source string to use.
4343 * @return Reference to this string.
4344 */
4345 basic_string&
4346 assign(const basic_string& __str);
4347
4348#if __cplusplus201703L >= 201103L
4349 /**
4350 * @brief Set value to contents of another string.
4351 * @param __str Source string to use.
4352 * @return Reference to this string.
4353 *
4354 * This function sets this string to the exact contents of @a __str.
4355 * @a __str is a valid, but unspecified string.
4356 */
4357 basic_string&
4358 assign(basic_string&& __str)
4359 noexcept(allocator_traits<_Alloc>::is_always_equal::value)
4360 {
4361 this->swap(__str);
4362 return *this;
4363 }
4364#endif // C++11
4365
4366 /**
4367 * @brief Set value to a substring of a string.
4368 * @param __str The string to use.
4369 * @param __pos Index of the first character of str.
4370 * @param __n Number of characters to use.
4371 * @return Reference to this string.
4372 * @throw std::out_of_range if @a pos is not a valid index.
4373 *
4374 * This function sets this string to the substring of @a __str
4375 * consisting of @a __n characters at @a __pos. If @a __n is
4376 * is larger than the number of available characters in @a
4377 * __str, the remainder of @a __str is used.
4378 */
4379 basic_string&
4380 assign(const basic_string& __str, size_type __pos, size_type __n = npos)
4381 { return this->assign(__str._M_data()
4382 + __str._M_check(__pos, "basic_string::assign"),
4383 __str._M_limit(__pos, __n)); }
4384
4385 /**
4386 * @brief Set value to a C substring.
4387 * @param __s The C string to use.
4388 * @param __n Number of characters to use.
4389 * @return Reference to this string.
4390 *
4391 * This function sets the value of this string to the first @a __n
4392 * characters of @a __s. If @a __n is is larger than the number of
4393 * available characters in @a __s, the remainder of @a __s is used.
4394 */
4395 basic_string&
4396 assign(const _CharT* __s, size_type __n);
4397
4398 /**
4399 * @brief Set value to contents of a C string.
4400 * @param __s The C string to use.
4401 * @return Reference to this string.
4402 *
4403 * This function sets the value of this string to the value of @a __s.
4404 * The data is copied, so there is no dependence on @a __s once the
4405 * function returns.
4406 */
4407 basic_string&
4408 assign(const _CharT* __s)
4409 {
4410 __glibcxx_requires_string(__s);
4411 return this->assign(__s, traits_type::length(__s));
4412 }
4413
4414 /**
4415 * @brief Set value to multiple characters.
4416 * @param __n Length of the resulting string.
4417 * @param __c The character to use.
4418 * @return Reference to this string.
4419 *
4420 * This function sets the value of this string to @a __n copies of
4421 * character @a __c.
4422 */
4423 basic_string&
4424 assign(size_type __n, _CharT __c)
4425 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
4426
4427 /**
4428 * @brief Set value to a range of characters.
4429 * @param __first Iterator referencing the first character to append.
4430 * @param __last Iterator marking the end of the range.
4431 * @return Reference to this string.
4432 *
4433 * Sets value of string to characters in the range [__first,__last).
4434 */
4435 template<class _InputIterator>
4436 basic_string&
4437 assign(_InputIterator __first, _InputIterator __last)
4438 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); }
4439
4440#if __cplusplus201703L >= 201103L
4441 /**
4442 * @brief Set value to an initializer_list of characters.
4443 * @param __l The initializer_list of characters to assign.
4444 * @return Reference to this string.
4445 */
4446 basic_string&
4447 assign(initializer_list<_CharT> __l)
4448 { return this->assign(__l.begin(), __l.size()); }
4449#endif // C++11
4450
4451#if __cplusplus201703L >= 201703L
4452 /**
4453 * @brief Set value from a string_view.
4454 * @param __svt The source object convertible to string_view.
4455 * @return Reference to this string.
4456 */
4457 template<typename _Tp>
4458 _If_sv<_Tp, basic_string&>
4459 assign(const _Tp& __svt)
4460 {
4461 __sv_type __sv = __svt;
4462 return this->assign(__sv.data(), __sv.size());
4463 }
4464
4465 /**
4466 * @brief Set value from a range of characters in a string_view.
4467 * @param __svt The source object convertible to string_view.
4468 * @param __pos The position in the string_view to assign from.
4469 * @param __n The number of characters to assign.
4470 * @return Reference to this string.
4471 */
4472 template<typename _Tp>
4473 _If_sv<_Tp, basic_string&>
4474 assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
4475 {
4476 __sv_type __sv = __svt;
4477 return assign(__sv.data()
4478 + std::__sv_check(__sv.size(), __pos, "basic_string::assign"),
4479 std::__sv_limit(__sv.size(), __pos, __n));
4480 }
4481#endif // C++17
4482
4483 /**
4484 * @brief Insert multiple characters.
4485 * @param __p Iterator referencing location in string to insert at.
4486 * @param __n Number of characters to insert
4487 * @param __c The character to insert.
4488 * @throw std::length_error If new length exceeds @c max_size().
4489 *
4490 * Inserts @a __n copies of character @a __c starting at the
4491 * position referenced by iterator @a __p. If adding
4492 * characters causes the length to exceed max_size(),
4493 * length_error is thrown. The value of the string doesn't
4494 * change if an error is thrown.
4495 */
4496 void
4497 insert(iterator __p, size_type __n, _CharT __c)
4498 { this->replace(__p, __p, __n, __c); }
4499
4500 /**
4501 * @brief Insert a range of characters.
4502 * @param __p Iterator referencing location in string to insert at.
4503 * @param __beg Start of range.
4504 * @param __end End of range.
4505 * @throw std::length_error If new length exceeds @c max_size().
4506 *
4507 * Inserts characters in range [__beg,__end). If adding
4508 * characters causes the length to exceed max_size(),
4509 * length_error is thrown. The value of the string doesn't
4510 * change if an error is thrown.
4511 */
4512 template<class _InputIterator>
4513 void
4514 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
4515 { this->replace(__p, __p, __beg, __end); }
4516
4517#if __cplusplus201703L >= 201103L
4518 /**
4519 * @brief Insert an initializer_list of characters.
4520 * @param __p Iterator referencing location in string to insert at.
4521 * @param __l The initializer_list of characters to insert.
4522 * @throw std::length_error If new length exceeds @c max_size().
4523 */
4524 void
4525 insert(iterator __p, initializer_list<_CharT> __l)
4526 {
4527 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4528 this->insert(__p - _M_ibegin(), __l.begin(), __l.size());
4529 }
4530#endif // C++11
4531
4532 /**
4533 * @brief Insert value of a string.
4534 * @param __pos1 Position in string to insert at.
4535 * @param __str The string to insert.
4536 * @return Reference to this string.
4537 * @throw std::length_error If new length exceeds @c max_size().
4538 *
4539 * Inserts value of @a __str starting at @a __pos1. If adding
4540 * characters causes the length to exceed max_size(),
4541 * length_error is thrown. The value of the string doesn't
4542 * change if an error is thrown.
4543 */
4544 basic_string&
4545 insert(size_type __pos1, const basic_string& __str)
4546 { return this->insert(__pos1, __str, size_type(0), __str.size()); }
4547
4548 /**
4549 * @brief Insert a substring.
4550 * @param __pos1 Position in string to insert at.
4551 * @param __str The string to insert.
4552 * @param __pos2 Start of characters in str to insert.
4553 * @param __n Number of characters to insert.
4554 * @return Reference to this string.
4555 * @throw std::length_error If new length exceeds @c max_size().
4556 * @throw std::out_of_range If @a pos1 > size() or
4557 * @a __pos2 > @a str.size().
4558 *
4559 * Starting at @a pos1, insert @a __n character of @a __str
4560 * beginning with @a __pos2. If adding characters causes the
4561 * length to exceed max_size(), length_error is thrown. If @a
4562 * __pos1 is beyond the end of this string or @a __pos2 is
4563 * beyond the end of @a __str, out_of_range is thrown. The
4564 * value of the string doesn't change if an error is thrown.
4565 */
4566 basic_string&
4567 insert(size_type __pos1, const basic_string& __str,
4568 size_type __pos2, size_type __n = npos)
4569 { return this->insert(__pos1, __str._M_data()
4570 + __str._M_check(__pos2, "basic_string::insert"),
4571 __str._M_limit(__pos2, __n)); }
4572
4573 /**
4574 * @brief Insert a C substring.
4575 * @param __pos Position in string to insert at.
4576 * @param __s The C string to insert.
4577 * @param __n The number of characters to insert.
4578 * @return Reference to this string.
4579 * @throw std::length_error If new length exceeds @c max_size().
4580 * @throw std::out_of_range If @a __pos is beyond the end of this
4581 * string.
4582 *
4583 * Inserts the first @a __n characters of @a __s starting at @a
4584 * __pos. If adding characters causes the length to exceed
4585 * max_size(), length_error is thrown. If @a __pos is beyond
4586 * end(), out_of_range is thrown. The value of the string
4587 * doesn't change if an error is thrown.
4588 */
4589 basic_string&
4590 insert(size_type __pos, const _CharT* __s, size_type __n);
4591
4592 /**
4593 * @brief Insert a C string.
4594 * @param __pos Position in string to insert at.
4595 * @param __s The C string to insert.
4596 * @return Reference to this string.
4597 * @throw std::length_error If new length exceeds @c max_size().
4598 * @throw std::out_of_range If @a pos is beyond the end of this
4599 * string.
4600 *
4601 * Inserts the first @a n characters of @a __s starting at @a __pos. If
4602 * adding characters causes the length to exceed max_size(),
4603 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
4604 * thrown. The value of the string doesn't change if an error is
4605 * thrown.
4606 */
4607 basic_string&
4608 insert(size_type __pos, const _CharT* __s)
4609 {
4610 __glibcxx_requires_string(__s);
4611 return this->insert(__pos, __s, traits_type::length(__s));
4612 }
4613
4614 /**
4615 * @brief Insert multiple characters.
4616 * @param __pos Index in string to insert at.
4617 * @param __n Number of characters to insert
4618 * @param __c The character to insert.
4619 * @return Reference to this string.
4620 * @throw std::length_error If new length exceeds @c max_size().
4621 * @throw std::out_of_range If @a __pos is beyond the end of this
4622 * string.
4623 *
4624 * Inserts @a __n copies of character @a __c starting at index
4625 * @a __pos. If adding characters causes the length to exceed
4626 * max_size(), length_error is thrown. If @a __pos > length(),
4627 * out_of_range is thrown. The value of the string doesn't
4628 * change if an error is thrown.
4629 */
4630 basic_string&
4631 insert(size_type __pos, size_type __n, _CharT __c)
4632 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
4633 size_type(0), __n, __c); }
4634
4635 /**
4636 * @brief Insert one character.
4637 * @param __p Iterator referencing position in string to insert at.
4638 * @param __c The character to insert.
4639 * @return Iterator referencing newly inserted char.
4640 * @throw std::length_error If new length exceeds @c max_size().
4641 *
4642 * Inserts character @a __c at position referenced by @a __p.
4643 * If adding character causes the length to exceed max_size(),
4644 * length_error is thrown. If @a __p is beyond end of string,
4645 * out_of_range is thrown. The value of the string doesn't
4646 * change if an error is thrown.
4647 */
4648 iterator
4649 insert(iterator __p, _CharT __c)
4650 {
4651 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend());
4652 const size_type __pos = __p - _M_ibegin();
4653 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
4654 _M_rep()->_M_set_leaked();
4655 return iterator(_M_data() + __pos);
4656 }
4657
4658#if __cplusplus201703L >= 201703L
4659 /**
4660 * @brief Insert a string_view.
4661 * @param __pos Position in string to insert at.
4662 * @param __svt The object convertible to string_view to insert.
4663 * @return Reference to this string.
4664 */
4665 template<typename _Tp>
4666 _If_sv<_Tp, basic_string&>
4667 insert(size_type __pos, const _Tp& __svt)
4668 {
4669 __sv_type __sv = __svt;
4670 return this->insert(__pos, __sv.data(), __sv.size());
4671 }
4672
4673 /**
4674 * @brief Insert a string_view.
4675 * @param __pos Position in string to insert at.
4676 * @param __svt The object convertible to string_view to insert from.
4677 * @param __pos Position in string_view to insert
4678 * from.
4679 * @param __n The number of characters to insert.
4680 * @return Reference to this string.
4681 */
4682 template<typename _Tp>
4683 _If_sv<_Tp, basic_string&>
4684 insert(size_type __pos1, const _Tp& __svt,
4685 size_type __pos2, size_type __n = npos)
4686 {
4687 __sv_type __sv = __svt;
4688 return this->replace(__pos1, size_type(0), __sv.data()
4689 + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"),
4690 std::__sv_limit(__sv.size(), __pos2, __n));
4691 }
4692#endif // C++17
4693
4694 /**
4695 * @brief Remove characters.
4696 * @param __pos Index of first character to remove (default 0).
4697 * @param __n Number of characters to remove (default remainder).
4698 * @return Reference to this string.
4699 * @throw std::out_of_range If @a pos is beyond the end of this
4700 * string.
4701 *
4702 * Removes @a __n characters from this string starting at @a
4703 * __pos. The length of the string is reduced by @a __n. If
4704 * there are < @a __n characters to remove, the remainder of
4705 * the string is truncated. If @a __p is beyond end of string,
4706 * out_of_range is thrown. The value of the string doesn't
4707 * change if an error is thrown.
4708 */
4709 basic_string&
4710 erase(size_type __pos = 0, size_type __n = npos)
4711 {
4712 _M_mutate(_M_check(__pos, "basic_string::erase"),
4713 _M_limit(__pos, __n), size_type(0));
4714 return *this;
4715 }
4716
4717 /**
4718 * @brief Remove one character.
4719 * @param __position Iterator referencing the character to remove.
4720 * @return iterator referencing same location after removal.
4721 *
4722 * Removes the character at @a __position from this string. The value
4723 * of the string doesn't change if an error is thrown.
4724 */
4725 iterator
4726 erase(iterator __position)
4727 {
4728 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin()
4729 && __position < _M_iend());
4730 const size_type __pos = __position - _M_ibegin();
4731 _M_mutate(__pos, size_type(1), size_type(0));
4732 _M_rep()->_M_set_leaked();
4733 return iterator(_M_data() + __pos);
4734 }
4735
4736 /**
4737 * @brief Remove a range of characters.
4738 * @param __first Iterator referencing the first character to remove.
4739 * @param __last Iterator referencing the end of the range.
4740 * @return Iterator referencing location of first after removal.
4741 *
4742 * Removes the characters in the range [first,last) from this string.
4743 * The value of the string doesn't change if an error is thrown.
4744 */
4745 iterator
4746 erase(iterator __first, iterator __last);
4747
4748#if __cplusplus201703L >= 201103L
4749 /**
4750 * @brief Remove the last character.
4751 *
4752 * The string must be non-empty.
4753 */
4754 void
4755 pop_back() // FIXME C++11: should be noexcept.
4756 {
4757 __glibcxx_assert(!empty())do { if (! (!empty())) std::__replacement_assert("/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/basic_string.h"
, 4757, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
4758 erase(size() - 1, 1);
4759 }
4760#endif // C++11
4761
4762 /**
4763 * @brief Replace characters with value from another string.
4764 * @param __pos Index of first character to replace.
4765 * @param __n Number of characters to be replaced.
4766 * @param __str String to insert.
4767 * @return Reference to this string.
4768 * @throw std::out_of_range If @a pos is beyond the end of this
4769 * string.
4770 * @throw std::length_error If new length exceeds @c max_size().
4771 *
4772 * Removes the characters in the range [__pos,__pos+__n) from
4773 * this string. In place, the value of @a __str is inserted.
4774 * If @a __pos is beyond end of string, out_of_range is thrown.
4775 * If the length of the result exceeds max_size(), length_error
4776 * is thrown. The value of the string doesn't change if an
4777 * error is thrown.
4778 */
4779 basic_string&
4780 replace(size_type __pos, size_type __n, const basic_string& __str)
4781 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
4782
4783 /**
4784 * @brief Replace characters with value from another string.
4785 * @param __pos1 Index of first character to replace.
4786 * @param __n1 Number of characters to be replaced.
4787 * @param __str String to insert.
4788 * @param __pos2 Index of first character of str to use.
4789 * @param __n2 Number of characters from str to use.
4790 * @return Reference to this string.
4791 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
4792 * __str.size().
4793 * @throw std::length_error If new length exceeds @c max_size().
4794 *
4795 * Removes the characters in the range [__pos1,__pos1 + n) from this
4796 * string. In place, the value of @a __str is inserted. If @a __pos is
4797 * beyond end of string, out_of_range is thrown. If the length of the
4798 * result exceeds max_size(), length_error is thrown. The value of the
4799 * string doesn't change if an error is thrown.
4800 */
4801 basic_string&
4802 replace(size_type __pos1, size_type __n1, const basic_string& __str,
4803 size_type __pos2, size_type __n2 = npos)
4804 { return this->replace(__pos1, __n1, __str._M_data()
4805 + __str._M_check(__pos2, "basic_string::replace"),
4806 __str._M_limit(__pos2, __n2)); }
4807
4808 /**
4809 * @brief Replace characters with value of a C substring.
4810 * @param __pos Index of first character to replace.
4811 * @param __n1 Number of characters to be replaced.
4812 * @param __s C string to insert.
4813 * @param __n2 Number of characters from @a s to use.
4814 * @return Reference to this string.
4815 * @throw std::out_of_range If @a pos1 > size().
4816 * @throw std::length_error If new length exceeds @c max_size().
4817 *
4818 * Removes the characters in the range [__pos,__pos + __n1)
4819 * from this string. In place, the first @a __n2 characters of
4820 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
4821 * @a __pos is beyond end of string, out_of_range is thrown. If
4822 * the length of result exceeds max_size(), length_error is
4823 * thrown. The value of the string doesn't change if an error
4824 * is thrown.
4825 */
4826 basic_string&
4827 replace(size_type __pos, size_type __n1, const _CharT* __s,
4828 size_type __n2);
4829
4830 /**
4831 * @brief Replace characters with value of a C string.
4832 * @param __pos Index of first character to replace.
4833 * @param __n1 Number of characters to be replaced.
4834 * @param __s C string to insert.
4835 * @return Reference to this string.
4836 * @throw std::out_of_range If @a pos > size().
4837 * @throw std::length_error If new length exceeds @c max_size().
4838 *
4839 * Removes the characters in the range [__pos,__pos + __n1)
4840 * from this string. In place, the characters of @a __s are
4841 * inserted. If @a __pos is beyond end of string, out_of_range
4842 * is thrown. If the length of result exceeds max_size(),
4843 * length_error is thrown. The value of the string doesn't
4844 * change if an error is thrown.
4845 */
4846 basic_string&
4847 replace(size_type __pos, size_type __n1, const _CharT* __s)
4848 {
4849 __glibcxx_requires_string(__s);
4850 return this->replace(__pos, __n1, __s, traits_type::length(__s));
4851 }
4852
4853 /**
4854 * @brief Replace characters with multiple characters.
4855 * @param __pos Index of first character to replace.
4856 * @param __n1 Number of characters to be replaced.
4857 * @param __n2 Number of characters to insert.
4858 * @param __c Character to insert.
4859 * @return Reference to this string.
4860 * @throw std::out_of_range If @a __pos > size().
4861 * @throw std::length_error If new length exceeds @c max_size().
4862 *
4863 * Removes the characters in the range [pos,pos + n1) from this
4864 * string. In place, @a __n2 copies of @a __c are inserted.
4865 * If @a __pos is beyond end of string, out_of_range is thrown.
4866 * If the length of result exceeds max_size(), length_error is
4867 * thrown. The value of the string doesn't change if an error
4868 * is thrown.
4869 */
4870 basic_string&
4871 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
4872 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
4873 _M_limit(__pos, __n1), __n2, __c); }
4874
4875 /**
4876 * @brief Replace range of characters with string.
4877 * @param __i1 Iterator referencing start of range to replace.
4878 * @param __i2 Iterator referencing end of range to replace.
4879 * @param __str String value to insert.
4880 * @return Reference to this string.
4881 * @throw std::length_error If new length exceeds @c max_size().
4882 *
4883 * Removes the characters in the range [__i1,__i2). In place,
4884 * the value of @a __str is inserted. If the length of result
4885 * exceeds max_size(), length_error is thrown. The value of
4886 * the string doesn't change if an error is thrown.
4887 */
4888 basic_string&
4889 replace(iterator __i1, iterator __i2, const basic_string& __str)
4890 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
4891
4892 /**
4893 * @brief Replace range of characters with C substring.
4894 * @param __i1 Iterator referencing start of range to replace.
4895 * @param __i2 Iterator referencing end of range to replace.
4896 * @param __s C string value to insert.
4897 * @param __n Number of characters from s to insert.
4898 * @return Reference to this string.
4899 * @throw std::length_error If new length exceeds @c max_size().
4900 *
4901 * Removes the characters in the range [__i1,__i2). In place,
4902 * the first @a __n characters of @a __s are inserted. If the
4903 * length of result exceeds max_size(), length_error is thrown.
4904 * The value of the string doesn't change if an error is
4905 * thrown.
4906 */
4907 basic_string&
4908 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n)
4909 {
4910 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4911 && __i2 <= _M_iend());
4912 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n);
4913 }
4914
4915 /**
4916 * @brief Replace range of characters with C string.
4917 * @param __i1 Iterator referencing start of range to replace.
4918 * @param __i2 Iterator referencing end of range to replace.
4919 * @param __s C string value to insert.
4920 * @return Reference to this string.
4921 * @throw std::length_error If new length exceeds @c max_size().
4922 *
4923 * Removes the characters in the range [__i1,__i2). In place,
4924 * the characters of @a __s are inserted. If the length of
4925 * result exceeds max_size(), length_error is thrown. The
4926 * value of the string doesn't change if an error is thrown.
4927 */
4928 basic_string&
4929 replace(iterator __i1, iterator __i2, const _CharT* __s)
4930 {
4931 __glibcxx_requires_string(__s);
4932 return this->replace(__i1, __i2, __s, traits_type::length(__s));
4933 }
4934
4935 /**
4936 * @brief Replace range of characters with multiple characters
4937 * @param __i1 Iterator referencing start of range to replace.
4938 * @param __i2 Iterator referencing end of range to replace.
4939 * @param __n Number of characters to insert.
4940 * @param __c Character to insert.
4941 * @return Reference to this string.
4942 * @throw std::length_error If new length exceeds @c max_size().
4943 *
4944 * Removes the characters in the range [__i1,__i2). In place,
4945 * @a __n copies of @a __c are inserted. If the length of
4946 * result exceeds max_size(), length_error is thrown. The
4947 * value of the string doesn't change if an error is thrown.
4948 */
4949 basic_string&
4950 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c)
4951 {
4952 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4953 && __i2 <= _M_iend());
4954 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c);
4955 }
4956
4957 /**
4958 * @brief Replace range of characters with range.
4959 * @param __i1 Iterator referencing start of range to replace.
4960 * @param __i2 Iterator referencing end of range to replace.
4961 * @param __k1 Iterator referencing start of range to insert.
4962 * @param __k2 Iterator referencing end of range to insert.
4963 * @return Reference to this string.
4964 * @throw std::length_error If new length exceeds @c max_size().
4965 *
4966 * Removes the characters in the range [__i1,__i2). In place,
4967 * characters in the range [__k1,__k2) are inserted. If the
4968 * length of result exceeds max_size(), length_error is thrown.
4969 * The value of the string doesn't change if an error is
4970 * thrown.
4971 */
4972 template<class _InputIterator>
4973 basic_string&
4974 replace(iterator __i1, iterator __i2,
4975 _InputIterator __k1, _InputIterator __k2)
4976 {
4977 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4978 && __i2 <= _M_iend());
4979 __glibcxx_requires_valid_range(__k1, __k2);
4980 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
4981 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
4982 }
4983
4984 // Specializations for the common case of pointer and iterator:
4985 // useful to avoid the overhead of temporary buffering in _M_replace.
4986 basic_string&
4987 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2)
4988 {
4989 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
4990 && __i2 <= _M_iend());
4991 __glibcxx_requires_valid_range(__k1, __k2);
4992 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
4993 __k1, __k2 - __k1);
4994 }
4995
4996 basic_string&
4997 replace(iterator __i1, iterator __i2,
4998 const _CharT* __k1, const _CharT* __k2)
4999 {
5000 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5001 && __i2 <= _M_iend());
5002 __glibcxx_requires_valid_range(__k1, __k2);
5003 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
5004 __k1, __k2 - __k1);
5005 }
5006
5007 basic_string&
5008 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2)
5009 {
5010 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5011 && __i2 <= _M_iend());
5012 __glibcxx_requires_valid_range(__k1, __k2);
5013 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
5014 __k1.base(), __k2 - __k1);
5015 }
5016
5017 basic_string&
5018 replace(iterator __i1, iterator __i2,
5019 const_iterator __k1, const_iterator __k2)
5020 {
5021 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2
5022 && __i2 <= _M_iend());
5023 __glibcxx_requires_valid_range(__k1, __k2);
5024 return this->replace(__i1 - _M_ibegin(), __i2 - __i1,
5025 __k1.base(), __k2 - __k1);
5026 }
5027
5028#if __cplusplus201703L >= 201103L
5029 /**
5030 * @brief Replace range of characters with initializer_list.
5031 * @param __i1 Iterator referencing start of range to replace.
5032 * @param __i2 Iterator referencing end of range to replace.
5033 * @param __l The initializer_list of characters to insert.
5034 * @return Reference to this string.
5035 * @throw std::length_error If new length exceeds @c max_size().
5036 *
5037 * Removes the characters in the range [__i1,__i2). In place,
5038 * characters in the range [__k1,__k2) are inserted. If the
5039 * length of result exceeds max_size(), length_error is thrown.
5040 * The value of the string doesn't change if an error is
5041 * thrown.
5042 */
5043 basic_string& replace(iterator __i1, iterator __i2,
5044 initializer_list<_CharT> __l)
5045 { return this->replace(__i1, __i2, __l.begin(), __l.end()); }
5046#endif // C++11
5047
5048#if __cplusplus201703L >= 201703L
5049 /**
5050 * @brief Replace range of characters with string_view.
5051 * @param __pos The position to replace at.
5052 * @param __n The number of characters to replace.
5053 * @param __svt The object convertible to string_view to insert.
5054 * @return Reference to this string.
5055 */
5056 template<typename _Tp>
5057 _If_sv<_Tp, basic_string&>
5058 replace(size_type __pos, size_type __n, const _Tp& __svt)
5059 {
5060 __sv_type __sv = __svt;
5061 return this->replace(__pos, __n, __sv.data(), __sv.size());
5062 }
5063
5064 /**
5065 * @brief Replace range of characters with string_view.
5066 * @param __pos1 The position to replace at.
5067 * @param __n1 The number of characters to replace.
5068 * @param __svt The object convertible to string_view to insert from.
5069 * @param __pos2 The position in the string_view to insert from.
5070 * @param __n2 The number of characters to insert.
5071 * @return Reference to this string.
5072 */
5073 template<typename _Tp>
5074 _If_sv<_Tp, basic_string&>
5075 replace(size_type __pos1, size_type __n1, const _Tp& __svt,
5076 size_type __pos2, size_type __n2 = npos)
5077 {
5078 __sv_type __sv = __svt;
5079 return this->replace(__pos1, __n1,
5080 __sv.data()
5081 + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"),
5082 std::__sv_limit(__sv.size(), __pos2, __n2));
5083 }
5084
5085 /**
5086 * @brief Replace range of characters with string_view.
5087 * @param __i1 An iterator referencing the start position
5088 to replace at.
5089 * @param __i2 An iterator referencing the end position
5090 for the replace.
5091 * @param __svt The object convertible to string_view to insert from.
5092 * @return Reference to this string.
5093 */
5094 template<typename _Tp>
5095 _If_sv<_Tp, basic_string&>
5096 replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt)
5097 {
5098 __sv_type __sv = __svt;
5099 return this->replace(__i1 - begin(), __i2 - __i1, __sv);
5100 }
5101#endif // C++17
5102
5103 private:
5104 template<class _Integer>
5105 basic_string&
5106 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n,
5107 _Integer __val, __true_type)
5108 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); }
5109
5110 template<class _InputIterator>
5111 basic_string&
5112 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1,
5113 _InputIterator __k2, __false_type);
5114
5115 basic_string&
5116 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
5117 _CharT __c);
5118
5119 basic_string&
5120 _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s,
5121 size_type __n2);
5122
5123 // _S_construct_aux is used to implement the 21.3.1 para 15 which
5124 // requires special behaviour if _InIter is an integral type
5125 template<class _InIterator>
5126 static _CharT*
5127 _S_construct_aux(_InIterator __beg, _InIterator __end,
5128 const _Alloc& __a, __false_type)
5129 {
5130 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
5131 return _S_construct(__beg, __end, __a, _Tag());
5132 }
5133
5134 // _GLIBCXX_RESOLVE_LIB_DEFECTS
5135 // 438. Ambiguity in the "do the right thing" clause
5136 template<class _Integer>
5137 static _CharT*
5138 _S_construct_aux(_Integer __beg, _Integer __end,
5139 const _Alloc& __a, __true_type)
5140 { return _S_construct_aux_2(static_cast<size_type>(__beg),
5141 __end, __a); }
5142
5143 static _CharT*
5144 _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a)
5145 { return _S_construct(__req, __c, __a); }
5146
5147 template<class _InIterator>
5148 static _CharT*
5149 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
5150 {
5151 typedef typename std::__is_integer<_InIterator>::__type _Integral;
5152 return _S_construct_aux(__beg, __end, __a, _Integral());
5153 }
5154
5155 // For Input Iterators, used in istreambuf_iterators, etc.
5156 template<class _InIterator>
5157 static _CharT*
5158 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
5159 input_iterator_tag);
5160
5161 // For forward_iterators up to random_access_iterators, used for
5162 // string::iterator, _CharT*, etc.
5163 template<class _FwdIterator>
5164 static _CharT*
5165 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
5166 forward_iterator_tag);
5167
5168 static _CharT*
5169 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
5170
5171 public:
5172
5173 /**
5174 * @brief Copy substring into C string.
5175 * @param __s C string to copy value into.
5176 * @param __n Number of characters to copy.
5177 * @param __pos Index of first character to copy.
5178 * @return Number of characters actually copied
5179 * @throw std::out_of_range If __pos > size().
5180 *
5181 * Copies up to @a __n characters starting at @a __pos into the
5182 * C string @a __s. If @a __pos is %greater than size(),
5183 * out_of_range is thrown.
5184 */
5185 size_type
5186 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
5187
5188 /**
5189 * @brief Swap contents with another string.
5190 * @param __s String to swap with.
5191 *
5192 * Exchanges the contents of this string with that of @a __s in constant
5193 * time.
5194 */
5195 void
5196 swap(basic_string& __s)
5197 _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value)noexcept(allocator_traits<_Alloc>::is_always_equal::value
)
;
5198
5199 // String operations:
5200 /**
5201 * @brief Return const pointer to null-terminated contents.
5202 *
5203 * This is a handle to internal data. Do not modify or dire things may
5204 * happen.
5205 */
5206 const _CharT*
5207 c_str() const _GLIBCXX_NOEXCEPTnoexcept
5208 { return _M_data(); }
5209
5210 /**
5211 * @brief Return const pointer to contents.
5212 *
5213 * This is a pointer to internal data. It is undefined to modify
5214 * the contents through the returned pointer. To get a pointer that
5215 * allows modifying the contents use @c &str[0] instead,
5216 * (or in C++17 the non-const @c str.data() overload).
5217 */
5218 const _CharT*
5219 data() const _GLIBCXX_NOEXCEPTnoexcept
5220 { return _M_data(); }
5221
5222#if __cplusplus201703L >= 201703L
5223 /**
5224 * @brief Return non-const pointer to contents.
5225 *
5226 * This is a pointer to the character sequence held by the string.
5227 * Modifying the characters in the sequence is allowed.
5228 */
5229 _CharT*
5230 data() noexcept
5231 {
5232 _M_leak();
5233 return _M_data();
5234 }
5235#endif
5236
5237 /**
5238 * @brief Return copy of allocator used to construct this string.
5239 */
5240 allocator_type
5241 get_allocator() const _GLIBCXX_NOEXCEPTnoexcept
5242 { return _M_dataplus; }
5243
5244 /**
5245 * @brief Find position of a C substring.
5246 * @param __s C string to locate.
5247 * @param __pos Index of character to search from.
5248 * @param __n Number of characters from @a s to search for.
5249 * @return Index of start of first occurrence.
5250 *
5251 * Starting from @a __pos, searches forward for the first @a
5252 * __n characters in @a __s within this string. If found,
5253 * returns the index where it begins. If not found, returns
5254 * npos.
5255 */
5256 size_type
5257 find(const _CharT* __s, size_type __pos, size_type __n) const
5258 _GLIBCXX_NOEXCEPTnoexcept;
5259
5260 /**
5261 * @brief Find position of a string.
5262 * @param __str String to locate.
5263 * @param __pos Index of character to search from (default 0).
5264 * @return Index of start of first occurrence.
5265 *
5266 * Starting from @a __pos, searches forward for value of @a __str within
5267 * this string. If found, returns the index where it begins. If not
5268 * found, returns npos.
5269 */
5270 size_type
5271 find(const basic_string& __str, size_type __pos = 0) const
5272 _GLIBCXX_NOEXCEPTnoexcept
5273 { return this->find(__str.data(), __pos, __str.size()); }
5274
5275 /**
5276 * @brief Find position of a C string.
5277 * @param __s C string to locate.
5278 * @param __pos Index of character to search from (default 0).
5279 * @return Index of start of first occurrence.
5280 *
5281 * Starting from @a __pos, searches forward for the value of @a
5282 * __s within this string. If found, returns the index where
5283 * it begins. If not found, returns npos.
5284 */
5285 size_type
5286 find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept
5287 {
5288 __glibcxx_requires_string(__s);
5289 return this->find(__s, __pos, traits_type::length(__s));
5290 }
5291
5292 /**
5293 * @brief Find position of a character.
5294 * @param __c Character to locate.
5295 * @param __pos Index of character to search from (default 0).
5296 * @return Index of first occurrence.
5297 *
5298 * Starting from @a __pos, searches forward for @a __c within
5299 * this string. If found, returns the index where it was
5300 * found. If not found, returns npos.
5301 */
5302 size_type
5303 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept;
5304
5305#if __cplusplus201703L >= 201703L
5306 /**
5307 * @brief Find position of a string_view.
5308 * @param __svt The object convertible to string_view to locate.
5309 * @param __pos Index of character to search from (default 0).
5310 * @return Index of start of first occurrence.
5311 */
5312 template<typename _Tp>
5313 _If_sv<_Tp, size_type>
5314 find(const _Tp& __svt, size_type __pos = 0) const
5315 noexcept(is_same<_Tp, __sv_type>::value)
5316 {
5317 __sv_type __sv = __svt;
5318 return this->find(__sv.data(), __pos, __sv.size());
5319 }
5320#endif // C++17
5321
5322 /**
5323 * @brief Find last position of a string.
5324 * @param __str String to locate.
5325 * @param __pos Index of character to search back from (default end).
5326 * @return Index of start of last occurrence.
5327 *
5328 * Starting from @a __pos, searches backward for value of @a
5329 * __str within this string. If found, returns the index where
5330 * it begins. If not found, returns npos.
5331 */
5332 size_type
5333 rfind(const basic_string& __str, size_type __pos = npos) const
5334 _GLIBCXX_NOEXCEPTnoexcept
5335 { return this->rfind(__str.data(), __pos, __str.size()); }
5336
5337 /**
5338 * @brief Find last position of a C substring.
5339 * @param __s C string to locate.
5340 * @param __pos Index of character to search back from.
5341 * @param __n Number of characters from s to search for.
5342 * @return Index of start of last occurrence.
5343 *
5344 * Starting from @a __pos, searches backward for the first @a
5345 * __n characters in @a __s within this string. If found,
5346 * returns the index where it begins. If not found, returns
5347 * npos.
5348 */
5349 size_type
5350 rfind(const _CharT* __s, size_type __pos, size_type __n) const
5351 _GLIBCXX_NOEXCEPTnoexcept;
5352
5353 /**
5354 * @brief Find last position of a C string.
5355 * @param __s C string to locate.
5356 * @param __pos Index of character to start search at (default end).
5357 * @return Index of start of last occurrence.
5358 *
5359 * Starting from @a __pos, searches backward for the value of
5360 * @a __s within this string. If found, returns the index
5361 * where it begins. If not found, returns npos.
5362 */
5363 size_type
5364 rfind(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept
5365 {
5366 __glibcxx_requires_string(__s);
5367 return this->rfind(__s, __pos, traits_type::length(__s));
5368 }
5369
5370 /**
5371 * @brief Find last position of a character.
5372 * @param __c Character to locate.
5373 * @param __pos Index of character to search back from (default end).
5374 * @return Index of last occurrence.
5375 *
5376 * Starting from @a __pos, searches backward for @a __c within
5377 * this string. If found, returns the index where it was
5378 * found. If not found, returns npos.
5379 */
5380 size_type
5381 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept;
5382
5383#if __cplusplus201703L >= 201703L
5384 /**
5385 * @brief Find last position of a string_view.
5386 * @param __svt The object convertible to string_view to locate.
5387 * @param __pos Index of character to search back from (default end).
5388 * @return Index of start of last occurrence.
5389 */
5390 template<typename _Tp>
5391 _If_sv<_Tp, size_type>
5392 rfind(const _Tp& __svt, size_type __pos = npos) const
5393 noexcept(is_same<_Tp, __sv_type>::value)
5394 {
5395 __sv_type __sv = __svt;
5396 return this->rfind(__sv.data(), __pos, __sv.size());
5397 }
5398#endif // C++17
5399
5400 /**
5401 * @brief Find position of a character of string.
5402 * @param __str String containing characters to locate.
5403 * @param __pos Index of character to search from (default 0).
5404 * @return Index of first occurrence.
5405 *
5406 * Starting from @a __pos, searches forward for one of the
5407 * characters of @a __str within this string. If found,
5408 * returns the index where it was found. If not found, returns
5409 * npos.
5410 */
5411 size_type
5412 find_first_of(const basic_string& __str, size_type __pos = 0) const
5413 _GLIBCXX_NOEXCEPTnoexcept
5414 { return this->find_first_of(__str.data(), __pos, __str.size()); }
5415
5416 /**
5417 * @brief Find position of a character of C substring.
5418 * @param __s String containing characters to locate.
5419 * @param __pos Index of character to search from.
5420 * @param __n Number of characters from s to search for.
5421 * @return Index of first occurrence.
5422 *
5423 * Starting from @a __pos, searches forward for one of the
5424 * first @a __n characters of @a __s within this string. If
5425 * found, returns the index where it was found. If not found,
5426 * returns npos.
5427 */
5428 size_type
5429 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
5430 _GLIBCXX_NOEXCEPTnoexcept;
5431
5432 /**
5433 * @brief Find position of a character of C string.
5434 * @param __s String containing characters to locate.
5435 * @param __pos Index of character to search from (default 0).
5436 * @return Index of first occurrence.
5437 *
5438 * Starting from @a __pos, searches forward for one of the
5439 * characters of @a __s within this string. If found, returns
5440 * the index where it was found. If not found, returns npos.
5441 */
5442 size_type
5443 find_first_of(const _CharT* __s, size_type __pos = 0) const
5444 _GLIBCXX_NOEXCEPTnoexcept
5445 {
5446 __glibcxx_requires_string(__s);
5447 return this->find_first_of(__s, __pos, traits_type::length(__s));
5448 }
5449
5450 /**
5451 * @brief Find position of a character.
5452 * @param __c Character to locate.
5453 * @param __pos Index of character to search from (default 0).
5454 * @return Index of first occurrence.
5455 *
5456 * Starting from @a __pos, searches forward for the character
5457 * @a __c within this string. If found, returns the index
5458 * where it was found. If not found, returns npos.
5459 *
5460 * Note: equivalent to find(__c, __pos).
5461 */
5462 size_type
5463 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept
5464 { return this->find(__c, __pos); }
5465
5466#if __cplusplus201703L >= 201703L
5467 /**
5468 * @brief Find position of a character of a string_view.
5469 * @param __svt An object convertible to string_view containing
5470 * characters to locate.
5471 * @param __pos Index of character to search from (default 0).
5472 * @return Index of first occurrence.
5473 */
5474 template<typename _Tp>
5475 _If_sv<_Tp, size_type>
5476 find_first_of(const _Tp& __svt, size_type __pos = 0) const
5477 noexcept(is_same<_Tp, __sv_type>::value)
5478 {
5479 __sv_type __sv = __svt;
5480 return this->find_first_of(__sv.data(), __pos, __sv.size());
5481 }
5482#endif // C++17
5483
5484 /**
5485 * @brief Find last position of a character of string.
5486 * @param __str String containing characters to locate.
5487 * @param __pos Index of character to search back from (default end).
5488 * @return Index of last occurrence.
5489 *
5490 * Starting from @a __pos, searches backward for one of the
5491 * characters of @a __str within this string. If found,
5492 * returns the index where it was found. If not found, returns
5493 * npos.
5494 */
5495 size_type
5496 find_last_of(const basic_string& __str, size_type __pos = npos) const
5497 _GLIBCXX_NOEXCEPTnoexcept
5498 { return this->find_last_of(__str.data(), __pos, __str.size()); }
5499
5500 /**
5501 * @brief Find last position of a character of C substring.
5502 * @param __s C string containing characters to locate.
5503 * @param __pos Index of character to search back from.
5504 * @param __n Number of characters from s to search for.
5505 * @return Index of last occurrence.
5506 *
5507 * Starting from @a __pos, searches backward for one of the
5508 * first @a __n characters of @a __s within this string. If
5509 * found, returns the index where it was found. If not found,
5510 * returns npos.
5511 */
5512 size_type
5513 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
5514 _GLIBCXX_NOEXCEPTnoexcept;
5515
5516 /**
5517 * @brief Find last position of a character of C string.
5518 * @param __s C string containing characters to locate.
5519 * @param __pos Index of character to search back from (default end).
5520 * @return Index of last occurrence.
5521 *
5522 * Starting from @a __pos, searches backward for one of the
5523 * characters of @a __s within this string. If found, returns
5524 * the index where it was found. If not found, returns npos.
5525 */
5526 size_type
5527 find_last_of(const _CharT* __s, size_type __pos = npos) const
5528 _GLIBCXX_NOEXCEPTnoexcept
5529 {
5530 __glibcxx_requires_string(__s);
5531 return this->find_last_of(__s, __pos, traits_type::length(__s));
5532 }
5533
5534 /**
5535 * @brief Find last position of a character.
5536 * @param __c Character to locate.
5537 * @param __pos Index of character to search back from (default end).
5538 * @return Index of last occurrence.
5539 *
5540 * Starting from @a __pos, searches backward for @a __c within
5541 * this string. If found, returns the index where it was
5542 * found. If not found, returns npos.
5543 *
5544 * Note: equivalent to rfind(__c, __pos).
5545 */
5546 size_type
5547 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept
5548 { return this->rfind(__c, __pos); }
5549
5550#if __cplusplus201703L >= 201703L
5551 /**
5552 * @brief Find last position of a character of string.
5553 * @param __svt An object convertible to string_view containing
5554 * characters to locate.
5555 * @param __pos Index of character to search back from (default end).
5556 * @return Index of last occurrence.
5557 */
5558 template<typename _Tp>
5559 _If_sv<_Tp, size_type>
5560 find_last_of(const _Tp& __svt, size_type __pos = npos) const
5561 noexcept(is_same<_Tp, __sv_type>::value)
5562 {
5563 __sv_type __sv = __svt;
5564 return this->find_last_of(__sv.data(), __pos, __sv.size());
5565 }
5566#endif // C++17
5567
5568 /**
5569 * @brief Find position of a character not in string.
5570 * @param __str String containing characters to avoid.
5571 * @param __pos Index of character to search from (default 0).
5572 * @return Index of first occurrence.
5573 *
5574 * Starting from @a __pos, searches forward for a character not contained
5575 * in @a __str within this string. If found, returns the index where it
5576 * was found. If not found, returns npos.
5577 */
5578 size_type
5579 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
5580 _GLIBCXX_NOEXCEPTnoexcept
5581 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
5582
5583 /**
5584 * @brief Find position of a character not in C substring.
5585 * @param __s C string containing characters to avoid.
5586 * @param __pos Index of character to search from.
5587 * @param __n Number of characters from __s to consider.
5588 * @return Index of first occurrence.
5589 *
5590 * Starting from @a __pos, searches forward for a character not
5591 * contained in the first @a __n characters of @a __s within
5592 * this string. If found, returns the index where it was
5593 * found. If not found, returns npos.
5594 */
5595 size_type
5596 find_first_not_of(const _CharT* __s, size_type __pos,
5597 size_type __n) const _GLIBCXX_NOEXCEPTnoexcept;
5598
5599 /**
5600 * @brief Find position of a character not in C string.
5601 * @param __s C string containing characters to avoid.
5602 * @param __pos Index of character to search from (default 0).
5603 * @return Index of first occurrence.
5604 *
5605 * Starting from @a __pos, searches forward for a character not
5606 * contained in @a __s within this string. If found, returns
5607 * the index where it was found. If not found, returns npos.
5608 */
5609 size_type
5610 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
5611 _GLIBCXX_NOEXCEPTnoexcept
5612 {
5613 __glibcxx_requires_string(__s);
5614 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
5615 }
5616
5617 /**
5618 * @brief Find position of a different character.
5619 * @param __c Character to avoid.
5620 * @param __pos Index of character to search from (default 0).
5621 * @return Index of first occurrence.
5622 *
5623 * Starting from @a __pos, searches forward for a character
5624 * other than @a __c within this string. If found, returns the
5625 * index where it was found. If not found, returns npos.
5626 */
5627 size_type
5628 find_first_not_of(_CharT __c, size_type __pos = 0) const
5629 _GLIBCXX_NOEXCEPTnoexcept;
5630
5631#if __cplusplus201703L >= 201703L
5632 /**
5633 * @brief Find position of a character not in a string_view.
5634 * @param __svt An object convertible to string_view containing
5635 * characters to avoid.
5636 * @param __pos Index of character to search from (default 0).
5637 * @return Index of first occurrence.
5638 */
5639 template<typename _Tp>
5640 _If_sv<_Tp, size_type>
5641 find_first_not_of(const _Tp& __svt, size_type __pos = 0) const
5642 noexcept(is_same<_Tp, __sv_type>::value)
5643 {
5644 __sv_type __sv = __svt;
5645 return this->find_first_not_of(__sv.data(), __pos, __sv.size());
5646 }
5647#endif // C++17
5648
5649 /**
5650 * @brief Find last position of a character not in string.
5651 * @param __str String containing characters to avoid.
5652 * @param __pos Index of character to search back from (default end).
5653 * @return Index of last occurrence.
5654 *
5655 * Starting from @a __pos, searches backward for a character
5656 * not contained in @a __str within this string. If found,
5657 * returns the index where it was found. If not found, returns
5658 * npos.
5659 */
5660 size_type
5661 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
5662 _GLIBCXX_NOEXCEPTnoexcept
5663 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
5664
5665 /**
5666 * @brief Find last position of a character not in C substring.
5667 * @param __s C string containing characters to avoid.
5668 * @param __pos Index of character to search back from.
5669 * @param __n Number of characters from s to consider.
5670 * @return Index of last occurrence.
5671 *
5672 * Starting from @a __pos, searches backward for a character not
5673 * contained in the first @a __n characters of @a __s within this string.
5674 * If found, returns the index where it was found. If not found,
5675 * returns npos.
5676 */
5677 size_type
5678 find_last_not_of(const _CharT* __s, size_type __pos,
5679 size_type __n) const _GLIBCXX_NOEXCEPTnoexcept;
5680 /**
5681 * @brief Find last position of a character not in C string.
5682 * @param __s C string containing characters to avoid.
5683 * @param __pos Index of character to search back from (default end).
5684 * @return Index of last occurrence.
5685 *
5686 * Starting from @a __pos, searches backward for a character
5687 * not contained in @a __s within this string. If found,
5688 * returns the index where it was found. If not found, returns
5689 * npos.
5690 */
5691 size_type
5692 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
5693 _GLIBCXX_NOEXCEPTnoexcept
5694 {
5695 __glibcxx_requires_string(__s);
5696 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
5697 }
5698
5699 /**
5700 * @brief Find last position of a different character.
5701 * @param __c Character to avoid.
5702 * @param __pos Index of character to search back from (default end).
5703 * @return Index of last occurrence.
5704 *
5705 * Starting from @a __pos, searches backward for a character other than
5706 * @a __c within this string. If found, returns the index where it was
5707 * found. If not found, returns npos.
5708 */
5709 size_type
5710 find_last_not_of(_CharT __c, size_type __pos = npos) const
5711 _GLIBCXX_NOEXCEPTnoexcept;
5712
5713#if __cplusplus201703L >= 201703L
5714 /**
5715 * @brief Find last position of a character not in a string_view.
5716 * @param __svt An object convertible to string_view containing
5717 * characters to avoid.
5718 * @param __pos Index of character to search back from (default end).
5719 * @return Index of last occurrence.
5720 */
5721 template<typename _Tp>
5722 _If_sv<_Tp, size_type>
5723 find_last_not_of(const _Tp& __svt, size_type __pos = npos) const
5724 noexcept(is_same<_Tp, __sv_type>::value)
5725 {
5726 __sv_type __sv = __svt;
5727 return this->find_last_not_of(__sv.data(), __pos, __sv.size());
5728 }
5729#endif // C++17
5730
5731 /**
5732 * @brief Get a substring.
5733 * @param __pos Index of first character (default 0).
5734 * @param __n Number of characters in substring (default remainder).
5735 * @return The new string.
5736 * @throw std::out_of_range If __pos > size().
5737 *
5738 * Construct and return a new string using the @a __n
5739 * characters starting at @a __pos. If the string is too
5740 * short, use the remainder of the characters. If @a __pos is
5741 * beyond the end of the string, out_of_range is thrown.
5742 */
5743 basic_string
5744 substr(size_type __pos = 0, size_type __n = npos) const
5745 { return basic_string(*this,
5746 _M_check(__pos, "basic_string::substr"), __n); }
5747
5748 /**
5749 * @brief Compare to a string.
5750 * @param __str String to compare against.
5751 * @return Integer < 0, 0, or > 0.
5752 *
5753 * Returns an integer < 0 if this string is ordered before @a
5754 * __str, 0 if their values are equivalent, or > 0 if this
5755 * string is ordered after @a __str. Determines the effective
5756 * length rlen of the strings to compare as the smallest of
5757 * size() and str.size(). The function then compares the two
5758 * strings by calling traits::compare(data(), str.data(),rlen).
5759 * If the result of the comparison is nonzero returns it,
5760 * otherwise the shorter one is ordered first.
5761 */
5762 int
5763 compare(const basic_string& __str) const
5764 {
5765 const size_type __size = this->size();
5766 const size_type __osize = __str.size();
5767 const size_type __len = std::min(__size, __osize);
5768
5769 int __r = traits_type::compare(_M_data(), __str.data(), __len);
5770 if (!__r)
5771 __r = _S_compare(__size, __osize);
5772 return __r;
5773 }
5774
5775#if __cplusplus201703L >= 201703L
5776 /**
5777 * @brief Compare to a string_view.
5778 * @param __svt An object convertible to string_view to compare against.
5779 * @return Integer < 0, 0, or > 0.
5780 */
5781 template<typename _Tp>
5782 _If_sv<_Tp, int>
5783 compare(const _Tp& __svt) const
5784 noexcept(is_same<_Tp, __sv_type>::value)
5785 {
5786 __sv_type __sv = __svt;
5787 const size_type __size = this->size();
5788 const size_type __osize = __sv.size();
5789 const size_type __len = std::min(__size, __osize);
5790
5791 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
5792 if (!__r)
5793 __r = _S_compare(__size, __osize);
5794 return __r;
5795 }
5796
5797 /**
5798 * @brief Compare to a string_view.
5799 * @param __pos A position in the string to start comparing from.
5800 * @param __n The number of characters to compare.
5801 * @param __svt An object convertible to string_view to compare
5802 * against.
5803 * @return Integer < 0, 0, or > 0.
5804 */
5805 template<typename _Tp>
5806 _If_sv<_Tp, int>
5807 compare(size_type __pos, size_type __n, const _Tp& __svt) const
5808 noexcept(is_same<_Tp, __sv_type>::value)
5809 {
5810 __sv_type __sv = __svt;
5811 return __sv_type(*this).substr(__pos, __n).compare(__sv);
5812 }
5813
5814 /**
5815 * @brief Compare to a string_view.
5816 * @param __pos1 A position in the string to start comparing from.
5817 * @param __n1 The number of characters to compare.
5818 * @param __svt An object convertible to string_view to compare
5819 * against.
5820 * @param __pos2 A position in the string_view to start comparing from.
5821 * @param __n2 The number of characters to compare.
5822 * @return Integer < 0, 0, or > 0.
5823 */
5824 template<typename _Tp>
5825 _If_sv<_Tp, int>
5826 compare(size_type __pos1, size_type __n1, const _Tp& __svt,
5827 size_type __pos2, size_type __n2 = npos) const
5828 noexcept(is_same<_Tp, __sv_type>::value)
5829 {
5830 __sv_type __sv = __svt;
5831 return __sv_type(*this)
5832 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
5833 }
5834#endif // C++17
5835
5836 /**
5837 * @brief Compare substring to a string.
5838 * @param __pos Index of first character of substring.
5839 * @param __n Number of characters in substring.
5840 * @param __str String to compare against.
5841 * @return Integer < 0, 0, or > 0.
5842 *
5843 * Form the substring of this string from the @a __n characters
5844 * starting at @a __pos. Returns an integer < 0 if the
5845 * substring is ordered before @a __str, 0 if their values are
5846 * equivalent, or > 0 if the substring is ordered after @a
5847 * __str. Determines the effective length rlen of the strings
5848 * to compare as the smallest of the length of the substring
5849 * and @a __str.size(). The function then compares the two
5850 * strings by calling
5851 * traits::compare(substring.data(),str.data(),rlen). If the
5852 * result of the comparison is nonzero returns it, otherwise
5853 * the shorter one is ordered first.
5854 */
5855 int
5856 compare(size_type __pos, size_type __n, const basic_string& __str) const;
5857
5858 /**
5859 * @brief Compare substring to a substring.
5860 * @param __pos1 Index of first character of substring.
5861 * @param __n1 Number of characters in substring.
5862 * @param __str String to compare against.
5863 * @param __pos2 Index of first character of substring of str.
5864 * @param __n2 Number of characters in substring of str.
5865 * @return Integer < 0, 0, or > 0.
5866 *
5867 * Form the substring of this string from the @a __n1
5868 * characters starting at @a __pos1. Form the substring of @a
5869 * __str from the @a __n2 characters starting at @a __pos2.
5870 * Returns an integer < 0 if this substring is ordered before
5871 * the substring of @a __str, 0 if their values are equivalent,
5872 * or > 0 if this substring is ordered after the substring of
5873 * @a __str. Determines the effective length rlen of the
5874 * strings to compare as the smallest of the lengths of the
5875 * substrings. The function then compares the two strings by
5876 * calling
5877 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
5878 * If the result of the comparison is nonzero returns it,
5879 * otherwise the shorter one is ordered first.
5880 */
5881 int
5882 compare(size_type __pos1, size_type __n1, const basic_string& __str,
5883 size_type __pos2, size_type __n2 = npos) const;
5884
5885 /**
5886 * @brief Compare to a C string.
5887 * @param __s C string to compare against.
5888 * @return Integer < 0, 0, or > 0.
5889 *
5890 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
5891 * their values are equivalent, or > 0 if this string is ordered after
5892 * @a __s. Determines the effective length rlen of the strings to
5893 * compare as the smallest of size() and the length of a string
5894 * constructed from @a __s. The function then compares the two strings
5895 * by calling traits::compare(data(),s,rlen). If the result of the
5896 * comparison is nonzero returns it, otherwise the shorter one is
5897 * ordered first.
5898 */
5899 int
5900 compare(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept;
5901
5902 // _GLIBCXX_RESOLVE_LIB_DEFECTS
5903 // 5 String::compare specification questionable
5904 /**
5905 * @brief Compare substring to a C string.
5906 * @param __pos Index of first character of substring.
5907 * @param __n1 Number of characters in substring.
5908 * @param __s C string to compare against.
5909 * @return Integer < 0, 0, or > 0.
5910 *
5911 * Form the substring of this string from the @a __n1
5912 * characters starting at @a pos. Returns an integer < 0 if
5913 * the substring is ordered before @a __s, 0 if their values
5914 * are equivalent, or > 0 if the substring is ordered after @a
5915 * __s. Determines the effective length rlen of the strings to
5916 * compare as the smallest of the length of the substring and
5917 * the length of a string constructed from @a __s. The
5918 * function then compares the two string by calling
5919 * traits::compare(substring.data(),__s,rlen). If the result of
5920 * the comparison is nonzero returns it, otherwise the shorter
5921 * one is ordered first.
5922 */
5923 int
5924 compare(size_type __pos, size_type __n1, const _CharT* __s) const;
5925
5926 /**
5927 * @brief Compare substring against a character %array.
5928 * @param __pos Index of first character of substring.
5929 * @param __n1 Number of characters in substring.
5930 * @param __s character %array to compare against.
5931 * @param __n2 Number of characters of s.
5932 * @return Integer < 0, 0, or > 0.
5933 *
5934 * Form the substring of this string from the @a __n1
5935 * characters starting at @a __pos. Form a string from the
5936 * first @a __n2 characters of @a __s. Returns an integer < 0
5937 * if this substring is ordered before the string from @a __s,
5938 * 0 if their values are equivalent, or > 0 if this substring
5939 * is ordered after the string from @a __s. Determines the
5940 * effective length rlen of the strings to compare as the
5941 * smallest of the length of the substring and @a __n2. The
5942 * function then compares the two strings by calling
5943 * traits::compare(substring.data(),s,rlen). If the result of
5944 * the comparison is nonzero returns it, otherwise the shorter
5945 * one is ordered first.
5946 *
5947 * NB: s must have at least n2 characters, &apos;\\0&apos; has
5948 * no special meaning.
5949 */
5950 int
5951 compare(size_type __pos, size_type __n1, const _CharT* __s,
5952 size_type __n2) const;
5953
5954#if __cplusplus201703L > 201703L
5955 bool
5956 starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
5957 { return __sv_type(this->data(), this->size()).starts_with(__x); }
5958
5959 bool
5960 starts_with(_CharT __x) const noexcept
5961 { return __sv_type(this->data(), this->size()).starts_with(__x); }
5962
5963 bool
5964 starts_with(const _CharT* __x) const noexcept
5965 { return __sv_type(this->data(), this->size()).starts_with(__x); }
5966
5967 bool
5968 ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
5969 { return __sv_type(this->data(), this->size()).ends_with(__x); }
5970
5971 bool
5972 ends_with(_CharT __x) const noexcept
5973 { return __sv_type(this->data(), this->size()).ends_with(__x); }
5974
5975 bool
5976 ends_with(const _CharT* __x) const noexcept
5977 { return __sv_type(this->data(), this->size()).ends_with(__x); }
5978#endif // C++20
5979
5980# ifdef _GLIBCXX_TM_TS_INTERNAL
5981 friend void
5982 ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
5983 void* exc);
5984 friend const char*
5985 ::_txnal_cow_string_c_str(const void *that);
5986 friend void
5987 ::_txnal_cow_string_D1(void *that);
5988 friend void
5989 ::_txnal_cow_string_D1_commit(void *that);
5990# endif
5991 };
5992#endif // !_GLIBCXX_USE_CXX11_ABI
5993
5994#if __cpp_deduction_guides201703L >= 201606
5995_GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 {
5996 template<typename _InputIterator, typename _CharT
5997 = typename iterator_traits<_InputIterator>::value_type,
5998 typename _Allocator = allocator<_CharT>,
5999 typename = _RequireInputIter<_InputIterator>,
6000 typename = _RequireAllocator<_Allocator>>
6001 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
6002 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
6003
6004 // _GLIBCXX_RESOLVE_LIB_DEFECTS
6005 // 3075. basic_string needs deduction guides from basic_string_view
6006 template<typename _CharT, typename _Traits,
6007 typename _Allocator = allocator<_CharT>,
6008 typename = _RequireAllocator<_Allocator>>
6009 basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
6010 -> basic_string<_CharT, _Traits, _Allocator>;
6011
6012 template<typename _CharT, typename _Traits,
6013 typename _Allocator = allocator<_CharT>,
6014 typename = _RequireAllocator<_Allocator>>
6015 basic_string(basic_string_view<_CharT, _Traits>,
6016 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
6017 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
6018 const _Allocator& = _Allocator())
6019 -> basic_string<_CharT, _Traits, _Allocator>;
6020_GLIBCXX_END_NAMESPACE_CXX11}
6021#endif
6022
6023 // operator+
6024 /**
6025 * @brief Concatenate two strings.
6026 * @param __lhs First string.
6027 * @param __rhs Last string.
6028 * @return New string with value of @a __lhs followed by @a __rhs.
6029 */
6030 template<typename _CharT, typename _Traits, typename _Alloc>
6031 basic_string<_CharT, _Traits, _Alloc>
6032 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6033 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6034 {
6035 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
6036 __str.append(__rhs);
6037 return __str;
6038 }
6039
6040 /**
6041 * @brief Concatenate C string and string.
6042 * @param __lhs First string.
6043 * @param __rhs Last string.
6044 * @return New string with value of @a __lhs followed by @a __rhs.
6045 */
6046 template<typename _CharT, typename _Traits, typename _Alloc>
6047 basic_string<_CharT,_Traits,_Alloc>
6048 operator+(const _CharT* __lhs,
6049 const basic_string<_CharT,_Traits,_Alloc>& __rhs);
6050
6051 /**
6052 * @brief Concatenate character and string.
6053 * @param __lhs First string.
6054 * @param __rhs Last string.
6055 * @return New string with @a __lhs followed by @a __rhs.
6056 */
6057 template<typename _CharT, typename _Traits, typename _Alloc>
6058 basic_string<_CharT,_Traits,_Alloc>
6059 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
6060
6061 /**
6062 * @brief Concatenate string and C string.
6063 * @param __lhs First string.
6064 * @param __rhs Last string.
6065 * @return New string with @a __lhs followed by @a __rhs.
6066 */
6067 template<typename _CharT, typename _Traits, typename _Alloc>
6068 inline basic_string<_CharT, _Traits, _Alloc>
6069 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6070 const _CharT* __rhs)
6071 {
6072 basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
6073 __str.append(__rhs);
6074 return __str;
6075 }
6076
6077 /**
6078 * @brief Concatenate string and character.
6079 * @param __lhs First string.
6080 * @param __rhs Last string.
6081 * @return New string with @a __lhs followed by @a __rhs.
6082 */
6083 template<typename _CharT, typename _Traits, typename _Alloc>
6084 inline basic_string<_CharT, _Traits, _Alloc>
6085 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
6086 {
6087 typedef basic_string<_CharT, _Traits, _Alloc> __string_type;
6088 typedef typename __string_type::size_type __size_type;
6089 __string_type __str(__lhs);
6090 __str.append(__size_type(1), __rhs);
6091 return __str;
6092 }
6093
6094#if __cplusplus201703L >= 201103L
6095 template<typename _CharT, typename _Traits, typename _Alloc>
6096 inline basic_string<_CharT, _Traits, _Alloc>
6097 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6098 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6099 { return std::move(__lhs.append(__rhs)); }
6100
6101 template<typename _CharT, typename _Traits, typename _Alloc>
6102 inline basic_string<_CharT, _Traits, _Alloc>
6103 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6104 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6105 { return std::move(__rhs.insert(0, __lhs)); }
6106
6107 template<typename _CharT, typename _Traits, typename _Alloc>
6108 inline basic_string<_CharT, _Traits, _Alloc>
6109 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6110 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6111 {
6112#if _GLIBCXX_USE_CXX11_ABI1
6113 using _Alloc_traits = allocator_traits<_Alloc>;
6114 bool __use_rhs = false;
6115 if _GLIBCXX17_CONSTEXPRconstexpr (typename _Alloc_traits::is_always_equal{})
6116 __use_rhs = true;
6117 else if (__lhs.get_allocator() == __rhs.get_allocator())
6118 __use_rhs = true;
6119 if (__use_rhs)
6120#endif
6121 {
6122 const auto __size = __lhs.size() + __rhs.size();
6123 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
6124 return std::move(__rhs.insert(0, __lhs));
6125 }
6126 return std::move(__lhs.append(__rhs));
6127 }
6128
6129 template<typename _CharT, typename _Traits, typename _Alloc>
6130 inline basic_string<_CharT, _Traits, _Alloc>
6131 operator+(const _CharT* __lhs,
6132 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6133 { return std::move(__rhs.insert(0, __lhs)); }
6134
6135 template<typename _CharT, typename _Traits, typename _Alloc>
6136 inline basic_string<_CharT, _Traits, _Alloc>
6137 operator+(_CharT __lhs,
6138 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
6139 { return std::move(__rhs.insert(0, 1, __lhs)); }
6140
6141 template<typename _CharT, typename _Traits, typename _Alloc>
6142 inline basic_string<_CharT, _Traits, _Alloc>
6143 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6144 const _CharT* __rhs)
6145 { return std::move(__lhs.append(__rhs)); }
6146
6147 template<typename _CharT, typename _Traits, typename _Alloc>
6148 inline basic_string<_CharT, _Traits, _Alloc>
6149 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
6150 _CharT __rhs)
6151 { return std::move(__lhs.append(1, __rhs)); }
6152#endif
6153
6154 // operator ==
6155 /**
6156 * @brief Test equivalence of two strings.
6157 * @param __lhs First string.
6158 * @param __rhs Second string.
6159 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
6160 */
6161 template<typename _CharT, typename _Traits, typename _Alloc>
6162 inline bool
6163 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6164 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6165 _GLIBCXX_NOEXCEPTnoexcept
6166 { return __lhs.compare(__rhs) == 0; }
6167
6168 template<typename _CharT>
6169 inline
6170 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type
6171 operator==(const basic_string<_CharT>& __lhs,
6172 const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPTnoexcept
6173 { return (__lhs.size() == __rhs.size()
6174 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(),
6175 __lhs.size())); }
6176
6177 /**
6178 * @brief Test equivalence of string and C string.
6179 * @param __lhs String.
6180 * @param __rhs C string.
6181 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
6182 */
6183 template<typename _CharT, typename _Traits, typename _Alloc>
6184 inline bool
6185 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6186 const _CharT* __rhs)
6187 { return __lhs.compare(__rhs) == 0; }
6188
6189#if __cpp_lib_three_way_comparison
6190 /**
6191 * @brief Three-way comparison of a string and a C string.
6192 * @param __lhs A string.
6193 * @param __rhs A null-terminated string.
6194 * @return A value indicating whether `__lhs` is less than, equal to,
6195 * greater than, or incomparable with `__rhs`.
6196 */
6197 template<typename _CharT, typename _Traits, typename _Alloc>
6198 inline auto
6199 operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6200 const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept
6201 -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
6202 { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
6203
6204 /**
6205 * @brief Three-way comparison of a string and a C string.
6206 * @param __lhs A string.
6207 * @param __rhs A null-terminated string.
6208 * @return A value indicating whether `__lhs` is less than, equal to,
6209 * greater than, or incomparable with `__rhs`.
6210 */
6211 template<typename _CharT, typename _Traits, typename _Alloc>
6212 inline auto
6213 operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6214 const _CharT* __rhs) noexcept
6215 -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
6216 { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
6217#else
6218 /**
6219 * @brief Test equivalence of C string and string.
6220 * @param __lhs C string.
6221 * @param __rhs String.
6222 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
6223 */
6224 template<typename _CharT, typename _Traits, typename _Alloc>
6225 inline bool
6226 operator==(const _CharT* __lhs,
6227 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6228 { return __rhs.compare(__lhs) == 0; }
6229
6230 // operator !=
6231 /**
6232 * @brief Test difference of two strings.
6233 * @param __lhs First string.
6234 * @param __rhs Second string.
6235 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
6236 */
6237 template<typename _CharT, typename _Traits, typename _Alloc>
6238 inline bool
6239 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6240 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6241 _GLIBCXX_NOEXCEPTnoexcept
6242 { return !(__lhs == __rhs); }
6243
6244 /**
6245 * @brief Test difference of C string and string.
6246 * @param __lhs C string.
6247 * @param __rhs String.
6248 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
6249 */
6250 template<typename _CharT, typename _Traits, typename _Alloc>
6251 inline bool
6252 operator!=(const _CharT* __lhs,
6253 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6254 { return !(__lhs == __rhs); }
6255
6256 /**
6257 * @brief Test difference of string and C string.
6258 * @param __lhs String.
6259 * @param __rhs C string.
6260 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
6261 */
6262 template<typename _CharT, typename _Traits, typename _Alloc>
6263 inline bool
6264 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6265 const _CharT* __rhs)
6266 { return !(__lhs == __rhs); }
6267
6268 // operator <
6269 /**
6270 * @brief Test if string precedes string.
6271 * @param __lhs First string.
6272 * @param __rhs Second string.
6273 * @return True if @a __lhs precedes @a __rhs. False otherwise.
6274 */
6275 template<typename _CharT, typename _Traits, typename _Alloc>
6276 inline bool
6277 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6278 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6279 _GLIBCXX_NOEXCEPTnoexcept
6280 { return __lhs.compare(__rhs) < 0; }
6281
6282 /**
6283 * @brief Test if string precedes C string.
6284 * @param __lhs String.
6285 * @param __rhs C string.
6286 * @return True if @a __lhs precedes @a __rhs. False otherwise.
6287 */
6288 template<typename _CharT, typename _Traits, typename _Alloc>
6289 inline bool
6290 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6291 const _CharT* __rhs)
6292 { return __lhs.compare(__rhs) < 0; }
6293
6294 /**
6295 * @brief Test if C string precedes string.
6296 * @param __lhs C string.
6297 * @param __rhs String.
6298 * @return True if @a __lhs precedes @a __rhs. False otherwise.
6299 */
6300 template<typename _CharT, typename _Traits, typename _Alloc>
6301 inline bool
6302 operator<(const _CharT* __lhs,
6303 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6304 { return __rhs.compare(__lhs) > 0; }
6305
6306 // operator >
6307 /**
6308 * @brief Test if string follows string.
6309 * @param __lhs First string.
6310 * @param __rhs Second string.
6311 * @return True if @a __lhs follows @a __rhs. False otherwise.
6312 */
6313 template<typename _CharT, typename _Traits, typename _Alloc>
6314 inline bool
6315 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6316 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6317 _GLIBCXX_NOEXCEPTnoexcept
6318 { return __lhs.compare(__rhs) > 0; }
6319
6320 /**
6321 * @brief Test if string follows C string.
6322 * @param __lhs String.
6323 * @param __rhs C string.
6324 * @return True if @a __lhs follows @a __rhs. False otherwise.
6325 */
6326 template<typename _CharT, typename _Traits, typename _Alloc>
6327 inline bool
6328 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6329 const _CharT* __rhs)
6330 { return __lhs.compare(__rhs) > 0; }
6331
6332 /**
6333 * @brief Test if C string follows string.
6334 * @param __lhs C string.
6335 * @param __rhs String.
6336 * @return True if @a __lhs follows @a __rhs. False otherwise.
6337 */
6338 template<typename _CharT, typename _Traits, typename _Alloc>
6339 inline bool
6340 operator>(const _CharT* __lhs,
6341 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6342 { return __rhs.compare(__lhs) < 0; }
6343
6344 // operator <=
6345 /**
6346 * @brief Test if string doesn't follow string.
6347 * @param __lhs First string.
6348 * @param __rhs Second string.
6349 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
6350 */
6351 template<typename _CharT, typename _Traits, typename _Alloc>
6352 inline bool
6353 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6354 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6355 _GLIBCXX_NOEXCEPTnoexcept
6356 { return __lhs.compare(__rhs) <= 0; }
6357
6358 /**
6359 * @brief Test if string doesn't follow C string.
6360 * @param __lhs String.
6361 * @param __rhs C string.
6362 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
6363 */
6364 template<typename _CharT, typename _Traits, typename _Alloc>
6365 inline bool
6366 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6367 const _CharT* __rhs)
6368 { return __lhs.compare(__rhs) <= 0; }
6369
6370 /**
6371 * @brief Test if C string doesn't follow string.
6372 * @param __lhs C string.
6373 * @param __rhs String.
6374 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
6375 */
6376 template<typename _CharT, typename _Traits, typename _Alloc>
6377 inline bool
6378 operator<=(const _CharT* __lhs,
6379 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6380 { return __rhs.compare(__lhs) >= 0; }
6381
6382 // operator >=
6383 /**
6384 * @brief Test if string doesn't precede string.
6385 * @param __lhs First string.
6386 * @param __rhs Second string.
6387 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
6388 */
6389 template<typename _CharT, typename _Traits, typename _Alloc>
6390 inline bool
6391 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6392 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6393 _GLIBCXX_NOEXCEPTnoexcept
6394 { return __lhs.compare(__rhs) >= 0; }
6395
6396 /**
6397 * @brief Test if string doesn't precede C string.
6398 * @param __lhs String.
6399 * @param __rhs C string.
6400 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
6401 */
6402 template<typename _CharT, typename _Traits, typename _Alloc>
6403 inline bool
6404 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
6405 const _CharT* __rhs)
6406 { return __lhs.compare(__rhs) >= 0; }
6407
6408 /**
6409 * @brief Test if C string doesn't precede string.
6410 * @param __lhs C string.
6411 * @param __rhs String.
6412 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
6413 */
6414 template<typename _CharT, typename _Traits, typename _Alloc>
6415 inline bool
6416 operator>=(const _CharT* __lhs,
6417 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
6418 { return __rhs.compare(__lhs) <= 0; }
6419#endif // three-way comparison
6420
6421 /**
6422 * @brief Swap contents of two strings.
6423 * @param __lhs First string.
6424 * @param __rhs Second string.
6425 *
6426 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
6427 */
6428 template<typename _CharT, typename _Traits, typename _Alloc>
6429 inline void
6430 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
6431 basic_string<_CharT, _Traits, _Alloc>& __rhs)
6432 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))noexcept(noexcept(__lhs.swap(__rhs)))
6433 { __lhs.swap(__rhs); }
6434
6435
6436 /**
6437 * @brief Read stream into a string.
6438 * @param __is Input stream.
6439 * @param __str Buffer to store into.
6440 * @return Reference to the input stream.
6441 *
6442 * Stores characters from @a __is into @a __str until whitespace is
6443 * found, the end of the stream is encountered, or str.max_size()
6444 * is reached. If is.width() is non-zero, that is the limit on the
6445 * number of characters stored into @a __str. Any previous
6446 * contents of @a __str are erased.
6447 */
6448 template<typename _CharT, typename _Traits, typename _Alloc>
6449 basic_istream<_CharT, _Traits>&
6450 operator>>(basic_istream<_CharT, _Traits>& __is,
6451 basic_string<_CharT, _Traits, _Alloc>& __str);
6452
6453 template<>
6454 basic_istream<char>&
6455 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
6456
6457 /**
6458 * @brief Write string to a stream.
6459 * @param __os Output stream.
6460 * @param __str String to write out.
6461 * @return Reference to the output stream.
6462 *
6463 * Output characters of @a __str into os following the same rules as for
6464 * writing a C string.
6465 */
6466 template<typename _CharT, typename _Traits, typename _Alloc>
6467 inline basic_ostream<_CharT, _Traits>&
6468 operator<<(basic_ostream<_CharT, _Traits>& __os,
6469 const basic_string<_CharT, _Traits, _Alloc>& __str)
6470 {
6471 // _GLIBCXX_RESOLVE_LIB_DEFECTS
6472 // 586. string inserter not a formatted function
6473 return __ostream_insert(__os, __str.data(), __str.size());
6474 }
6475
6476 /**
6477 * @brief Read a line from stream into a string.
6478 * @param __is Input stream.
6479 * @param __str Buffer to store into.
6480 * @param __delim Character marking end of line.
6481 * @return Reference to the input stream.
6482 *
6483 * Stores characters from @a __is into @a __str until @a __delim is
6484 * found, the end of the stream is encountered, or str.max_size()
6485 * is reached. Any previous contents of @a __str are erased. If
6486 * @a __delim is encountered, it is extracted but not stored into
6487 * @a __str.
6488 */
6489 template<typename _CharT, typename _Traits, typename _Alloc>
6490 basic_istream<_CharT, _Traits>&
6491 getline(basic_istream<_CharT, _Traits>& __is,
6492 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
6493
6494 /**
6495 * @brief Read a line from stream into a string.
6496 * @param __is Input stream.
6497 * @param __str Buffer to store into.
6498 * @return Reference to the input stream.
6499 *
6500 * Stores characters from is into @a __str until &apos;\n&apos; is
6501 * found, the end of the stream is encountered, or str.max_size()
6502 * is reached. Any previous contents of @a __str are erased. If
6503 * end of line is encountered, it is extracted but not stored into
6504 * @a __str.
6505 */
6506 template<typename _CharT, typename _Traits, typename _Alloc>
6507 inline basic_istream<_CharT, _Traits>&
6508 getline(basic_istream<_CharT, _Traits>& __is,
6509 basic_string<_CharT, _Traits, _Alloc>& __str)
6510 { return std::getline(__is, __str, __is.widen('\n')); }
6511
6512#if __cplusplus201703L >= 201103L
6513 /// Read a line from an rvalue stream into a string.
6514 template<typename _CharT, typename _Traits, typename _Alloc>
6515 inline basic_istream<_CharT, _Traits>&
6516 getline(basic_istream<_CharT, _Traits>&& __is,
6517 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
6518 { return std::getline(__is, __str, __delim); }
6519
6520 /// Read a line from an rvalue stream into a string.
6521 template<typename _CharT, typename _Traits, typename _Alloc>
6522 inline basic_istream<_CharT, _Traits>&
6523 getline(basic_istream<_CharT, _Traits>&& __is,
6524 basic_string<_CharT, _Traits, _Alloc>& __str)
6525 { return std::getline(__is, __str); }
6526#endif
6527
6528 template<>
6529 basic_istream<char>&
6530 getline(basic_istream<char>& __in, basic_string<char>& __str,
6531 char __delim);
6532
6533#ifdef _GLIBCXX_USE_WCHAR_T1
6534 template<>
6535 basic_istream<wchar_t>&
6536 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
6537 wchar_t __delim);
6538#endif
6539
6540_GLIBCXX_END_NAMESPACE_VERSION
6541} // namespace
6542
6543#if __cplusplus201703L >= 201103L
6544
6545#include <ext/string_conversions.h>
6546#include <bits/charconv.h>
6547
6548namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
6549{
6550_GLIBCXX_BEGIN_NAMESPACE_VERSION
6551_GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 {
6552
6553#if _GLIBCXX_USE_C99_STDLIB1
6554 // 21.4 Numeric Conversions [string.conversions].
6555 inline int
6556 stoi(const string& __str, size_t* __idx = 0, int __base = 10)
6557 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
6558 __idx, __base); }
6559
6560 inline long
6561 stol(const string& __str, size_t* __idx = 0, int __base = 10)
6562 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
6563 __idx, __base); }
6564
6565 inline unsigned long
6566 stoul(const string& __str, size_t* __idx = 0, int __base = 10)
6567 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
6568 __idx, __base); }
6569
6570 inline long long
6571 stoll(const string& __str, size_t* __idx = 0, int __base = 10)
6572 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
6573 __idx, __base); }
6574
6575 inline unsigned long long
6576 stoull(const string& __str, size_t* __idx = 0, int __base = 10)
6577 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
6578 __idx, __base); }
6579
6580 // NB: strtof vs strtod.
6581 inline float
6582 stof(const string& __str, size_t* __idx = 0)
6583 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
6584
6585 inline double
6586 stod(const string& __str, size_t* __idx = 0)
6587 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
6588
6589 inline long double
6590 stold(const string& __str, size_t* __idx = 0)
6591 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
6592#endif // _GLIBCXX_USE_C99_STDLIB
6593
6594 // DR 1261. Insufficent overloads for to_string / to_wstring
6595
6596 inline string
6597 to_string(int __val)
6598 {
6599 const bool __neg = __val < 0;
6600 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
6601 const auto __len = __detail::__to_chars_len(__uval);
6602 string __str(__neg + __len, '-');
6603 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6604 return __str;
6605 }
6606
6607 inline string
6608 to_string(unsigned __val)
6609 {
6610 string __str(__detail::__to_chars_len(__val), '\0');
6611 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6612 return __str;
6613 }
6614
6615 inline string
6616 to_string(long __val)
6617 {
6618 const bool __neg = __val < 0;
6619 const unsigned long __uval = __neg ? (unsigned long)~__val + 1ul : __val;
6620 const auto __len = __detail::__to_chars_len(__uval);
6621 string __str(__neg + __len, '-');
6622 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6623 return __str;
6624 }
6625
6626 inline string
6627 to_string(unsigned long __val)
6628 {
6629 string __str(__detail::__to_chars_len(__val), '\0');
6630 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6631 return __str;
6632 }
6633
6634 inline string
6635 to_string(long long __val)
6636 {
6637 const bool __neg = __val < 0;
6638 const unsigned long long __uval
6639 = __neg ? (unsigned long long)~__val + 1ull : __val;
6640 const auto __len = __detail::__to_chars_len(__uval);
6641 string __str(__neg + __len, '-');
6642 __detail::__to_chars_10_impl(&__str[__neg], __len, __uval);
6643 return __str;
6644 }
6645
6646 inline string
6647 to_string(unsigned long long __val)
6648 {
6649 string __str(__detail::__to_chars_len(__val), '\0');
6650 __detail::__to_chars_10_impl(&__str[0], __str.size(), __val);
6651 return __str;
6652 }
6653
6654#if _GLIBCXX_USE_C99_STDIO1
6655 // NB: (v)snprintf vs sprintf.
6656
6657 inline string
6658 to_string(float __val)
6659 {
6660 const int __n =
6661 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6662 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6663 "%f", __val);
6664 }
6665
6666 inline string
6667 to_string(double __val)
6668 {
6669 const int __n =
6670 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6671 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6672 "%f", __val);
6673 }
6674
6675 inline string
6676 to_string(long double __val)
6677 {
6678 const int __n =
6679 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6680 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
6681 "%Lf", __val);
6682 }
6683#endif // _GLIBCXX_USE_C99_STDIO
6684
6685#if defined(_GLIBCXX_USE_WCHAR_T1) && _GLIBCXX_USE_C99_WCHAR1
6686 inline int
6687 stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
6688 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
6689 __idx, __base); }
6690
6691 inline long
6692 stol(const wstring& __str, size_t* __idx = 0, int __base = 10)
6693 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
6694 __idx, __base); }
6695
6696 inline unsigned long
6697 stoul(const wstring& __str, size_t* __idx = 0, int __base = 10)
6698 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
6699 __idx, __base); }
6700
6701 inline long long
6702 stoll(const wstring& __str, size_t* __idx = 0, int __base = 10)
6703 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
6704 __idx, __base); }
6705
6706 inline unsigned long long
6707 stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
6708 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
6709 __idx, __base); }
6710
6711 // NB: wcstof vs wcstod.
6712 inline float
6713 stof(const wstring& __str, size_t* __idx = 0)
6714 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
6715
6716 inline double
6717 stod(const wstring& __str, size_t* __idx = 0)
6718 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
6719
6720 inline long double
6721 stold(const wstring& __str, size_t* __idx = 0)
6722 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
6723
6724#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6725 // DR 1261.
6726 inline wstring
6727 to_wstring(int __val)
6728 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int),
6729 L"%d", __val); }
6730
6731 inline wstring
6732 to_wstring(unsigned __val)
6733 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6734 4 * sizeof(unsigned),
6735 L"%u", __val); }
6736
6737 inline wstring
6738 to_wstring(long __val)
6739 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long),
6740 L"%ld", __val); }
6741
6742 inline wstring
6743 to_wstring(unsigned long __val)
6744 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6745 4 * sizeof(unsigned long),
6746 L"%lu", __val); }
6747
6748 inline wstring
6749 to_wstring(long long __val)
6750 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6751 4 * sizeof(long long),
6752 L"%lld", __val); }
6753
6754 inline wstring
6755 to_wstring(unsigned long long __val)
6756 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf,
6757 4 * sizeof(unsigned long long),
6758 L"%llu", __val); }
6759
6760 inline wstring
6761 to_wstring(float __val)
6762 {
6763 const int __n =
6764 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
6765 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6766 L"%f", __val);
6767 }
6768
6769 inline wstring
6770 to_wstring(double __val)
6771 {
6772 const int __n =
6773 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
6774 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6775 L"%f", __val);
6776 }
6777
6778 inline wstring
6779 to_wstring(long double __val)
6780 {
6781 const int __n =
6782 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
6783 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n,
6784 L"%Lf", __val);
6785 }
6786#endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF
6787#endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR
6788
6789_GLIBCXX_END_NAMESPACE_CXX11}
6790_GLIBCXX_END_NAMESPACE_VERSION
6791} // namespace
6792
6793#endif /* C++11 */
6794
6795#if __cplusplus201703L >= 201103L
6796
6797#include <bits/functional_hash.h>
6798
6799namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
6800{
6801_GLIBCXX_BEGIN_NAMESPACE_VERSION
6802
6803 // DR 1182.
6804
6805#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
6806 /// std::hash specialization for string.
6807 template<>
6808 struct hash<string>
6809 : public __hash_base<size_t, string>
6810 {
6811 size_t
6812 operator()(const string& __s) const noexcept
6813 { return std::_Hash_impl::hash(__s.data(), __s.length()); }
6814 };
6815
6816 template<>
6817 struct __is_fast_hash<hash<string>> : std::false_type
6818 { };
6819
6820#ifdef _GLIBCXX_USE_WCHAR_T1
6821 /// std::hash specialization for wstring.
6822 template<>
6823 struct hash<wstring>
6824 : public __hash_base<size_t, wstring>
6825 {
6826 size_t
6827 operator()(const wstring& __s) const noexcept
6828 { return std::_Hash_impl::hash(__s.data(),
6829 __s.length() * sizeof(wchar_t)); }
6830 };
6831
6832 template<>
6833 struct __is_fast_hash<hash<wstring>> : std::false_type
6834 { };
6835#endif
6836#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
6837
6838#ifdef _GLIBCXX_USE_CHAR8_T
6839 /// std::hash specialization for u8string.
6840 template<>
6841 struct hash<u8string>
6842 : public __hash_base<size_t, u8string>
6843 {
6844 size_t
6845 operator()(const u8string& __s) const noexcept
6846 { return std::_Hash_impl::hash(__s.data(),
6847 __s.length() * sizeof(char8_t)); }
6848 };
6849
6850 template<>
6851 struct __is_fast_hash<hash<u8string>> : std::false_type
6852 { };
6853#endif
6854
6855 /// std::hash specialization for u16string.
6856 template<>
6857 struct hash<u16string>
6858 : public __hash_base<size_t, u16string>
6859 {
6860 size_t
6861 operator()(const u16string& __s) const noexcept
6862 { return std::_Hash_impl::hash(__s.data(),
6863 __s.length() * sizeof(char16_t)); }
6864 };
6865
6866 template<>
6867 struct __is_fast_hash<hash<u16string>> : std::false_type
6868 { };
6869
6870 /// std::hash specialization for u32string.
6871 template<>
6872 struct hash<u32string>
6873 : public __hash_base<size_t, u32string>
6874 {
6875 size_t
6876 operator()(const u32string& __s) const noexcept
6877 { return std::_Hash_impl::hash(__s.data(),
6878 __s.length() * sizeof(char32_t)); }
6879 };
6880
6881 template<>
6882 struct __is_fast_hash<hash<u32string>> : std::false_type
6883 { };
6884
6885#if __cplusplus201703L >= 201402L
6886
6887#define __cpp_lib_string_udls201304 201304
6888
6889 inline namespace literals
6890 {
6891 inline namespace string_literals
6892 {
6893#pragma GCC diagnostic push
6894#pragma GCC diagnostic ignored "-Wliteral-suffix"
6895 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11")))
6896 inline basic_string<char>
6897 operator""s(const char* __str, size_t __len)
6898 { return basic_string<char>{__str, __len}; }
6899
6900#ifdef _GLIBCXX_USE_WCHAR_T1
6901 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11")))
6902 inline basic_string<wchar_t>
6903 operator""s(const wchar_t* __str, size_t __len)
6904 { return basic_string<wchar_t>{__str, __len}; }
6905#endif
6906
6907#ifdef _GLIBCXX_USE_CHAR8_T
6908 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11")))
6909 inline basic_string<char8_t>
6910 operator""s(const char8_t* __str, size_t __len)
6911 { return basic_string<char8_t>{__str, __len}; }
6912#endif
6913
6914 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11")))
6915 inline basic_string<char16_t>
6916 operator""s(const char16_t* __str, size_t __len)
6917 { return basic_string<char16_t>{__str, __len}; }
6918
6919 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11")))
6920 inline basic_string<char32_t>
6921 operator""s(const char32_t* __str, size_t __len)
6922 { return basic_string<char32_t>{__str, __len}; }
6923
6924#pragma GCC diagnostic pop
6925 } // inline namespace string_literals
6926 } // inline namespace literals
6927
6928#if __cplusplus201703L >= 201703L
6929 namespace __detail::__variant
6930 {
6931 template<typename> struct _Never_valueless_alt; // see <variant>
6932
6933 // Provide the strong exception-safety guarantee when emplacing a
6934 // basic_string into a variant, but only if moving the string cannot throw.
6935 template<typename _Tp, typename _Traits, typename _Alloc>
6936 struct _Never_valueless_alt<std::basic_string<_Tp, _Traits, _Alloc>>
6937 : __and_<
6938 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
6939 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
6940 >::type
6941 { };
6942 } // namespace __detail::__variant
6943#endif // C++17
6944#endif // C++14
6945
6946_GLIBCXX_END_NAMESPACE_VERSION
6947} // namespace std
6948
6949#endif // C++11
6950
6951#endif /* _BASIC_STRING_H */