/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/ASTMatchers/ASTMatchers.h
Line | Count | Source (jump to first uncovered line) |
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 <string> |
94 | | #include <utility> |
95 | | #include <vector> |
96 | | |
97 | | namespace clang { |
98 | | namespace ast_matchers { |
99 | | |
100 | | /// Maps string IDs to AST nodes matched by parts of a matcher. |
101 | | /// |
102 | | /// The bound nodes are generated by calling \c bind("id") on the node matchers |
103 | | /// of the nodes we want to access later. |
104 | | /// |
105 | | /// The instances of BoundNodes are created by \c MatchFinder when the user's |
106 | | /// callbacks are executed every time a match is found. |
107 | | class BoundNodes { |
108 | | public: |
109 | | /// Returns the AST node bound to \c ID. |
110 | | /// |
111 | | /// Returns NULL if there was no node bound to \c ID or if there is a node but |
112 | | /// it cannot be converted to the specified type. |
113 | | template <typename T> |
114 | 13.7k | const T *getNodeAs(StringRef ID) const { |
115 | 13.7k | return MyBoundNodes.getNodeAs<T>(ID); |
116 | 13.7k | } clang::CXXDeleteExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::CXXDeleteExpr>(llvm::StringRef) const Line | Count | Source | 114 | 43 | const T *getNodeAs(StringRef ID) const { | 115 | 43 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 43 | } |
clang::CallExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::CallExpr>(llvm::StringRef) const Line | Count | Source | 114 | 166 | const T *getNodeAs(StringRef ID) const { | 115 | 166 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 166 | } |
clang::Decl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::Decl>(llvm::StringRef) const Line | Count | Source | 114 | 1.72k | const T *getNodeAs(StringRef ID) const { | 115 | 1.72k | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 1.72k | } |
clang::QualType const* clang::ast_matchers::BoundNodes::getNodeAs<clang::QualType>(llvm::StringRef) const Line | Count | Source | 114 | 461 | const T *getNodeAs(StringRef ID) const { | 115 | 461 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 461 | } |
clang::ParmVarDecl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::ParmVarDecl>(llvm::StringRef) const Line | Count | Source | 114 | 82 | const T *getNodeAs(StringRef ID) const { | 115 | 82 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 82 | } |
clang::Expr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::Expr>(llvm::StringRef) const Line | Count | Source | 114 | 1.40k | const T *getNodeAs(StringRef ID) const { | 115 | 1.40k | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 1.40k | } |
clang::ObjCMethodDecl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::ObjCMethodDecl>(llvm::StringRef) const Line | Count | Source | 114 | 27 | const T *getNodeAs(StringRef ID) const { | 115 | 27 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 27 | } |
clang::ObjCAutoreleasePoolStmt const* clang::ast_matchers::BoundNodes::getNodeAs<clang::ObjCAutoreleasePoolStmt>(llvm::StringRef) const Line | Count | Source | 114 | 43 | const T *getNodeAs(StringRef ID) const { | 115 | 43 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 43 | } |
clang::CastExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::CastExpr>(llvm::StringRef) const Line | Count | Source | 114 | 2 | const T *getNodeAs(StringRef ID) const { | 115 | 2 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 2 | } |
clang::CXXRecordDecl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::CXXRecordDecl>(llvm::StringRef) const Line | Count | Source | 114 | 918 | const T *getNodeAs(StringRef ID) const { | 115 | 918 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 918 | } |
clang::Stmt const* clang::ast_matchers::BoundNodes::getNodeAs<clang::Stmt>(llvm::StringRef) const Line | Count | Source | 114 | 3.36k | const T *getNodeAs(StringRef ID) const { | 115 | 3.36k | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 3.36k | } |
clang::ObjCMessageExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::ObjCMessageExpr>(llvm::StringRef) const Line | Count | Source | 114 | 20 | const T *getNodeAs(StringRef ID) const { | 115 | 20 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 20 | } |
clang::MemberExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::MemberExpr>(llvm::StringRef) const Line | Count | Source | 114 | 19 | const T *getNodeAs(StringRef ID) const { | 115 | 19 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 19 | } |
clang::ObjCIvarRefExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::ObjCIvarRefExpr>(llvm::StringRef) const Line | Count | Source | 114 | 2 | const T *getNodeAs(StringRef ID) const { | 115 | 2 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 2 | } |
clang::DeclRefExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::DeclRefExpr>(llvm::StringRef) const Line | Count | Source | 114 | 200 | const T *getNodeAs(StringRef ID) const { | 115 | 200 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 200 | } |
clang::IntegerLiteral const* clang::ast_matchers::BoundNodes::getNodeAs<clang::IntegerLiteral>(llvm::StringRef) const Line | Count | Source | 114 | 257 | const T *getNodeAs(StringRef ID) const { | 115 | 257 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 257 | } |
clang::BinaryOperator const* clang::ast_matchers::BoundNodes::getNodeAs<clang::BinaryOperator>(llvm::StringRef) const Line | Count | Source | 114 | 120 | const T *getNodeAs(StringRef ID) const { | 115 | 120 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 120 | } |
clang::VarDecl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::VarDecl>(llvm::StringRef) const Line | Count | Source | 114 | 1.32k | const T *getNodeAs(StringRef ID) const { | 115 | 1.32k | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 1.32k | } |
clang::NamedDecl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::NamedDecl>(llvm::StringRef) const Line | Count | Source | 114 | 1.21k | const T *getNodeAs(StringRef ID) const { | 115 | 1.21k | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 1.21k | } |
clang::FunctionDecl const* clang::ast_matchers::BoundNodes::getNodeAs<clang::FunctionDecl>(llvm::StringRef) const Line | Count | Source | 114 | 2.16k | const T *getNodeAs(StringRef ID) const { | 115 | 2.16k | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 2.16k | } |
clang::CXXMemberCallExpr const* clang::ast_matchers::BoundNodes::getNodeAs<clang::CXXMemberCallExpr>(llvm::StringRef) const Line | Count | Source | 114 | 90 | const T *getNodeAs(StringRef ID) const { | 115 | 90 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 90 | } |
clang::IfStmt const* clang::ast_matchers::BoundNodes::getNodeAs<clang::IfStmt>(llvm::StringRef) const Line | Count | Source | 114 | 138 | const T *getNodeAs(StringRef ID) const { | 115 | 138 | return MyBoundNodes.getNodeAs<T>(ID); | 116 | 138 | } |
|
117 | | |
118 | | /// Type of mapping from binding identifiers to bound nodes. This type |
119 | | /// is an associative container with a key type of \c std::string and a value |
120 | | /// type of \c clang::DynTypedNode |
121 | | using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap; |
122 | | |
123 | | /// Retrieve mapping from binding identifiers to bound nodes. |
124 | 4.32k | const IDToNodeMap &getMap() const { |
125 | 4.32k | return MyBoundNodes.getMap(); |
126 | 4.32k | } |
127 | | |
128 | | private: |
129 | | friend class internal::BoundNodesTreeBuilder; |
130 | | |
131 | | /// Create BoundNodes from a pre-filled map of bindings. |
132 | | BoundNodes(internal::BoundNodesMap &MyBoundNodes) |
133 | 40.2k | : MyBoundNodes(MyBoundNodes) {} |
134 | | |
135 | | internal::BoundNodesMap MyBoundNodes; |
136 | | }; |
137 | | |
138 | | /// Types of matchers for the top-level classes in the AST class |
139 | | /// hierarchy. |
140 | | /// @{ |
141 | | using DeclarationMatcher = internal::Matcher<Decl>; |
142 | | using StatementMatcher = internal::Matcher<Stmt>; |
143 | | using TypeMatcher = internal::Matcher<QualType>; |
144 | | using TypeLocMatcher = internal::Matcher<TypeLoc>; |
145 | | using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>; |
146 | | using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>; |
147 | | using CXXBaseSpecifierMatcher = internal::Matcher<CXXBaseSpecifier>; |
148 | | using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>; |
149 | | using TemplateArgumentMatcher = internal::Matcher<TemplateArgument>; |
150 | | using TemplateArgumentLocMatcher = internal::Matcher<TemplateArgumentLoc>; |
151 | | using LambdaCaptureMatcher = internal::Matcher<LambdaCapture>; |
152 | | using AttrMatcher = internal::Matcher<Attr>; |
153 | | /// @} |
154 | | |
155 | | /// Matches any node. |
156 | | /// |
157 | | /// Useful when another matcher requires a child matcher, but there's no |
158 | | /// additional constraint. This will often be used with an explicit conversion |
159 | | /// to an \c internal::Matcher<> type such as \c TypeMatcher. |
160 | | /// |
161 | | /// Example: \c DeclarationMatcher(anything()) matches all declarations, e.g., |
162 | | /// \code |
163 | | /// "int* p" and "void f()" in |
164 | | /// int* p; |
165 | | /// void f(); |
166 | | /// \endcode |
167 | | /// |
168 | | /// Usable as: Any Matcher |
169 | 399 | inline internal::TrueMatcher anything() { return internal::TrueMatcher(); } |
170 | | |
171 | | /// Matches the top declaration context. |
172 | | /// |
173 | | /// Given |
174 | | /// \code |
175 | | /// int X; |
176 | | /// namespace NS { |
177 | | /// int Y; |
178 | | /// } // namespace NS |
179 | | /// \endcode |
180 | | /// decl(hasDeclContext(translationUnitDecl())) |
181 | | /// matches "int X", but not "int Y". |
182 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl> |
183 | | translationUnitDecl; |
184 | | |
185 | | /// Matches typedef declarations. |
186 | | /// |
187 | | /// Given |
188 | | /// \code |
189 | | /// typedef int X; |
190 | | /// using Y = int; |
191 | | /// \endcode |
192 | | /// typedefDecl() |
193 | | /// matches "typedef int X", but not "using Y = int" |
194 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> |
195 | | typedefDecl; |
196 | | |
197 | | /// Matches typedef name declarations. |
198 | | /// |
199 | | /// Given |
200 | | /// \code |
201 | | /// typedef int X; |
202 | | /// using Y = int; |
203 | | /// \endcode |
204 | | /// typedefNameDecl() |
205 | | /// matches "typedef int X" and "using Y = int" |
206 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl> |
207 | | typedefNameDecl; |
208 | | |
209 | | /// Matches type alias declarations. |
210 | | /// |
211 | | /// Given |
212 | | /// \code |
213 | | /// typedef int X; |
214 | | /// using Y = int; |
215 | | /// \endcode |
216 | | /// typeAliasDecl() |
217 | | /// matches "using Y = int", but not "typedef int X" |
218 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> |
219 | | typeAliasDecl; |
220 | | |
221 | | /// Matches type alias template declarations. |
222 | | /// |
223 | | /// typeAliasTemplateDecl() matches |
224 | | /// \code |
225 | | /// template <typename T> |
226 | | /// using Y = X<T>; |
227 | | /// \endcode |
228 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl> |
229 | | typeAliasTemplateDecl; |
230 | | |
231 | | /// Matches AST nodes that were expanded within the main-file. |
232 | | /// |
233 | | /// Example matches X but not Y |
234 | | /// (matcher = cxxRecordDecl(isExpansionInMainFile()) |
235 | | /// \code |
236 | | /// #include <Y.h> |
237 | | /// class X {}; |
238 | | /// \endcode |
239 | | /// Y.h: |
240 | | /// \code |
241 | | /// class Y {}; |
242 | | /// \endcode |
243 | | /// |
244 | | /// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc> |
245 | | AST_POLYMORPHIC_MATCHER(isExpansionInMainFile, |
246 | 0 | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) { |
247 | 0 | auto &SourceManager = Finder->getASTContext().getSourceManager(); |
248 | 0 | return SourceManager.isInMainFile( |
249 | 0 | SourceManager.getExpansionLoc(Node.getBeginLoc())); |
250 | 0 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInMainFileMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInMainFileMatcher<clang::Stmt>::matches(clang::Stmt const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInMainFileMatcher<clang::TypeLoc>::matches(clang::TypeLoc const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const |
251 | | |
252 | | /// Matches AST nodes that were expanded within system-header-files. |
253 | | /// |
254 | | /// Example matches Y but not X |
255 | | /// (matcher = cxxRecordDecl(isExpansionInSystemHeader()) |
256 | | /// \code |
257 | | /// #include <SystemHeader.h> |
258 | | /// class X {}; |
259 | | /// \endcode |
260 | | /// SystemHeader.h: |
261 | | /// \code |
262 | | /// class Y {}; |
263 | | /// \endcode |
264 | | /// |
265 | | /// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc> |
266 | | AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader, |
267 | 0 | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) { |
268 | 0 | auto &SourceManager = Finder->getASTContext().getSourceManager(); |
269 | 0 | auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc()); |
270 | 0 | if (ExpansionLoc.isInvalid()) { |
271 | 0 | return false; |
272 | 0 | } |
273 | 0 | return SourceManager.isInSystemHeader(ExpansionLoc); |
274 | 0 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInSystemHeaderMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInSystemHeaderMatcher<clang::Stmt>::matches(clang::Stmt const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInSystemHeaderMatcher<clang::TypeLoc>::matches(clang::TypeLoc const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const |
275 | | |
276 | | /// Matches AST nodes that were expanded within files whose name is |
277 | | /// partially matching a given regex. |
278 | | /// |
279 | | /// Example matches Y but not X |
280 | | /// (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) |
281 | | /// \code |
282 | | /// #include "ASTMatcher.h" |
283 | | /// class X {}; |
284 | | /// \endcode |
285 | | /// ASTMatcher.h: |
286 | | /// \code |
287 | | /// class Y {}; |
288 | | /// \endcode |
289 | | /// |
290 | | /// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc> |
291 | | AST_POLYMORPHIC_MATCHER_REGEX(isExpansionInFileMatching, |
292 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, |
293 | | TypeLoc), |
294 | 0 | RegExp) { |
295 | 0 | auto &SourceManager = Finder->getASTContext().getSourceManager(); |
296 | 0 | auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc()); |
297 | 0 | if (ExpansionLoc.isInvalid()) { |
298 | 0 | return false; |
299 | 0 | } |
300 | 0 | auto FileEntry = |
301 | 0 | SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc)); |
302 | 0 | if (!FileEntry) { |
303 | 0 | return false; |
304 | 0 | } |
305 | | |
306 | 0 | auto Filename = FileEntry->getName(); |
307 | 0 | return RegExp->match(Filename); |
308 | 0 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInFileMatching0Matcher<clang::Decl, std::__1::shared_ptr<llvm::Regex> >::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInFileMatching0Matcher<clang::Stmt, std::__1::shared_ptr<llvm::Regex> >::matches(clang::Stmt const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpansionInFileMatching0Matcher<clang::TypeLoc, std::__1::shared_ptr<llvm::Regex> >::matches(clang::TypeLoc const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const |
309 | | |
310 | | /// Matches statements that are (transitively) expanded from the named macro. |
311 | | /// Does not match if only part of the statement is expanded from that macro or |
312 | | /// if different parts of the statement are expanded from different |
313 | | /// appearances of the macro. |
314 | | AST_POLYMORPHIC_MATCHER_P(isExpandedFromMacro, |
315 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc), |
316 | 68 | std::string, MacroName) { |
317 | | // Verifies that the statement' beginning and ending are both expanded from |
318 | | // the same instance of the given macro. |
319 | 68 | auto& Context = Finder->getASTContext(); |
320 | 68 | llvm::Optional<SourceLocation> B = |
321 | 68 | internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); |
322 | 68 | if (!B) return false14 ; |
323 | 54 | llvm::Optional<SourceLocation> E = |
324 | 54 | internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); |
325 | 54 | if (!E) return false0 ; |
326 | 54 | return *B == *E; |
327 | 54 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpandedFromMacro0Matcher<clang::Decl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Unexecuted instantiation: clang::ast_matchers::internal::matcher_isExpandedFromMacro0Matcher<clang::Stmt, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::Stmt const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_isExpandedFromMacro0Matcher<clang::TypeLoc, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::TypeLoc const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 316 | 12 | std::string, MacroName) { | 317 | | // Verifies that the statement' beginning and ending are both expanded from | 318 | | // the same instance of the given macro. | 319 | 12 | auto& Context = Finder->getASTContext(); | 320 | 12 | llvm::Optional<SourceLocation> B = | 321 | 12 | internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); | 322 | 12 | if (!B) return false10 ; | 323 | 2 | llvm::Optional<SourceLocation> E = | 324 | 2 | internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); | 325 | 2 | if (!E) return false0 ; | 326 | 2 | return *B == *E; | 327 | 2 | } |
clang::ast_matchers::internal::matcher_isExpandedFromMacro0Matcher<clang::CallExpr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::CallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 316 | 20 | std::string, MacroName) { | 317 | | // Verifies that the statement' beginning and ending are both expanded from | 318 | | // the same instance of the given macro. | 319 | 20 | auto& Context = Finder->getASTContext(); | 320 | 20 | llvm::Optional<SourceLocation> B = | 321 | 20 | internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); | 322 | 20 | if (!B) return false4 ; | 323 | 16 | llvm::Optional<SourceLocation> E = | 324 | 16 | internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); | 325 | 16 | if (!E) return false0 ; | 326 | 16 | return *B == *E; | 327 | 16 | } |
clang::ast_matchers::internal::matcher_isExpandedFromMacro0Matcher<clang::CXXOperatorCallExpr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::CXXOperatorCallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 316 | 4 | std::string, MacroName) { | 317 | | // Verifies that the statement' beginning and ending are both expanded from | 318 | | // the same instance of the given macro. | 319 | 4 | auto& Context = Finder->getASTContext(); | 320 | 4 | llvm::Optional<SourceLocation> B = | 321 | 4 | internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); | 322 | 4 | if (!B) return false0 ; | 323 | 4 | llvm::Optional<SourceLocation> E = | 324 | 4 | internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); | 325 | 4 | if (!E) return false0 ; | 326 | 4 | return *B == *E; | 327 | 4 | } |
clang::ast_matchers::internal::matcher_isExpandedFromMacro0Matcher<clang::CXXMemberCallExpr, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::CXXMemberCallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 316 | 32 | std::string, MacroName) { | 317 | | // Verifies that the statement' beginning and ending are both expanded from | 318 | | // the same instance of the given macro. | 319 | 32 | auto& Context = Finder->getASTContext(); | 320 | 32 | llvm::Optional<SourceLocation> B = | 321 | 32 | internal::getExpansionLocOfMacro(MacroName, Node.getBeginLoc(), Context); | 322 | 32 | if (!B) return false0 ; | 323 | 32 | llvm::Optional<SourceLocation> E = | 324 | 32 | internal::getExpansionLocOfMacro(MacroName, Node.getEndLoc(), Context); | 325 | 32 | if (!E) return false0 ; | 326 | 32 | return *B == *E; | 327 | 32 | } |
|
328 | | |
329 | | /// Matches declarations. |
330 | | /// |
331 | | /// Examples matches \c X, \c C, and the friend declaration inside \c C; |
332 | | /// \code |
333 | | /// void X(); |
334 | | /// class C { |
335 | | /// friend X; |
336 | | /// }; |
337 | | /// \endcode |
338 | | extern const internal::VariadicAllOfMatcher<Decl> decl; |
339 | | |
340 | | /// Matches decomposition-declarations. |
341 | | /// |
342 | | /// Examples matches the declaration node with \c foo and \c bar, but not |
343 | | /// \c number. |
344 | | /// (matcher = declStmt(has(decompositionDecl()))) |
345 | | /// |
346 | | /// \code |
347 | | /// int number = 42; |
348 | | /// auto [foo, bar] = std::make_pair{42, 42}; |
349 | | /// \endcode |
350 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, DecompositionDecl> |
351 | | decompositionDecl; |
352 | | |
353 | | /// Matches binding declarations |
354 | | /// Example matches \c foo and \c bar |
355 | | /// (matcher = bindingDecl() |
356 | | /// |
357 | | /// \code |
358 | | /// auto [foo, bar] = std::make_pair{42, 42}; |
359 | | /// \endcode |
360 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, BindingDecl> |
361 | | bindingDecl; |
362 | | |
363 | | /// Matches a declaration of a linkage specification. |
364 | | /// |
365 | | /// Given |
366 | | /// \code |
367 | | /// extern "C" {} |
368 | | /// \endcode |
369 | | /// linkageSpecDecl() |
370 | | /// matches "extern "C" {}" |
371 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl> |
372 | | linkageSpecDecl; |
373 | | |
374 | | /// Matches a declaration of anything that could have a name. |
375 | | /// |
376 | | /// Example matches \c X, \c S, the anonymous union type, \c i, and \c U; |
377 | | /// \code |
378 | | /// typedef int X; |
379 | | /// struct S { |
380 | | /// union { |
381 | | /// int i; |
382 | | /// } U; |
383 | | /// }; |
384 | | /// \endcode |
385 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl; |
386 | | |
387 | | /// Matches a declaration of label. |
388 | | /// |
389 | | /// Given |
390 | | /// \code |
391 | | /// goto FOO; |
392 | | /// FOO: bar(); |
393 | | /// \endcode |
394 | | /// labelDecl() |
395 | | /// matches 'FOO:' |
396 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl; |
397 | | |
398 | | /// Matches a declaration of a namespace. |
399 | | /// |
400 | | /// Given |
401 | | /// \code |
402 | | /// namespace {} |
403 | | /// namespace test {} |
404 | | /// \endcode |
405 | | /// namespaceDecl() |
406 | | /// matches "namespace {}" and "namespace test {}" |
407 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> |
408 | | namespaceDecl; |
409 | | |
410 | | /// Matches a declaration of a namespace alias. |
411 | | /// |
412 | | /// Given |
413 | | /// \code |
414 | | /// namespace test {} |
415 | | /// namespace alias = ::test; |
416 | | /// \endcode |
417 | | /// namespaceAliasDecl() |
418 | | /// matches "namespace alias" but not "namespace test" |
419 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl> |
420 | | namespaceAliasDecl; |
421 | | |
422 | | /// Matches class, struct, and union declarations. |
423 | | /// |
424 | | /// Example matches \c X, \c Z, \c U, and \c S |
425 | | /// \code |
426 | | /// class X; |
427 | | /// template<class T> class Z {}; |
428 | | /// struct S {}; |
429 | | /// union U {}; |
430 | | /// \endcode |
431 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl; |
432 | | |
433 | | /// Matches C++ class declarations. |
434 | | /// |
435 | | /// Example matches \c X, \c Z |
436 | | /// \code |
437 | | /// class X; |
438 | | /// template<class T> class Z {}; |
439 | | /// \endcode |
440 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> |
441 | | cxxRecordDecl; |
442 | | |
443 | | /// Matches C++ class template declarations. |
444 | | /// |
445 | | /// Example matches \c Z |
446 | | /// \code |
447 | | /// template<class T> class Z {}; |
448 | | /// \endcode |
449 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl> |
450 | | classTemplateDecl; |
451 | | |
452 | | /// Matches C++ class template specializations. |
453 | | /// |
454 | | /// Given |
455 | | /// \code |
456 | | /// template<typename T> class A {}; |
457 | | /// template<> class A<double> {}; |
458 | | /// A<int> a; |
459 | | /// \endcode |
460 | | /// classTemplateSpecializationDecl() |
461 | | /// matches the specializations \c A<int> and \c A<double> |
462 | | extern const internal::VariadicDynCastAllOfMatcher< |
463 | | Decl, ClassTemplateSpecializationDecl> |
464 | | classTemplateSpecializationDecl; |
465 | | |
466 | | /// Matches C++ class template partial specializations. |
467 | | /// |
468 | | /// Given |
469 | | /// \code |
470 | | /// template<class T1, class T2, int I> |
471 | | /// class A {}; |
472 | | /// |
473 | | /// template<class T, int I> |
474 | | /// class A<T, T*, I> {}; |
475 | | /// |
476 | | /// template<> |
477 | | /// class A<int, int, 1> {}; |
478 | | /// \endcode |
479 | | /// classTemplatePartialSpecializationDecl() |
480 | | /// matches the specialization \c A<T,T*,I> but not \c A<int,int,1> |
481 | | extern const internal::VariadicDynCastAllOfMatcher< |
482 | | Decl, ClassTemplatePartialSpecializationDecl> |
483 | | classTemplatePartialSpecializationDecl; |
484 | | |
485 | | /// Matches declarator declarations (field, variable, function |
486 | | /// and non-type template parameter declarations). |
487 | | /// |
488 | | /// Given |
489 | | /// \code |
490 | | /// class X { int y; }; |
491 | | /// \endcode |
492 | | /// declaratorDecl() |
493 | | /// matches \c int y. |
494 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl> |
495 | | declaratorDecl; |
496 | | |
497 | | /// Matches parameter variable declarations. |
498 | | /// |
499 | | /// Given |
500 | | /// \code |
501 | | /// void f(int x); |
502 | | /// \endcode |
503 | | /// parmVarDecl() |
504 | | /// matches \c int x. |
505 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> |
506 | | parmVarDecl; |
507 | | |
508 | | /// Matches C++ access specifier declarations. |
509 | | /// |
510 | | /// Given |
511 | | /// \code |
512 | | /// class C { |
513 | | /// public: |
514 | | /// int a; |
515 | | /// }; |
516 | | /// \endcode |
517 | | /// accessSpecDecl() |
518 | | /// matches 'public:' |
519 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl> |
520 | | accessSpecDecl; |
521 | | |
522 | | /// Matches class bases. |
523 | | /// |
524 | | /// Examples matches \c public virtual B. |
525 | | /// \code |
526 | | /// class B {}; |
527 | | /// class C : public virtual B {}; |
528 | | /// \endcode |
529 | | extern const internal::VariadicAllOfMatcher<CXXBaseSpecifier> cxxBaseSpecifier; |
530 | | |
531 | | /// Matches constructor initializers. |
532 | | /// |
533 | | /// Examples matches \c i(42). |
534 | | /// \code |
535 | | /// class C { |
536 | | /// C() : i(42) {} |
537 | | /// int i; |
538 | | /// }; |
539 | | /// \endcode |
540 | | extern const internal::VariadicAllOfMatcher<CXXCtorInitializer> |
541 | | cxxCtorInitializer; |
542 | | |
543 | | /// Matches template arguments. |
544 | | /// |
545 | | /// Given |
546 | | /// \code |
547 | | /// template <typename T> struct C {}; |
548 | | /// C<int> c; |
549 | | /// \endcode |
550 | | /// templateArgument() |
551 | | /// matches 'int' in C<int>. |
552 | | extern const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument; |
553 | | |
554 | | /// Matches template arguments (with location info). |
555 | | /// |
556 | | /// Given |
557 | | /// \code |
558 | | /// template <typename T> struct C {}; |
559 | | /// C<int> c; |
560 | | /// \endcode |
561 | | /// templateArgumentLoc() |
562 | | /// matches 'int' in C<int>. |
563 | | extern const internal::VariadicAllOfMatcher<TemplateArgumentLoc> |
564 | | templateArgumentLoc; |
565 | | |
566 | | /// Matches template name. |
567 | | /// |
568 | | /// Given |
569 | | /// \code |
570 | | /// template <typename T> class X { }; |
571 | | /// X<int> xi; |
572 | | /// \endcode |
573 | | /// templateName() |
574 | | /// matches 'X' in X<int>. |
575 | | extern const internal::VariadicAllOfMatcher<TemplateName> templateName; |
576 | | |
577 | | /// Matches non-type template parameter declarations. |
578 | | /// |
579 | | /// Given |
580 | | /// \code |
581 | | /// template <typename T, int N> struct C {}; |
582 | | /// \endcode |
583 | | /// nonTypeTemplateParmDecl() |
584 | | /// matches 'N', but not 'T'. |
585 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, |
586 | | NonTypeTemplateParmDecl> |
587 | | nonTypeTemplateParmDecl; |
588 | | |
589 | | /// Matches template type parameter declarations. |
590 | | /// |
591 | | /// Given |
592 | | /// \code |
593 | | /// template <typename T, int N> struct C {}; |
594 | | /// \endcode |
595 | | /// templateTypeParmDecl() |
596 | | /// matches 'T', but not 'N'. |
597 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl> |
598 | | templateTypeParmDecl; |
599 | | |
600 | | /// Matches template template parameter declarations. |
601 | | /// |
602 | | /// Given |
603 | | /// \code |
604 | | /// template <template <typename> class Z, int N> struct C {}; |
605 | | /// \endcode |
606 | | /// templateTypeParmDecl() |
607 | | /// matches 'Z', but not 'N'. |
608 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, |
609 | | TemplateTemplateParmDecl> |
610 | | templateTemplateParmDecl; |
611 | | |
612 | | /// Matches public C++ declarations and C++ base specifers that specify public |
613 | | /// inheritance. |
614 | | /// |
615 | | /// Examples: |
616 | | /// \code |
617 | | /// class C { |
618 | | /// public: int a; // fieldDecl(isPublic()) matches 'a' |
619 | | /// protected: int b; |
620 | | /// private: int c; |
621 | | /// }; |
622 | | /// \endcode |
623 | | /// |
624 | | /// \code |
625 | | /// class Base {}; |
626 | | /// class Derived1 : public Base {}; // matches 'Base' |
627 | | /// struct Derived2 : Base {}; // matches 'Base' |
628 | | /// \endcode |
629 | | AST_POLYMORPHIC_MATCHER(isPublic, |
630 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, |
631 | 102 | CXXBaseSpecifier)) { |
632 | 102 | return getAccessSpecifier(Node) == AS_public; |
633 | 102 | } clang::ast_matchers::internal::matcher_isPublicMatcher<clang::CXXMethodDecl>::matches(clang::CXXMethodDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 631 | 2 | CXXBaseSpecifier)) { | 632 | 2 | return getAccessSpecifier(Node) == AS_public; | 633 | 2 | } |
Unexecuted instantiation: clang::ast_matchers::internal::matcher_isPublicMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_isPublicMatcher<clang::CXXBaseSpecifier>::matches(clang::CXXBaseSpecifier const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 631 | 100 | CXXBaseSpecifier)) { | 632 | 100 | return getAccessSpecifier(Node) == AS_public; | 633 | 100 | } |
|
634 | | |
635 | | /// Matches protected C++ declarations and C++ base specifers that specify |
636 | | /// protected inheritance. |
637 | | /// |
638 | | /// Examples: |
639 | | /// \code |
640 | | /// class C { |
641 | | /// public: int a; |
642 | | /// protected: int b; // fieldDecl(isProtected()) matches 'b' |
643 | | /// private: int c; |
644 | | /// }; |
645 | | /// \endcode |
646 | | /// |
647 | | /// \code |
648 | | /// class Base {}; |
649 | | /// class Derived : protected Base {}; // matches 'Base' |
650 | | /// \endcode |
651 | | AST_POLYMORPHIC_MATCHER(isProtected, |
652 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, |
653 | 60 | CXXBaseSpecifier)) { |
654 | 60 | return getAccessSpecifier(Node) == AS_protected; |
655 | 60 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isProtectedMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_isProtectedMatcher<clang::CXXBaseSpecifier>::matches(clang::CXXBaseSpecifier const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 653 | 60 | CXXBaseSpecifier)) { | 654 | 60 | return getAccessSpecifier(Node) == AS_protected; | 655 | 60 | } |
|
656 | | |
657 | | /// Matches private C++ declarations and C++ base specifers that specify private |
658 | | /// inheritance. |
659 | | /// |
660 | | /// Examples: |
661 | | /// \code |
662 | | /// class C { |
663 | | /// public: int a; |
664 | | /// protected: int b; |
665 | | /// private: int c; // fieldDecl(isPrivate()) matches 'c' |
666 | | /// }; |
667 | | /// \endcode |
668 | | /// |
669 | | /// \code |
670 | | /// struct Base {}; |
671 | | /// struct Derived1 : private Base {}; // matches 'Base' |
672 | | /// class Derived2 : Base {}; // matches 'Base' |
673 | | /// \endcode |
674 | | AST_POLYMORPHIC_MATCHER(isPrivate, |
675 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, |
676 | 100 | CXXBaseSpecifier)) { |
677 | 100 | return getAccessSpecifier(Node) == AS_private; |
678 | 100 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isPrivateMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_isPrivateMatcher<clang::CXXBaseSpecifier>::matches(clang::CXXBaseSpecifier const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 676 | 100 | CXXBaseSpecifier)) { | 677 | 100 | return getAccessSpecifier(Node) == AS_private; | 678 | 100 | } |
|
679 | | |
680 | | /// Matches non-static data members that are bit-fields. |
681 | | /// |
682 | | /// Given |
683 | | /// \code |
684 | | /// class C { |
685 | | /// int a : 2; |
686 | | /// int b; |
687 | | /// }; |
688 | | /// \endcode |
689 | | /// fieldDecl(isBitField()) |
690 | | /// matches 'int a;' but not 'int b;'. |
691 | 168 | AST_MATCHER(FieldDecl, isBitField) { |
692 | 168 | return Node.isBitField(); |
693 | 168 | } |
694 | | |
695 | | /// Matches non-static data members that are bit-fields of the specified |
696 | | /// bit width. |
697 | | /// |
698 | | /// Given |
699 | | /// \code |
700 | | /// class C { |
701 | | /// int a : 2; |
702 | | /// int b : 4; |
703 | | /// int c : 2; |
704 | | /// }; |
705 | | /// \endcode |
706 | | /// fieldDecl(hasBitWidth(2)) |
707 | | /// matches 'int a;' and 'int c;' but not 'int b;'. |
708 | 56 | AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width) { |
709 | 56 | return Node.isBitField() && |
710 | 56 | Node.getBitWidthValue(Finder->getASTContext()) == Width; |
711 | 56 | } |
712 | | |
713 | | /// Matches non-static data members that have an in-class initializer. |
714 | | /// |
715 | | /// Given |
716 | | /// \code |
717 | | /// class C { |
718 | | /// int a = 2; |
719 | | /// int b = 3; |
720 | | /// int c; |
721 | | /// }; |
722 | | /// \endcode |
723 | | /// fieldDecl(hasInClassInitializer(integerLiteral(equals(2)))) |
724 | | /// matches 'int a;' but not 'int b;'. |
725 | | /// fieldDecl(hasInClassInitializer(anything())) |
726 | | /// matches 'int a;' and 'int b;' but not 'int c;'. |
727 | | AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher<Expr>, |
728 | 80 | InnerMatcher) { |
729 | 80 | const Expr *Initializer = Node.getInClassInitializer(); |
730 | 80 | return (Initializer != nullptr && |
731 | 80 | InnerMatcher.matches(*Initializer, Finder, Builder)40 ); |
732 | 80 | } |
733 | | |
734 | | /// Determines whether the function is "main", which is the entry point |
735 | | /// into an executable program. |
736 | 266 | AST_MATCHER(FunctionDecl, isMain) { |
737 | 266 | return Node.isMain(); |
738 | 266 | } |
739 | | |
740 | | /// Matches the specialized template of a specialization declaration. |
741 | | /// |
742 | | /// Given |
743 | | /// \code |
744 | | /// template<typename T> class A {}; #1 |
745 | | /// template<> class A<int> {}; #2 |
746 | | /// \endcode |
747 | | /// classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl())) |
748 | | /// matches '#2' with classTemplateDecl() matching the class template |
749 | | /// declaration of 'A' at #1. |
750 | | AST_MATCHER_P(ClassTemplateSpecializationDecl, hasSpecializedTemplate, |
751 | 10 | internal::Matcher<ClassTemplateDecl>, InnerMatcher) { |
752 | 10 | const ClassTemplateDecl* Decl = Node.getSpecializedTemplate(); |
753 | 10 | return (Decl != nullptr && |
754 | 10 | InnerMatcher.matches(*Decl, Finder, Builder)); |
755 | 10 | } |
756 | | |
757 | | /// Matches an entity that has been implicitly added by the compiler (e.g. |
758 | | /// implicit default/copy constructors). |
759 | | AST_POLYMORPHIC_MATCHER(isImplicit, |
760 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Attr, |
761 | 76 | LambdaCapture)) { |
762 | 76 | return Node.isImplicit(); |
763 | 76 | } Unexecuted instantiation: clang::ast_matchers::internal::matcher_isImplicitMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_isImplicitMatcher<clang::Attr>::matches(clang::Attr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 761 | 4 | LambdaCapture)) { | 762 | 4 | return Node.isImplicit(); | 763 | 4 | } |
clang::ast_matchers::internal::matcher_isImplicitMatcher<clang::LambdaCapture>::matches(clang::LambdaCapture const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 761 | 72 | LambdaCapture)) { | 762 | 72 | return Node.isImplicit(); | 763 | 72 | } |
|
764 | | |
765 | | /// Matches classTemplateSpecializations, templateSpecializationType and |
766 | | /// functionDecl that have at least one TemplateArgument matching the given |
767 | | /// InnerMatcher. |
768 | | /// |
769 | | /// Given |
770 | | /// \code |
771 | | /// template<typename T> class A {}; |
772 | | /// template<> class A<double> {}; |
773 | | /// A<int> a; |
774 | | /// |
775 | | /// template<typename T> f() {}; |
776 | | /// void func() { f<int>(); }; |
777 | | /// \endcode |
778 | | /// |
779 | | /// \endcode |
780 | | /// classTemplateSpecializationDecl(hasAnyTemplateArgument( |
781 | | /// refersToType(asString("int")))) |
782 | | /// matches the specialization \c A<int> |
783 | | /// |
784 | | /// functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) |
785 | | /// matches the specialization \c f<int> |
786 | | AST_POLYMORPHIC_MATCHER_P( |
787 | | hasAnyTemplateArgument, |
788 | | AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, |
789 | | TemplateSpecializationType, |
790 | | FunctionDecl), |
791 | 172 | internal::Matcher<TemplateArgument>, InnerMatcher) { |
792 | 172 | ArrayRef<TemplateArgument> List = |
793 | 172 | internal::getTemplateSpecializationArgs(Node); |
794 | 172 | return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, |
795 | 172 | Builder) != List.end(); |
796 | 172 | } clang::ast_matchers::internal::matcher_hasAnyTemplateArgument0Matcher<clang::ClassTemplateSpecializationDecl, clang::ast_matchers::internal::Matcher<clang::TemplateArgument> >::matches(clang::ClassTemplateSpecializationDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 791 | 160 | internal::Matcher<TemplateArgument>, InnerMatcher) { | 792 | 160 | ArrayRef<TemplateArgument> List = | 793 | 160 | internal::getTemplateSpecializationArgs(Node); | 794 | 160 | return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, | 795 | 160 | Builder) != List.end(); | 796 | 160 | } |
clang::ast_matchers::internal::matcher_hasAnyTemplateArgument0Matcher<clang::TemplateSpecializationType, clang::ast_matchers::internal::Matcher<clang::TemplateArgument> >::matches(clang::TemplateSpecializationType const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 791 | 6 | internal::Matcher<TemplateArgument>, InnerMatcher) { | 792 | 6 | ArrayRef<TemplateArgument> List = | 793 | 6 | internal::getTemplateSpecializationArgs(Node); | 794 | 6 | return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, | 795 | 6 | Builder) != List.end(); | 796 | 6 | } |
clang::ast_matchers::internal::matcher_hasAnyTemplateArgument0Matcher<clang::FunctionDecl, clang::ast_matchers::internal::Matcher<clang::TemplateArgument> >::matches(clang::FunctionDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 791 | 6 | internal::Matcher<TemplateArgument>, InnerMatcher) { | 792 | 6 | ArrayRef<TemplateArgument> List = | 793 | 6 | internal::getTemplateSpecializationArgs(Node); | 794 | 6 | return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, | 795 | 6 | Builder) != List.end(); | 796 | 6 | } |
|
797 | | |
798 | | /// Causes all nested matchers to be matched with the specified traversal kind. |
799 | | /// |
800 | | /// Given |
801 | | /// \code |
802 | | /// void foo() |
803 | | /// { |
804 | | /// int i = 3.0; |
805 | | /// } |
806 | | /// \endcode |
807 | | /// The matcher |
808 | | /// \code |
809 | | /// traverse(TK_IgnoreUnlessSpelledInSource, |
810 | | /// varDecl(hasInitializer(floatLiteral().bind("init"))) |
811 | | /// ) |
812 | | /// \endcode |
813 | | /// matches the variable declaration with "init" bound to the "3.0". |
814 | | template <typename T> |
815 | | internal::Matcher<T> traverse(TraversalKind TK, |
816 | 497 | const internal::Matcher<T> &InnerMatcher) { |
817 | 497 | return internal::DynTypedMatcher::constructRestrictedWrapper( |
818 | 497 | new internal::TraversalMatcher<T>(TK, InnerMatcher), |
819 | 497 | InnerMatcher.getID().first) |
820 | 497 | .template unconditionalConvertTo<T>(); |
821 | 497 | } clang::ast_matchers::internal::Matcher<clang::Decl> clang::ast_matchers::traverse<clang::Decl>(clang::TraversalKind, clang::ast_matchers::internal::Matcher<clang::Decl> const&) Line | Count | Source | 816 | 8 | const internal::Matcher<T> &InnerMatcher) { | 817 | 8 | return internal::DynTypedMatcher::constructRestrictedWrapper( | 818 | 8 | new internal::TraversalMatcher<T>(TK, InnerMatcher), | 819 | 8 | InnerMatcher.getID().first) | 820 | 8 | .template unconditionalConvertTo<T>(); | 821 | 8 | } |
clang::ast_matchers::internal::Matcher<clang::Stmt> clang::ast_matchers::traverse<clang::Stmt>(clang::TraversalKind, clang::ast_matchers::internal::Matcher<clang::Stmt> const&) Line | Count | Source | 816 | 489 | const internal::Matcher<T> &InnerMatcher) { | 817 | 489 | return internal::DynTypedMatcher::constructRestrictedWrapper( | 818 | 489 | new internal::TraversalMatcher<T>(TK, InnerMatcher), | 819 | 489 | InnerMatcher.getID().first) | 820 | 489 | .template unconditionalConvertTo<T>(); | 821 | 489 | } |
|
822 | | |
823 | | template <typename T> |
824 | | internal::BindableMatcher<T> |
825 | 898 | traverse(TraversalKind TK, const internal::BindableMatcher<T> &InnerMatcher) { |
826 | 898 | return internal::BindableMatcher<T>( |
827 | 898 | internal::DynTypedMatcher::constructRestrictedWrapper( |
828 | 898 | new internal::TraversalMatcher<T>(TK, InnerMatcher), |
829 | 898 | InnerMatcher.getID().first) |
830 | 898 | .template unconditionalConvertTo<T>()); |
831 | 898 | } |
832 | | |
833 | | template <typename... T> |
834 | | internal::TraversalWrapper<internal::VariadicOperatorMatcher<T...>> |
835 | | traverse(TraversalKind TK, |
836 | | const internal::VariadicOperatorMatcher<T...> &InnerMatcher) { |
837 | | return internal::TraversalWrapper<internal::VariadicOperatorMatcher<T...>>( |
838 | | TK, InnerMatcher); |
839 | | } |
840 | | |
841 | | template <template <typename ToArg, typename FromArg> class ArgumentAdapterT, |
842 | | typename T, typename ToTypes> |
843 | | internal::TraversalWrapper< |
844 | | internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>> |
845 | | traverse(TraversalKind TK, const internal::ArgumentAdaptingMatcherFuncAdaptor< |
846 | | ArgumentAdapterT, T, ToTypes> &InnerMatcher) { |
847 | | return internal::TraversalWrapper< |
848 | | internal::ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, |
849 | | ToTypes>>(TK, InnerMatcher); |
850 | | } |
851 | | |
852 | | template <template <typename T, typename... P> class MatcherT, typename... P, |
853 | | typename ReturnTypesF> |
854 | | internal::TraversalWrapper< |
855 | | internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>> |
856 | | traverse(TraversalKind TK, |
857 | | const internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...> |
858 | | &InnerMatcher) { |
859 | | return internal::TraversalWrapper< |
860 | | internal::PolymorphicMatcher<MatcherT, ReturnTypesF, P...>>(TK, |
861 | | InnerMatcher); |
862 | | } |
863 | | |
864 | | template <typename... T> |
865 | | internal::Matcher<typename internal::GetClade<T...>::Type> |
866 | | traverse(TraversalKind TK, const internal::MapAnyOfHelper<T...> &InnerMatcher) { |
867 | | return traverse(TK, InnerMatcher.with()); |
868 | | } |
869 | | |
870 | | /// Matches expressions that match InnerMatcher after any implicit AST |
871 | | /// nodes are stripped off. |
872 | | /// |
873 | | /// Parentheses and explicit casts are not discarded. |
874 | | /// Given |
875 | | /// \code |
876 | | /// class C {}; |
877 | | /// C a = C(); |
878 | | /// C b; |
879 | | /// C c = b; |
880 | | /// \endcode |
881 | | /// The matchers |
882 | | /// \code |
883 | | /// varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) |
884 | | /// \endcode |
885 | | /// would match the declarations for a, b, and c. |
886 | | /// While |
887 | | /// \code |
888 | | /// varDecl(hasInitializer(cxxConstructExpr())) |
889 | | /// \endcode |
890 | | /// only match the declarations for b and c. |
891 | | AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, |
892 | 329 | InnerMatcher) { |
893 | 329 | return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder); |
894 | 329 | } |
895 | | |
896 | | /// Matches expressions that match InnerMatcher after any implicit casts |
897 | | /// are stripped off. |
898 | | /// |
899 | | /// Parentheses and explicit casts are not discarded. |
900 | | /// Given |
901 | | /// \code |
902 | | /// int arr[5]; |
903 | | /// int a = 0; |
904 | | /// char b = 0; |
905 | | /// const int c = a; |
906 | | /// int *d = arr; |
907 | | /// long e = (long) 0l; |
908 | | /// \endcode |
909 | | /// The matchers |
910 | | /// \code |
911 | | /// varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) |
912 | | /// varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) |
913 | | /// \endcode |
914 | | /// would match the declarations for a, b, c, and d, but not e. |
915 | | /// While |
916 | | /// \code |
917 | | /// varDecl(hasInitializer(integerLiteral())) |
918 | | /// varDecl(hasInitializer(declRefExpr())) |
919 | | /// \endcode |
920 | | /// only match the declarations for a. |
921 | | AST_MATCHER_P(Expr, ignoringImpCasts, |
922 | 355 | internal::Matcher<Expr>, InnerMatcher) { |
923 | 355 | return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder); |
924 | 355 | } |
925 | | |
926 | | /// Matches expressions that match InnerMatcher after parentheses and |
927 | | /// casts are stripped off. |
928 | | /// |
929 | | /// Implicit and non-C Style casts are also discarded. |
930 | | /// Given |
931 | | /// \code |
932 | | /// int a = 0; |
933 | | /// char b = (0); |
934 | | /// void* c = reinterpret_cast<char*>(0); |
935 | | /// char d = char(0); |
936 | | /// \endcode |
937 | | /// The matcher |
938 | | /// varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) |
939 | | /// would match the declarations for a, b, c, and d. |
940 | | /// while |
941 | | /// varDecl(hasInitializer(integerLiteral())) |
942 | | /// only match the declaration for a. |
943 | 90 | AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher) { |
944 | 90 | return InnerMatcher.matches(*Node.IgnoreParenCasts(), Finder, Builder); |
945 | 90 | } |
946 | | |
947 | | /// Matches expressions that match InnerMatcher after implicit casts and |
948 | | /// parentheses are stripped off. |
949 | | /// |
950 | | /// Explicit casts are not discarded. |
951 | | /// Given |
952 | | /// \code |
953 | | /// int arr[5]; |
954 | | /// int a = 0; |
955 | | /// char b = (0); |
956 | | /// const int c = a; |
957 | | /// int *d = (arr); |
958 | | /// long e = ((long) 0l); |
959 | | /// \endcode |
960 | | /// The matchers |
961 | | /// varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) |
962 | | /// varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) |
963 | | /// would match the declarations for a, b, c, and d, but not e. |
964 | | /// while |
965 | | /// varDecl(hasInitializer(integerLiteral())) |
966 | | /// varDecl(hasInitializer(declRefExpr())) |
967 | | /// would only match the declaration for a. |
968 | | AST_MATCHER_P(Expr, ignoringParenImpCasts, |
969 | 3.05k | internal::Matcher<Expr>, InnerMatcher) { |
970 | 3.05k | return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder); |
971 | 3.05k | } |
972 | | |
973 | | /// Matches types that match InnerMatcher after any parens are stripped. |
974 | | /// |
975 | | /// Given |
976 | | /// \code |
977 | | /// void (*fp)(void); |
978 | | /// \endcode |
979 | | /// The matcher |
980 | | /// \code |
981 | | /// varDecl(hasType(pointerType(pointee(ignoringParens(functionType()))))) |
982 | | /// \endcode |
983 | | /// would match the declaration for fp. |
984 | | AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher<QualType>, |
985 | 70 | InnerMatcher, 0) { |
986 | 70 | return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); |
987 | 70 | } |
988 | | |
989 | | /// Overload \c ignoringParens for \c Expr. |
990 | | /// |
991 | | /// Given |
992 | | /// \code |
993 | | /// const char* str = ("my-string"); |
994 | | /// \endcode |
995 | | /// The matcher |
996 | | /// \code |
997 | | /// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()))) |
998 | | /// \endcode |
999 | | /// would match the implicit cast resulting from the assignment. |
1000 | | AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher<Expr>, |
1001 | 17.3k | InnerMatcher, 1) { |
1002 | 17.3k | const Expr *E = Node.IgnoreParens(); |
1003 | 17.3k | return InnerMatcher.matches(*E, Finder, Builder); |
1004 | 17.3k | } |
1005 | | |
1006 | | /// Matches expressions that are instantiation-dependent even if it is |
1007 | | /// neither type- nor value-dependent. |
1008 | | /// |
1009 | | /// In the following example, the expression sizeof(sizeof(T() + T())) |
1010 | | /// is instantiation-dependent (since it involves a template parameter T), |
1011 | | /// but is neither type- nor value-dependent, since the type of the inner |
1012 | | /// sizeof is known (std::size_t) and therefore the size of the outer |
1013 | | /// sizeof is known. |
1014 | | /// \code |
1015 | | /// template<typename T> |
1016 | | /// void f(T x, T y) { sizeof(sizeof(T() + T()); } |
1017 | | /// \endcode |
1018 | | /// expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) |
1019 | 100 | AST_MATCHER(Expr, isInstantiationDependent) { |
1020 | 100 | return Node.isInstantiationDependent(); |
1021 | 100 | } |
1022 | | |
1023 | | /// Matches expressions that are type-dependent because the template type |
1024 | | /// is not yet instantiated. |
1025 | | /// |
1026 | | /// For example, the expressions "x" and "x + y" are type-dependent in |
1027 | | /// the following code, but "y" is not type-dependent: |
1028 | | /// \code |
1029 | | /// template<typename T> |
1030 | | /// void add(T x, int y) { |
1031 | | /// x + y; |
1032 | | /// } |
1033 | | /// \endcode |
1034 | | /// expr(isTypeDependent()) matches x + y |
1035 | 321 | AST_MATCHER(Expr, isTypeDependent) { return Node.isTypeDependent(); } |
1036 | | |
1037 | | /// Matches expression that are value-dependent because they contain a |
1038 | | /// non-type template parameter. |
1039 | | /// |
1040 | | /// For example, the array bound of "Chars" in the following example is |
1041 | | /// value-dependent. |
1042 | | /// \code |
1043 | | /// template<int Size> int f() { return Size; } |
1044 | | /// \endcode |
1045 | | /// expr(isValueDependent()) matches return Size |
1046 | 100 | AST_MATCHER(Expr, isValueDependent) { return Node.isValueDependent(); } |
1047 | | |
1048 | | /// Matches classTemplateSpecializations, templateSpecializationType and |
1049 | | /// functionDecl where the n'th TemplateArgument matches the given InnerMatcher. |
1050 | | /// |
1051 | | /// Given |
1052 | | /// \code |
1053 | | /// template<typename T, typename U> class A {}; |
1054 | | /// A<bool, int> b; |
1055 | | /// A<int, bool> c; |
1056 | | /// |
1057 | | /// template<typename T> void f() {} |
1058 | | /// void func() { f<int>(); }; |
1059 | | /// \endcode |
1060 | | /// classTemplateSpecializationDecl(hasTemplateArgument( |
1061 | | /// 1, refersToType(asString("int")))) |
1062 | | /// matches the specialization \c A<bool, int> |
1063 | | /// |
1064 | | /// functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) |
1065 | | /// matches the specialization \c f<int> |
1066 | | AST_POLYMORPHIC_MATCHER_P2( |
1067 | | hasTemplateArgument, |
1068 | | AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, |
1069 | | TemplateSpecializationType, |
1070 | | FunctionDecl), |
1071 | 3.96k | unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) { |
1072 | 3.96k | ArrayRef<TemplateArgument> List = |
1073 | 3.96k | internal::getTemplateSpecializationArgs(Node); |
1074 | 3.96k | if (List.size() <= N) |
1075 | 10 | return false; |
1076 | 3.95k | return InnerMatcher.matches(List[N], Finder, Builder); |
1077 | 3.96k | } clang::ast_matchers::internal::matcher_hasTemplateArgument0Matcher<clang::ClassTemplateSpecializationDecl, unsigned int, clang::ast_matchers::internal::Matcher<clang::TemplateArgument> >::matches(clang::ClassTemplateSpecializationDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 1071 | 3.93k | unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) { | 1072 | 3.93k | ArrayRef<TemplateArgument> List = | 1073 | 3.93k | internal::getTemplateSpecializationArgs(Node); | 1074 | 3.93k | if (List.size() <= N) | 1075 | 0 | return false; | 1076 | 3.93k | return InnerMatcher.matches(List[N], Finder, Builder); | 1077 | 3.93k | } |
clang::ast_matchers::internal::matcher_hasTemplateArgument0Matcher<clang::TemplateSpecializationType, unsigned int, clang::ast_matchers::internal::Matcher<clang::TemplateArgument> >::matches(clang::TemplateSpecializationType const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 1071 | 4 | unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) { | 1072 | 4 | ArrayRef<TemplateArgument> List = | 1073 | 4 | internal::getTemplateSpecializationArgs(Node); | 1074 | 4 | if (List.size() <= N) | 1075 | 0 | return false; | 1076 | 4 | return InnerMatcher.matches(List[N], Finder, Builder); | 1077 | 4 | } |
clang::ast_matchers::internal::matcher_hasTemplateArgument0Matcher<clang::FunctionDecl, unsigned int, clang::ast_matchers::internal::Matcher<clang::TemplateArgument> >::matches(clang::FunctionDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 1071 | 22 | unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) { | 1072 | 22 | ArrayRef<TemplateArgument> List = | 1073 | 22 | internal::getTemplateSpecializationArgs(Node); | 1074 | 22 | if (List.size() <= N) | 1075 | 10 | return false; | 1076 | 12 | return InnerMatcher.matches(List[N], Finder, Builder); | 1077 | 22 | } |
|
1078 | | |
1079 | | /// Matches if the number of template arguments equals \p N. |
1080 | | /// |
1081 | | /// Given |
1082 | | /// \code |
1083 | | /// template<typename T> struct C {}; |
1084 | | /// C<int> c; |
1085 | | /// \endcode |
1086 | | /// classTemplateSpecializationDecl(templateArgumentCountIs(1)) |
1087 | | /// matches C<int>. |
1088 | | AST_POLYMORPHIC_MATCHER_P( |
1089 | | templateArgumentCountIs, |
1090 | | AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, |
1091 | | TemplateSpecializationType), |
1092 | 80 | unsigned, N) { |
1093 | 80 | return internal::getTemplateSpecializationArgs(Node).size() == N; |
1094 | 80 | } clang::ast_matchers::internal::matcher_templateArgumentCountIs0Matcher<clang::ClassTemplateSpecializationDecl, unsigned int>::matches(clang::ClassTemplateSpecializationDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 1092 | 40 | unsigned, N) { | 1093 | 40 | return internal::getTemplateSpecializationArgs(Node).size() == N; | 1094 | 40 | } |
clang::ast_matchers::internal::matcher_templateArgumentCountIs0Matcher<clang::TemplateSpecializationType, unsigned int>::matches(clang::TemplateSpecializationType const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 1092 | 40 | unsigned, N) { | 1093 | 40 | return internal::getTemplateSpecializationArgs(Node).size() == N; | 1094 | 40 | } |
|
1095 | | |
1096 | | /// Matches a TemplateArgument that refers to a certain type. |
1097 | | /// |
1098 | | /// Given |
1099 | | /// \code |
1100 | | /// struct X {}; |
1101 | | /// template<typename T> struct A {}; |
1102 | | /// A<X> a; |
1103 | | /// \endcode |
1104 | | /// classTemplateSpecializationDecl(hasAnyTemplateArgument( |
1105 | | /// refersToType(class(hasName("X"))))) |
1106 | | /// matches the specialization \c A<X> |
1107 | | AST_MATCHER_P(TemplateArgument, refersToType, |
1108 | 3.99k | internal::Matcher<QualType>, InnerMatcher) { |
1109 | 3.99k | if (Node.getKind() != TemplateArgument::Type) |
1110 | 0 | return false; |
1111 | 3.99k | return InnerMatcher.matches(Node.getAsType(), Finder, Builder); |
1112 | 3.99k | } |
1113 | | |
1114 | | /// Matches a TemplateArgument that refers to a certain template. |
1115 | | /// |
1116 | | /// Given |
1117 | | /// \code |
1118 | | /// template<template <typename> class S> class X {}; |
1119 | | /// template<typename T> class Y {}; |
1120 | | /// X<Y> xi; |
1121 | | /// \endcode |
1122 | | /// classTemplateSpecializationDecl(hasAnyTemplateArgument( |
1123 | | /// refersToTemplate(templateName()))) |
1124 | | /// matches the specialization \c X<Y> |
1125 | | AST_MATCHER_P(TemplateArgument, refersToTemplate, |
1126 | 2 | internal::Matcher<TemplateName>, InnerMatcher) { |
1127 | 2 | if (Node.getKind() != TemplateArgument::Template) |
1128 | 0 | return false; |
1129 | 2 | return InnerMatcher.matches(Node.getAsTemplate(), Finder, Builder); |
1130 | 2 | } |
1131 | | |
1132 | | /// Matches a canonical TemplateArgument that refers to a certain |
1133 | | /// declaration. |
1134 | | /// |
1135 | | /// Given |
1136 | | /// \code |
1137 | | /// struct B { int next; }; |
1138 | | /// template<int(B::*next_ptr)> struct A {}; |
1139 | | /// A<&B::next> a; |
1140 | | /// \endcode |
1141 | | /// classTemplateSpecializationDecl(hasAnyTemplateArgument( |
1142 | | /// refersToDeclaration(fieldDecl(hasName("next"))))) |
1143 | | /// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching |
1144 | | /// \c B::next |
1145 | | AST_MATCHER_P(TemplateArgument, refersToDeclaration, |
1146 | 6 | internal::Matcher<Decl>, InnerMatcher) { |
1147 | 6 | if (Node.getKind() == TemplateArgument::Declaration) |
1148 | 2 | return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder); |
1149 | 4 | return false; |
1150 | 6 | } |
1151 | | |
1152 | | /// Matches a sugar TemplateArgument that refers to a certain expression. |
1153 | | /// |
1154 | | /// Given |
1155 | | /// \code |
1156 | | /// struct B { int next; }; |
1157 | | /// template<int(B::*next_ptr)> struct A {}; |
1158 | | /// A<&B::next> a; |
1159 | | /// \endcode |
1160 | | /// templateSpecializationType(hasAnyTemplateArgument( |
1161 | | /// isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) |
1162 | | /// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching |
1163 | | /// \c B::next |
1164 | 44 | AST_MATCHER_P(TemplateArgument, isExpr, internal::Matcher<Expr>, InnerMatcher) { |
1165 | 44 | if (Node.getKind() == TemplateArgument::Expression) |
1166 | 30 | return InnerMatcher.matches(*Node.getAsExpr(), Finder, Builder); |
1167 | 14 | return false; |
1168 | 44 | } |
1169 | | |
1170 | | /// Matches a TemplateArgument that is an integral value. |
1171 | | /// |
1172 | | /// Given |
1173 | | /// \code |
1174 | | /// template<int T> struct C {}; |
1175 | | /// C<42> c; |
1176 | | /// \endcode |
1177 | | /// classTemplateSpecializationDecl( |
1178 | | /// hasAnyTemplateArgument(isIntegral())) |
1179 | | /// matches the implicit instantiation of C in C<42> |
1180 | | /// with isIntegral() matching 42. |
1181 | 40 | AST_MATCHER(TemplateArgument, isIntegral) { |
1182 | 40 | return Node.getKind() == TemplateArgument::Integral; |
1183 | 40 | } |
1184 | | |
1185 | | /// Matches a TemplateArgument that refers to an integral type. |
1186 | | /// |
1187 | | /// Given |
1188 | | /// \code |
1189 | | /// template<int T> struct C {}; |
1190 | | /// C<42> c; |
1191 | | /// \endcode |
1192 | | /// classTemplateSpecializationDecl( |
1193 | | /// hasAnyTemplateArgument(refersToIntegralType(asString("int")))) |
1194 | | /// matches the implicit instantiation of C in C<42>. |
1195 | | AST_MATCHER_P(TemplateArgument, refersToIntegralType, |
1196 | 4 | internal::Matcher<QualType>, InnerMatcher) { |
1197 | 4 | if (Node.getKind() != TemplateArgument::Integral) |
1198 | 0 | return false; |
1199 | 4 | return InnerMatcher.matches(Node.getIntegralType(), Finder, Builder); |
1200 | 4 | } |
1201 | | |
1202 | | /// Matches a TemplateArgument of integral type with a given value. |
1203 | | /// |
1204 | | /// Note that 'Value' is a string as the template argument's value is |
1205 | | /// an arbitrary precision integer. 'Value' must be euqal to the canonical |
1206 | | /// representation of that integral value in base 10. |
1207 | | /// |
1208 | | /// Given |
1209 | | /// \code |
1210 | | /// template<int T> struct C {}; |
1211 | | /// C<42> c; |
1212 | | /// \endcode |
1213 | | /// classTemplateSpecializationDecl( |
1214 | | /// hasAnyTemplateArgument(equalsIntegralValue("42"))) |
1215 | | /// matches the implicit instantiation of C in C<42>. |
1216 | | AST_MATCHER_P(TemplateArgument, equalsIntegralValue, |
1217 | 80 | std::string, Value) { |
1218 | 80 | if (Node.getKind() != TemplateArgument::Integral) |
1219 | 0 | return false; |
1220 | 80 | return toString(Node.getAsIntegral(), 10) == Value; |
1221 | 80 | } |
1222 | | |
1223 | | /// Matches an Objective-C autorelease pool statement. |
1224 | | /// |
1225 | | /// Given |
1226 | | /// \code |
1227 | | /// @autoreleasepool { |
1228 | | /// int x = 0; |
1229 | | /// } |
1230 | | /// \endcode |
1231 | | /// autoreleasePoolStmt(stmt()) matches the declaration of "x" |
1232 | | /// inside the autorelease pool. |
1233 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
1234 | | ObjCAutoreleasePoolStmt> autoreleasePoolStmt; |
1235 | | |
1236 | | /// Matches any value declaration. |
1237 | | /// |
1238 | | /// Example matches A, B, C and F |
1239 | | /// \code |
1240 | | /// enum X { A, B, C }; |
1241 | | /// void F(); |
1242 | | /// \endcode |
1243 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl; |
1244 | | |
1245 | | /// Matches C++ constructor declarations. |
1246 | | /// |
1247 | | /// Example matches Foo::Foo() and Foo::Foo(int) |
1248 | | /// \code |
1249 | | /// class Foo { |
1250 | | /// public: |
1251 | | /// Foo(); |
1252 | | /// Foo(int); |
1253 | | /// int DoSomething(); |
1254 | | /// }; |
1255 | | /// \endcode |
1256 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl> |
1257 | | cxxConstructorDecl; |
1258 | | |
1259 | | /// Matches explicit C++ destructor declarations. |
1260 | | /// |
1261 | | /// Example matches Foo::~Foo() |
1262 | | /// \code |
1263 | | /// class Foo { |
1264 | | /// public: |
1265 | | /// virtual ~Foo(); |
1266 | | /// }; |
1267 | | /// \endcode |
1268 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl> |
1269 | | cxxDestructorDecl; |
1270 | | |
1271 | | /// Matches enum declarations. |
1272 | | /// |
1273 | | /// Example matches X |
1274 | | /// \code |
1275 | | /// enum X { |
1276 | | /// A, B, C |
1277 | | /// }; |
1278 | | /// \endcode |
1279 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl; |
1280 | | |
1281 | | /// Matches enum constants. |
1282 | | /// |
1283 | | /// Example matches A, B, C |
1284 | | /// \code |
1285 | | /// enum X { |
1286 | | /// A, B, C |
1287 | | /// }; |
1288 | | /// \endcode |
1289 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl> |
1290 | | enumConstantDecl; |
1291 | | |
1292 | | /// Matches tag declarations. |
1293 | | /// |
1294 | | /// Example matches X, Z, U, S, E |
1295 | | /// \code |
1296 | | /// class X; |
1297 | | /// template<class T> class Z {}; |
1298 | | /// struct S {}; |
1299 | | /// union U {}; |
1300 | | /// enum E { |
1301 | | /// A, B, C |
1302 | | /// }; |
1303 | | /// \endcode |
1304 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, TagDecl> tagDecl; |
1305 | | |
1306 | | /// Matches method declarations. |
1307 | | /// |
1308 | | /// Example matches y |
1309 | | /// \code |
1310 | | /// class X { void y(); }; |
1311 | | /// \endcode |
1312 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> |
1313 | | cxxMethodDecl; |
1314 | | |
1315 | | /// Matches conversion operator declarations. |
1316 | | /// |
1317 | | /// Example matches the operator. |
1318 | | /// \code |
1319 | | /// class X { operator int() const; }; |
1320 | | /// \endcode |
1321 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl> |
1322 | | cxxConversionDecl; |
1323 | | |
1324 | | /// Matches user-defined and implicitly generated deduction guide. |
1325 | | /// |
1326 | | /// Example matches the deduction guide. |
1327 | | /// \code |
1328 | | /// template<typename T> |
1329 | | /// class X { X(int) }; |
1330 | | /// X(int) -> X<int>; |
1331 | | /// \endcode |
1332 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl> |
1333 | | cxxDeductionGuideDecl; |
1334 | | |
1335 | | /// Matches variable declarations. |
1336 | | /// |
1337 | | /// Note: this does not match declarations of member variables, which are |
1338 | | /// "field" declarations in Clang parlance. |
1339 | | /// |
1340 | | /// Example matches a |
1341 | | /// \code |
1342 | | /// int a; |
1343 | | /// \endcode |
1344 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl; |
1345 | | |
1346 | | /// Matches field declarations. |
1347 | | /// |
1348 | | /// Given |
1349 | | /// \code |
1350 | | /// class X { int m; }; |
1351 | | /// \endcode |
1352 | | /// fieldDecl() |
1353 | | /// matches 'm'. |
1354 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl; |
1355 | | |
1356 | | /// Matches indirect field declarations. |
1357 | | /// |
1358 | | /// Given |
1359 | | /// \code |
1360 | | /// struct X { struct { int a; }; }; |
1361 | | /// \endcode |
1362 | | /// indirectFieldDecl() |
1363 | | /// matches 'a'. |
1364 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl> |
1365 | | indirectFieldDecl; |
1366 | | |
1367 | | /// Matches function declarations. |
1368 | | /// |
1369 | | /// Example matches f |
1370 | | /// \code |
1371 | | /// void f(); |
1372 | | /// \endcode |
1373 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> |
1374 | | functionDecl; |
1375 | | |
1376 | | /// Matches C++ function template declarations. |
1377 | | /// |
1378 | | /// Example matches f |
1379 | | /// \code |
1380 | | /// template<class T> void f(T t) {} |
1381 | | /// \endcode |
1382 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl> |
1383 | | functionTemplateDecl; |
1384 | | |
1385 | | /// Matches friend declarations. |
1386 | | /// |
1387 | | /// Given |
1388 | | /// \code |
1389 | | /// class X { friend void foo(); }; |
1390 | | /// \endcode |
1391 | | /// friendDecl() |
1392 | | /// matches 'friend void foo()'. |
1393 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl; |
1394 | | |
1395 | | /// Matches statements. |
1396 | | /// |
1397 | | /// Given |
1398 | | /// \code |
1399 | | /// { ++a; } |
1400 | | /// \endcode |
1401 | | /// stmt() |
1402 | | /// matches both the compound statement '{ ++a; }' and '++a'. |
1403 | | extern const internal::VariadicAllOfMatcher<Stmt> stmt; |
1404 | | |
1405 | | /// Matches declaration statements. |
1406 | | /// |
1407 | | /// Given |
1408 | | /// \code |
1409 | | /// int a; |
1410 | | /// \endcode |
1411 | | /// declStmt() |
1412 | | /// matches 'int a'. |
1413 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt; |
1414 | | |
1415 | | /// Matches member expressions. |
1416 | | /// |
1417 | | /// Given |
1418 | | /// \code |
1419 | | /// class Y { |
1420 | | /// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } |
1421 | | /// int a; static int b; |
1422 | | /// }; |
1423 | | /// \endcode |
1424 | | /// memberExpr() |
1425 | | /// matches this->x, x, y.x, a, this->b |
1426 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr; |
1427 | | |
1428 | | /// Matches unresolved member expressions. |
1429 | | /// |
1430 | | /// Given |
1431 | | /// \code |
1432 | | /// struct X { |
1433 | | /// template <class T> void f(); |
1434 | | /// void g(); |
1435 | | /// }; |
1436 | | /// template <class T> void h() { X x; x.f<T>(); x.g(); } |
1437 | | /// \endcode |
1438 | | /// unresolvedMemberExpr() |
1439 | | /// matches x.f<T> |
1440 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr> |
1441 | | unresolvedMemberExpr; |
1442 | | |
1443 | | /// Matches member expressions where the actual member referenced could not be |
1444 | | /// resolved because the base expression or the member name was dependent. |
1445 | | /// |
1446 | | /// Given |
1447 | | /// \code |
1448 | | /// template <class T> void f() { T t; t.g(); } |
1449 | | /// \endcode |
1450 | | /// cxxDependentScopeMemberExpr() |
1451 | | /// matches t.g |
1452 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
1453 | | CXXDependentScopeMemberExpr> |
1454 | | cxxDependentScopeMemberExpr; |
1455 | | |
1456 | | /// Matches call expressions. |
1457 | | /// |
1458 | | /// Example matches x.y() and y() |
1459 | | /// \code |
1460 | | /// X x; |
1461 | | /// x.y(); |
1462 | | /// y(); |
1463 | | /// \endcode |
1464 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr; |
1465 | | |
1466 | | /// Matches call expressions which were resolved using ADL. |
1467 | | /// |
1468 | | /// Example matches y(x) but not y(42) or NS::y(x). |
1469 | | /// \code |
1470 | | /// namespace NS { |
1471 | | /// struct X {}; |
1472 | | /// void y(X); |
1473 | | /// } |
1474 | | /// |
1475 | | /// void y(...); |
1476 | | /// |
1477 | | /// void test() { |
1478 | | /// NS::X x; |
1479 | | /// y(x); // Matches |
1480 | | /// NS::y(x); // Doesn't match |
1481 | | /// y(42); // Doesn't match |
1482 | | /// using NS::y; |
1483 | | /// y(x); // Found by both unqualified lookup and ADL, doesn't match |
1484 | | // } |
1485 | | /// \endcode |
1486 | 200 | AST_MATCHER(CallExpr, usesADL) { return Node.usesADL(); } |
1487 | | |
1488 | | /// Matches lambda expressions. |
1489 | | /// |
1490 | | /// Example matches [&](){return 5;} |
1491 | | /// \code |
1492 | | /// [&](){return 5;} |
1493 | | /// \endcode |
1494 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr; |
1495 | | |
1496 | | /// Matches member call expressions. |
1497 | | /// |
1498 | | /// Example matches x.y() |
1499 | | /// \code |
1500 | | /// X x; |
1501 | | /// x.y(); |
1502 | | /// \endcode |
1503 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr> |
1504 | | cxxMemberCallExpr; |
1505 | | |
1506 | | /// Matches ObjectiveC Message invocation expressions. |
1507 | | /// |
1508 | | /// The innermost message send invokes the "alloc" class method on the |
1509 | | /// NSString class, while the outermost message send invokes the |
1510 | | /// "initWithString" instance method on the object returned from |
1511 | | /// NSString's "alloc". This matcher should match both message sends. |
1512 | | /// \code |
1513 | | /// [[NSString alloc] initWithString:@"Hello"] |
1514 | | /// \endcode |
1515 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr> |
1516 | | objcMessageExpr; |
1517 | | |
1518 | | /// Matches ObjectiveC String literal expressions. |
1519 | | /// |
1520 | | /// Example matches @"abcd" |
1521 | | /// \code |
1522 | | /// NSString *s = @"abcd"; |
1523 | | /// \endcode |
1524 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCStringLiteral> |
1525 | | objcStringLiteral; |
1526 | | |
1527 | | /// Matches Objective-C interface declarations. |
1528 | | /// |
1529 | | /// Example matches Foo |
1530 | | /// \code |
1531 | | /// @interface Foo |
1532 | | /// @end |
1533 | | /// \endcode |
1534 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl> |
1535 | | objcInterfaceDecl; |
1536 | | |
1537 | | /// Matches Objective-C implementation declarations. |
1538 | | /// |
1539 | | /// Example matches Foo |
1540 | | /// \code |
1541 | | /// @implementation Foo |
1542 | | /// @end |
1543 | | /// \endcode |
1544 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl> |
1545 | | objcImplementationDecl; |
1546 | | |
1547 | | /// Matches Objective-C protocol declarations. |
1548 | | /// |
1549 | | /// Example matches FooDelegate |
1550 | | /// \code |
1551 | | /// @protocol FooDelegate |
1552 | | /// @end |
1553 | | /// \endcode |
1554 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl> |
1555 | | objcProtocolDecl; |
1556 | | |
1557 | | /// Matches Objective-C category declarations. |
1558 | | /// |
1559 | | /// Example matches Foo (Additions) |
1560 | | /// \code |
1561 | | /// @interface Foo (Additions) |
1562 | | /// @end |
1563 | | /// \endcode |
1564 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl> |
1565 | | objcCategoryDecl; |
1566 | | |
1567 | | /// Matches Objective-C category definitions. |
1568 | | /// |
1569 | | /// Example matches Foo (Additions) |
1570 | | /// \code |
1571 | | /// @implementation Foo (Additions) |
1572 | | /// @end |
1573 | | /// \endcode |
1574 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl> |
1575 | | objcCategoryImplDecl; |
1576 | | |
1577 | | /// Matches Objective-C method declarations. |
1578 | | /// |
1579 | | /// Example matches both declaration and definition of -[Foo method] |
1580 | | /// \code |
1581 | | /// @interface Foo |
1582 | | /// - (void)method; |
1583 | | /// @end |
1584 | | /// |
1585 | | /// @implementation Foo |
1586 | | /// - (void)method {} |
1587 | | /// @end |
1588 | | /// \endcode |
1589 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> |
1590 | | objcMethodDecl; |
1591 | | |
1592 | | /// Matches block declarations. |
1593 | | /// |
1594 | | /// Example matches the declaration of the nameless block printing an input |
1595 | | /// integer. |
1596 | | /// |
1597 | | /// \code |
1598 | | /// myFunc(^(int p) { |
1599 | | /// printf("%d", p); |
1600 | | /// }) |
1601 | | /// \endcode |
1602 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> |
1603 | | blockDecl; |
1604 | | |
1605 | | /// Matches Objective-C instance variable declarations. |
1606 | | /// |
1607 | | /// Example matches _enabled |
1608 | | /// \code |
1609 | | /// @implementation Foo { |
1610 | | /// BOOL _enabled; |
1611 | | /// } |
1612 | | /// @end |
1613 | | /// \endcode |
1614 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> |
1615 | | objcIvarDecl; |
1616 | | |
1617 | | /// Matches Objective-C property declarations. |
1618 | | /// |
1619 | | /// Example matches enabled |
1620 | | /// \code |
1621 | | /// @interface Foo |
1622 | | /// @property BOOL enabled; |
1623 | | /// @end |
1624 | | /// \endcode |
1625 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl> |
1626 | | objcPropertyDecl; |
1627 | | |
1628 | | /// Matches Objective-C \@throw statements. |
1629 | | /// |
1630 | | /// Example matches \@throw |
1631 | | /// \code |
1632 | | /// @throw obj; |
1633 | | /// \endcode |
1634 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt> |
1635 | | objcThrowStmt; |
1636 | | |
1637 | | /// Matches Objective-C @try statements. |
1638 | | /// |
1639 | | /// Example matches @try |
1640 | | /// \code |
1641 | | /// @try {} |
1642 | | /// @catch (...) {} |
1643 | | /// \endcode |
1644 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> |
1645 | | objcTryStmt; |
1646 | | |
1647 | | /// Matches Objective-C @catch statements. |
1648 | | /// |
1649 | | /// Example matches @catch |
1650 | | /// \code |
1651 | | /// @try {} |
1652 | | /// @catch (...) {} |
1653 | | /// \endcode |
1654 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt> |
1655 | | objcCatchStmt; |
1656 | | |
1657 | | /// Matches Objective-C @finally statements. |
1658 | | /// |
1659 | | /// Example matches @finally |
1660 | | /// \code |
1661 | | /// @try {} |
1662 | | /// @finally {} |
1663 | | /// \endcode |
1664 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt> |
1665 | | objcFinallyStmt; |
1666 | | |
1667 | | /// Matches expressions that introduce cleanups to be run at the end |
1668 | | /// of the sub-expression's evaluation. |
1669 | | /// |
1670 | | /// Example matches std::string() |
1671 | | /// \code |
1672 | | /// const std::string str = std::string(); |
1673 | | /// \endcode |
1674 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups> |
1675 | | exprWithCleanups; |
1676 | | |
1677 | | /// Matches init list expressions. |
1678 | | /// |
1679 | | /// Given |
1680 | | /// \code |
1681 | | /// int a[] = { 1, 2 }; |
1682 | | /// struct B { int x, y; }; |
1683 | | /// B b = { 5, 6 }; |
1684 | | /// \endcode |
1685 | | /// initListExpr() |
1686 | | /// matches "{ 1, 2 }" and "{ 5, 6 }" |
1687 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> |
1688 | | initListExpr; |
1689 | | |
1690 | | /// Matches the syntactic form of init list expressions |
1691 | | /// (if expression have it). |
1692 | | AST_MATCHER_P(InitListExpr, hasSyntacticForm, |
1693 | 12 | internal::Matcher<Expr>, InnerMatcher) { |
1694 | 12 | const Expr *SyntForm = Node.getSyntacticForm(); |
1695 | 12 | return (SyntForm != nullptr && |
1696 | 12 | InnerMatcher.matches(*SyntForm, Finder, Builder)4 ); |
1697 | 12 | } |
1698 | | |
1699 | | /// Matches C++ initializer list expressions. |
1700 | | /// |
1701 | | /// Given |
1702 | | /// \code |
1703 | | /// std::vector<int> a({ 1, 2, 3 }); |
1704 | | /// std::vector<int> b = { 4, 5 }; |
1705 | | /// int c[] = { 6, 7 }; |
1706 | | /// std::pair<int, int> d = { 8, 9 }; |
1707 | | /// \endcode |
1708 | | /// cxxStdInitializerListExpr() |
1709 | | /// matches "{ 1, 2, 3 }" and "{ 4, 5 }" |
1710 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
1711 | | CXXStdInitializerListExpr> |
1712 | | cxxStdInitializerListExpr; |
1713 | | |
1714 | | /// Matches implicit initializers of init list expressions. |
1715 | | /// |
1716 | | /// Given |
1717 | | /// \code |
1718 | | /// point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; |
1719 | | /// \endcode |
1720 | | /// implicitValueInitExpr() |
1721 | | /// matches "[0].y" (implicitly) |
1722 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr> |
1723 | | implicitValueInitExpr; |
1724 | | |
1725 | | /// Matches paren list expressions. |
1726 | | /// ParenListExprs don't have a predefined type and are used for late parsing. |
1727 | | /// In the final AST, they can be met in template declarations. |
1728 | | /// |
1729 | | /// Given |
1730 | | /// \code |
1731 | | /// template<typename T> class X { |
1732 | | /// void f() { |
1733 | | /// X x(*this); |
1734 | | /// int a = 0, b = 1; int i = (a, b); |
1735 | | /// } |
1736 | | /// }; |
1737 | | /// \endcode |
1738 | | /// parenListExpr() matches "*this" but NOT matches (a, b) because (a, b) |
1739 | | /// has a predefined type and is a ParenExpr, not a ParenListExpr. |
1740 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> |
1741 | | parenListExpr; |
1742 | | |
1743 | | /// Matches substitutions of non-type template parameters. |
1744 | | /// |
1745 | | /// Given |
1746 | | /// \code |
1747 | | /// template <int N> |
1748 | | /// struct A { static const int n = N; }; |
1749 | | /// struct B : public A<42> {}; |
1750 | | /// \endcode |
1751 | | /// substNonTypeTemplateParmExpr() |
1752 | | /// matches "N" in the right-hand side of "static const int n = N;" |
1753 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
1754 | | SubstNonTypeTemplateParmExpr> |
1755 | | substNonTypeTemplateParmExpr; |
1756 | | |
1757 | | /// Matches using declarations. |
1758 | | /// |
1759 | | /// Given |
1760 | | /// \code |
1761 | | /// namespace X { int x; } |
1762 | | /// using X::x; |
1763 | | /// \endcode |
1764 | | /// usingDecl() |
1765 | | /// matches \code using X::x \endcode |
1766 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; |
1767 | | |
1768 | | /// Matches using-enum declarations. |
1769 | | /// |
1770 | | /// Given |
1771 | | /// \code |
1772 | | /// namespace X { enum x {...}; } |
1773 | | /// using enum X::x; |
1774 | | /// \endcode |
1775 | | /// usingEnumDecl() |
1776 | | /// matches \code using enum X::x \endcode |
1777 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingEnumDecl> |
1778 | | usingEnumDecl; |
1779 | | |
1780 | | /// Matches using namespace declarations. |
1781 | | /// |
1782 | | /// Given |
1783 | | /// \code |
1784 | | /// namespace X { int x; } |
1785 | | /// using namespace X; |
1786 | | /// \endcode |
1787 | | /// usingDirectiveDecl() |
1788 | | /// matches \code using namespace X \endcode |
1789 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl> |
1790 | | usingDirectiveDecl; |
1791 | | |
1792 | | /// Matches reference to a name that can be looked up during parsing |
1793 | | /// but could not be resolved to a specific declaration. |
1794 | | /// |
1795 | | /// Given |
1796 | | /// \code |
1797 | | /// template<typename T> |
1798 | | /// T foo() { T a; return a; } |
1799 | | /// template<typename T> |
1800 | | /// void bar() { |
1801 | | /// foo<T>(); |
1802 | | /// } |
1803 | | /// \endcode |
1804 | | /// unresolvedLookupExpr() |
1805 | | /// matches \code foo<T>() \endcode |
1806 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr> |
1807 | | unresolvedLookupExpr; |
1808 | | |
1809 | | /// Matches unresolved using value declarations. |
1810 | | /// |
1811 | | /// Given |
1812 | | /// \code |
1813 | | /// template<typename X> |
1814 | | /// class C : private X { |
1815 | | /// using X::x; |
1816 | | /// }; |
1817 | | /// \endcode |
1818 | | /// unresolvedUsingValueDecl() |
1819 | | /// matches \code using X::x \endcode |
1820 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, |
1821 | | UnresolvedUsingValueDecl> |
1822 | | unresolvedUsingValueDecl; |
1823 | | |
1824 | | /// Matches unresolved using value declarations that involve the |
1825 | | /// typename. |
1826 | | /// |
1827 | | /// Given |
1828 | | /// \code |
1829 | | /// template <typename T> |
1830 | | /// struct Base { typedef T Foo; }; |
1831 | | /// |
1832 | | /// template<typename T> |
1833 | | /// struct S : private Base<T> { |
1834 | | /// using typename Base<T>::Foo; |
1835 | | /// }; |
1836 | | /// \endcode |
1837 | | /// unresolvedUsingTypenameDecl() |
1838 | | /// matches \code using Base<T>::Foo \endcode |
1839 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, |
1840 | | UnresolvedUsingTypenameDecl> |
1841 | | unresolvedUsingTypenameDecl; |
1842 | | |
1843 | | /// Matches a constant expression wrapper. |
1844 | | /// |
1845 | | /// Example matches the constant in the case statement: |
1846 | | /// (matcher = constantExpr()) |
1847 | | /// \code |
1848 | | /// switch (a) { |
1849 | | /// case 37: break; |
1850 | | /// } |
1851 | | /// \endcode |
1852 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr> |
1853 | | constantExpr; |
1854 | | |
1855 | | /// Matches parentheses used in expressions. |
1856 | | /// |
1857 | | /// Example matches (foo() + 1) |
1858 | | /// \code |
1859 | | /// int foo() { return 1; } |
1860 | | /// int a = (foo() + 1); |
1861 | | /// \endcode |
1862 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr; |
1863 | | |
1864 | | /// Matches constructor call expressions (including implicit ones). |
1865 | | /// |
1866 | | /// Example matches string(ptr, n) and ptr within arguments of f |
1867 | | /// (matcher = cxxConstructExpr()) |
1868 | | /// \code |
1869 | | /// void f(const string &a, const string &b); |
1870 | | /// char *ptr; |
1871 | | /// int n; |
1872 | | /// f(string(ptr, n), ptr); |
1873 | | /// \endcode |
1874 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr> |
1875 | | cxxConstructExpr; |
1876 | | |
1877 | | /// Matches unresolved constructor call expressions. |
1878 | | /// |
1879 | | /// Example matches T(t) in return statement of f |
1880 | | /// (matcher = cxxUnresolvedConstructExpr()) |
1881 | | /// \code |
1882 | | /// template <typename T> |
1883 | | /// void f(const T& t) { return T(t); } |
1884 | | /// \endcode |
1885 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
1886 | | CXXUnresolvedConstructExpr> |
1887 | | cxxUnresolvedConstructExpr; |
1888 | | |
1889 | | /// Matches implicit and explicit this expressions. |
1890 | | /// |
1891 | | /// Example matches the implicit this expression in "return i". |
1892 | | /// (matcher = cxxThisExpr()) |
1893 | | /// \code |
1894 | | /// struct foo { |
1895 | | /// int i; |
1896 | | /// int f() { return i; } |
1897 | | /// }; |
1898 | | /// \endcode |
1899 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> |
1900 | | cxxThisExpr; |
1901 | | |
1902 | | /// Matches nodes where temporaries are created. |
1903 | | /// |
1904 | | /// Example matches FunctionTakesString(GetStringByValue()) |
1905 | | /// (matcher = cxxBindTemporaryExpr()) |
1906 | | /// \code |
1907 | | /// FunctionTakesString(GetStringByValue()); |
1908 | | /// FunctionTakesStringByPointer(GetStringPointer()); |
1909 | | /// \endcode |
1910 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr> |
1911 | | cxxBindTemporaryExpr; |
1912 | | |
1913 | | /// Matches nodes where temporaries are materialized. |
1914 | | /// |
1915 | | /// Example: Given |
1916 | | /// \code |
1917 | | /// struct T {void func();}; |
1918 | | /// T f(); |
1919 | | /// void g(T); |
1920 | | /// \endcode |
1921 | | /// materializeTemporaryExpr() matches 'f()' in these statements |
1922 | | /// \code |
1923 | | /// T u(f()); |
1924 | | /// g(f()); |
1925 | | /// f().func(); |
1926 | | /// \endcode |
1927 | | /// but does not match |
1928 | | /// \code |
1929 | | /// f(); |
1930 | | /// \endcode |
1931 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
1932 | | MaterializeTemporaryExpr> |
1933 | | materializeTemporaryExpr; |
1934 | | |
1935 | | /// Matches new expressions. |
1936 | | /// |
1937 | | /// Given |
1938 | | /// \code |
1939 | | /// new X; |
1940 | | /// \endcode |
1941 | | /// cxxNewExpr() |
1942 | | /// matches 'new X'. |
1943 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr; |
1944 | | |
1945 | | /// Matches delete expressions. |
1946 | | /// |
1947 | | /// Given |
1948 | | /// \code |
1949 | | /// delete X; |
1950 | | /// \endcode |
1951 | | /// cxxDeleteExpr() |
1952 | | /// matches 'delete X'. |
1953 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> |
1954 | | cxxDeleteExpr; |
1955 | | |
1956 | | /// Matches noexcept expressions. |
1957 | | /// |
1958 | | /// Given |
1959 | | /// \code |
1960 | | /// bool a() noexcept; |
1961 | | /// bool b() noexcept(true); |
1962 | | /// bool c() noexcept(false); |
1963 | | /// bool d() noexcept(noexcept(a())); |
1964 | | /// bool e = noexcept(b()) || noexcept(c()); |
1965 | | /// \endcode |
1966 | | /// cxxNoexceptExpr() |
1967 | | /// matches `noexcept(a())`, `noexcept(b())` and `noexcept(c())`. |
1968 | | /// doesn't match the noexcept specifier in the declarations a, b, c or d. |
1969 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNoexceptExpr> |
1970 | | cxxNoexceptExpr; |
1971 | | |
1972 | | /// Matches array subscript expressions. |
1973 | | /// |
1974 | | /// Given |
1975 | | /// \code |
1976 | | /// int i = a[1]; |
1977 | | /// \endcode |
1978 | | /// arraySubscriptExpr() |
1979 | | /// matches "a[1]" |
1980 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr> |
1981 | | arraySubscriptExpr; |
1982 | | |
1983 | | /// Matches the value of a default argument at the call site. |
1984 | | /// |
1985 | | /// Example matches the CXXDefaultArgExpr placeholder inserted for the |
1986 | | /// default value of the second parameter in the call expression f(42) |
1987 | | /// (matcher = cxxDefaultArgExpr()) |
1988 | | /// \code |
1989 | | /// void f(int x, int y = 0); |
1990 | | /// f(42); |
1991 | | /// \endcode |
1992 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr> |
1993 | | cxxDefaultArgExpr; |
1994 | | |
1995 | | /// Matches overloaded operator calls. |
1996 | | /// |
1997 | | /// Note that if an operator isn't overloaded, it won't match. Instead, use |
1998 | | /// binaryOperator matcher. |
1999 | | /// Currently it does not match operators such as new delete. |
2000 | | /// FIXME: figure out why these do not match? |
2001 | | /// |
2002 | | /// Example matches both operator<<((o << b), c) and operator<<(o, b) |
2003 | | /// (matcher = cxxOperatorCallExpr()) |
2004 | | /// \code |
2005 | | /// ostream &operator<< (ostream &out, int i) { }; |
2006 | | /// ostream &o; int b = 1, c = 1; |
2007 | | /// o << b << c; |
2008 | | /// \endcode |
2009 | | /// See also the binaryOperation() matcher for more-general matching of binary |
2010 | | /// uses of this AST node. |
2011 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr> |
2012 | | cxxOperatorCallExpr; |
2013 | | |
2014 | | /// Matches rewritten binary operators |
2015 | | /// |
2016 | | /// Example matches use of "<": |
2017 | | /// \code |
2018 | | /// #include <compare> |
2019 | | /// struct HasSpaceshipMem { |
2020 | | /// int a; |
2021 | | /// constexpr auto operator<=>(const HasSpaceshipMem&) const = default; |
2022 | | /// }; |
2023 | | /// void compare() { |
2024 | | /// HasSpaceshipMem hs1, hs2; |
2025 | | /// if (hs1 < hs2) |
2026 | | /// return; |
2027 | | /// } |
2028 | | /// \endcode |
2029 | | /// See also the binaryOperation() matcher for more-general matching |
2030 | | /// of this AST node. |
2031 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
2032 | | CXXRewrittenBinaryOperator> |
2033 | | cxxRewrittenBinaryOperator; |
2034 | | |
2035 | | /// Matches expressions. |
2036 | | /// |
2037 | | /// Example matches x() |
2038 | | /// \code |
2039 | | /// void f() { x(); } |
2040 | | /// \endcode |
2041 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; |
2042 | | |
2043 | | /// Matches expressions that refer to declarations. |
2044 | | /// |
2045 | | /// Example matches x in if (x) |
2046 | | /// \code |
2047 | | /// bool x; |
2048 | | /// if (x) {} |
2049 | | /// \endcode |
2050 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> |
2051 | | declRefExpr; |
2052 | | |
2053 | | /// Matches a reference to an ObjCIvar. |
2054 | | /// |
2055 | | /// Example: matches "a" in "init" method: |
2056 | | /// \code |
2057 | | /// @implementation A { |
2058 | | /// NSString *a; |
2059 | | /// } |
2060 | | /// - (void) init { |
2061 | | /// a = @"hello"; |
2062 | | /// } |
2063 | | /// \endcode |
2064 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> |
2065 | | objcIvarRefExpr; |
2066 | | |
2067 | | /// Matches a reference to a block. |
2068 | | /// |
2069 | | /// Example: matches "^{}": |
2070 | | /// \code |
2071 | | /// void f() { ^{}(); } |
2072 | | /// \endcode |
2073 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr; |
2074 | | |
2075 | | /// Matches if statements. |
2076 | | /// |
2077 | | /// Example matches 'if (x) {}' |
2078 | | /// \code |
2079 | | /// if (x) {} |
2080 | | /// \endcode |
2081 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt; |
2082 | | |
2083 | | /// Matches for statements. |
2084 | | /// |
2085 | | /// Example matches 'for (;;) {}' |
2086 | | /// \code |
2087 | | /// for (;;) {} |
2088 | | /// int i[] = {1, 2, 3}; for (auto a : i); |
2089 | | /// \endcode |
2090 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; |
2091 | | |
2092 | | /// Matches the increment statement of a for loop. |
2093 | | /// |
2094 | | /// Example: |
2095 | | /// forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) |
2096 | | /// matches '++x' in |
2097 | | /// \code |
2098 | | /// for (x; x < N; ++x) { } |
2099 | | /// \endcode |
2100 | | AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, |
2101 | 163 | InnerMatcher) { |
2102 | 163 | const Stmt *const Increment = Node.getInc(); |
2103 | 163 | return (Increment != nullptr && |
2104 | 163 | InnerMatcher.matches(*Increment, Finder, Builder)); |
2105 | 163 | } |
2106 | | |
2107 | | /// Matches the initialization statement of a for loop. |
2108 | | /// |
2109 | | /// Example: |
2110 | | /// forStmt(hasLoopInit(declStmt())) |
2111 | | /// matches 'int x = 0' in |
2112 | | /// \code |
2113 | | /// for (int x = 0; x < N; ++x) { } |
2114 | | /// \endcode |
2115 | | AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, |
2116 | 167 | InnerMatcher) { |
2117 | 167 | const Stmt *const Init = Node.getInit(); |
2118 | 167 | return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder)165 ); |
2119 | 167 | } |
2120 | | |
2121 | | /// Matches range-based for statements. |
2122 | | /// |
2123 | | /// cxxForRangeStmt() matches 'for (auto a : i)' |
2124 | | /// \code |
2125 | | /// int i[] = {1, 2, 3}; for (auto a : i); |
2126 | | /// for(int j = 0; j < 5; ++j); |
2127 | | /// \endcode |
2128 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> |
2129 | | cxxForRangeStmt; |
2130 | | |
2131 | | /// Matches the initialization statement of a for loop. |
2132 | | /// |
2133 | | /// Example: |
2134 | | /// forStmt(hasLoopVariable(anything())) |
2135 | | /// matches 'int x' in |
2136 | | /// \code |
2137 | | /// for (int x : a) { } |
2138 | | /// \endcode |
2139 | | AST_MATCHER_P(CXXForRangeStmt, hasLoopVariable, internal::Matcher<VarDecl>, |
2140 | 37 | InnerMatcher) { |
2141 | 37 | const VarDecl *const Var = Node.getLoopVariable(); |
2142 | 37 | return (Var != nullptr && InnerMatcher.matches(*Var, Finder, Builder)); |
2143 | 37 | } |
2144 | | |
2145 | | /// Matches the range initialization statement of a for loop. |
2146 | | /// |
2147 | | /// Example: |
2148 | | /// forStmt(hasRangeInit(anything())) |
2149 | | /// matches 'a' in |
2150 | | /// \code |
2151 | | /// for (int x : a) { } |
2152 | | /// \endcode |
2153 | | AST_MATCHER_P(CXXForRangeStmt, hasRangeInit, internal::Matcher<Expr>, |
2154 | 41 | InnerMatcher) { |
2155 | 41 | const Expr *const Init = Node.getRangeInit(); |
2156 | 41 | return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder)); |
2157 | 41 | } |
2158 | | |
2159 | | /// Matches while statements. |
2160 | | /// |
2161 | | /// Given |
2162 | | /// \code |
2163 | | /// while (true) {} |
2164 | | /// \endcode |
2165 | | /// whileStmt() |
2166 | | /// matches 'while (true) {}'. |
2167 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt; |
2168 | | |
2169 | | /// Matches do statements. |
2170 | | /// |
2171 | | /// Given |
2172 | | /// \code |
2173 | | /// do {} while (true); |
2174 | | /// \endcode |
2175 | | /// doStmt() |
2176 | | /// matches 'do {} while(true)' |
2177 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt; |
2178 | | |
2179 | | /// Matches break statements. |
2180 | | /// |
2181 | | /// Given |
2182 | | /// \code |
2183 | | /// while (true) { break; } |
2184 | | /// \endcode |
2185 | | /// breakStmt() |
2186 | | /// matches 'break' |
2187 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt; |
2188 | | |
2189 | | /// Matches continue statements. |
2190 | | /// |
2191 | | /// Given |
2192 | | /// \code |
2193 | | /// while (true) { continue; } |
2194 | | /// \endcode |
2195 | | /// continueStmt() |
2196 | | /// matches 'continue' |
2197 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> |
2198 | | continueStmt; |
2199 | | |
2200 | | /// Matches co_return statements. |
2201 | | /// |
2202 | | /// Given |
2203 | | /// \code |
2204 | | /// while (true) { co_return; } |
2205 | | /// \endcode |
2206 | | /// coreturnStmt() |
2207 | | /// matches 'co_return' |
2208 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoreturnStmt> |
2209 | | coreturnStmt; |
2210 | | |
2211 | | /// Matches return statements. |
2212 | | /// |
2213 | | /// Given |
2214 | | /// \code |
2215 | | /// return 1; |
2216 | | /// \endcode |
2217 | | /// returnStmt() |
2218 | | /// matches 'return 1' |
2219 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt; |
2220 | | |
2221 | | /// Matches goto statements. |
2222 | | /// |
2223 | | /// Given |
2224 | | /// \code |
2225 | | /// goto FOO; |
2226 | | /// FOO: bar(); |
2227 | | /// \endcode |
2228 | | /// gotoStmt() |
2229 | | /// matches 'goto FOO' |
2230 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt; |
2231 | | |
2232 | | /// Matches label statements. |
2233 | | /// |
2234 | | /// Given |
2235 | | /// \code |
2236 | | /// goto FOO; |
2237 | | /// FOO: bar(); |
2238 | | /// \endcode |
2239 | | /// labelStmt() |
2240 | | /// matches 'FOO:' |
2241 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt; |
2242 | | |
2243 | | /// Matches address of label statements (GNU extension). |
2244 | | /// |
2245 | | /// Given |
2246 | | /// \code |
2247 | | /// FOO: bar(); |
2248 | | /// void *ptr = &&FOO; |
2249 | | /// goto *bar; |
2250 | | /// \endcode |
2251 | | /// addrLabelExpr() |
2252 | | /// matches '&&FOO' |
2253 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> |
2254 | | addrLabelExpr; |
2255 | | |
2256 | | /// Matches switch statements. |
2257 | | /// |
2258 | | /// Given |
2259 | | /// \code |
2260 | | /// switch(a) { case 42: break; default: break; } |
2261 | | /// \endcode |
2262 | | /// switchStmt() |
2263 | | /// matches 'switch(a)'. |
2264 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt; |
2265 | | |
2266 | | /// Matches case and default statements inside switch statements. |
2267 | | /// |
2268 | | /// Given |
2269 | | /// \code |
2270 | | /// switch(a) { case 42: break; default: break; } |
2271 | | /// \endcode |
2272 | | /// switchCase() |
2273 | | /// matches 'case 42:' and 'default:'. |
2274 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase; |
2275 | | |
2276 | | /// Matches case statements inside switch statements. |
2277 | | /// |
2278 | | /// Given |
2279 | | /// \code |
2280 | | /// switch(a) { case 42: break; default: break; } |
2281 | | /// \endcode |
2282 | | /// caseStmt() |
2283 | | /// matches 'case 42:'. |
2284 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt; |
2285 | | |
2286 | | /// Matches default statements inside switch statements. |
2287 | | /// |
2288 | | /// Given |
2289 | | /// \code |
2290 | | /// switch(a) { case 42: break; default: break; } |
2291 | | /// \endcode |
2292 | | /// defaultStmt() |
2293 | | /// matches 'default:'. |
2294 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> |
2295 | | defaultStmt; |
2296 | | |
2297 | | /// Matches compound statements. |
2298 | | /// |
2299 | | /// Example matches '{}' and '{{}}' in 'for (;;) {{}}' |
2300 | | /// \code |
2301 | | /// for (;;) {{}} |
2302 | | /// \endcode |
2303 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> |
2304 | | compoundStmt; |
2305 | | |
2306 | | /// Matches catch statements. |
2307 | | /// |
2308 | | /// \code |
2309 | | /// try {} catch(int i) {} |
2310 | | /// \endcode |
2311 | | /// cxxCatchStmt() |
2312 | | /// matches 'catch(int i)' |
2313 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> |
2314 | | cxxCatchStmt; |
2315 | | |
2316 | | /// Matches try statements. |
2317 | | /// |
2318 | | /// \code |
2319 | | /// try {} catch(int i) {} |
2320 | | /// \endcode |
2321 | | /// cxxTryStmt() |
2322 | | /// matches 'try {}' |
2323 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt; |
2324 | | |
2325 | | /// Matches throw expressions. |
2326 | | /// |
2327 | | /// \code |
2328 | | /// try { throw 5; } catch(int i) {} |
2329 | | /// \endcode |
2330 | | /// cxxThrowExpr() |
2331 | | /// matches 'throw 5' |
2332 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> |
2333 | | cxxThrowExpr; |
2334 | | |
2335 | | /// Matches null statements. |
2336 | | /// |
2337 | | /// \code |
2338 | | /// foo();; |
2339 | | /// \endcode |
2340 | | /// nullStmt() |
2341 | | /// matches the second ';' |
2342 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt; |
2343 | | |
2344 | | /// Matches asm statements. |
2345 | | /// |
2346 | | /// \code |
2347 | | /// int i = 100; |
2348 | | /// __asm("mov al, 2"); |
2349 | | /// \endcode |
2350 | | /// asmStmt() |
2351 | | /// matches '__asm("mov al, 2")' |
2352 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt; |
2353 | | |
2354 | | /// Matches bool literals. |
2355 | | /// |
2356 | | /// Example matches true |
2357 | | /// \code |
2358 | | /// true |
2359 | | /// \endcode |
2360 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr> |
2361 | | cxxBoolLiteral; |
2362 | | |
2363 | | /// Matches string literals (also matches wide string literals). |
2364 | | /// |
2365 | | /// Example matches "abcd", L"abcd" |
2366 | | /// \code |
2367 | | /// char *s = "abcd"; |
2368 | | /// wchar_t *ws = L"abcd"; |
2369 | | /// \endcode |
2370 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> |
2371 | | stringLiteral; |
2372 | | |
2373 | | /// Matches character literals (also matches wchar_t). |
2374 | | /// |
2375 | | /// Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), |
2376 | | /// though. |
2377 | | /// |
2378 | | /// Example matches 'a', L'a' |
2379 | | /// \code |
2380 | | /// char ch = 'a'; |
2381 | | /// wchar_t chw = L'a'; |
2382 | | /// \endcode |
2383 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral> |
2384 | | characterLiteral; |
2385 | | |
2386 | | /// Matches integer literals of all sizes / encodings, e.g. |
2387 | | /// 1, 1L, 0x1 and 1U. |
2388 | | /// |
2389 | | /// Does not match character-encoded integers such as L'a'. |
2390 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> |
2391 | | integerLiteral; |
2392 | | |
2393 | | /// Matches float literals of all sizes / encodings, e.g. |
2394 | | /// 1.0, 1.0f, 1.0L and 1e10. |
2395 | | /// |
2396 | | /// Does not match implicit conversions such as |
2397 | | /// \code |
2398 | | /// float a = 10; |
2399 | | /// \endcode |
2400 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> |
2401 | | floatLiteral; |
2402 | | |
2403 | | /// Matches imaginary literals, which are based on integer and floating |
2404 | | /// point literals e.g.: 1i, 1.0i |
2405 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> |
2406 | | imaginaryLiteral; |
2407 | | |
2408 | | /// Matches fixed point literals |
2409 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, FixedPointLiteral> |
2410 | | fixedPointLiteral; |
2411 | | |
2412 | | /// Matches user defined literal operator call. |
2413 | | /// |
2414 | | /// Example match: "foo"_suffix |
2415 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> |
2416 | | userDefinedLiteral; |
2417 | | |
2418 | | /// Matches compound (i.e. non-scalar) literals |
2419 | | /// |
2420 | | /// Example match: {1}, (1, 2) |
2421 | | /// \code |
2422 | | /// int array[4] = {1}; |
2423 | | /// vector int myvec = (vector int)(1, 2); |
2424 | | /// \endcode |
2425 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> |
2426 | | compoundLiteralExpr; |
2427 | | |
2428 | | /// Matches co_await expressions. |
2429 | | /// |
2430 | | /// Given |
2431 | | /// \code |
2432 | | /// co_await 1; |
2433 | | /// \endcode |
2434 | | /// coawaitExpr() |
2435 | | /// matches 'co_await 1' |
2436 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoawaitExpr> |
2437 | | coawaitExpr; |
2438 | | /// Matches co_await expressions where the type of the promise is dependent |
2439 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, DependentCoawaitExpr> |
2440 | | dependentCoawaitExpr; |
2441 | | /// Matches co_yield expressions. |
2442 | | /// |
2443 | | /// Given |
2444 | | /// \code |
2445 | | /// co_yield 1; |
2446 | | /// \endcode |
2447 | | /// coyieldExpr() |
2448 | | /// matches 'co_yield 1' |
2449 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CoyieldExpr> |
2450 | | coyieldExpr; |
2451 | | |
2452 | | /// Matches nullptr literal. |
2453 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> |
2454 | | cxxNullPtrLiteralExpr; |
2455 | | |
2456 | | /// Matches GNU __builtin_choose_expr. |
2457 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> |
2458 | | chooseExpr; |
2459 | | |
2460 | | /// Matches GNU __null expression. |
2461 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> |
2462 | | gnuNullExpr; |
2463 | | |
2464 | | /// Matches C11 _Generic expression. |
2465 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr> |
2466 | | genericSelectionExpr; |
2467 | | |
2468 | | /// Matches atomic builtins. |
2469 | | /// Example matches __atomic_load_n(ptr, 1) |
2470 | | /// \code |
2471 | | /// void foo() { int *ptr; __atomic_load_n(ptr, 1); } |
2472 | | /// \endcode |
2473 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr; |
2474 | | |
2475 | | /// Matches statement expression (GNU extension). |
2476 | | /// |
2477 | | /// Example match: ({ int X = 4; X; }) |
2478 | | /// \code |
2479 | | /// int C = ({ int X = 4; X; }); |
2480 | | /// \endcode |
2481 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr; |
2482 | | |
2483 | | /// Matches binary operator expressions. |
2484 | | /// |
2485 | | /// Example matches a || b |
2486 | | /// \code |
2487 | | /// !(a || b) |
2488 | | /// \endcode |
2489 | | /// See also the binaryOperation() matcher for more-general matching. |
2490 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator> |
2491 | | binaryOperator; |
2492 | | |
2493 | | /// Matches unary operator expressions. |
2494 | | /// |
2495 | | /// Example matches !a |
2496 | | /// \code |
2497 | | /// !a || b |
2498 | | /// \endcode |
2499 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> |
2500 | | unaryOperator; |
2501 | | |
2502 | | /// Matches conditional operator expressions. |
2503 | | /// |
2504 | | /// Example matches a ? b : c |
2505 | | /// \code |
2506 | | /// (a ? b : c) + 42 |
2507 | | /// \endcode |
2508 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator> |
2509 | | conditionalOperator; |
2510 | | |
2511 | | /// Matches binary conditional operator expressions (GNU extension). |
2512 | | /// |
2513 | | /// Example matches a ?: b |
2514 | | /// \code |
2515 | | /// (a ?: b) + 42; |
2516 | | /// \endcode |
2517 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
2518 | | BinaryConditionalOperator> |
2519 | | binaryConditionalOperator; |
2520 | | |
2521 | | /// Matches opaque value expressions. They are used as helpers |
2522 | | /// to reference another expressions and can be met |
2523 | | /// in BinaryConditionalOperators, for example. |
2524 | | /// |
2525 | | /// Example matches 'a' |
2526 | | /// \code |
2527 | | /// (a ?: c) + 42; |
2528 | | /// \endcode |
2529 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr> |
2530 | | opaqueValueExpr; |
2531 | | |
2532 | | /// Matches a C++ static_assert declaration. |
2533 | | /// |
2534 | | /// Example: |
2535 | | /// staticAssertDecl() |
2536 | | /// matches |
2537 | | /// static_assert(sizeof(S) == sizeof(int)) |
2538 | | /// in |
2539 | | /// \code |
2540 | | /// struct S { |
2541 | | /// int x; |
2542 | | /// }; |
2543 | | /// static_assert(sizeof(S) == sizeof(int)); |
2544 | | /// \endcode |
2545 | | extern const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl> |
2546 | | staticAssertDecl; |
2547 | | |
2548 | | /// Matches a reinterpret_cast expression. |
2549 | | /// |
2550 | | /// Either the source expression or the destination type can be matched |
2551 | | /// using has(), but hasDestinationType() is more specific and can be |
2552 | | /// more readable. |
2553 | | /// |
2554 | | /// Example matches reinterpret_cast<char*>(&p) in |
2555 | | /// \code |
2556 | | /// void* p = reinterpret_cast<char*>(&p); |
2557 | | /// \endcode |
2558 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr> |
2559 | | cxxReinterpretCastExpr; |
2560 | | |
2561 | | /// Matches a C++ static_cast expression. |
2562 | | /// |
2563 | | /// \see hasDestinationType |
2564 | | /// \see reinterpretCast |
2565 | | /// |
2566 | | /// Example: |
2567 | | /// cxxStaticCastExpr() |
2568 | | /// matches |
2569 | | /// static_cast<long>(8) |
2570 | | /// in |
2571 | | /// \code |
2572 | | /// long eight(static_cast<long>(8)); |
2573 | | /// \endcode |
2574 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr> |
2575 | | cxxStaticCastExpr; |
2576 | | |
2577 | | /// Matches a dynamic_cast expression. |
2578 | | /// |
2579 | | /// Example: |
2580 | | /// cxxDynamicCastExpr() |
2581 | | /// matches |
2582 | | /// dynamic_cast<D*>(&b); |
2583 | | /// in |
2584 | | /// \code |
2585 | | /// struct B { virtual ~B() {} }; struct D : B {}; |
2586 | | /// B b; |
2587 | | /// D* p = dynamic_cast<D*>(&b); |
2588 | | /// \endcode |
2589 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr> |
2590 | | cxxDynamicCastExpr; |
2591 | | |
2592 | | /// Matches a const_cast expression. |
2593 | | /// |
2594 | | /// Example: Matches const_cast<int*>(&r) in |
2595 | | /// \code |
2596 | | /// int n = 42; |
2597 | | /// const int &r(n); |
2598 | | /// int* p = const_cast<int*>(&r); |
2599 | | /// \endcode |
2600 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr> |
2601 | | cxxConstCastExpr; |
2602 | | |
2603 | | /// Matches a C-style cast expression. |
2604 | | /// |
2605 | | /// Example: Matches (int) 2.2f in |
2606 | | /// \code |
2607 | | /// int i = (int) 2.2f; |
2608 | | /// \endcode |
2609 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr> |
2610 | | cStyleCastExpr; |
2611 | | |
2612 | | /// Matches explicit cast expressions. |
2613 | | /// |
2614 | | /// Matches any cast expression written in user code, whether it be a |
2615 | | /// C-style cast, a functional-style cast, or a keyword cast. |
2616 | | /// |
2617 | | /// Does not match implicit conversions. |
2618 | | /// |
2619 | | /// Note: the name "explicitCast" is chosen to match Clang's terminology, as |
2620 | | /// Clang uses the term "cast" to apply to implicit conversions as well as to |
2621 | | /// actual cast expressions. |
2622 | | /// |
2623 | | /// \see hasDestinationType. |
2624 | | /// |
2625 | | /// Example: matches all five of the casts in |
2626 | | /// \code |
2627 | | /// int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42))))) |
2628 | | /// \endcode |
2629 | | /// but does not match the implicit conversion in |
2630 | | /// \code |
2631 | | /// long ell = 42; |
2632 | | /// \endcode |
2633 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr> |
2634 | | explicitCastExpr; |
2635 | | |
2636 | | /// Matches the implicit cast nodes of Clang's AST. |
2637 | | /// |
2638 | | /// This matches many different places, including function call return value |
2639 | | /// eliding, as well as any type conversions. |
2640 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr> |
2641 | | implicitCastExpr; |
2642 | | |
2643 | | /// Matches any cast nodes of Clang's AST. |
2644 | | /// |
2645 | | /// Example: castExpr() matches each of the following: |
2646 | | /// \code |
2647 | | /// (int) 3; |
2648 | | /// const_cast<Expr *>(SubExpr); |
2649 | | /// char c = 0; |
2650 | | /// \endcode |
2651 | | /// but does not match |
2652 | | /// \code |
2653 | | /// int i = (0); |
2654 | | /// int k = 0; |
2655 | | /// \endcode |
2656 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr; |
2657 | | |
2658 | | /// Matches functional cast expressions |
2659 | | /// |
2660 | | /// Example: Matches Foo(bar); |
2661 | | /// \code |
2662 | | /// Foo f = bar; |
2663 | | /// Foo g = (Foo) bar; |
2664 | | /// Foo h = Foo(bar); |
2665 | | /// \endcode |
2666 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr> |
2667 | | cxxFunctionalCastExpr; |
2668 | | |
2669 | | /// Matches functional cast expressions having N != 1 arguments |
2670 | | /// |
2671 | | /// Example: Matches Foo(bar, bar) |
2672 | | /// \code |
2673 | | /// Foo h = Foo(bar, bar); |
2674 | | /// \endcode |
2675 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr> |
2676 | | cxxTemporaryObjectExpr; |
2677 | | |
2678 | | /// Matches predefined identifier expressions [C99 6.4.2.2]. |
2679 | | /// |
2680 | | /// Example: Matches __func__ |
2681 | | /// \code |
2682 | | /// printf("%s", __func__); |
2683 | | /// \endcode |
2684 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr> |
2685 | | predefinedExpr; |
2686 | | |
2687 | | /// Matches C99 designated initializer expressions [C99 6.7.8]. |
2688 | | /// |
2689 | | /// Example: Matches { [2].y = 1.0, [0].x = 1.0 } |
2690 | | /// \code |
2691 | | /// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; |
2692 | | /// \endcode |
2693 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr> |
2694 | | designatedInitExpr; |
2695 | | |
2696 | | /// Matches designated initializer expressions that contain |
2697 | | /// a specific number of designators. |
2698 | | /// |
2699 | | /// Example: Given |
2700 | | /// \code |
2701 | | /// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; |
2702 | | /// point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }; |
2703 | | /// \endcode |
2704 | | /// designatorCountIs(2) |
2705 | | /// matches '{ [2].y = 1.0, [0].x = 1.0 }', |
2706 | | /// but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'. |
2707 | 60 | AST_MATCHER_P(DesignatedInitExpr, designatorCountIs, unsigned, N) { |
2708 | 60 | return Node.size() == N; |
2709 | 60 | } |
2710 | | |
2711 | | /// Matches \c QualTypes in the clang AST. |
2712 | | extern const internal::VariadicAllOfMatcher<QualType> qualType; |
2713 | | |
2714 | | /// Matches \c Types in the clang AST. |
2715 | | extern const internal::VariadicAllOfMatcher<Type> type; |
2716 | | |
2717 | | /// Matches \c TypeLocs in the clang AST. |
2718 | | extern const internal::VariadicAllOfMatcher<TypeLoc> typeLoc; |
2719 | | |
2720 | | /// Matches if any of the given matchers matches. |
2721 | | /// |
2722 | | /// Unlike \c anyOf, \c eachOf will generate a match result for each |
2723 | | /// matching submatcher. |
2724 | | /// |
2725 | | /// For example, in: |
2726 | | /// \code |
2727 | | /// class A { int a; int b; }; |
2728 | | /// \endcode |
2729 | | /// The matcher: |
2730 | | /// \code |
2731 | | /// cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), |
2732 | | /// has(fieldDecl(hasName("b")).bind("v")))) |
2733 | | /// \endcode |
2734 | | /// will generate two results binding "v", the first of which binds |
2735 | | /// the field declaration of \c a, the second the field declaration of |
2736 | | /// \c b. |
2737 | | /// |
2738 | | /// Usable as: Any Matcher |
2739 | | extern const internal::VariadicOperatorMatcherFunc< |
2740 | | 2, std::numeric_limits<unsigned>::max()> |
2741 | | eachOf; |
2742 | | |
2743 | | /// Matches if any of the given matchers matches. |
2744 | | /// |
2745 | | /// Usable as: Any Matcher |
2746 | | extern const internal::VariadicOperatorMatcherFunc< |
2747 | | 2, std::numeric_limits<unsigned>::max()> |
2748 | | anyOf; |
2749 | | |
2750 | | /// Matches if all given matchers match. |
2751 | | /// |
2752 | | /// Usable as: Any Matcher |
2753 | | extern const internal::VariadicOperatorMatcherFunc< |
2754 | | 2, std::numeric_limits<unsigned>::max()> |
2755 | | allOf; |
2756 | | |
2757 | | /// Matches any node regardless of the submatcher. |
2758 | | /// |
2759 | | /// However, \c optionally will retain any bindings generated by the submatcher. |
2760 | | /// Useful when additional information which may or may not present about a main |
2761 | | /// matching node is desired. |
2762 | | /// |
2763 | | /// For example, in: |
2764 | | /// \code |
2765 | | /// class Foo { |
2766 | | /// int bar; |
2767 | | /// } |
2768 | | /// \endcode |
2769 | | /// The matcher: |
2770 | | /// \code |
2771 | | /// cxxRecordDecl( |
2772 | | /// optionally(has( |
2773 | | /// fieldDecl(hasName("bar")).bind("var") |
2774 | | /// ))).bind("record") |
2775 | | /// \endcode |
2776 | | /// will produce a result binding for both "record" and "var". |
2777 | | /// The matcher will produce a "record" binding for even if there is no data |
2778 | | /// member named "bar" in that class. |
2779 | | /// |
2780 | | /// Usable as: Any Matcher |
2781 | | extern const internal::VariadicOperatorMatcherFunc<1, 1> optionally; |
2782 | | |
2783 | | /// Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) |
2784 | | /// |
2785 | | /// Given |
2786 | | /// \code |
2787 | | /// Foo x = bar; |
2788 | | /// int y = sizeof(x) + alignof(x); |
2789 | | /// \endcode |
2790 | | /// unaryExprOrTypeTraitExpr() |
2791 | | /// matches \c sizeof(x) and \c alignof(x) |
2792 | | extern const internal::VariadicDynCastAllOfMatcher<Stmt, |
2793 | | UnaryExprOrTypeTraitExpr> |
2794 | | unaryExprOrTypeTraitExpr; |
2795 | | |
2796 | | /// Matches any of the \p NodeMatchers with InnerMatchers nested within |
2797 | | /// |
2798 | | /// Given |
2799 | | /// \code |
2800 | | /// if (true); |
2801 | | /// for (; true; ); |
2802 | | /// \endcode |
2803 | | /// with the matcher |
2804 | | /// \code |
2805 | | /// mapAnyOf(ifStmt, forStmt).with( |
2806 | | /// hasCondition(cxxBoolLiteralExpr(equals(true))) |
2807 | | /// ).bind("trueCond") |
2808 | | /// \endcode |
2809 | | /// matches the \c if and the \c for. It is equivalent to: |
2810 | | /// \code |
2811 | | /// auto trueCond = hasCondition(cxxBoolLiteralExpr(equals(true))); |
2812 | | /// anyOf( |
2813 | | /// ifStmt(trueCond).bind("trueCond"), |
2814 | | /// forStmt(trueCond).bind("trueCond") |
2815 | | /// ); |
2816 | | /// \endcode |
2817 | | /// |
2818 | | /// The with() chain-call accepts zero or more matchers which are combined |
2819 | | /// as-if with allOf() in each of the node matchers. |
2820 | | /// Usable as: Any Matcher |
2821 | | template <typename T, typename... U> |
2822 | | auto mapAnyOf(internal::VariadicDynCastAllOfMatcher<T, U> const &...) { |
2823 | | return internal::MapAnyOfHelper<U...>(); |
2824 | | } |
2825 | | |
2826 | | /// Matches nodes which can be used with binary operators. |
2827 | | /// |
2828 | | /// The code |
2829 | | /// \code |
2830 | | /// var1 != var2; |
2831 | | /// \endcode |
2832 | | /// might be represented in the clang AST as a binaryOperator, a |
2833 | | /// cxxOperatorCallExpr or a cxxRewrittenBinaryOperator, depending on |
2834 | | /// |
2835 | | /// * whether the types of var1 and var2 are fundamental (binaryOperator) or at |
2836 | | /// least one is a class type (cxxOperatorCallExpr) |
2837 | | /// * whether the code appears in a template declaration, if at least one of the |
2838 | | /// vars is a dependent-type (binaryOperator) |
2839 | | /// * whether the code relies on a rewritten binary operator, such as a |
2840 | | /// spaceship operator or an inverted equality operator |
2841 | | /// (cxxRewrittenBinaryOperator) |
2842 | | /// |
2843 | | /// This matcher elides details in places where the matchers for the nodes are |
2844 | | /// compatible. |
2845 | | /// |
2846 | | /// Given |
2847 | | /// \code |
2848 | | /// binaryOperation( |
2849 | | /// hasOperatorName("!="), |
2850 | | /// hasLHS(expr().bind("lhs")), |
2851 | | /// hasRHS(expr().bind("rhs")) |
2852 | | /// ) |
2853 | | /// \endcode |
2854 | | /// matches each use of "!=" in: |
2855 | | /// \code |
2856 | | /// struct S{ |
2857 | | /// bool operator!=(const S&) const; |
2858 | | /// }; |
2859 | | /// |
2860 | | /// void foo() |
2861 | | /// { |
2862 | | /// 1 != 2; |
2863 | | /// S() != S(); |
2864 | | /// } |
2865 | | /// |
2866 | | /// template<typename T> |
2867 | | /// void templ() |
2868 | | /// { |
2869 | | /// 1 != 2; |
2870 | | /// T() != S(); |
2871 | | /// } |
2872 | | /// struct HasOpEq |
2873 | | /// { |
2874 | | /// bool operator==(const HasOpEq &) const; |
2875 | | /// }; |
2876 | | /// |
2877 | | /// void inverse() |
2878 | | /// { |
2879 | | /// HasOpEq s1; |
2880 | | /// HasOpEq s2; |
2881 | | /// if (s1 != s2) |
2882 | | /// return; |
2883 | | /// } |
2884 | | /// |
2885 | | /// struct HasSpaceship |
2886 | | /// { |
2887 | | /// bool operator<=>(const HasOpEq &) const; |
2888 | | /// }; |
2889 | | /// |
2890 | | /// void use_spaceship() |
2891 | | /// { |
2892 | | /// HasSpaceship s1; |
2893 | | /// HasSpaceship s2; |
2894 | | /// if (s1 != s2) |
2895 | | /// return; |
2896 | | /// } |
2897 | | /// \endcode |
2898 | | extern const internal::MapAnyOfMatcher<BinaryOperator, CXXOperatorCallExpr, |
2899 | | CXXRewrittenBinaryOperator> |
2900 | | binaryOperation; |
2901 | | |
2902 | | /// Matches function calls and constructor calls |
2903 | | /// |
2904 | | /// Because CallExpr and CXXConstructExpr do not share a common |
2905 | | /// base class with API accessing arguments etc, AST Matchers for code |
2906 | | /// which should match both are typically duplicated. This matcher |
2907 | | /// removes the need for duplication. |
2908 | | /// |
2909 | | /// Given code |
2910 | | /// \code |
2911 | | /// struct ConstructorTakesInt |
2912 | | /// { |
2913 | | /// ConstructorTakesInt(int i) {} |
2914 | | /// }; |
2915 | | /// |
2916 | | /// void callTakesInt(int i) |
2917 | | /// { |
2918 | | /// } |
2919 | | /// |
2920 | | /// void doCall() |
2921 | | /// { |
2922 | | /// callTakesInt(42); |
2923 | | /// } |
2924 | | /// |
2925 | | /// void doConstruct() |
2926 | | /// { |
2927 | | /// ConstructorTakesInt cti(42); |
2928 | | /// } |
2929 | | /// \endcode |
2930 | | /// |
2931 | | /// The matcher |
2932 | | /// \code |
2933 | | /// invocation(hasArgument(0, integerLiteral(equals(42)))) |
2934 | | /// \endcode |
2935 | | /// matches the expression in both doCall and doConstruct |
2936 | | extern const internal::MapAnyOfMatcher<CallExpr, CXXConstructExpr> invocation; |
2937 | | |
2938 | | /// Matches unary expressions that have a specific type of argument. |
2939 | | /// |
2940 | | /// Given |
2941 | | /// \code |
2942 | | /// int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); |
2943 | | /// \endcode |
2944 | | /// unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) |
2945 | | /// matches \c sizeof(a) and \c alignof(c) |
2946 | | AST_MATCHER_P(UnaryExprOrTypeTraitExpr, hasArgumentOfType, |
2947 | 115 | internal::Matcher<QualType>, InnerMatcher) { |
2948 | 115 | const QualType ArgumentType = Node.getTypeOfArgument(); |
2949 | 115 | return InnerMatcher.matches(ArgumentType, Finder, Builder); |
2950 | 115 | } |
2951 | | |
2952 | | /// Matches unary expressions of a certain kind. |
2953 | | /// |
2954 | | /// Given |
2955 | | /// \code |
2956 | | /// int x; |
2957 | | /// int s = sizeof(x) + alignof(x) |
2958 | | /// \endcode |
2959 | | /// unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) |
2960 | | /// matches \c sizeof(x) |
2961 | | /// |
2962 | | /// If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter |
2963 | | /// should be passed as a quoted string. e.g., ofKind("UETT_SizeOf"). |
2964 | 176 | AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind) { |
2965 | 176 | return Node.getKind() == Kind; |
2966 | 176 | } |
2967 | | |
2968 | | /// Same as unaryExprOrTypeTraitExpr, but only matching |
2969 | | /// alignof. |
2970 | | inline internal::BindableMatcher<Stmt> alignOfExpr( |
2971 | 14 | const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { |
2972 | 14 | return stmt(unaryExprOrTypeTraitExpr( |
2973 | 14 | allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)), |
2974 | 14 | InnerMatcher))); |
2975 | 14 | } |
2976 | | |
2977 | | /// Same as unaryExprOrTypeTraitExpr, but only matching |
2978 | | /// sizeof. |
2979 | | inline internal::BindableMatcher<Stmt> sizeOfExpr( |
2980 | 394 | const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { |
2981 | 394 | return stmt(unaryExprOrTypeTraitExpr( |
2982 | 394 | allOf(ofKind(UETT_SizeOf), InnerMatcher))); |
2983 | 394 | } |
2984 | | |
2985 | | /// Matches NamedDecl nodes that have the specified name. |
2986 | | /// |
2987 | | /// Supports specifying enclosing namespaces or classes by prefixing the name |
2988 | | /// with '<enclosing>::'. |
2989 | | /// Does not match typedefs of an underlying type with the given name. |
2990 | | /// |
2991 | | /// Example matches X (Name == "X") |
2992 | | /// \code |
2993 | | /// class X; |
2994 | | /// \endcode |
2995 | | /// |
2996 | | /// Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") |
2997 | | /// \code |
2998 | | /// namespace a { namespace b { class X; } } |
2999 | | /// \endcode |
3000 | 59.4k | inline internal::Matcher<NamedDecl> hasName(StringRef Name) { |
3001 | 59.4k | return internal::Matcher<NamedDecl>( |
3002 | 59.4k | new internal::HasNameMatcher({std::string(Name)})); |
3003 | 59.4k | } |
3004 | | |
3005 | | /// Matches NamedDecl nodes that have any of the specified names. |
3006 | | /// |
3007 | | /// This matcher is only provided as a performance optimization of hasName. |
3008 | | /// \code |
3009 | | /// hasAnyName(a, b, c) |
3010 | | /// \endcode |
3011 | | /// is equivalent to, but faster than |
3012 | | /// \code |
3013 | | /// anyOf(hasName(a), hasName(b), hasName(c)) |
3014 | | /// \endcode |
3015 | | extern const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef, |
3016 | | internal::hasAnyNameFunc> |
3017 | | hasAnyName; |
3018 | | |
3019 | | /// Matches NamedDecl nodes whose fully qualified names contain |
3020 | | /// a substring matched by the given RegExp. |
3021 | | /// |
3022 | | /// Supports specifying enclosing namespaces or classes by |
3023 | | /// prefixing the name with '<enclosing>::'. Does not match typedefs |
3024 | | /// of an underlying type with the given name. |
3025 | | /// |
3026 | | /// Example matches X (regexp == "::X") |
3027 | | /// \code |
3028 | | /// class X; |
3029 | | /// \endcode |
3030 | | /// |
3031 | | /// Example matches X (regexp is one of "::X", "^foo::.*X", among others) |
3032 | | /// \code |
3033 | | /// namespace foo { namespace bar { class X; } } |
3034 | | /// \endcode |
3035 | 3.74k | AST_MATCHER_REGEX(NamedDecl, matchesName, RegExp) { |
3036 | 3.74k | std::string FullNameString = "::" + Node.getQualifiedNameAsString(); |
3037 | 3.74k | return RegExp->match(FullNameString); |
3038 | 3.74k | } |
3039 | | |
3040 | | /// Matches overloaded operator names. |
3041 | | /// |
3042 | | /// Matches overloaded operator names specified in strings without the |
3043 | | /// "operator" prefix: e.g. "<<". |
3044 | | /// |
3045 | | /// Given: |
3046 | | /// \code |
3047 | | /// class A { int operator*(); }; |
3048 | | /// const A &operator<<(const A &a, const A &b); |
3049 | | /// A a; |
3050 | | /// a << a; // <-- This matches |
3051 | | /// \endcode |
3052 | | /// |
3053 | | /// \c cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the |
3054 | | /// specified line and |
3055 | | /// \c cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) |
3056 | | /// matches the declaration of \c A. |
3057 | | /// |
3058 | | /// Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl> |
3059 | | inline internal::PolymorphicMatcher< |
3060 | | internal::HasOverloadedOperatorNameMatcher, |
3061 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), |
3062 | | std::vector<std::string>> |
3063 | 3.00k | hasOverloadedOperatorName(StringRef Name) { |
3064 | 3.00k | return internal::PolymorphicMatcher< |
3065 | 3.00k | internal::HasOverloadedOperatorNameMatcher, |
3066 | 3.00k | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), |
3067 | 3.00k | std::vector<std::string>>({std::string(Name)}); |
3068 | 3.00k | } |
3069 | | |
3070 | | /// Matches overloaded operator names. |
3071 | | /// |
3072 | | /// Matches overloaded operator names specified in strings without the |
3073 | | /// "operator" prefix: e.g. "<<". |
3074 | | /// |
3075 | | /// hasAnyOverloadedOperatorName("+", "-") |
3076 | | /// Is equivalent to |
3077 | | /// anyOf(hasOverloadedOperatorName("+"), hasOverloadedOperatorName("-")) |
3078 | | extern const internal::VariadicFunction< |
3079 | | internal::PolymorphicMatcher<internal::HasOverloadedOperatorNameMatcher, |
3080 | | AST_POLYMORPHIC_SUPPORTED_TYPES( |
3081 | | CXXOperatorCallExpr, FunctionDecl), |
3082 | | std::vector<std::string>>, |
3083 | | StringRef, internal::hasAnyOverloadedOperatorNameFunc> |
3084 | | hasAnyOverloadedOperatorName; |
3085 | | |
3086 | | /// Matches template-dependent, but known, member names. |
3087 | | /// |
3088 | | /// In template declarations, dependent members are not resolved and so can |
3089 | | /// not be matched to particular named declarations. |
3090 | | /// |
3091 | | /// This matcher allows to match on the known name of members. |
3092 | | /// |
3093 | | /// Given |
3094 | | /// \code |
3095 | | /// template <typename T> |
3096 | | /// struct S { |
3097 | | /// void mem(); |
3098 | | /// }; |
3099 | | /// template <typename T> |
3100 | | /// void x() { |
3101 | | /// S<T> s; |
3102 | | /// s.mem(); |
3103 | | /// } |
3104 | | /// \endcode |
3105 | | /// \c cxxDependentScopeMemberExpr(hasMemberName("mem")) matches `s.mem()` |
3106 | 8 | AST_MATCHER_P(CXXDependentScopeMemberExpr, hasMemberName, std::string, N) { |
3107 | 8 | return Node.getMember().getAsString() == N; |
3108 | 8 | } |
3109 | | |
3110 | | /// Matches template-dependent, but known, member names against an already-bound |
3111 | | /// node |
3112 | | /// |
3113 | | /// In template declarations, dependent members are not resolved and so can |
3114 | | /// not be matched to particular named declarations. |
3115 | | /// |
3116 | | /// This matcher allows to match on the name of already-bound VarDecl, FieldDecl |
3117 | | /// and CXXMethodDecl nodes. |
3118 | | /// |
3119 | | /// Given |
3120 | | /// \code |
3121 | | /// template <typename T> |
3122 | | /// struct S { |
3123 | | /// void mem(); |
3124 | | /// }; |
3125 | | /// template <typename T> |
3126 | | /// void x() { |
3127 | | /// S<T> s; |
3128 | | /// s.mem(); |
3129 | | /// } |
3130 | | /// \endcode |
3131 | | /// The matcher |
3132 | | /// @code |
3133 | | /// \c cxxDependentScopeMemberExpr( |
3134 | | /// hasObjectExpression(declRefExpr(hasType(templateSpecializationType( |
3135 | | /// hasDeclaration(classTemplateDecl(has(cxxRecordDecl(has( |
3136 | | /// cxxMethodDecl(hasName("mem")).bind("templMem") |
3137 | | /// ))))) |
3138 | | /// )))), |
3139 | | /// memberHasSameNameAsBoundNode("templMem") |
3140 | | /// ) |
3141 | | /// @endcode |
3142 | | /// first matches and binds the @c mem member of the @c S template, then |
3143 | | /// compares its name to the usage in @c s.mem() in the @c x function template |
3144 | | AST_MATCHER_P(CXXDependentScopeMemberExpr, memberHasSameNameAsBoundNode, |
3145 | 7 | std::string, BindingID) { |
3146 | 7 | auto MemberName = Node.getMember().getAsString(); |
3147 | | |
3148 | 7 | return Builder->removeBindings( |
3149 | 7 | [this, MemberName](const BoundNodesMap &Nodes) { |
3150 | 7 | const auto &BN = Nodes.getNode(this->BindingID); |
3151 | 7 | if (const auto *ND = BN.get<NamedDecl>()) { |
3152 | 7 | if (!isa<FieldDecl, CXXMethodDecl, VarDecl>(ND)) |
3153 | 1 | return true; |
3154 | 6 | return ND->getName() != MemberName; |
3155 | 7 | } |
3156 | 0 | return true; |
3157 | 7 | }); |
3158 | 7 | } |
3159 | | |
3160 | | /// Matches C++ classes that are directly or indirectly derived from a class |
3161 | | /// matching \c Base, or Objective-C classes that directly or indirectly |
3162 | | /// subclass a class matching \c Base. |
3163 | | /// |
3164 | | /// Note that a class is not considered to be derived from itself. |
3165 | | /// |
3166 | | /// Example matches Y, Z, C (Base == hasName("X")) |
3167 | | /// \code |
3168 | | /// class X; |
3169 | | /// class Y : public X {}; // directly derived |
3170 | | /// class Z : public Y {}; // indirectly derived |
3171 | | /// typedef X A; |
3172 | | /// typedef A B; |
3173 | | /// class C : public B {}; // derived from a typedef of X |
3174 | | /// \endcode |
3175 | | /// |
3176 | | /// In the following example, Bar matches isDerivedFrom(hasName("X")): |
3177 | | /// \code |
3178 | | /// class Foo; |
3179 | | /// typedef Foo X; |
3180 | | /// class Bar : public Foo {}; // derived from a type that X is a typedef of |
3181 | | /// \endcode |
3182 | | /// |
3183 | | /// In the following example, Bar matches isDerivedFrom(hasName("NSObject")) |
3184 | | /// \code |
3185 | | /// @interface NSObject @end |
3186 | | /// @interface Bar : NSObject @end |
3187 | | /// \endcode |
3188 | | /// |
3189 | | /// Usable as: Matcher<CXXRecordDecl>, Matcher<ObjCInterfaceDecl> |
3190 | | AST_POLYMORPHIC_MATCHER_P( |
3191 | | isDerivedFrom, |
3192 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), |
3193 | 5.59k | internal::Matcher<NamedDecl>, Base) { |
3194 | | // Check if the node is a C++ struct/union/class. |
3195 | 5.59k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) |
3196 | 4.47k | return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false); |
3197 | | |
3198 | | // The node must be an Objective-C class. |
3199 | 1.12k | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); |
3200 | 1.12k | return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, |
3201 | 1.12k | /*Directly=*/false); |
3202 | 5.59k | } clang::ast_matchers::internal::matcher_isDerivedFrom0Matcher<clang::CXXRecordDecl, clang::ast_matchers::internal::Matcher<clang::NamedDecl> >::matches(clang::CXXRecordDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3193 | 4.47k | internal::Matcher<NamedDecl>, Base) { | 3194 | | // Check if the node is a C++ struct/union/class. | 3195 | 4.47k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3196 | 4.47k | return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false); | 3197 | | | 3198 | | // The node must be an Objective-C class. | 3199 | 0 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3200 | 0 | return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, | 3201 | 0 | /*Directly=*/false); | 3202 | 4.47k | } |
clang::ast_matchers::internal::matcher_isDerivedFrom0Matcher<clang::ObjCInterfaceDecl, clang::ast_matchers::internal::Matcher<clang::NamedDecl> >::matches(clang::ObjCInterfaceDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3193 | 1.12k | internal::Matcher<NamedDecl>, Base) { | 3194 | | // Check if the node is a C++ struct/union/class. | 3195 | 1.12k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3196 | 0 | return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/false); | 3197 | | | 3198 | | // The node must be an Objective-C class. | 3199 | 1.12k | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3200 | 1.12k | return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, | 3201 | 1.12k | /*Directly=*/false); | 3202 | 1.12k | } |
|
3203 | | |
3204 | | /// Overloaded method as shortcut for \c isDerivedFrom(hasName(...)). |
3205 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3206 | | isDerivedFrom, |
3207 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), |
3208 | 4.25k | std::string, BaseName, 1) { |
3209 | 4.25k | if (BaseName.empty()) |
3210 | 100 | return false; |
3211 | | |
3212 | 4.15k | const auto M = isDerivedFrom(hasName(BaseName)); |
3213 | | |
3214 | 4.15k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) |
3215 | 3.25k | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); |
3216 | | |
3217 | 896 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); |
3218 | 896 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); |
3219 | 4.15k | } clang::ast_matchers::internal::matcher_isDerivedFrom1Matcher<clang::CXXRecordDecl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::CXXRecordDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3208 | 3.35k | std::string, BaseName, 1) { | 3209 | 3.35k | if (BaseName.empty()) | 3210 | 100 | return false; | 3211 | | | 3212 | 3.25k | const auto M = isDerivedFrom(hasName(BaseName)); | 3213 | | | 3214 | 3.25k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3215 | 3.25k | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3216 | | | 3217 | 0 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3218 | 0 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3219 | 3.25k | } |
clang::ast_matchers::internal::matcher_isDerivedFrom1Matcher<clang::ObjCInterfaceDecl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::ObjCInterfaceDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3208 | 896 | std::string, BaseName, 1) { | 3209 | 896 | if (BaseName.empty()) | 3210 | 0 | return false; | 3211 | | | 3212 | 896 | const auto M = isDerivedFrom(hasName(BaseName)); | 3213 | | | 3214 | 896 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3215 | 0 | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3216 | | | 3217 | 896 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3218 | 896 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3219 | 896 | } |
|
3220 | | |
3221 | | /// Matches C++ classes that have a direct or indirect base matching \p |
3222 | | /// BaseSpecMatcher. |
3223 | | /// |
3224 | | /// Example: |
3225 | | /// matcher hasAnyBase(hasType(cxxRecordDecl(hasName("SpecialBase")))) |
3226 | | /// \code |
3227 | | /// class Foo; |
3228 | | /// class Bar : Foo {}; |
3229 | | /// class Baz : Bar {}; |
3230 | | /// class SpecialBase; |
3231 | | /// class Proxy : SpecialBase {}; // matches Proxy |
3232 | | /// class IndirectlyDerived : Proxy {}; //matches IndirectlyDerived |
3233 | | /// \endcode |
3234 | | /// |
3235 | | // FIXME: Refactor this and isDerivedFrom to reuse implementation. |
3236 | | AST_MATCHER_P(CXXRecordDecl, hasAnyBase, internal::Matcher<CXXBaseSpecifier>, |
3237 | 1.72k | BaseSpecMatcher) { |
3238 | 1.72k | return internal::matchesAnyBase(Node, BaseSpecMatcher, Finder, Builder); |
3239 | 1.72k | } |
3240 | | |
3241 | | /// Matches C++ classes that have a direct base matching \p BaseSpecMatcher. |
3242 | | /// |
3243 | | /// Example: |
3244 | | /// matcher hasDirectBase(hasType(cxxRecordDecl(hasName("SpecialBase")))) |
3245 | | /// \code |
3246 | | /// class Foo; |
3247 | | /// class Bar : Foo {}; |
3248 | | /// class Baz : Bar {}; |
3249 | | /// class SpecialBase; |
3250 | | /// class Proxy : SpecialBase {}; // matches Proxy |
3251 | | /// class IndirectlyDerived : Proxy {}; // doesn't match |
3252 | | /// \endcode |
3253 | | AST_MATCHER_P(CXXRecordDecl, hasDirectBase, internal::Matcher<CXXBaseSpecifier>, |
3254 | 504 | BaseSpecMatcher) { |
3255 | 504 | return Node.hasDefinition() && |
3256 | 504 | llvm::any_of(Node.bases(), [&](const CXXBaseSpecifier &Base) 222 { |
3257 | 170 | return BaseSpecMatcher.matches(Base, Finder, Builder); |
3258 | 170 | }); |
3259 | 504 | } |
3260 | | |
3261 | | /// Similar to \c isDerivedFrom(), but also matches classes that directly |
3262 | | /// match \c Base. |
3263 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3264 | | isSameOrDerivedFrom, |
3265 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), |
3266 | 1.40k | internal::Matcher<NamedDecl>, Base, 0) { |
3267 | 1.40k | const auto M = anyOf(Base, isDerivedFrom(Base)); |
3268 | | |
3269 | 1.40k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) |
3270 | 1.10k | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); |
3271 | | |
3272 | 308 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); |
3273 | 308 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); |
3274 | 1.40k | } clang::ast_matchers::internal::matcher_isSameOrDerivedFrom0Matcher<clang::CXXRecordDecl, clang::ast_matchers::internal::Matcher<clang::NamedDecl> >::matches(clang::CXXRecordDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3266 | 1.10k | internal::Matcher<NamedDecl>, Base, 0) { | 3267 | 1.10k | const auto M = anyOf(Base, isDerivedFrom(Base)); | 3268 | | | 3269 | 1.10k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3270 | 1.10k | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3271 | | | 3272 | 0 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3273 | 0 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3274 | 1.10k | } |
clang::ast_matchers::internal::matcher_isSameOrDerivedFrom0Matcher<clang::ObjCInterfaceDecl, clang::ast_matchers::internal::Matcher<clang::NamedDecl> >::matches(clang::ObjCInterfaceDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3266 | 308 | internal::Matcher<NamedDecl>, Base, 0) { | 3267 | 308 | const auto M = anyOf(Base, isDerivedFrom(Base)); | 3268 | | | 3269 | 308 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3270 | 0 | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3271 | | | 3272 | 308 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3273 | 308 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3274 | 308 | } |
|
3275 | | |
3276 | | /// Overloaded method as shortcut for |
3277 | | /// \c isSameOrDerivedFrom(hasName(...)). |
3278 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3279 | | isSameOrDerivedFrom, |
3280 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), |
3281 | 1.50k | std::string, BaseName, 1) { |
3282 | 1.50k | if (BaseName.empty()) |
3283 | 100 | return false; |
3284 | | |
3285 | 1.40k | const auto M = isSameOrDerivedFrom(hasName(BaseName)); |
3286 | | |
3287 | 1.40k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) |
3288 | 1.09k | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); |
3289 | | |
3290 | 308 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); |
3291 | 308 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); |
3292 | 1.40k | } clang::ast_matchers::internal::matcher_isSameOrDerivedFrom1Matcher<clang::CXXRecordDecl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::CXXRecordDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3281 | 1.19k | std::string, BaseName, 1) { | 3282 | 1.19k | if (BaseName.empty()) | 3283 | 100 | return false; | 3284 | | | 3285 | 1.09k | const auto M = isSameOrDerivedFrom(hasName(BaseName)); | 3286 | | | 3287 | 1.09k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3288 | 1.09k | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3289 | | | 3290 | 0 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3291 | 0 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3292 | 1.09k | } |
clang::ast_matchers::internal::matcher_isSameOrDerivedFrom1Matcher<clang::ObjCInterfaceDecl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::ObjCInterfaceDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3281 | 308 | std::string, BaseName, 1) { | 3282 | 308 | if (BaseName.empty()) | 3283 | 0 | return false; | 3284 | | | 3285 | 308 | const auto M = isSameOrDerivedFrom(hasName(BaseName)); | 3286 | | | 3287 | 308 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3288 | 0 | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3289 | | | 3290 | 308 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3291 | 308 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3292 | 308 | } |
|
3293 | | |
3294 | | /// Matches C++ or Objective-C classes that are directly derived from a class |
3295 | | /// matching \c Base. |
3296 | | /// |
3297 | | /// Note that a class is not considered to be derived from itself. |
3298 | | /// |
3299 | | /// Example matches Y, C (Base == hasName("X")) |
3300 | | /// \code |
3301 | | /// class X; |
3302 | | /// class Y : public X {}; // directly derived |
3303 | | /// class Z : public Y {}; // indirectly derived |
3304 | | /// typedef X A; |
3305 | | /// typedef A B; |
3306 | | /// class C : public B {}; // derived from a typedef of X |
3307 | | /// \endcode |
3308 | | /// |
3309 | | /// In the following example, Bar matches isDerivedFrom(hasName("X")): |
3310 | | /// \code |
3311 | | /// class Foo; |
3312 | | /// typedef Foo X; |
3313 | | /// class Bar : public Foo {}; // derived from a type that X is a typedef of |
3314 | | /// \endcode |
3315 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3316 | | isDirectlyDerivedFrom, |
3317 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), |
3318 | 1.26k | internal::Matcher<NamedDecl>, Base, 0) { |
3319 | | // Check if the node is a C++ struct/union/class. |
3320 | 1.26k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) |
3321 | 420 | return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/true); |
3322 | | |
3323 | | // The node must be an Objective-C class. |
3324 | 840 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); |
3325 | 840 | return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, |
3326 | 840 | /*Directly=*/true); |
3327 | 1.26k | } clang::ast_matchers::internal::matcher_isDirectlyDerivedFrom0Matcher<clang::CXXRecordDecl, clang::ast_matchers::internal::Matcher<clang::NamedDecl> >::matches(clang::CXXRecordDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3318 | 420 | internal::Matcher<NamedDecl>, Base, 0) { | 3319 | | // Check if the node is a C++ struct/union/class. | 3320 | 420 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3321 | 420 | return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/true); | 3322 | | | 3323 | | // The node must be an Objective-C class. | 3324 | 0 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3325 | 0 | return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, | 3326 | 0 | /*Directly=*/true); | 3327 | 420 | } |
clang::ast_matchers::internal::matcher_isDirectlyDerivedFrom0Matcher<clang::ObjCInterfaceDecl, clang::ast_matchers::internal::Matcher<clang::NamedDecl> >::matches(clang::ObjCInterfaceDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3318 | 840 | internal::Matcher<NamedDecl>, Base, 0) { | 3319 | | // Check if the node is a C++ struct/union/class. | 3320 | 840 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3321 | 0 | return Finder->classIsDerivedFrom(RD, Base, Builder, /*Directly=*/true); | 3322 | | | 3323 | | // The node must be an Objective-C class. | 3324 | 840 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3325 | 840 | return Finder->objcClassIsDerivedFrom(InterfaceDecl, Base, Builder, | 3326 | 840 | /*Directly=*/true); | 3327 | 840 | } |
|
3328 | | |
3329 | | /// Overloaded method as shortcut for \c isDirectlyDerivedFrom(hasName(...)). |
3330 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3331 | | isDirectlyDerivedFrom, |
3332 | | AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, ObjCInterfaceDecl), |
3333 | 1.32k | std::string, BaseName, 1) { |
3334 | 1.32k | if (BaseName.empty()) |
3335 | 100 | return false; |
3336 | 1.22k | const auto M = isDirectlyDerivedFrom(hasName(BaseName)); |
3337 | | |
3338 | 1.22k | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) |
3339 | 380 | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); |
3340 | | |
3341 | 840 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); |
3342 | 840 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); |
3343 | 1.22k | } clang::ast_matchers::internal::matcher_isDirectlyDerivedFrom1Matcher<clang::CXXRecordDecl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::CXXRecordDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3333 | 480 | std::string, BaseName, 1) { | 3334 | 480 | if (BaseName.empty()) | 3335 | 100 | return false; | 3336 | 380 | const auto M = isDirectlyDerivedFrom(hasName(BaseName)); | 3337 | | | 3338 | 380 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3339 | 380 | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3340 | | | 3341 | 0 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3342 | 0 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3343 | 380 | } |
clang::ast_matchers::internal::matcher_isDirectlyDerivedFrom1Matcher<clang::ObjCInterfaceDecl, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::matches(clang::ObjCInterfaceDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3333 | 840 | std::string, BaseName, 1) { | 3334 | 840 | if (BaseName.empty()) | 3335 | 0 | return false; | 3336 | 840 | const auto M = isDirectlyDerivedFrom(hasName(BaseName)); | 3337 | | | 3338 | 840 | if (const auto *RD = dyn_cast<CXXRecordDecl>(&Node)) | 3339 | 0 | return Matcher<CXXRecordDecl>(M).matches(*RD, Finder, Builder); | 3340 | | | 3341 | 840 | const auto *InterfaceDecl = cast<ObjCInterfaceDecl>(&Node); | 3342 | 840 | return Matcher<ObjCInterfaceDecl>(M).matches(*InterfaceDecl, Finder, Builder); | 3343 | 840 | } |
|
3344 | | /// Matches the first method of a class or struct that satisfies \c |
3345 | | /// InnerMatcher. |
3346 | | /// |
3347 | | /// Given: |
3348 | | /// \code |
3349 | | /// class A { void func(); }; |
3350 | | /// class B { void member(); }; |
3351 | | /// \endcode |
3352 | | /// |
3353 | | /// \c cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of |
3354 | | /// \c A but not \c B. |
3355 | | AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>, |
3356 | 212 | InnerMatcher) { |
3357 | 212 | BoundNodesTreeBuilder Result(*Builder); |
3358 | 212 | auto MatchIt = matchesFirstInPointerRange(InnerMatcher, Node.method_begin(), |
3359 | 212 | Node.method_end(), Finder, &Result); |
3360 | 212 | if (MatchIt == Node.method_end()) |
3361 | 138 | return false; |
3362 | | |
3363 | 74 | if (Finder->isTraversalIgnoringImplicitNodes() && (*MatchIt)->isImplicit()8 ) |
3364 | 8 | return false; |
3365 | 66 | *Builder = std::move(Result); |
3366 | 66 | return true; |
3367 | 74 | } |
3368 | | |
3369 | | /// Matches the generated class of lambda expressions. |
3370 | | /// |
3371 | | /// Given: |
3372 | | /// \code |
3373 | | /// auto x = []{}; |
3374 | | /// \endcode |
3375 | | /// |
3376 | | /// \c cxxRecordDecl(isLambda()) matches the implicit class declaration of |
3377 | | /// \c decltype(x) |
3378 | 200 | AST_MATCHER(CXXRecordDecl, isLambda) { |
3379 | 200 | return Node.isLambda(); |
3380 | 200 | } |
3381 | | |
3382 | | /// Matches AST nodes that have child AST nodes that match the |
3383 | | /// provided matcher. |
3384 | | /// |
3385 | | /// Example matches X, Y |
3386 | | /// (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) |
3387 | | /// \code |
3388 | | /// class X {}; // Matches X, because X::X is a class of name X inside X. |
3389 | | /// class Y { class X {}; }; |
3390 | | /// class Z { class Y { class X {}; }; }; // Does not match Z. |
3391 | | /// \endcode |
3392 | | /// |
3393 | | /// ChildT must be an AST base type. |
3394 | | /// |
3395 | | /// Usable as: Any Matcher |
3396 | | /// Note that has is direct matcher, so it also matches things like implicit |
3397 | | /// casts and paren casts. If you are matching with expr then you should |
3398 | | /// probably consider using ignoringParenImpCasts like: |
3399 | | /// has(ignoringParenImpCasts(expr())). |
3400 | | extern const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has; |
3401 | | |
3402 | | /// Matches AST nodes that have descendant AST nodes that match the |
3403 | | /// provided matcher. |
3404 | | /// |
3405 | | /// Example matches X, Y, Z |
3406 | | /// (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) |
3407 | | /// \code |
3408 | | /// class X {}; // Matches X, because X::X is a class of name X inside X. |
3409 | | /// class Y { class X {}; }; |
3410 | | /// class Z { class Y { class X {}; }; }; |
3411 | | /// \endcode |
3412 | | /// |
3413 | | /// DescendantT must be an AST base type. |
3414 | | /// |
3415 | | /// Usable as: Any Matcher |
3416 | | extern const internal::ArgumentAdaptingMatcherFunc< |
3417 | | internal::HasDescendantMatcher> |
3418 | | hasDescendant; |
3419 | | |
3420 | | /// Matches AST nodes that have child AST nodes that match the |
3421 | | /// provided matcher. |
3422 | | /// |
3423 | | /// Example matches X, Y, Y::X, Z::Y, Z::Y::X |
3424 | | /// (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) |
3425 | | /// \code |
3426 | | /// class X {}; |
3427 | | /// class Y { class X {}; }; // Matches Y, because Y::X is a class of name X |
3428 | | /// // inside Y. |
3429 | | /// class Z { class Y { class X {}; }; }; // Does not match Z. |
3430 | | /// \endcode |
3431 | | /// |
3432 | | /// ChildT must be an AST base type. |
3433 | | /// |
3434 | | /// As opposed to 'has', 'forEach' will cause a match for each result that |
3435 | | /// matches instead of only on the first one. |
3436 | | /// |
3437 | | /// Usable as: Any Matcher |
3438 | | extern const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> |
3439 | | forEach; |
3440 | | |
3441 | | /// Matches AST nodes that have descendant AST nodes that match the |
3442 | | /// provided matcher. |
3443 | | /// |
3444 | | /// Example matches X, A, A::X, B, B::C, B::C::X |
3445 | | /// (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) |
3446 | | /// \code |
3447 | | /// class X {}; |
3448 | | /// class A { class X {}; }; // Matches A, because A::X is a class of name |
3449 | | /// // X inside A. |
3450 | | /// class B { class C { class X {}; }; }; |
3451 | | /// \endcode |
3452 | | /// |
3453 | | /// DescendantT must be an AST base type. |
3454 | | /// |
3455 | | /// As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for |
3456 | | /// each result that matches instead of only on the first one. |
3457 | | /// |
3458 | | /// Note: Recursively combined ForEachDescendant can cause many matches: |
3459 | | /// cxxRecordDecl(forEachDescendant(cxxRecordDecl( |
3460 | | /// forEachDescendant(cxxRecordDecl()) |
3461 | | /// ))) |
3462 | | /// will match 10 times (plus injected class name matches) on: |
3463 | | /// \code |
3464 | | /// class A { class B { class C { class D { class E {}; }; }; }; }; |
3465 | | /// \endcode |
3466 | | /// |
3467 | | /// Usable as: Any Matcher |
3468 | | extern const internal::ArgumentAdaptingMatcherFunc< |
3469 | | internal::ForEachDescendantMatcher> |
3470 | | forEachDescendant; |
3471 | | |
3472 | | /// Matches if the node or any descendant matches. |
3473 | | /// |
3474 | | /// Generates results for each match. |
3475 | | /// |
3476 | | /// For example, in: |
3477 | | /// \code |
3478 | | /// class A { class B {}; class C {}; }; |
3479 | | /// \endcode |
3480 | | /// The matcher: |
3481 | | /// \code |
3482 | | /// cxxRecordDecl(hasName("::A"), |
3483 | | /// findAll(cxxRecordDecl(isDefinition()).bind("m"))) |
3484 | | /// \endcode |
3485 | | /// will generate results for \c A, \c B and \c C. |
3486 | | /// |
3487 | | /// Usable as: Any Matcher |
3488 | | template <typename T> |
3489 | 2.74k | internal::Matcher<T> findAll(const internal::Matcher<T> &Matcher) { |
3490 | 2.74k | return eachOf(Matcher, forEachDescendant(Matcher)); |
3491 | 2.74k | } clang::ast_matchers::internal::Matcher<clang::Stmt> clang::ast_matchers::findAll<clang::Stmt>(clang::ast_matchers::internal::Matcher<clang::Stmt> const&) Line | Count | Source | 3489 | 2.73k | internal::Matcher<T> findAll(const internal::Matcher<T> &Matcher) { | 3490 | 2.73k | return eachOf(Matcher, forEachDescendant(Matcher)); | 3491 | 2.73k | } |
clang::ast_matchers::internal::Matcher<clang::Decl> clang::ast_matchers::findAll<clang::Decl>(clang::ast_matchers::internal::Matcher<clang::Decl> const&) Line | Count | Source | 3489 | 4 | internal::Matcher<T> findAll(const internal::Matcher<T> &Matcher) { | 3490 | 4 | return eachOf(Matcher, forEachDescendant(Matcher)); | 3491 | 4 | } |
|
3492 | | |
3493 | | /// Matches AST nodes that have a parent that matches the provided |
3494 | | /// matcher. |
3495 | | /// |
3496 | | /// Given |
3497 | | /// \code |
3498 | | /// void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } |
3499 | | /// \endcode |
3500 | | /// \c compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". |
3501 | | /// |
3502 | | /// Usable as: Any Matcher |
3503 | | extern const internal::ArgumentAdaptingMatcherFunc< |
3504 | | internal::HasParentMatcher, |
3505 | | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>, |
3506 | | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>> |
3507 | | hasParent; |
3508 | | |
3509 | | /// Matches AST nodes that have an ancestor that matches the provided |
3510 | | /// matcher. |
3511 | | /// |
3512 | | /// Given |
3513 | | /// \code |
3514 | | /// void f() { if (true) { int x = 42; } } |
3515 | | /// void g() { for (;;) { int x = 43; } } |
3516 | | /// \endcode |
3517 | | /// \c expr(integerLiteral(hasAncestor(ifStmt()))) matches \c 42, but not 43. |
3518 | | /// |
3519 | | /// Usable as: Any Matcher |
3520 | | extern const internal::ArgumentAdaptingMatcherFunc< |
3521 | | internal::HasAncestorMatcher, |
3522 | | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>, |
3523 | | internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc, Attr>> |
3524 | | hasAncestor; |
3525 | | |
3526 | | /// Matches if the provided matcher does not match. |
3527 | | /// |
3528 | | /// Example matches Y (matcher = cxxRecordDecl(unless(hasName("X")))) |
3529 | | /// \code |
3530 | | /// class X {}; |
3531 | | /// class Y {}; |
3532 | | /// \endcode |
3533 | | /// |
3534 | | /// Usable as: Any Matcher |
3535 | | extern const internal::VariadicOperatorMatcherFunc<1, 1> unless; |
3536 | | |
3537 | | /// Matches a node if the declaration associated with that node |
3538 | | /// matches the given matcher. |
3539 | | /// |
3540 | | /// The associated declaration is: |
3541 | | /// - for type nodes, the declaration of the underlying type |
3542 | | /// - for CallExpr, the declaration of the callee |
3543 | | /// - for MemberExpr, the declaration of the referenced member |
3544 | | /// - for CXXConstructExpr, the declaration of the constructor |
3545 | | /// - for CXXNewExpr, the declaration of the operator new |
3546 | | /// - for ObjCIvarExpr, the declaration of the ivar |
3547 | | /// |
3548 | | /// For type nodes, hasDeclaration will generally match the declaration of the |
3549 | | /// sugared type. Given |
3550 | | /// \code |
3551 | | /// class X {}; |
3552 | | /// typedef X Y; |
3553 | | /// Y y; |
3554 | | /// \endcode |
3555 | | /// in varDecl(hasType(hasDeclaration(decl()))) the decl will match the |
3556 | | /// typedefDecl. A common use case is to match the underlying, desugared type. |
3557 | | /// This can be achieved by using the hasUnqualifiedDesugaredType matcher: |
3558 | | /// \code |
3559 | | /// varDecl(hasType(hasUnqualifiedDesugaredType( |
3560 | | /// recordType(hasDeclaration(decl()))))) |
3561 | | /// \endcode |
3562 | | /// In this matcher, the decl will match the CXXRecordDecl of class X. |
3563 | | /// |
3564 | | /// Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, |
3565 | | /// Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, |
3566 | | /// Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, |
3567 | | /// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, |
3568 | | /// Matcher<TagType>, Matcher<TemplateSpecializationType>, |
3569 | | /// Matcher<TemplateTypeParmType>, Matcher<TypedefType>, |
3570 | | /// Matcher<UnresolvedUsingType> |
3571 | | inline internal::PolymorphicMatcher< |
3572 | | internal::HasDeclarationMatcher, |
3573 | | void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>> |
3574 | 30.6k | hasDeclaration(const internal::Matcher<Decl> &InnerMatcher) { |
3575 | 30.6k | return internal::PolymorphicMatcher< |
3576 | 30.6k | internal::HasDeclarationMatcher, |
3577 | 30.6k | void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>( |
3578 | 30.6k | InnerMatcher); |
3579 | 30.6k | } |
3580 | | |
3581 | | /// Matches a \c NamedDecl whose underlying declaration matches the given |
3582 | | /// matcher. |
3583 | | /// |
3584 | | /// Given |
3585 | | /// \code |
3586 | | /// namespace N { template<class T> void f(T t); } |
3587 | | /// template <class T> void g() { using N::f; f(T()); } |
3588 | | /// \endcode |
3589 | | /// \c unresolvedLookupExpr(hasAnyDeclaration( |
3590 | | /// namedDecl(hasUnderlyingDecl(hasName("::N::f"))))) |
3591 | | /// matches the use of \c f in \c g() . |
3592 | | AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher<NamedDecl>, |
3593 | 2 | InnerMatcher) { |
3594 | 2 | const NamedDecl *UnderlyingDecl = Node.getUnderlyingDecl(); |
3595 | | |
3596 | 2 | return UnderlyingDecl != nullptr && |
3597 | 2 | InnerMatcher.matches(*UnderlyingDecl, Finder, Builder); |
3598 | 2 | } |
3599 | | |
3600 | | /// Matches on the implicit object argument of a member call expression, after |
3601 | | /// stripping off any parentheses or implicit casts. |
3602 | | /// |
3603 | | /// Given |
3604 | | /// \code |
3605 | | /// class Y { public: void m(); }; |
3606 | | /// Y g(); |
3607 | | /// class X : public Y {}; |
3608 | | /// void z(Y y, X x) { y.m(); (g()).m(); x.m(); } |
3609 | | /// \endcode |
3610 | | /// cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))) |
3611 | | /// matches `y.m()` and `(g()).m()`. |
3612 | | /// cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X"))))) |
3613 | | /// matches `x.m()`. |
3614 | | /// cxxMemberCallExpr(on(callExpr())) |
3615 | | /// matches `(g()).m()`. |
3616 | | /// |
3617 | | /// FIXME: Overload to allow directly matching types? |
3618 | | AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, |
3619 | 2.29k | InnerMatcher) { |
3620 | 2.29k | const Expr *ExprNode = Node.getImplicitObjectArgument() |
3621 | 2.29k | ->IgnoreParenImpCasts(); |
3622 | 2.29k | return (ExprNode != nullptr && |
3623 | 2.29k | InnerMatcher.matches(*ExprNode, Finder, Builder)); |
3624 | 2.29k | } |
3625 | | |
3626 | | |
3627 | | /// Matches on the receiver of an ObjectiveC Message expression. |
3628 | | /// |
3629 | | /// Example |
3630 | | /// matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *"))); |
3631 | | /// matches the [webView ...] message invocation. |
3632 | | /// \code |
3633 | | /// NSString *webViewJavaScript = ... |
3634 | | /// UIWebView *webView = ... |
3635 | | /// [webView stringByEvaluatingJavaScriptFromString:webViewJavascript]; |
3636 | | /// \endcode |
3637 | | AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>, |
3638 | 11 | InnerMatcher) { |
3639 | 11 | const QualType TypeDecl = Node.getReceiverType(); |
3640 | 11 | return InnerMatcher.matches(TypeDecl, Finder, Builder); |
3641 | 11 | } |
3642 | | |
3643 | | /// Returns true when the Objective-C method declaration is a class method. |
3644 | | /// |
3645 | | /// Example |
3646 | | /// matcher = objcMethodDecl(isClassMethod()) |
3647 | | /// matches |
3648 | | /// \code |
3649 | | /// @interface I + (void)foo; @end |
3650 | | /// \endcode |
3651 | | /// but not |
3652 | | /// \code |
3653 | | /// @interface I - (void)bar; @end |
3654 | | /// \endcode |
3655 | 8 | AST_MATCHER(ObjCMethodDecl, isClassMethod) { |
3656 | 8 | return Node.isClassMethod(); |
3657 | 8 | } |
3658 | | |
3659 | | /// Returns true when the Objective-C method declaration is an instance method. |
3660 | | /// |
3661 | | /// Example |
3662 | | /// matcher = objcMethodDecl(isInstanceMethod()) |
3663 | | /// matches |
3664 | | /// \code |
3665 | | /// @interface I - (void)bar; @end |
3666 | | /// \endcode |
3667 | | /// but not |
3668 | | /// \code |
3669 | | /// @interface I + (void)foo; @end |
3670 | | /// \endcode |
3671 | 8 | AST_MATCHER(ObjCMethodDecl, isInstanceMethod) { |
3672 | 8 | return Node.isInstanceMethod(); |
3673 | 8 | } |
3674 | | |
3675 | | /// Returns true when the Objective-C message is sent to a class. |
3676 | | /// |
3677 | | /// Example |
3678 | | /// matcher = objcMessageExpr(isClassMessage()) |
3679 | | /// matches |
3680 | | /// \code |
3681 | | /// [NSString stringWithFormat:@"format"]; |
3682 | | /// \endcode |
3683 | | /// but not |
3684 | | /// \code |
3685 | | /// NSString *x = @"hello"; |
3686 | | /// [x containsString:@"h"]; |
3687 | | /// \endcode |
3688 | 4 | AST_MATCHER(ObjCMessageExpr, isClassMessage) { |
3689 | 4 | return Node.isClassMessage(); |
3690 | 4 | } |
3691 | | |
3692 | | /// Returns true when the Objective-C message is sent to an instance. |
3693 | | /// |
3694 | | /// Example |
3695 | | /// matcher = objcMessageExpr(isInstanceMessage()) |
3696 | | /// matches |
3697 | | /// \code |
3698 | | /// NSString *x = @"hello"; |
3699 | | /// [x containsString:@"h"]; |
3700 | | /// \endcode |
3701 | | /// but not |
3702 | | /// \code |
3703 | | /// [NSString stringWithFormat:@"format"]; |
3704 | | /// \endcode |
3705 | 4 | AST_MATCHER(ObjCMessageExpr, isInstanceMessage) { |
3706 | 4 | return Node.isInstanceMessage(); |
3707 | 4 | } |
3708 | | |
3709 | | /// Matches if the Objective-C message is sent to an instance, |
3710 | | /// and the inner matcher matches on that instance. |
3711 | | /// |
3712 | | /// For example the method call in |
3713 | | /// \code |
3714 | | /// NSString *x = @"hello"; |
3715 | | /// [x containsString:@"h"]; |
3716 | | /// \endcode |
3717 | | /// is matched by |
3718 | | /// objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x")))))) |
3719 | | AST_MATCHER_P(ObjCMessageExpr, hasReceiver, internal::Matcher<Expr>, |
3720 | 15 | InnerMatcher) { |
3721 | 15 | const Expr *ReceiverNode = Node.getInstanceReceiver(); |
3722 | 15 | return (ReceiverNode != nullptr && |
3723 | 15 | InnerMatcher.matches(*ReceiverNode->IgnoreParenImpCasts(), Finder, |
3724 | 13 | Builder)); |
3725 | 15 | } |
3726 | | |
3727 | | /// Matches when BaseName == Selector.getAsString() |
3728 | | /// |
3729 | | /// matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:")); |
3730 | | /// matches the outer message expr in the code below, but NOT the message |
3731 | | /// invocation for self.bodyView. |
3732 | | /// \code |
3733 | | /// [self.bodyView loadHTMLString:html baseURL:NULL]; |
3734 | | /// \endcode |
3735 | 53 | AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) { |
3736 | 53 | Selector Sel = Node.getSelector(); |
3737 | 53 | return BaseName == Sel.getAsString(); |
3738 | 53 | } |
3739 | | |
3740 | | /// Matches when at least one of the supplied string equals to the |
3741 | | /// Selector.getAsString() |
3742 | | /// |
3743 | | /// matcher = objCMessageExpr(hasSelector("methodA:", "methodB:")); |
3744 | | /// matches both of the expressions below: |
3745 | | /// \code |
3746 | | /// [myObj methodA:argA]; |
3747 | | /// [myObj methodB:argB]; |
3748 | | /// \endcode |
3749 | | extern const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, |
3750 | | StringRef, |
3751 | | internal::hasAnySelectorFunc> |
3752 | | hasAnySelector; |
3753 | | |
3754 | | /// Matches ObjC selectors whose name contains |
3755 | | /// a substring matched by the given RegExp. |
3756 | | /// matcher = objCMessageExpr(matchesSelector("loadHTMLString\:baseURL?")); |
3757 | | /// matches the outer message expr in the code below, but NOT the message |
3758 | | /// invocation for self.bodyView. |
3759 | | /// \code |
3760 | | /// [self.bodyView loadHTMLString:html baseURL:NULL]; |
3761 | | /// \endcode |
3762 | 12 | AST_MATCHER_REGEX(ObjCMessageExpr, matchesSelector, RegExp) { |
3763 | 12 | std::string SelectorString = Node.getSelector().getAsString(); |
3764 | 12 | return RegExp->match(SelectorString); |
3765 | 12 | } |
3766 | | |
3767 | | /// Matches when the selector is the empty selector |
3768 | | /// |
3769 | | /// Matches only when the selector of the objCMessageExpr is NULL. This may |
3770 | | /// represent an error condition in the tree! |
3771 | 2 | AST_MATCHER(ObjCMessageExpr, hasNullSelector) { |
3772 | 2 | return Node.getSelector().isNull(); |
3773 | 2 | } |
3774 | | |
3775 | | /// Matches when the selector is a Unary Selector |
3776 | | /// |
3777 | | /// matcher = objCMessageExpr(matchesSelector(hasUnarySelector()); |
3778 | | /// matches self.bodyView in the code below, but NOT the outer message |
3779 | | /// invocation of "loadHTMLString:baseURL:". |
3780 | | /// \code |
3781 | | /// [self.bodyView loadHTMLString:html baseURL:NULL]; |
3782 | | /// \endcode |
3783 | 2 | AST_MATCHER(ObjCMessageExpr, hasUnarySelector) { |
3784 | 2 | return Node.getSelector().isUnarySelector(); |
3785 | 2 | } |
3786 | | |
3787 | | /// Matches when the selector is a keyword selector |
3788 | | /// |
3789 | | /// objCMessageExpr(hasKeywordSelector()) matches the generated setFrame |
3790 | | /// message expression in |
3791 | | /// |
3792 | | /// \code |
3793 | | /// UIWebView *webView = ...; |
3794 | | /// CGRect bodyFrame = webView.frame; |
3795 | | /// bodyFrame.size.height = self.bodyContentHeight; |
3796 | | /// webView.frame = bodyFrame; |
3797 | | /// // ^---- matches here |
3798 | | /// \endcode |
3799 | 0 | AST_MATCHER(ObjCMessageExpr, hasKeywordSelector) { |
3800 | 0 | return Node.getSelector().isKeywordSelector(); |
3801 | 0 | } |
3802 | | |
3803 | | /// Matches when the selector has the specified number of arguments |
3804 | | /// |
3805 | | /// matcher = objCMessageExpr(numSelectorArgs(0)); |
3806 | | /// matches self.bodyView in the code below |
3807 | | /// |
3808 | | /// matcher = objCMessageExpr(numSelectorArgs(2)); |
3809 | | /// matches the invocation of "loadHTMLString:baseURL:" but not that |
3810 | | /// of self.bodyView |
3811 | | /// \code |
3812 | | /// [self.bodyView loadHTMLString:html baseURL:NULL]; |
3813 | | /// \endcode |
3814 | 2 | AST_MATCHER_P(ObjCMessageExpr, numSelectorArgs, unsigned, N) { |
3815 | 2 | return Node.getSelector().getNumArgs() == N; |
3816 | 2 | } |
3817 | | |
3818 | | /// Matches if the call expression's callee expression matches. |
3819 | | /// |
3820 | | /// Given |
3821 | | /// \code |
3822 | | /// class Y { void x() { this->x(); x(); Y y; y.x(); } }; |
3823 | | /// void f() { f(); } |
3824 | | /// \endcode |
3825 | | /// callExpr(callee(expr())) |
3826 | | /// matches this->x(), x(), y.x(), f() |
3827 | | /// with callee(...) |
3828 | | /// matching this->x, x, y.x, f respectively |
3829 | | /// |
3830 | | /// Note: Callee cannot take the more general internal::Matcher<Expr> |
3831 | | /// because this introduces ambiguous overloads with calls to Callee taking a |
3832 | | /// internal::Matcher<Decl>, as the matcher hierarchy is purely |
3833 | | /// implemented in terms of implicit casts. |
3834 | | AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>, |
3835 | 299 | InnerMatcher) { |
3836 | 299 | const Expr *ExprNode = Node.getCallee(); |
3837 | 299 | return (ExprNode != nullptr && |
3838 | 299 | InnerMatcher.matches(*ExprNode, Finder, Builder)); |
3839 | 299 | } |
3840 | | |
3841 | | /// Matches if the call expression's callee's declaration matches the |
3842 | | /// given matcher. |
3843 | | /// |
3844 | | /// Example matches y.x() (matcher = callExpr(callee( |
3845 | | /// cxxMethodDecl(hasName("x"))))) |
3846 | | /// \code |
3847 | | /// class Y { public: void x(); }; |
3848 | | /// void z() { Y y; y.x(); } |
3849 | | /// \endcode |
3850 | | AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher<Decl>, InnerMatcher, |
3851 | 5.74k | 1) { |
3852 | 5.74k | return callExpr(hasDeclaration(InnerMatcher)).matches(Node, Finder, Builder); |
3853 | 5.74k | } |
3854 | | |
3855 | | /// Matches if the expression's or declaration's type matches a type |
3856 | | /// matcher. |
3857 | | /// |
3858 | | /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) |
3859 | | /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) |
3860 | | /// and U (matcher = typedefDecl(hasType(asString("int"))) |
3861 | | /// and friend class X (matcher = friendDecl(hasType("X")) |
3862 | | /// and public virtual X (matcher = cxxBaseSpecifier(hasType( |
3863 | | /// asString("class X"))) |
3864 | | /// \code |
3865 | | /// class X {}; |
3866 | | /// void y(X &x) { x; X z; } |
3867 | | /// typedef int U; |
3868 | | /// class Y { friend class X; }; |
3869 | | /// class Z : public virtual X {}; |
3870 | | /// \endcode |
3871 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3872 | | hasType, |
3873 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl, |
3874 | | ValueDecl, CXXBaseSpecifier), |
3875 | 12.0k | internal::Matcher<QualType>, InnerMatcher, 0) { |
3876 | 12.0k | QualType QT = internal::getUnderlyingType(Node); |
3877 | 12.0k | if (!QT.isNull()) |
3878 | 12.0k | return InnerMatcher.matches(QT, Finder, Builder); |
3879 | 20 | return false; |
3880 | 12.0k | } clang::ast_matchers::internal::matcher_hasType0Matcher<clang::ExplicitCastExpr, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::ExplicitCastExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 246 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 246 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 246 | if (!QT.isNull()) | 3878 | 246 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 246 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::CStyleCastExpr, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::CStyleCastExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 7 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 7 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 7 | if (!QT.isNull()) | 3878 | 7 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 7 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::FieldDecl, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::FieldDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 239 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 239 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 239 | if (!QT.isNull()) | 3878 | 239 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 239 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::VarDecl, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::VarDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 3.17k | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 3.17k | QualType QT = internal::getUnderlyingType(Node); | 3877 | 3.17k | if (!QT.isNull()) | 3878 | 3.17k | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 3.17k | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::ParmVarDecl, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::ParmVarDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 500 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 500 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 500 | if (!QT.isNull()) | 3878 | 500 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 500 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::Expr, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::Expr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 5.91k | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 5.91k | QualType QT = internal::getUnderlyingType(Node); | 3877 | 5.91k | if (!QT.isNull()) | 3878 | 5.89k | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 20 | return false; | 3880 | 5.91k | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::FriendDecl, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::FriendDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 20 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 20 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 20 | if (!QT.isNull()) | 3878 | 20 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 20 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::TypedefNameDecl, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::TypedefNameDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 26 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 26 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 26 | if (!QT.isNull()) | 3878 | 26 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 26 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::ValueDecl, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::ValueDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 96 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 96 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 96 | if (!QT.isNull()) | 3878 | 96 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 96 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::CXXBaseSpecifier, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::CXXBaseSpecifier const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 4 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 4 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 4 | if (!QT.isNull()) | 3878 | 4 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 4 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::DeclRefExpr, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::DeclRefExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 37 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 37 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 37 | if (!QT.isNull()) | 3878 | 37 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 37 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::CallExpr, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::CallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 420 | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 420 | QualType QT = internal::getUnderlyingType(Node); | 3877 | 420 | if (!QT.isNull()) | 3878 | 420 | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 420 | } |
clang::ast_matchers::internal::matcher_hasType0Matcher<clang::CXXConstructExpr, clang::ast_matchers::internal::Matcher<clang::QualType> >::matches(clang::CXXConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3875 | 1.40k | internal::Matcher<QualType>, InnerMatcher, 0) { | 3876 | 1.40k | QualType QT = internal::getUnderlyingType(Node); | 3877 | 1.40k | if (!QT.isNull()) | 3878 | 1.40k | return InnerMatcher.matches(QT, Finder, Builder); | 3879 | 0 | return false; | 3880 | 1.40k | } |
|
3881 | | |
3882 | | /// Overloaded to match the declaration of the expression's or value |
3883 | | /// declaration's type. |
3884 | | /// |
3885 | | /// In case of a value declaration (for example a variable declaration), |
3886 | | /// this resolves one layer of indirection. For example, in the value |
3887 | | /// declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of |
3888 | | /// X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the |
3889 | | /// declaration of x. |
3890 | | /// |
3891 | | /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) |
3892 | | /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) |
3893 | | /// and friend class X (matcher = friendDecl(hasType("X")) |
3894 | | /// and public virtual X (matcher = cxxBaseSpecifier(hasType( |
3895 | | /// cxxRecordDecl(hasName("X")))) |
3896 | | /// \code |
3897 | | /// class X {}; |
3898 | | /// void y(X &x) { x; X z; } |
3899 | | /// class Y { friend class X; }; |
3900 | | /// class Z : public virtual X {}; |
3901 | | /// \endcode |
3902 | | /// |
3903 | | /// Example matches class Derived |
3904 | | /// (matcher = cxxRecordDecl(hasAnyBase(hasType(cxxRecordDecl(hasName("Base")))))) |
3905 | | /// \code |
3906 | | /// class Base {}; |
3907 | | /// class Derived : Base {}; |
3908 | | /// \endcode |
3909 | | /// |
3910 | | /// Usable as: Matcher<Expr>, Matcher<FriendDecl>, Matcher<ValueDecl>, |
3911 | | /// Matcher<CXXBaseSpecifier> |
3912 | | AST_POLYMORPHIC_MATCHER_P_OVERLOAD( |
3913 | | hasType, |
3914 | | AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, ValueDecl, |
3915 | | CXXBaseSpecifier), |
3916 | 1.70k | internal::Matcher<Decl>, InnerMatcher, 1) { |
3917 | 1.70k | QualType QT = internal::getUnderlyingType(Node); |
3918 | 1.70k | if (!QT.isNull()) |
3919 | 1.70k | return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder); |
3920 | 0 | return false; |
3921 | 1.70k | } clang::ast_matchers::internal::matcher_hasType1Matcher<clang::VarDecl, clang::ast_matchers::internal::Matcher<clang::Decl> >::matches(clang::VarDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3916 | 102 | internal::Matcher<Decl>, InnerMatcher, 1) { | 3917 | 102 | QualType QT = internal::getUnderlyingType(Node); | 3918 | 102 | if (!QT.isNull()) | 3919 | 102 | return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder); | 3920 | 0 | return false; | 3921 | 102 | } |
clang::ast_matchers::internal::matcher_hasType1Matcher<clang::Expr, clang::ast_matchers::internal::Matcher<clang::Decl> >::matches(clang::Expr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3916 | 1.40k | internal::Matcher<Decl>, InnerMatcher, 1) { | 3917 | 1.40k | QualType QT = internal::getUnderlyingType(Node); | 3918 | 1.40k | if (!QT.isNull()) | 3919 | 1.40k | return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder); | 3920 | 0 | return false; | 3921 | 1.40k | } |
clang::ast_matchers::internal::matcher_hasType1Matcher<clang::FriendDecl, clang::ast_matchers::internal::Matcher<clang::Decl> >::matches(clang::FriendDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3916 | 20 | internal::Matcher<Decl>, InnerMatcher, 1) { | 3917 | 20 | QualType QT = internal::getUnderlyingType(Node); | 3918 | 20 | if (!QT.isNull()) | 3919 | 20 | return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder); | 3920 | 0 | return false; | 3921 | 20 | } |
Unexecuted instantiation: clang::ast_matchers::internal::matcher_hasType1Matcher<clang::ValueDecl, clang::ast_matchers::internal::Matcher<clang::Decl> >::matches(clang::ValueDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_hasType1Matcher<clang::CXXBaseSpecifier, clang::ast_matchers::internal::Matcher<clang::Decl> >::matches(clang::CXXBaseSpecifier const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3916 | 184 | internal::Matcher<Decl>, InnerMatcher, 1) { | 3917 | 184 | QualType QT = internal::getUnderlyingType(Node); | 3918 | 184 | if (!QT.isNull()) | 3919 | 184 | return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder); | 3920 | 0 | return false; | 3921 | 184 | } |
|
3922 | | |
3923 | | /// Matches if the type location of a node matches the inner matcher. |
3924 | | /// |
3925 | | /// Examples: |
3926 | | /// \code |
3927 | | /// int x; |
3928 | | /// \endcode |
3929 | | /// declaratorDecl(hasTypeLoc(loc(asString("int")))) |
3930 | | /// matches int x |
3931 | | /// |
3932 | | /// \code |
3933 | | /// auto x = int(3); |
3934 | | /// \code |
3935 | | /// cxxTemporaryObjectExpr(hasTypeLoc(loc(asString("int")))) |
3936 | | /// matches int(3) |
3937 | | /// |
3938 | | /// \code |
3939 | | /// struct Foo { Foo(int, int); }; |
3940 | | /// auto x = Foo(1, 2); |
3941 | | /// \code |
3942 | | /// cxxFunctionalCastExpr(hasTypeLoc(loc(asString("struct Foo")))) |
3943 | | /// matches Foo(1, 2) |
3944 | | /// |
3945 | | /// Usable as: Matcher<BlockDecl>, Matcher<CXXBaseSpecifier>, |
3946 | | /// Matcher<CXXCtorInitializer>, Matcher<CXXFunctionalCastExpr>, |
3947 | | /// Matcher<CXXNewExpr>, Matcher<CXXTemporaryObjectExpr>, |
3948 | | /// Matcher<CXXUnresolvedConstructExpr>, |
3949 | | /// Matcher<ClassTemplateSpecializationDecl>, Matcher<CompoundLiteralExpr>, |
3950 | | /// Matcher<DeclaratorDecl>, Matcher<ExplicitCastExpr>, |
3951 | | /// Matcher<ObjCPropertyDecl>, Matcher<TemplateArgumentLoc>, |
3952 | | /// Matcher<TypedefNameDecl> |
3953 | | AST_POLYMORPHIC_MATCHER_P( |
3954 | | hasTypeLoc, |
3955 | | AST_POLYMORPHIC_SUPPORTED_TYPES( |
3956 | | BlockDecl, CXXBaseSpecifier, CXXCtorInitializer, CXXFunctionalCastExpr, |
3957 | | CXXNewExpr, CXXTemporaryObjectExpr, CXXUnresolvedConstructExpr, |
3958 | | ClassTemplateSpecializationDecl, CompoundLiteralExpr, DeclaratorDecl, |
3959 | | ExplicitCastExpr, ObjCPropertyDecl, TemplateArgumentLoc, |
3960 | | TypedefNameDecl), |
3961 | 160 | internal::Matcher<TypeLoc>, Inner) { |
3962 | 160 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); |
3963 | 160 | if (source == nullptr) { |
3964 | | // This happens for example for implicit destructors. |
3965 | 24 | return false; |
3966 | 24 | } |
3967 | 136 | return Inner.matches(source->getTypeLoc(), Finder, Builder); |
3968 | 160 | } clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::BlockDecl, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::BlockDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 2 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 2 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 2 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 2 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 2 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CXXBaseSpecifier, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CXXBaseSpecifier const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 2 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 2 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 2 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 2 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 2 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CXXCtorInitializer, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CXXCtorInitializer const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 2 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 2 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 2 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 2 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 2 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CXXFunctionalCastExpr, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CXXFunctionalCastExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 3 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 3 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 3 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 3 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 3 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CXXNewExpr, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CXXNewExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 4 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 4 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 4 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 4 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 4 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CXXTemporaryObjectExpr, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CXXTemporaryObjectExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 3 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 3 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 3 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 3 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 3 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CXXUnresolvedConstructExpr, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CXXUnresolvedConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 2 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 2 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 2 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 2 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 2 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::ClassTemplateSpecializationDecl, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::ClassTemplateSpecializationDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 54 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 54 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 54 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 4 | return false; | 3966 | 4 | } | 3967 | 50 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 54 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::CompoundLiteralExpr, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::CompoundLiteralExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 2 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 2 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 2 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 2 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 2 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::DeclaratorDecl, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::DeclaratorDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 26 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 26 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 26 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 20 | return false; | 3966 | 20 | } | 3967 | 6 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 26 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::ExplicitCastExpr, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::ExplicitCastExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 4 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 4 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 4 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 4 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 4 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::ObjCPropertyDecl, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::ObjCPropertyDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 2 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 2 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 2 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 2 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 2 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::TemplateArgumentLoc, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::TemplateArgumentLoc const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 42 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 42 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 42 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 42 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 42 | } |
clang::ast_matchers::internal::matcher_hasTypeLoc0Matcher<clang::TypedefNameDecl, clang::ast_matchers::internal::Matcher<clang::TypeLoc> >::matches(clang::TypedefNameDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 3961 | 12 | internal::Matcher<TypeLoc>, Inner) { | 3962 | 12 | TypeSourceInfo *source = internal::GetTypeSourceInfo(Node); | 3963 | 12 | if (source == nullptr) { | 3964 | | // This happens for example for implicit destructors. | 3965 | 0 | return false; | 3966 | 0 | } | 3967 | 12 | return Inner.matches(source->getTypeLoc(), Finder, Builder); | 3968 | 12 | } |
|
3969 | | |
3970 | | /// Matches if the matched type is represented by the given string. |
3971 | | /// |
3972 | | /// Given |
3973 | | /// \code |
3974 | | /// class Y { public: void x(); }; |
3975 | | /// void z() { Y* y; y->x(); } |
3976 | | /// \endcode |
3977 | | /// cxxMemberCallExpr(on(hasType(asString("class Y *")))) |
3978 | | /// matches y->x() |
3979 | 1.15k | AST_MATCHER_P(QualType, asString, std::string, Name) { |
3980 | 1.15k | return Name == Node.getAsString(); |
3981 | 1.15k | } |
3982 | | |
3983 | | /// Matches if the matched type is a pointer type and the pointee type |
3984 | | /// matches the specified matcher. |
3985 | | /// |
3986 | | /// Example matches y->x() |
3987 | | /// (matcher = cxxMemberCallExpr(on(hasType(pointsTo |
3988 | | /// cxxRecordDecl(hasName("Y"))))))) |
3989 | | /// \code |
3990 | | /// class Y { public: void x(); }; |
3991 | | /// void z() { Y *y; y->x(); } |
3992 | | /// \endcode |
3993 | | AST_MATCHER_P( |
3994 | | QualType, pointsTo, internal::Matcher<QualType>, |
3995 | 634 | InnerMatcher) { |
3996 | 634 | return (!Node.isNull() && Node->isAnyPointerType() && |
3997 | 634 | InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)436 ); |
3998 | 634 | } |
3999 | | |
4000 | | /// Overloaded to match the pointee type's declaration. |
4001 | | AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher<Decl>, |
4002 | 388 | InnerMatcher, 1) { |
4003 | 388 | return pointsTo(qualType(hasDeclaration(InnerMatcher))) |
4004 | 388 | .matches(Node, Finder, Builder); |
4005 | 388 | } |
4006 | | |
4007 | | /// Matches if the matched type matches the unqualified desugared |
4008 | | /// type of the matched node. |
4009 | | /// |
4010 | | /// For example, in: |
4011 | | /// \code |
4012 | | /// class A {}; |
4013 | | /// using B = A; |
4014 | | /// \endcode |
4015 | | /// The matcher type(hasUnqualifiedDesugaredType(recordType())) matches |
4016 | | /// both B and A. |
4017 | | AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher<Type>, |
4018 | 5.12k | InnerMatcher) { |
4019 | 5.12k | return InnerMatcher.matches(*Node.getUnqualifiedDesugaredType(), Finder, |
4020 | 5.12k | Builder); |
4021 | 5.12k | } |
4022 | | |
4023 | | /// Matches if the matched type is a reference type and the referenced |
4024 | | /// type matches the specified matcher. |
4025 | | /// |
4026 | | /// Example matches X &x and const X &y |
4027 | | /// (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) |
4028 | | /// \code |
4029 | | /// class X { |
4030 | | /// void a(X b) { |
4031 | | /// X &x = b; |
4032 | | /// const X &y = b; |
4033 | | /// } |
4034 | | /// }; |
4035 | | /// \endcode |
4036 | | AST_MATCHER_P(QualType, references, internal::Matcher<QualType>, |
4037 | 322 | InnerMatcher) { |
4038 | 322 | return (!Node.isNull() && Node->isReferenceType() && |
4039 | 322 | InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)102 ); |
4040 | 322 | } |
4041 | | |
4042 | | /// Matches QualTypes whose canonical type matches InnerMatcher. |
4043 | | /// |
4044 | | /// Given: |
4045 | | /// \code |
4046 | | /// typedef int &int_ref; |
4047 | | /// int a; |
4048 | | /// int_ref b = a; |
4049 | | /// \endcode |
4050 | | /// |
4051 | | /// \c varDecl(hasType(qualType(referenceType()))))) will not match the |
4052 | | /// declaration of b but \c |
4053 | | /// varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. |
4054 | | AST_MATCHER_P(QualType, hasCanonicalType, internal::Matcher<QualType>, |
4055 | 2.57k | InnerMatcher) { |
4056 | 2.57k | if (Node.isNull()) |
4057 | 0 | return false; |
4058 | 2.57k | return InnerMatcher.matches(Node.getCanonicalType(), Finder, Builder); |
4059 | 2.57k | } |
4060 | | |
4061 | | /// Overloaded to match the referenced type's declaration. |
4062 | | AST_MATCHER_P_OVERLOAD(QualType, references, internal::Matcher<Decl>, |
4063 | 218 | InnerMatcher, 1) { |
4064 | 218 | return references(qualType(hasDeclaration(InnerMatcher))) |
4065 | 218 | .matches(Node, Finder, Builder); |
4066 | 218 | } |
4067 | | |
4068 | | /// Matches on the implicit object argument of a member call expression. Unlike |
4069 | | /// `on`, matches the argument directly without stripping away anything. |
4070 | | /// |
4071 | | /// Given |
4072 | | /// \code |
4073 | | /// class Y { public: void m(); }; |
4074 | | /// Y g(); |
4075 | | /// class X : public Y { void g(); }; |
4076 | | /// void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); } |
4077 | | /// \endcode |
4078 | | /// cxxMemberCallExpr(onImplicitObjectArgument(hasType( |
4079 | | /// cxxRecordDecl(hasName("Y"))))) |
4080 | | /// matches `y.m()`, `x.m()` and (g()).m(), but not `x.g()`. |
4081 | | /// cxxMemberCallExpr(on(callExpr())) |
4082 | | /// does not match `(g()).m()`, because the parens are not ignored. |
4083 | | /// |
4084 | | /// FIXME: Overload to allow directly matching types? |
4085 | | AST_MATCHER_P(CXXMemberCallExpr, onImplicitObjectArgument, |
4086 | 182 | internal::Matcher<Expr>, InnerMatcher) { |
4087 | 182 | const Expr *ExprNode = Node.getImplicitObjectArgument(); |
4088 | 182 | return (ExprNode != nullptr && |
4089 | 182 | InnerMatcher.matches(*ExprNode, Finder, Builder)); |
4090 | 182 | } |
4091 | | |
4092 | | /// Matches if the type of the expression's implicit object argument either |
4093 | | /// matches the InnerMatcher, or is a pointer to a type that matches the |
4094 | | /// InnerMatcher. |
4095 | | /// |
4096 | | /// Given |
4097 | | /// \code |
4098 | | /// class Y { public: void m(); }; |
4099 | | /// class X : public Y { void g(); }; |
4100 | | /// void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); } |
4101 | | /// \endcode |
4102 | | /// cxxMemberCallExpr(thisPointerType(hasDeclaration( |
4103 | | /// cxxRecordDecl(hasName("Y"))))) |
4104 | | /// matches `y.m()`, `p->m()` and `x.m()`. |
4105 | | /// cxxMemberCallExpr(thisPointerType(hasDeclaration( |
4106 | | /// cxxRecordDecl(hasName("X"))))) |
4107 | | /// matches `x.g()`. |
4108 | | AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, |
4109 | 0 | internal::Matcher<QualType>, InnerMatcher, 0) { |
4110 | 0 | return onImplicitObjectArgument( |
4111 | 0 | anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) |
4112 | 0 | .matches(Node, Finder, Builder); |
4113 | 0 | } |
4114 | | |
4115 | | /// Overloaded to match the type's declaration. |
4116 | | AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, |
4117 | 140 | internal::Matcher<Decl>, InnerMatcher, 1) { |
4118 | 140 | return onImplicitObjectArgument( |
4119 | 140 | anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) |
4120 | 140 | .matches(Node, Finder, Builder); |
4121 | 140 | } |
4122 | | |
4123 | | /// Matches a DeclRefExpr that refers to a declaration that matches the |
4124 | | /// specified matcher. |
4125 | | /// |
4126 | | /// Example matches x in if(x) |
4127 | | /// (matcher = declRefExpr(to(varDecl(hasName("x"))))) |
4128 | | /// \code |
4129 | | /// bool x; |
4130 | | /// if (x) {} |
4131 | | /// \endcode |
4132 | | AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, |
4133 | 3.38k | InnerMatcher) { |
4134 | 3.38k | const Decl *DeclNode = Node.getDecl(); |
4135 | 3.38k | return (DeclNode != nullptr && |
4136 | 3.38k | InnerMatcher.matches(*DeclNode, Finder, Builder)); |
4137 | 3.38k | } |
4138 | | |
4139 | | /// Matches if a node refers to a declaration through a specific |
4140 | | /// using shadow declaration. |
4141 | | /// |
4142 | | /// Examples: |
4143 | | /// \code |
4144 | | /// namespace a { int f(); } |
4145 | | /// using a::f; |
4146 | | /// int x = f(); |
4147 | | /// \endcode |
4148 | | /// declRefExpr(throughUsingDecl(anything())) |
4149 | | /// matches \c f |
4150 | | /// |
4151 | | /// \code |
4152 | | /// namespace a { class X{}; } |
4153 | | /// using a::X; |
4154 | | /// X x; |
4155 | | /// \code |
4156 | | /// typeLoc(loc(usingType(throughUsingDecl(anything())))) |
4157 | | /// matches \c X |
4158 | | /// |
4159 | | /// Usable as: Matcher<DeclRefExpr>, Matcher<UsingType> |
4160 | | AST_POLYMORPHIC_MATCHER_P(throughUsingDecl, |
4161 | | AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr, |
4162 | | UsingType), |
4163 | 4 | internal::Matcher<UsingShadowDecl>, Inner) { |
4164 | 4 | const NamedDecl *FoundDecl = Node.getFoundDecl(); |
4165 | 4 | if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl)) |
4166 | 2 | return Inner.matches(*UsingDecl, Finder, Builder); |
4167 | 2 | return false; |
4168 | 4 | } clang::ast_matchers::internal::matcher_throughUsingDecl0Matcher<clang::DeclRefExpr, clang::ast_matchers::internal::Matcher<clang::UsingShadowDecl> >::matches(clang::DeclRefExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4163 | 4 | internal::Matcher<UsingShadowDecl>, Inner) { | 4164 | 4 | const NamedDecl *FoundDecl = Node.getFoundDecl(); | 4165 | 4 | if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl)) | 4166 | 2 | return Inner.matches(*UsingDecl, Finder, Builder); | 4167 | 2 | return false; | 4168 | 4 | } |
Unexecuted instantiation: clang::ast_matchers::internal::matcher_throughUsingDecl0Matcher<clang::UsingType, clang::ast_matchers::internal::Matcher<clang::UsingShadowDecl> >::matches(clang::UsingType const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const |
4169 | | |
4170 | | /// Matches an \c OverloadExpr if any of the declarations in the set of |
4171 | | /// overloads matches the given matcher. |
4172 | | /// |
4173 | | /// Given |
4174 | | /// \code |
4175 | | /// template <typename T> void foo(T); |
4176 | | /// template <typename T> void bar(T); |
4177 | | /// template <typename T> void baz(T t) { |
4178 | | /// foo(t); |
4179 | | /// bar(t); |
4180 | | /// } |
4181 | | /// \endcode |
4182 | | /// unresolvedLookupExpr(hasAnyDeclaration( |
4183 | | /// functionTemplateDecl(hasName("foo")))) |
4184 | | /// matches \c foo in \c foo(t); but not \c bar in \c bar(t); |
4185 | | AST_MATCHER_P(OverloadExpr, hasAnyDeclaration, internal::Matcher<Decl>, |
4186 | 14 | InnerMatcher) { |
4187 | 14 | return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(), |
4188 | 14 | Node.decls_end(), Finder, |
4189 | 14 | Builder) != Node.decls_end(); |
4190 | 14 | } |
4191 | | |
4192 | | /// Matches the Decl of a DeclStmt which has a single declaration. |
4193 | | /// |
4194 | | /// Given |
4195 | | /// \code |
4196 | | /// int a, b; |
4197 | | /// int c; |
4198 | | /// \endcode |
4199 | | /// declStmt(hasSingleDecl(anything())) |
4200 | | /// matches 'int c;' but not 'int a, b;'. |
4201 | 480 | AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher) { |
4202 | 480 | if (Node.isSingleDecl()) { |
4203 | 478 | const Decl *FoundDecl = Node.getSingleDecl(); |
4204 | 478 | return InnerMatcher.matches(*FoundDecl, Finder, Builder); |
4205 | 478 | } |
4206 | 2 | return false; |
4207 | 480 | } |
4208 | | |
4209 | | /// Matches a variable declaration that has an initializer expression |
4210 | | /// that matches the given matcher. |
4211 | | /// |
4212 | | /// Example matches x (matcher = varDecl(hasInitializer(callExpr()))) |
4213 | | /// \code |
4214 | | /// bool y() { return true; } |
4215 | | /// bool x = y(); |
4216 | | /// \endcode |
4217 | | AST_MATCHER_P( |
4218 | | VarDecl, hasInitializer, internal::Matcher<Expr>, |
4219 | 1.48k | InnerMatcher) { |
4220 | 1.48k | const Expr *Initializer = Node.getAnyInitializer(); |
4221 | 1.48k | return (Initializer != nullptr && |
4222 | 1.48k | InnerMatcher.matches(*Initializer, Finder, Builder)1.19k ); |
4223 | 1.48k | } |
4224 | | |
4225 | | /// Matches a variable serving as the implicit variable for a lambda init- |
4226 | | /// capture. |
4227 | | /// |
4228 | | /// Example matches x (matcher = varDecl(isInitCapture())) |
4229 | | /// \code |
4230 | | /// auto f = [x=3]() { return x; }; |
4231 | | /// \endcode |
4232 | 40 | AST_MATCHER(VarDecl, isInitCapture) { return Node.isInitCapture(); } |
4233 | | |
4234 | | /// Matches each lambda capture in a lambda expression. |
4235 | | /// |
4236 | | /// Given |
4237 | | /// \code |
4238 | | /// int main() { |
4239 | | /// int x, y; |
4240 | | /// float z; |
4241 | | /// auto f = [=]() { return x + y + z; }; |
4242 | | /// } |
4243 | | /// \endcode |
4244 | | /// lambdaExpr(forEachLambdaCapture( |
4245 | | /// lambdaCapture(capturesVar(varDecl(hasType(isInteger())))))) |
4246 | | /// will trigger two matches, binding for 'x' and 'y' respectively. |
4247 | | AST_MATCHER_P(LambdaExpr, forEachLambdaCapture, |
4248 | 38 | internal::Matcher<LambdaCapture>, InnerMatcher) { |
4249 | 38 | BoundNodesTreeBuilder Result; |
4250 | 38 | bool Matched = false; |
4251 | 90 | for (const auto &Capture : Node.captures()) { |
4252 | 90 | if (Finder->isTraversalIgnoringImplicitNodes() && Capture.isImplicit()38 ) |
4253 | 36 | continue; |
4254 | 54 | BoundNodesTreeBuilder CaptureBuilder(*Builder); |
4255 | 54 | if (InnerMatcher.matches(Capture, Finder, &CaptureBuilder)) { |
4256 | 38 | Matched = true; |
4257 | 38 | Result.addMatch(CaptureBuilder); |
4258 | 38 | } |
4259 | 54 | } |
4260 | 38 | *Builder = std::move(Result); |
4261 | 38 | return Matched; |
4262 | 38 | } |
4263 | | |
4264 | | /// \brief Matches a static variable with local scope. |
4265 | | /// |
4266 | | /// Example matches y (matcher = varDecl(isStaticLocal())) |
4267 | | /// \code |
4268 | | /// void f() { |
4269 | | /// int x; |
4270 | | /// static int y; |
4271 | | /// } |
4272 | | /// static int z; |
4273 | | /// \endcode |
4274 | 112 | AST_MATCHER(VarDecl, isStaticLocal) { |
4275 | 112 | return Node.isStaticLocal(); |
4276 | 112 | } |
4277 | | |
4278 | | /// Matches a variable declaration that has function scope and is a |
4279 | | /// non-static local variable. |
4280 | | /// |
4281 | | /// Example matches x (matcher = varDecl(hasLocalStorage()) |
4282 | | /// \code |
4283 | | /// void f() { |
4284 | | /// int x; |
4285 | | /// static int y; |
4286 | | /// } |
4287 | | /// int z; |
4288 | | /// \endcode |
4289 | 84 | AST_MATCHER(VarDecl, hasLocalStorage) { |
4290 | 84 | return Node.hasLocalStorage(); |
4291 | 84 | } |
4292 | | |
4293 | | /// Matches a variable declaration that does not have local storage. |
4294 | | /// |
4295 | | /// Example matches y and z (matcher = varDecl(hasGlobalStorage()) |
4296 | | /// \code |
4297 | | /// void f() { |
4298 | | /// int x; |
4299 | | /// static int y; |
4300 | | /// } |
4301 | | /// int z; |
4302 | | /// \endcode |
4303 | 84 | AST_MATCHER(VarDecl, hasGlobalStorage) { |
4304 | 84 | return Node.hasGlobalStorage(); |
4305 | 84 | } |
4306 | | |
4307 | | /// Matches a variable declaration that has automatic storage duration. |
4308 | | /// |
4309 | | /// Example matches x, but not y, z, or a. |
4310 | | /// (matcher = varDecl(hasAutomaticStorageDuration()) |
4311 | | /// \code |
4312 | | /// void f() { |
4313 | | /// int x; |
4314 | | /// static int y; |
4315 | | /// thread_local int z; |
4316 | | /// } |
4317 | | /// int a; |
4318 | | /// \endcode |
4319 | 84 | AST_MATCHER(VarDecl, hasAutomaticStorageDuration) { |
4320 | 84 | return Node.getStorageDuration() == SD_Automatic; |
4321 | 84 | } |
4322 | | |
4323 | | /// Matches a variable declaration that has static storage duration. |
4324 | | /// It includes the variable declared at namespace scope and those declared |
4325 | | /// with "static" and "extern" storage class specifiers. |
4326 | | /// |
4327 | | /// \code |
4328 | | /// void f() { |
4329 | | /// int x; |
4330 | | /// static int y; |
4331 | | /// thread_local int z; |
4332 | | /// } |
4333 | | /// int a; |
4334 | | /// static int b; |
4335 | | /// extern int c; |
4336 | | /// varDecl(hasStaticStorageDuration()) |
4337 | | /// matches the function declaration y, a, b and c. |
4338 | | /// \endcode |
4339 | 144 | AST_MATCHER(VarDecl, hasStaticStorageDuration) { |
4340 | 144 | return Node.getStorageDuration() == SD_Static; |
4341 | 144 | } |
4342 | | |
4343 | | /// Matches a variable declaration that has thread storage duration. |
4344 | | /// |
4345 | | /// Example matches z, but not x, z, or a. |
4346 | | /// (matcher = varDecl(hasThreadStorageDuration()) |
4347 | | /// \code |
4348 | | /// void f() { |
4349 | | /// int x; |
4350 | | /// static int y; |
4351 | | /// thread_local int z; |
4352 | | /// } |
4353 | | /// int a; |
4354 | | /// \endcode |
4355 | 92 | AST_MATCHER(VarDecl, hasThreadStorageDuration) { |
4356 | 92 | return Node.getStorageDuration() == SD_Thread; |
4357 | 92 | } |
4358 | | |
4359 | | /// Matches a variable declaration that is an exception variable from |
4360 | | /// a C++ catch block, or an Objective-C \@catch statement. |
4361 | | /// |
4362 | | /// Example matches x (matcher = varDecl(isExceptionVariable()) |
4363 | | /// \code |
4364 | | /// void f(int y) { |
4365 | | /// try { |
4366 | | /// } catch (int x) { |
4367 | | /// } |
4368 | | /// } |
4369 | | /// \endcode |
4370 | 40 | AST_MATCHER(VarDecl, isExceptionVariable) { |
4371 | 40 | return Node.isExceptionVariable(); |
4372 | 40 | } |
4373 | | |
4374 | | /// Checks that a call expression or a constructor call expression has |
4375 | | /// a specific number of arguments (including absent default arguments). |
4376 | | /// |
4377 | | /// Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) |
4378 | | /// \code |
4379 | | /// void f(int x, int y); |
4380 | | /// f(0, 0); |
4381 | | /// \endcode |
4382 | | AST_POLYMORPHIC_MATCHER_P(argumentCountIs, |
4383 | | AST_POLYMORPHIC_SUPPORTED_TYPES( |
4384 | | CallExpr, CXXConstructExpr, |
4385 | | CXXUnresolvedConstructExpr, ObjCMessageExpr), |
4386 | 1.07k | unsigned, N) { |
4387 | 1.07k | unsigned NumArgs = Node.getNumArgs(); |
4388 | 1.07k | if (!Finder->isTraversalIgnoringImplicitNodes()) |
4389 | 1.07k | return NumArgs == N; |
4390 | 8 | while (4 NumArgs) { |
4391 | 8 | if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1))) |
4392 | 4 | break; |
4393 | 4 | --NumArgs; |
4394 | 4 | } |
4395 | 4 | return NumArgs == N; |
4396 | 1.07k | } clang::ast_matchers::internal::matcher_argumentCountIs0Matcher<clang::CallExpr, unsigned int>::matches(clang::CallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4386 | 99 | unsigned, N) { | 4387 | 99 | unsigned NumArgs = Node.getNumArgs(); | 4388 | 99 | if (!Finder->isTraversalIgnoringImplicitNodes()) | 4389 | 95 | return NumArgs == N; | 4390 | 8 | while (4 NumArgs) { | 4391 | 8 | if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1))) | 4392 | 4 | break; | 4393 | 4 | --NumArgs; | 4394 | 4 | } | 4395 | 4 | return NumArgs == N; | 4396 | 99 | } |
clang::ast_matchers::internal::matcher_argumentCountIs0Matcher<clang::CXXConstructExpr, unsigned int>::matches(clang::CXXConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4386 | 746 | unsigned, N) { | 4387 | 746 | unsigned NumArgs = Node.getNumArgs(); | 4388 | 746 | if (!Finder->isTraversalIgnoringImplicitNodes()) | 4389 | 746 | return NumArgs == N; | 4390 | 0 | while (NumArgs) { | 4391 | 0 | if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1))) | 4392 | 0 | break; | 4393 | 0 | --NumArgs; | 4394 | 0 | } | 4395 | 0 | return NumArgs == N; | 4396 | 746 | } |
clang::ast_matchers::internal::matcher_argumentCountIs0Matcher<clang::CXXUnresolvedConstructExpr, unsigned int>::matches(clang::CXXUnresolvedConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4386 | 4 | unsigned, N) { | 4387 | 4 | unsigned NumArgs = Node.getNumArgs(); | 4388 | 4 | if (!Finder->isTraversalIgnoringImplicitNodes()) | 4389 | 4 | return NumArgs == N; | 4390 | 0 | while (NumArgs) { | 4391 | 0 | if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1))) | 4392 | 0 | break; | 4393 | 0 | --NumArgs; | 4394 | 0 | } | 4395 | 0 | return NumArgs == N; | 4396 | 4 | } |
clang::ast_matchers::internal::matcher_argumentCountIs0Matcher<clang::ObjCMessageExpr, unsigned int>::matches(clang::ObjCMessageExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4386 | 2 | unsigned, N) { | 4387 | 2 | unsigned NumArgs = Node.getNumArgs(); | 4388 | 2 | if (!Finder->isTraversalIgnoringImplicitNodes()) | 4389 | 2 | return NumArgs == N; | 4390 | 0 | while (NumArgs) { | 4391 | 0 | if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1))) | 4392 | 0 | break; | 4393 | 0 | --NumArgs; | 4394 | 0 | } | 4395 | 0 | return NumArgs == N; | 4396 | 2 | } |
clang::ast_matchers::internal::matcher_argumentCountIs0Matcher<clang::CXXOperatorCallExpr, unsigned int>::matches(clang::CXXOperatorCallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4386 | 223 | unsigned, N) { | 4387 | 223 | unsigned NumArgs = Node.getNumArgs(); | 4388 | 223 | if (!Finder->isTraversalIgnoringImplicitNodes()) | 4389 | 223 | return NumArgs == N; | 4390 | 0 | while (NumArgs) { | 4391 | 0 | if (!isa<CXXDefaultArgExpr>(Node.getArg(NumArgs - 1))) | 4392 | 0 | break; | 4393 | 0 | --NumArgs; | 4394 | 0 | } | 4395 | 0 | return NumArgs == N; | 4396 | 223 | } |
|
4397 | | |
4398 | | /// Matches the n'th argument of a call expression or a constructor |
4399 | | /// call expression. |
4400 | | /// |
4401 | | /// Example matches y in x(y) |
4402 | | /// (matcher = callExpr(hasArgument(0, declRefExpr()))) |
4403 | | /// \code |
4404 | | /// void x(int) { int y; x(y); } |
4405 | | /// \endcode |
4406 | | AST_POLYMORPHIC_MATCHER_P2(hasArgument, |
4407 | | AST_POLYMORPHIC_SUPPORTED_TYPES( |
4408 | | CallExpr, CXXConstructExpr, |
4409 | | CXXUnresolvedConstructExpr, ObjCMessageExpr), |
4410 | 2.11k | unsigned, N, internal::Matcher<Expr>, InnerMatcher) { |
4411 | 2.11k | if (N >= Node.getNumArgs()) |
4412 | 124 | return false; |
4413 | 1.99k | const Expr *Arg = Node.getArg(N); |
4414 | 1.99k | if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)91 ) |
4415 | 2 | return false; |
4416 | 1.99k | return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); |
4417 | 1.99k | } clang::ast_matchers::internal::matcher_hasArgument0Matcher<clang::CallExpr, unsigned int, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4410 | 761 | unsigned, N, internal::Matcher<Expr>, InnerMatcher) { | 4411 | 761 | if (N >= Node.getNumArgs()) | 4412 | 2 | return false; | 4413 | 759 | const Expr *Arg = Node.getArg(N); | 4414 | 759 | if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)44 ) | 4415 | 2 | return false; | 4416 | 757 | return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); | 4417 | 759 | } |
clang::ast_matchers::internal::matcher_hasArgument0Matcher<clang::CXXConstructExpr, unsigned int, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CXXConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4410 | 974 | unsigned, N, internal::Matcher<Expr>, InnerMatcher) { | 4411 | 974 | if (N >= Node.getNumArgs()) | 4412 | 122 | return false; | 4413 | 852 | const Expr *Arg = Node.getArg(N); | 4414 | 852 | if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)42 ) | 4415 | 0 | return false; | 4416 | 852 | return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); | 4417 | 852 | } |
clang::ast_matchers::internal::matcher_hasArgument0Matcher<clang::CXXUnresolvedConstructExpr, unsigned int, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CXXUnresolvedConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4410 | 4 | unsigned, N, internal::Matcher<Expr>, InnerMatcher) { | 4411 | 4 | if (N >= Node.getNumArgs()) | 4412 | 0 | return false; | 4413 | 4 | const Expr *Arg = Node.getArg(N); | 4414 | 4 | if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)0 ) | 4415 | 0 | return false; | 4416 | 4 | return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); | 4417 | 4 | } |
Unexecuted instantiation: clang::ast_matchers::internal::matcher_hasArgument0Matcher<clang::ObjCMessageExpr, unsigned int, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::ObjCMessageExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const clang::ast_matchers::internal::matcher_hasArgument0Matcher<clang::CXXOperatorCallExpr, unsigned int, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CXXOperatorCallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4410 | 319 | unsigned, N, internal::Matcher<Expr>, InnerMatcher) { | 4411 | 319 | if (N >= Node.getNumArgs()) | 4412 | 0 | return false; | 4413 | 319 | const Expr *Arg = Node.getArg(N); | 4414 | 319 | if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)5 ) | 4415 | 0 | return false; | 4416 | 319 | return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); | 4417 | 319 | } |
clang::ast_matchers::internal::matcher_hasArgument0Matcher<clang::CXXMemberCallExpr, unsigned int, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CXXMemberCallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4410 | 60 | unsigned, N, internal::Matcher<Expr>, InnerMatcher) { | 4411 | 60 | if (N >= Node.getNumArgs()) | 4412 | 0 | return false; | 4413 | 60 | const Expr *Arg = Node.getArg(N); | 4414 | 60 | if (Finder->isTraversalIgnoringImplicitNodes() && isa<CXXDefaultArgExpr>(Arg)0 ) | 4415 | 0 | return false; | 4416 | 60 | return InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, Builder); | 4417 | 60 | } |
|
4418 | | |
4419 | | /// Matches the n'th item of an initializer list expression. |
4420 | | /// |
4421 | | /// Example matches y. |
4422 | | /// (matcher = initListExpr(hasInit(0, expr()))) |
4423 | | /// \code |
4424 | | /// int x{y}. |
4425 | | /// \endcode |
4426 | | AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N, |
4427 | 40 | ast_matchers::internal::Matcher<Expr>, InnerMatcher) { |
4428 | 40 | return N < Node.getNumInits() && |
4429 | 40 | InnerMatcher.matches(*Node.getInit(N), Finder, Builder)24 ; |
4430 | 40 | } |
4431 | | |
4432 | | /// Matches declaration statements that contain a specific number of |
4433 | | /// declarations. |
4434 | | /// |
4435 | | /// Example: Given |
4436 | | /// \code |
4437 | | /// int a, b; |
4438 | | /// int c; |
4439 | | /// int d = 2, e; |
4440 | | /// \endcode |
4441 | | /// declCountIs(2) |
4442 | | /// matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'. |
4443 | 112 | AST_MATCHER_P(DeclStmt, declCountIs, unsigned, N) { |
4444 | 112 | return std::distance(Node.decl_begin(), Node.decl_end()) == (ptrdiff_t)N; |
4445 | 112 | } |
4446 | | |
4447 | | /// Matches the n'th declaration of a declaration statement. |
4448 | | /// |
4449 | | /// Note that this does not work for global declarations because the AST |
4450 | | /// breaks up multiple-declaration DeclStmt's into multiple single-declaration |
4451 | | /// DeclStmt's. |
4452 | | /// Example: Given non-global declarations |
4453 | | /// \code |
4454 | | /// int a, b = 0; |
4455 | | /// int c; |
4456 | | /// int d = 2, e; |
4457 | | /// \endcode |
4458 | | /// declStmt(containsDeclaration( |
4459 | | /// 0, varDecl(hasInitializer(anything())))) |
4460 | | /// matches only 'int d = 2, e;', and |
4461 | | /// declStmt(containsDeclaration(1, varDecl())) |
4462 | | /// \code |
4463 | | /// matches 'int a, b = 0' as well as 'int d = 2, e;' |
4464 | | /// but 'int c;' is not matched. |
4465 | | /// \endcode |
4466 | | AST_MATCHER_P2(DeclStmt, containsDeclaration, unsigned, N, |
4467 | 9 | internal::Matcher<Decl>, InnerMatcher) { |
4468 | 9 | const unsigned NumDecls = std::distance(Node.decl_begin(), Node.decl_end()); |
4469 | 9 | if (N >= NumDecls) |
4470 | 2 | return false; |
4471 | 7 | DeclStmt::const_decl_iterator Iterator = Node.decl_begin(); |
4472 | 7 | std::advance(Iterator, N); |
4473 | 7 | return InnerMatcher.matches(**Iterator, Finder, Builder); |
4474 | 9 | } |
4475 | | |
4476 | | /// Matches a C++ catch statement that has a catch-all handler. |
4477 | | /// |
4478 | | /// Given |
4479 | | /// \code |
4480 | | /// try { |
4481 | | /// // ... |
4482 | | /// } catch (int) { |
4483 | | /// // ... |
4484 | | /// } catch (...) { |
4485 | | /// // ... |
4486 | | /// } |
4487 | | /// \endcode |
4488 | | /// cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int). |
4489 | 60 | AST_MATCHER(CXXCatchStmt, isCatchAll) { |
4490 | 60 | return Node.getExceptionDecl() == nullptr; |
4491 | 60 | } |
4492 | | |
4493 | | /// Matches a constructor initializer. |
4494 | | /// |
4495 | | /// Given |
4496 | | /// \code |
4497 | | /// struct Foo { |
4498 | | /// Foo() : foo_(1) { } |
4499 | | /// int foo_; |
4500 | | /// }; |
4501 | | /// \endcode |
4502 | | /// cxxRecordDecl(has(cxxConstructorDecl( |
4503 | | /// hasAnyConstructorInitializer(anything()) |
4504 | | /// ))) |
4505 | | /// record matches Foo, hasAnyConstructorInitializer matches foo_(1) |
4506 | | AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, |
4507 | 136 | internal::Matcher<CXXCtorInitializer>, InnerMatcher) { |
4508 | 136 | auto MatchIt = matchesFirstInPointerRange(InnerMatcher, Node.init_begin(), |
4509 | 136 | Node.init_end(), Finder, Builder); |
4510 | 136 | if (MatchIt == Node.init_end()) |
4511 | 96 | return false; |
4512 | 40 | return (*MatchIt)->isWritten() || !Finder->isTraversalIgnoringImplicitNodes()16 ; |
4513 | 136 | } |
4514 | | |
4515 | | /// Matches the field declaration of a constructor initializer. |
4516 | | /// |
4517 | | /// Given |
4518 | | /// \code |
4519 | | /// struct Foo { |
4520 | | /// Foo() : foo_(1) { } |
4521 | | /// int foo_; |
4522 | | /// }; |
4523 | | /// \endcode |
4524 | | /// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( |
4525 | | /// forField(hasName("foo_")))))) |
4526 | | /// matches Foo |
4527 | | /// with forField matching foo_ |
4528 | | AST_MATCHER_P(CXXCtorInitializer, forField, |
4529 | 121 | internal::Matcher<FieldDecl>, InnerMatcher) { |
4530 | 121 | const FieldDecl *NodeAsDecl = Node.getAnyMember(); |
4531 | 121 | return (NodeAsDecl != nullptr && |
4532 | 121 | InnerMatcher.matches(*NodeAsDecl, Finder, Builder)91 ); |
4533 | 121 | } |
4534 | | |
4535 | | /// Matches the initializer expression of a constructor initializer. |
4536 | | /// |
4537 | | /// Given |
4538 | | /// \code |
4539 | | /// struct Foo { |
4540 | | /// Foo() : foo_(1) { } |
4541 | | /// int foo_; |
4542 | | /// }; |
4543 | | /// \endcode |
4544 | | /// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( |
4545 | | /// withInitializer(integerLiteral(equals(1))))))) |
4546 | | /// matches Foo |
4547 | | /// with withInitializer matching (1) |
4548 | | AST_MATCHER_P(CXXCtorInitializer, withInitializer, |
4549 | 19 | internal::Matcher<Expr>, InnerMatcher) { |
4550 | 19 | const Expr* NodeAsExpr = Node.getInit(); |
4551 | 19 | return (NodeAsExpr != nullptr && |
4552 | 19 | InnerMatcher.matches(*NodeAsExpr, Finder, Builder)); |
4553 | 19 | } |
4554 | | |
4555 | | /// Matches a constructor initializer if it is explicitly written in |
4556 | | /// code (as opposed to implicitly added by the compiler). |
4557 | | /// |
4558 | | /// Given |
4559 | | /// \code |
4560 | | /// struct Foo { |
4561 | | /// Foo() { } |
4562 | | /// Foo(int) : foo_("A") { } |
4563 | | /// string foo_; |
4564 | | /// }; |
4565 | | /// \endcode |
4566 | | /// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) |
4567 | | /// will match Foo(int), but not Foo() |
4568 | 18 | AST_MATCHER(CXXCtorInitializer, isWritten) { |
4569 | 18 | return Node.isWritten(); |
4570 | 18 | } |
4571 | | |
4572 | | /// Matches a constructor initializer if it is initializing a base, as |
4573 | | /// opposed to a member. |
4574 | | /// |
4575 | | /// Given |
4576 | | /// \code |
4577 | | /// struct B {}; |
4578 | | /// struct D : B { |
4579 | | /// int I; |
4580 | | /// D(int i) : I(i) {} |
4581 | | /// }; |
4582 | | /// struct E : B { |
4583 | | /// E() : B() {} |
4584 | | /// }; |
4585 | | /// \endcode |
4586 | | /// cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) |
4587 | | /// will match E(), but not match D(int). |
4588 | 16 | AST_MATCHER(CXXCtorInitializer, isBaseInitializer) { |
4589 | 16 | return Node.isBaseInitializer(); |
4590 | 16 | } |
4591 | | |
4592 | | /// Matches a constructor initializer if it is initializing a member, as |
4593 | | /// opposed to a base. |
4594 | | /// |
4595 | | /// Given |
4596 | | /// \code |
4597 | | /// struct B {}; |
4598 | | /// struct D : B { |
4599 | | /// int I; |
4600 | | /// D(int i) : I(i) {} |
4601 | | /// }; |
4602 | | /// struct E : B { |
4603 | | /// E() : B() {} |
4604 | | /// }; |
4605 | | /// \endcode |
4606 | | /// cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) |
4607 | | /// will match D(int), but not match E(). |
4608 | 12 | AST_MATCHER(CXXCtorInitializer, isMemberInitializer) { |
4609 | 12 | return Node.isMemberInitializer(); |
4610 | 12 | } |
4611 | | |
4612 | | /// Matches any argument of a call expression or a constructor call |
4613 | | /// expression, or an ObjC-message-send expression. |
4614 | | /// |
4615 | | /// Given |
4616 | | /// \code |
4617 | | /// void x(int, int, int) { int y; x(1, y, 42); } |
4618 | | /// \endcode |
4619 | | /// callExpr(hasAnyArgument(declRefExpr())) |
4620 | | /// matches x(1, y, 42) |
4621 | | /// with hasAnyArgument(...) |
4622 | | /// matching y |
4623 | | /// |
4624 | | /// For ObjectiveC, given |
4625 | | /// \code |
4626 | | /// @interface I - (void) f:(int) y; @end |
4627 | | /// void foo(I *i) { [i f:12]; } |
4628 | | /// \endcode |
4629 | | /// objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) |
4630 | | /// matches [i f:12] |
4631 | | AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, |
4632 | | AST_POLYMORPHIC_SUPPORTED_TYPES( |
4633 | | CallExpr, CXXConstructExpr, |
4634 | | CXXUnresolvedConstructExpr, ObjCMessageExpr), |
4635 | 557 | internal::Matcher<Expr>, InnerMatcher) { |
4636 | 557 | for (const Expr *Arg : Node.arguments()) { |
4637 | 508 | if (Finder->isTraversalIgnoringImplicitNodes() && |
4638 | 508 | isa<CXXDefaultArgExpr>(Arg)26 ) |
4639 | 2 | break; |
4640 | 506 | BoundNodesTreeBuilder Result(*Builder); |
4641 | 506 | if (InnerMatcher.matches(*Arg, Finder, &Result)) { |
4642 | 138 | *Builder = std::move(Result); |
4643 | 138 | return true; |
4644 | 138 | } |
4645 | 506 | } |
4646 | 419 | return false; |
4647 | 557 | } clang::ast_matchers::internal::matcher_hasAnyArgument0Matcher<clang::CallExpr, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CallExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4635 | 472 | internal::Matcher<Expr>, InnerMatcher) { | 4636 | 472 | for (const Expr *Arg : Node.arguments()) { | 4637 | 413 | if (Finder->isTraversalIgnoringImplicitNodes() && | 4638 | 413 | isa<CXXDefaultArgExpr>(Arg)16 ) | 4639 | 2 | break; | 4640 | 411 | BoundNodesTreeBuilder Result(*Builder); | 4641 | 411 | if (InnerMatcher.matches(*Arg, Finder, &Result)) { | 4642 | 89 | *Builder = std::move(Result); | 4643 | 89 | return true; | 4644 | 89 | } | 4645 | 411 | } | 4646 | 383 | return false; | 4647 | 472 | } |
clang::ast_matchers::internal::matcher_hasAnyArgument0Matcher<clang::ObjCMessageExpr, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::ObjCMessageExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4635 | 61 | internal::Matcher<Expr>, InnerMatcher) { | 4636 | 64 | for (const Expr *Arg : Node.arguments()) { | 4637 | 64 | if (Finder->isTraversalIgnoringImplicitNodes() && | 4638 | 64 | isa<CXXDefaultArgExpr>(Arg)0 ) | 4639 | 0 | break; | 4640 | 64 | BoundNodesTreeBuilder Result(*Builder); | 4641 | 64 | if (InnerMatcher.matches(*Arg, Finder, &Result)) { | 4642 | 30 | *Builder = std::move(Result); | 4643 | 30 | return true; | 4644 | 30 | } | 4645 | 64 | } | 4646 | 31 | return false; | 4647 | 61 | } |
clang::ast_matchers::internal::matcher_hasAnyArgument0Matcher<clang::CXXConstructExpr, clang::ast_matchers::internal::Matcher<clang::Expr> >::matches(clang::CXXConstructExpr const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const Line | Count | Source | 4635 | 16 | internal::Matcher<Expr>, InnerMatcher) { | 4636 | 20 | for (const Expr *Arg : Node.arguments()) { | 4637 | 20 | if (Finder->isTraversalIgnoringImplicitNodes() && | 4638 | 20 | isa<CXXDefaultArgExpr>(Arg)10 ) | 4639 | 0 | break; | 4640 | 20 | BoundNodesTreeBuilder Result(*Builder); | 4641 | 20 | if (InnerMatcher.matches(*Arg, Finder, &Result)) { | 4642 | 14 | *Builder = std::move(Result); | 4643 | 14 | return true; | 4644 | |
|