Go to the documentation of this file.
49#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
50#define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
57#define AST_MATCHER_FUNCTION(ReturnType, DefineMatcher) \
58 inline ReturnType DefineMatcher##_getInstance(); \
59 inline ReturnType DefineMatcher() { \
60 return ::clang::ast_matchers::internal::MemoizedMatcher< \
61 ReturnType, DefineMatcher##_getInstance>::getInstance(); \
63 inline ReturnType DefineMatcher##_getInstance()
76#define AST_MATCHER_FUNCTION_P(ReturnType, DefineMatcher, ParamType, Param) \
77 AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, Param, \
79#define AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, \
81 inline ReturnType DefineMatcher(ParamType const &Param); \
82 typedef ReturnType (&DefineMatcher##_Type##OverloadId)(ParamType const &); \
83 inline ReturnType DefineMatcher(ParamType const &Param)
96#define AST_MATCHER(Type, DefineMatcher) \
97 namespace internal { \
98 class matcher_##DefineMatcher##Matcher \
99 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
101 explicit matcher_##DefineMatcher##Matcher() = default; \
102 bool matches(const Type &Node, \
103 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
104 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
105 *Builder) const override; \
108 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher() { \
109 return ::clang::ast_matchers::internal::makeMatcher( \
110 new internal::matcher_##DefineMatcher##Matcher()); \
112 inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
114 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
115 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
130#define AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) \
131 AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, 0)
133#define AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, \
135 namespace internal { \
136 class matcher_##DefineMatcher##OverloadId##Matcher \
137 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
139 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
140 ParamType const &A##Param) \
141 : Param(A##Param) {} \
142 bool matches(const Type &Node, \
143 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
144 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
145 *Builder) const override; \
151 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
152 ParamType const &Param) { \
153 return ::clang::ast_matchers::internal::makeMatcher( \
154 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param)); \
156 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
157 &DefineMatcher##_Type##OverloadId)(ParamType const &Param); \
158 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
160 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
161 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
177#define AST_MATCHER_P2(Type, DefineMatcher, ParamType1, Param1, ParamType2, \
179 AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, ParamType2, \
182#define AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, \
183 ParamType2, Param2, OverloadId) \
184 namespace internal { \
185 class matcher_##DefineMatcher##OverloadId##Matcher \
186 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
188 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \
189 ParamType2 const &A##Param2) \
190 : Param1(A##Param1), Param2(A##Param2) {} \
191 bool matches(const Type &Node, \
192 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
193 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
194 *Builder) const override; \
201 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
202 ParamType1 const &Param1, ParamType2 const &Param2) { \
203 return ::clang::ast_matchers::internal::makeMatcher( \
204 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1, \
207 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
208 &DefineMatcher##_Type##OverloadId)(ParamType1 const &Param1, \
209 ParamType2 const &Param2); \
210 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
212 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
213 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
223#define AST_POLYMORPHIC_SUPPORTED_TYPES(...) \
224 void(::clang::ast_matchers::internal::TypeList<__VA_ARGS__>)
232#define AST_POLYMORPHIC_MATCHER(DefineMatcher, ReturnTypesF) \
233 namespace internal { \
234 template <typename NodeType> \
235 class matcher_##DefineMatcher##Matcher \
236 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
238 bool matches(const NodeType &Node, \
239 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
240 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
241 *Builder) const override; \
244 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
245 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF> \
247 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
248 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF>(); \
250 template <typename NodeType> \
251 bool internal::matcher_##DefineMatcher##Matcher<NodeType>::matches( \
252 const NodeType &Node, \
253 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
254 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
265#define AST_POLYMORPHIC_MATCHER_P(DefineMatcher, ReturnTypesF, ParamType, \
267 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType, \
270#define AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, \
271 ParamType, Param, OverloadId) \
272 namespace internal { \
273 template <typename NodeType, typename ParamT> \
274 class matcher_##DefineMatcher##OverloadId##Matcher \
275 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
277 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
278 ParamType const &A##Param) \
279 : Param(A##Param) {} \
280 bool matches(const NodeType &Node, \
281 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
282 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
283 *Builder) const override; \
289 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
290 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
292 DefineMatcher(ParamType const &Param) { \
293 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
294 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
297 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
298 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
299 ParamType> (&DefineMatcher##_Type##OverloadId)(ParamType const &Param); \
300 template <typename NodeType, typename ParamT> \
302 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
303 const NodeType &Node, \
304 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
305 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
316#define AST_POLYMORPHIC_MATCHER_P2(DefineMatcher, ReturnTypesF, ParamType1, \
317 Param1, ParamType2, Param2) \
318 AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType1, \
319 Param1, ParamType2, Param2, 0)
321#define AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, \
322 ParamType1, Param1, ParamType2, \
323 Param2, OverloadId) \
324 namespace internal { \
325 template <typename NodeType, typename ParamT1, typename ParamT2> \
326 class matcher_##DefineMatcher##OverloadId##Matcher \
327 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
329 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \
330 ParamType2 const &A##Param2) \
331 : Param1(A##Param1), Param2(A##Param2) {} \
332 bool matches(const NodeType &Node, \
333 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
334 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
335 *Builder) const override; \
342 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
343 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
344 ParamType1, ParamType2> \
345 DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) { \
346 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
347 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
348 ParamType1, ParamType2>(Param1, Param2); \
350 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
351 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
352 ParamType1, ParamType2> (&DefineMatcher##_Type##OverloadId)( \
353 ParamType1 const &Param1, ParamType2 const &Param2); \
354 template <typename NodeType, typename ParamT1, typename ParamT2> \
355 bool internal::matcher_##DefineMatcher##OverloadId##Matcher< \
356 NodeType, ParamT1, ParamT2>:: \
357 matches(const NodeType &Node, \
358 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
359 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
365#define AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \
367 namespace internal { \
368 template <typename T> struct TypeMatcher##MatcherName##Getter { \
369 static QualType (T::*value())() const { return &T::FunctionName; } \
372 CLANG_ABI extern const ::clang::ast_matchers::internal:: \
373 TypeTraversePolymorphicMatcher< \
375 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
376 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
377 ReturnTypesF>::Func MatcherName
379#define AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \
380 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
382 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
383 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
384 ReturnTypesF>::Func MatcherName
393#define AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \
394 namespace internal { \
395 template <typename T> struct TypeMatcher##MatcherName##Getter { \
396 static QualType (T::*value())() const { return &T::FunctionName; } \
399 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
401 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
402 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
403 ReturnTypesF>::Func MatcherName
405#define AST_TYPELOC_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \
407 namespace internal { \
408 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \
409 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
412 CLANG_ABI extern const ::clang::ast_matchers::internal:: \
413 TypeTraversePolymorphicMatcher< \
415 ::clang::ast_matchers::internal:: \
416 TypeLocMatcher##MatcherName##Getter, \
417 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
418 ReturnTypesF>::Func MatcherName##Loc; \
419 AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName##Type, ReturnTypesF)
421#define AST_TYPELOC_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \
422 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
424 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \
425 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
426 ReturnTypesF>::Func MatcherName##Loc; \
427 AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF)
431#define AST_TYPELOC_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \
432 namespace internal { \
433 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \
434 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
437 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
439 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \
440 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
441 ReturnTypesF>::Func MatcherName##Loc; \
442 AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName##Type, ReturnTypesF)
457#define AST_MATCHER_REGEX(Type, DefineMatcher, Param) \
458 AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, 0)
460#define AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, OverloadId) \
461 namespace internal { \
462 class matcher_##DefineMatcher##OverloadId##Matcher \
463 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
465 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
466 std::shared_ptr<llvm::Regex> RE) \
467 : Param(std::move(RE)) {} \
468 bool matches(const Type &Node, \
469 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
470 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
471 *Builder) const override; \
474 std::shared_ptr<llvm::Regex> Param; \
477 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
478 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
479 return ::clang::ast_matchers::internal::makeMatcher( \
480 new internal::matcher_##DefineMatcher##OverloadId##Matcher( \
481 ::clang::ast_matchers::internal::createAndVerifyRegex( \
482 Param, RegexFlags, #DefineMatcher))); \
484 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
485 llvm::StringRef Param) { \
486 return DefineMatcher(Param, llvm::Regex::NoFlags); \
489 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
490 &DefineMatcher##_Type##OverloadId##Flags)(llvm::StringRef, \
491 llvm::Regex::RegexFlags); \
492 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
493 &DefineMatcher##_Type##OverloadId)(llvm::StringRef); \
494 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
496 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
497 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
507#define AST_POLYMORPHIC_MATCHER_REGEX(DefineMatcher, ReturnTypesF, Param) \
508 AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, Param, 0)
510#define AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, \
512 namespace internal { \
513 template <typename NodeType, typename ParamT> \
514 class matcher_##DefineMatcher##OverloadId##Matcher \
515 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
517 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
518 std::shared_ptr<llvm::Regex> RE) \
519 : Param(std::move(RE)) {} \
520 bool matches(const NodeType &Node, \
521 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
522 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
523 *Builder) const override; \
526 std::shared_ptr<llvm::Regex> Param; \
529 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
530 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
531 std::shared_ptr<llvm::Regex>> \
532 DefineMatcher(llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
533 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
534 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
535 std::shared_ptr<llvm::Regex>>( \
536 ::clang::ast_matchers::internal::createAndVerifyRegex( \
537 Param, RegexFlags, #DefineMatcher)); \
539 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
540 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
541 std::shared_ptr<llvm::Regex>> \
542 DefineMatcher(llvm::StringRef Param) { \
543 return DefineMatcher(Param, llvm::Regex::NoFlags); \
545 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
546 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
547 std::shared_ptr<llvm::Regex>> ( \
548 &DefineMatcher##_Type##OverloadId##Flags)( \
549 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags); \
550 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
551 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
552 std::shared_ptr<llvm::Regex>> (&DefineMatcher##_Type##OverloadId)( \
553 llvm::StringRef Param); \
554 template <typename NodeType, typename ParamT> \
556 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
557 const NodeType &Node, \
558 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
559 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \