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; \ 146 ParamType const Param; \ 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; \ 195 ParamType1 const Param1; \ 196 ParamType2 const Param2; \ 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::PolymorphicMatcherWithParam0< \ 243 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF> \ 245 return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam0< \ 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; \ 284 ParamType const Param; \ 287 inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1< \ 288 internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType, \ 290 DefineMatcher(ParamType const &Param) { \ 291 return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1< \ 292 internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType, \ 293 ReturnTypesF>(Param); \ 295 typedef ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1< \ 296 internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType, \ 297 ReturnTypesF>(&DefineMatcher##_Type##OverloadId)( \ 298 ParamType const &Param); \ 299 template <typename NodeType, typename ParamT> \ 301 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \ 302 const NodeType &Node, \ 303 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \ 304 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \ 315 #define AST_POLYMORPHIC_MATCHER_P2(DefineMatcher, ReturnTypesF, ParamType1, \ 316 Param1, ParamType2, Param2) \ 317 AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType1, \ 318 Param1, ParamType2, Param2, 0) 320 #define AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, \ 321 ParamType1, Param1, ParamType2, \ 322 Param2, OverloadId) \ 323 namespace internal { \ 324 template <typename NodeType, typename ParamT1, typename ParamT2> \ 325 class matcher_##DefineMatcher##OverloadId##Matcher \ 326 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \ 328 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \ 329 ParamType2 const &A##Param2) \ 330 : Param1(A##Param1), Param2(A##Param2) {} \ 331 bool matches(const NodeType &Node, \ 332 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \ 333 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \ 334 *Builder) const override; \ 337 ParamType1 const Param1; \ 338 ParamType2 const Param2; \ 341 inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2< \ 342 internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1, \ 343 ParamType2, ReturnTypesF> \ 344 DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) { \ 345 return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2< \ 346 internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1, \ 347 ParamType2, ReturnTypesF>(Param1, Param2); \ 349 typedef ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2< \ 350 internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1, \ 351 ParamType2, ReturnTypesF>(&DefineMatcher##_Type##OverloadId)( \ 352 ParamType1 const &Param1, ParamType2 const &Param2); \ 353 template <typename NodeType, typename ParamT1, typename ParamT2> \ 354 bool internal::matcher_##DefineMatcher##OverloadId##Matcher< \ 355 NodeType, ParamT1, ParamT2>:: \ 356 matches(const NodeType &Node, \ 357 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \ 358 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \ 364 #define AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \ 366 namespace internal { \ 367 template <typename T> struct TypeMatcher##MatcherName##Getter { \ 368 static QualType (T::*value())() const { return &T::FunctionName; } \ 371 extern const ::clang::ast_matchers::internal:: \ 372 TypeTraversePolymorphicMatcher< \ 374 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \ 375 ::clang::ast_matchers::internal::TypeTraverseMatcher, \ 376 ReturnTypesF>::Func MatcherName 378 #define AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \ 379 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \ 381 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \ 382 ::clang::ast_matchers::internal::TypeTraverseMatcher, \ 383 ReturnTypesF>::Func MatcherName 392 #define AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \ 393 namespace internal { \ 394 template <typename T> struct TypeMatcher##MatcherName##Getter { \ 395 static QualType (T::*value())() const { return &T::FunctionName; } \ 398 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \ 400 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \ 401 ::clang::ast_matchers::internal::TypeTraverseMatcher, \ 402 ReturnTypesF>::Func MatcherName 404 #define AST_TYPELOC_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \ 406 namespace internal { \ 407 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \ 408 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \ 411 extern const ::clang::ast_matchers::internal:: \ 412 TypeTraversePolymorphicMatcher< \ 414 ::clang::ast_matchers::internal:: \ 415 TypeLocMatcher##MatcherName##Getter, \ 416 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \ 417 ReturnTypesF>::Func MatcherName##Loc; \ 418 AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName##Type, ReturnTypesF) 420 #define AST_TYPELOC_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \ 421 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \ 423 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \ 424 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \ 425 ReturnTypesF>::Func MatcherName##Loc; \ 426 AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) 430 #define AST_TYPELOC_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \ 431 namespace internal { \ 432 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \ 433 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \ 436 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \ 438 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \ 439 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \ 440 ReturnTypesF>::Func MatcherName##Loc; \ 441 AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName##Type, ReturnTypesF) 443 #endif // LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H