Go to the documentation of this file.
49#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
50#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
55#define AST_MATCHER_FUNCTION(ReturnType, DefineMatcher) \
56 inline ReturnType DefineMatcher##_getInstance(); \
57 inline ReturnType DefineMatcher() { \
58 return ::clang::ast_matchers::internal::MemoizedMatcher< \
59 ReturnType, DefineMatcher##_getInstance>::getInstance(); \
61 inline ReturnType DefineMatcher##_getInstance()
74#define AST_MATCHER_FUNCTION_P(ReturnType, DefineMatcher, ParamType, Param) \
75 AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, Param, \
77#define AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, \
79 inline ReturnType DefineMatcher(ParamType const &Param); \
80 typedef ReturnType (&DefineMatcher##_Type##OverloadId)(ParamType const &); \
81 inline ReturnType DefineMatcher(ParamType const &Param)
94#define AST_MATCHER(Type, DefineMatcher) \
95 namespace internal { \
96 class matcher_##DefineMatcher##Matcher \
97 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
99 explicit matcher_##DefineMatcher##Matcher() = default; \
100 bool matches(const Type &Node, \
101 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
102 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
103 *Builder) const override; \
106 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher() { \
107 return ::clang::ast_matchers::internal::makeMatcher( \
108 new internal::matcher_##DefineMatcher##Matcher()); \
110 inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
112 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
113 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
128#define AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) \
129 AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, 0)
131#define AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, \
133 namespace internal { \
134 class matcher_##DefineMatcher##OverloadId##Matcher \
135 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
137 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
138 ParamType const &A##Param) \
139 : Param(A##Param) {} \
140 bool matches(const Type &Node, \
141 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
142 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
143 *Builder) const override; \
149 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
150 ParamType const &Param) { \
151 return ::clang::ast_matchers::internal::makeMatcher( \
152 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param)); \
154 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
155 &DefineMatcher##_Type##OverloadId)(ParamType const &Param); \
156 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
158 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
159 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
175#define AST_MATCHER_P2(Type, DefineMatcher, ParamType1, Param1, ParamType2, \
177 AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, ParamType2, \
180#define AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, \
181 ParamType2, Param2, OverloadId) \
182 namespace internal { \
183 class matcher_##DefineMatcher##OverloadId##Matcher \
184 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
186 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \
187 ParamType2 const &A##Param2) \
188 : Param1(A##Param1), Param2(A##Param2) {} \
189 bool matches(const Type &Node, \
190 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
191 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
192 *Builder) const override; \
199 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
200 ParamType1 const &Param1, ParamType2 const &Param2) { \
201 return ::clang::ast_matchers::internal::makeMatcher( \
202 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1, \
205 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
206 &DefineMatcher##_Type##OverloadId)(ParamType1 const &Param1, \
207 ParamType2 const &Param2); \
208 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
210 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
211 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
221#define AST_POLYMORPHIC_SUPPORTED_TYPES(...) \
222 void(::clang::ast_matchers::internal::TypeList<__VA_ARGS__>)
230#define AST_POLYMORPHIC_MATCHER(DefineMatcher, ReturnTypesF) \
231 namespace internal { \
232 template <typename NodeType> \
233 class matcher_##DefineMatcher##Matcher \
234 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
236 bool matches(const NodeType &Node, \
237 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
238 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
239 *Builder) const override; \
242 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
243 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF> \
245 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
246 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF>(); \
248 template <typename NodeType> \
249 bool internal::matcher_##DefineMatcher##Matcher<NodeType>::matches( \
250 const NodeType &Node, \
251 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
252 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
263#define AST_POLYMORPHIC_MATCHER_P(DefineMatcher, ReturnTypesF, ParamType, \
265 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType, \
268#define AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, \
269 ParamType, Param, OverloadId) \
270 namespace internal { \
271 template <typename NodeType, typename ParamT> \
272 class matcher_##DefineMatcher##OverloadId##Matcher \
273 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
275 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
276 ParamType const &A##Param) \
277 : Param(A##Param) {} \
278 bool matches(const NodeType &Node, \
279 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
280 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
281 *Builder) const override; \
287 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
288 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
290 DefineMatcher(ParamType const &Param) { \
291 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
292 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
295 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
296 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
297 ParamType> (&DefineMatcher##_Type##OverloadId)(ParamType const &Param); \
298 template <typename NodeType, typename ParamT> \
300 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
301 const NodeType &Node, \
302 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
303 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
314#define AST_POLYMORPHIC_MATCHER_P2(DefineMatcher, ReturnTypesF, ParamType1, \
315 Param1, ParamType2, Param2) \
316 AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType1, \
317 Param1, ParamType2, Param2, 0)
319#define AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, \
320 ParamType1, Param1, ParamType2, \
321 Param2, OverloadId) \
322 namespace internal { \
323 template <typename NodeType, typename ParamT1, typename ParamT2> \
324 class matcher_##DefineMatcher##OverloadId##Matcher \
325 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
327 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \
328 ParamType2 const &A##Param2) \
329 : Param1(A##Param1), Param2(A##Param2) {} \
330 bool matches(const NodeType &Node, \
331 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
332 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
333 *Builder) const override; \
340 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
341 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
342 ParamType1, ParamType2> \
343 DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) { \
344 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
345 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
346 ParamType1, ParamType2>(Param1, Param2); \
348 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
349 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
350 ParamType1, ParamType2> (&DefineMatcher##_Type##OverloadId)( \
351 ParamType1 const &Param1, ParamType2 const &Param2); \
352 template <typename NodeType, typename ParamT1, typename ParamT2> \
353 bool internal::matcher_##DefineMatcher##OverloadId##Matcher< \
354 NodeType, ParamT1, ParamT2>:: \
355 matches(const NodeType &Node, \
356 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
357 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
363#define AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \
365 namespace internal { \
366 template <typename T> struct TypeMatcher##MatcherName##Getter { \
367 static QualType (T::*value())() const { return &T::FunctionName; } \
370 extern const ::clang::ast_matchers::internal:: \
371 TypeTraversePolymorphicMatcher< \
373 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
374 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
375 ReturnTypesF>::Func MatcherName
377#define AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \
378 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
380 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
381 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
382 ReturnTypesF>::Func MatcherName
391#define AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \
392 namespace internal { \
393 template <typename T> struct TypeMatcher##MatcherName##Getter { \
394 static QualType (T::*value())() const { return &T::FunctionName; } \
397 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
399 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
400 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
401 ReturnTypesF>::Func MatcherName
403#define AST_TYPELOC_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \
405 namespace internal { \
406 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \
407 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
410 extern const ::clang::ast_matchers::internal:: \
411 TypeTraversePolymorphicMatcher< \
413 ::clang::ast_matchers::internal:: \
414 TypeLocMatcher##MatcherName##Getter, \
415 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
416 ReturnTypesF>::Func MatcherName##Loc; \
417 AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName##Type, ReturnTypesF)
419#define AST_TYPELOC_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \
420 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
422 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \
423 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
424 ReturnTypesF>::Func MatcherName##Loc; \
425 AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF)
429#define AST_TYPELOC_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \
430 namespace internal { \
431 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \
432 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
435 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
437 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \
438 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
439 ReturnTypesF>::Func MatcherName##Loc; \
440 AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName##Type, ReturnTypesF)
455#define AST_MATCHER_REGEX(Type, DefineMatcher, Param) \
456 AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, 0)
458#define AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, OverloadId) \
459 namespace internal { \
460 class matcher_##DefineMatcher##OverloadId##Matcher \
461 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
463 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
464 std::shared_ptr<llvm::Regex> RE) \
465 : Param(std::move(RE)) {} \
466 bool matches(const Type &Node, \
467 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
468 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
469 *Builder) const override; \
472 std::shared_ptr<llvm::Regex> Param; \
475 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
476 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
477 return ::clang::ast_matchers::internal::makeMatcher( \
478 new internal::matcher_##DefineMatcher##OverloadId##Matcher( \
479 ::clang::ast_matchers::internal::createAndVerifyRegex( \
480 Param, RegexFlags, #DefineMatcher))); \
482 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
483 llvm::StringRef Param) { \
484 return DefineMatcher(Param, llvm::Regex::NoFlags); \
487 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
488 &DefineMatcher##_Type##OverloadId##Flags)(llvm::StringRef, \
489 llvm::Regex::RegexFlags); \
490 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
491 &DefineMatcher##_Type##OverloadId)(llvm::StringRef); \
492 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
494 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
495 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
505#define AST_POLYMORPHIC_MATCHER_REGEX(DefineMatcher, ReturnTypesF, Param) \
506 AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, Param, 0)
508#define AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, \
510 namespace internal { \
511 template <typename NodeType, typename ParamT> \
512 class matcher_##DefineMatcher##OverloadId##Matcher \
513 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
515 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
516 std::shared_ptr<llvm::Regex> RE) \
517 : Param(std::move(RE)) {} \
518 bool matches(const NodeType &Node, \
519 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
520 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
521 *Builder) const override; \
524 std::shared_ptr<llvm::Regex> Param; \
527 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
528 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
529 std::shared_ptr<llvm::Regex>> \
530 DefineMatcher(llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
531 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
532 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
533 std::shared_ptr<llvm::Regex>>( \
534 ::clang::ast_matchers::internal::createAndVerifyRegex( \
535 Param, RegexFlags, #DefineMatcher)); \
537 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
538 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
539 std::shared_ptr<llvm::Regex>> \
540 DefineMatcher(llvm::StringRef Param) { \
541 return DefineMatcher(Param, llvm::Regex::NoFlags); \
543 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
544 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
545 std::shared_ptr<llvm::Regex>> ( \
546 &DefineMatcher##_Type##OverloadId##Flags)( \
547 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags); \
548 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
549 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
550 std::shared_ptr<llvm::Regex>> (&DefineMatcher##_Type##OverloadId)( \
551 llvm::StringRef Param); \
552 template <typename NodeType, typename ParamT> \
554 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
555 const NodeType &Node, \
556 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
557 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \