File indexing completed on 2026-05-10 08:36:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
0050 #define LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H
0051
0052 #include "clang/Support/Compiler.h"
0053
0054
0055
0056
0057 #define AST_MATCHER_FUNCTION(ReturnType, DefineMatcher) \
0058 inline ReturnType DefineMatcher##_getInstance(); \
0059 inline ReturnType DefineMatcher() { \
0060 return ::clang::ast_matchers::internal::MemoizedMatcher< \
0061 ReturnType, DefineMatcher##_getInstance>::getInstance(); \
0062 } \
0063 inline ReturnType DefineMatcher##_getInstance()
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 #define AST_MATCHER_FUNCTION_P(ReturnType, DefineMatcher, ParamType, Param) \
0077 AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, Param, \
0078 0)
0079 #define AST_MATCHER_FUNCTION_P_OVERLOAD(ReturnType, DefineMatcher, ParamType, \
0080 Param, OverloadId) \
0081 inline ReturnType DefineMatcher(ParamType const &Param); \
0082 typedef ReturnType (&DefineMatcher##_Type##OverloadId)(ParamType const &); \
0083 inline ReturnType DefineMatcher(ParamType const &Param)
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 #define AST_MATCHER(Type, DefineMatcher) \
0097 namespace internal { \
0098 class matcher_##DefineMatcher##Matcher \
0099 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
0100 public: \
0101 explicit matcher_##DefineMatcher##Matcher() = default; \
0102 bool matches(const Type &Node, \
0103 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0104 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0105 *Builder) const override; \
0106 }; \
0107 } \
0108 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher() { \
0109 return ::clang::ast_matchers::internal::makeMatcher( \
0110 new internal::matcher_##DefineMatcher##Matcher()); \
0111 } \
0112 inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
0113 const Type &Node, \
0114 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0115 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 #define AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) \
0131 AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, 0)
0132
0133 #define AST_MATCHER_P_OVERLOAD(Type, DefineMatcher, ParamType, Param, \
0134 OverloadId) \
0135 namespace internal { \
0136 class matcher_##DefineMatcher##OverloadId##Matcher \
0137 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
0138 public: \
0139 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
0140 ParamType const &A##Param) \
0141 : Param(A##Param) {} \
0142 bool matches(const Type &Node, \
0143 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0144 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0145 *Builder) const override; \
0146 \
0147 private: \
0148 ParamType Param; \
0149 }; \
0150 } \
0151 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
0152 ParamType const &Param) { \
0153 return ::clang::ast_matchers::internal::makeMatcher( \
0154 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param)); \
0155 } \
0156 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
0157 &DefineMatcher##_Type##OverloadId)(ParamType const &Param); \
0158 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
0159 const Type &Node, \
0160 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0161 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 #define AST_MATCHER_P2(Type, DefineMatcher, ParamType1, Param1, ParamType2, \
0178 Param2) \
0179 AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, ParamType2, \
0180 Param2, 0)
0181
0182 #define AST_MATCHER_P2_OVERLOAD(Type, DefineMatcher, ParamType1, Param1, \
0183 ParamType2, Param2, OverloadId) \
0184 namespace internal { \
0185 class matcher_##DefineMatcher##OverloadId##Matcher \
0186 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
0187 public: \
0188 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \
0189 ParamType2 const &A##Param2) \
0190 : Param1(A##Param1), Param2(A##Param2) {} \
0191 bool matches(const Type &Node, \
0192 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0193 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0194 *Builder) const override; \
0195 \
0196 private: \
0197 ParamType1 Param1; \
0198 ParamType2 Param2; \
0199 }; \
0200 } \
0201 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
0202 ParamType1 const &Param1, ParamType2 const &Param2) { \
0203 return ::clang::ast_matchers::internal::makeMatcher( \
0204 new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1, \
0205 Param2)); \
0206 } \
0207 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
0208 &DefineMatcher##_Type##OverloadId)(ParamType1 const &Param1, \
0209 ParamType2 const &Param2); \
0210 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
0211 const Type &Node, \
0212 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0213 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 #define AST_POLYMORPHIC_SUPPORTED_TYPES(...) \
0224 void(::clang::ast_matchers::internal::TypeList<__VA_ARGS__>)
0225
0226
0227
0228
0229
0230
0231
0232 #define AST_POLYMORPHIC_MATCHER(DefineMatcher, ReturnTypesF) \
0233 namespace internal { \
0234 template <typename NodeType> \
0235 class matcher_##DefineMatcher##Matcher \
0236 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
0237 public: \
0238 bool matches(const NodeType &Node, \
0239 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0240 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0241 *Builder) const override; \
0242 }; \
0243 } \
0244 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
0245 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF> \
0246 DefineMatcher() { \
0247 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
0248 internal::matcher_##DefineMatcher##Matcher, ReturnTypesF>(); \
0249 } \
0250 template <typename NodeType> \
0251 bool internal::matcher_##DefineMatcher##Matcher<NodeType>::matches( \
0252 const NodeType &Node, \
0253 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0254 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 #define AST_POLYMORPHIC_MATCHER_P(DefineMatcher, ReturnTypesF, ParamType, \
0266 Param) \
0267 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType, \
0268 Param, 0)
0269
0270 #define AST_POLYMORPHIC_MATCHER_P_OVERLOAD(DefineMatcher, ReturnTypesF, \
0271 ParamType, Param, OverloadId) \
0272 namespace internal { \
0273 template <typename NodeType, typename ParamT> \
0274 class matcher_##DefineMatcher##OverloadId##Matcher \
0275 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
0276 public: \
0277 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
0278 ParamType const &A##Param) \
0279 : Param(A##Param) {} \
0280 bool matches(const NodeType &Node, \
0281 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0282 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0283 *Builder) const override; \
0284 \
0285 private: \
0286 ParamType Param; \
0287 }; \
0288 } \
0289 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
0290 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0291 ParamType> \
0292 DefineMatcher(ParamType const &Param) { \
0293 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
0294 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0295 ParamType>(Param); \
0296 } \
0297 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
0298 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0299 ParamType> (&DefineMatcher##_Type##OverloadId)(ParamType const &Param); \
0300 template <typename NodeType, typename ParamT> \
0301 bool internal:: \
0302 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
0303 const NodeType &Node, \
0304 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0305 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
0306 const
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316 #define AST_POLYMORPHIC_MATCHER_P2(DefineMatcher, ReturnTypesF, ParamType1, \
0317 Param1, ParamType2, Param2) \
0318 AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, ParamType1, \
0319 Param1, ParamType2, Param2, 0)
0320
0321 #define AST_POLYMORPHIC_MATCHER_P2_OVERLOAD(DefineMatcher, ReturnTypesF, \
0322 ParamType1, Param1, ParamType2, \
0323 Param2, OverloadId) \
0324 namespace internal { \
0325 template <typename NodeType, typename ParamT1, typename ParamT2> \
0326 class matcher_##DefineMatcher##OverloadId##Matcher \
0327 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
0328 public: \
0329 matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1, \
0330 ParamType2 const &A##Param2) \
0331 : Param1(A##Param1), Param2(A##Param2) {} \
0332 bool matches(const NodeType &Node, \
0333 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0334 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0335 *Builder) const override; \
0336 \
0337 private: \
0338 ParamType1 Param1; \
0339 ParamType2 Param2; \
0340 }; \
0341 } \
0342 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
0343 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0344 ParamType1, ParamType2> \
0345 DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) { \
0346 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
0347 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0348 ParamType1, ParamType2>(Param1, Param2); \
0349 } \
0350 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
0351 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0352 ParamType1, ParamType2> (&DefineMatcher##_Type##OverloadId)( \
0353 ParamType1 const &Param1, ParamType2 const &Param2); \
0354 template <typename NodeType, typename ParamT1, typename ParamT2> \
0355 bool internal::matcher_##DefineMatcher##OverloadId##Matcher< \
0356 NodeType, ParamT1, ParamT2>:: \
0357 matches(const NodeType &Node, \
0358 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0359 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
0360 const
0361
0362
0363
0364
0365 #define AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \
0366 ReturnTypesF) \
0367 namespace internal { \
0368 template <typename T> struct TypeMatcher##MatcherName##Getter { \
0369 static QualType (T::*value())() const { return &T::FunctionName; } \
0370 }; \
0371 } \
0372 CLANG_ABI extern const ::clang::ast_matchers::internal:: \
0373 TypeTraversePolymorphicMatcher< \
0374 QualType, \
0375 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
0376 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
0377 ReturnTypesF>::Func MatcherName
0378
0379 #define AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \
0380 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
0381 QualType, \
0382 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
0383 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
0384 ReturnTypesF>::Func MatcherName
0385
0386
0387
0388
0389
0390
0391
0392
0393 #define AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \
0394 namespace internal { \
0395 template <typename T> struct TypeMatcher##MatcherName##Getter { \
0396 static QualType (T::*value())() const { return &T::FunctionName; } \
0397 }; \
0398 } \
0399 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
0400 QualType, \
0401 ::clang::ast_matchers::internal::TypeMatcher##MatcherName##Getter, \
0402 ::clang::ast_matchers::internal::TypeTraverseMatcher, \
0403 ReturnTypesF>::Func MatcherName
0404
0405 #define AST_TYPELOC_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName, \
0406 ReturnTypesF) \
0407 namespace internal { \
0408 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \
0409 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
0410 }; \
0411 } \
0412 CLANG_ABI extern const ::clang::ast_matchers::internal:: \
0413 TypeTraversePolymorphicMatcher< \
0414 TypeLoc, \
0415 ::clang::ast_matchers::internal:: \
0416 TypeLocMatcher##MatcherName##Getter, \
0417 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
0418 ReturnTypesF>::Func MatcherName##Loc; \
0419 AST_TYPE_TRAVERSE_MATCHER_DECL(MatcherName, FunctionName##Type, ReturnTypesF)
0420
0421 #define AST_TYPELOC_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF) \
0422 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
0423 TypeLoc, \
0424 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \
0425 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
0426 ReturnTypesF>::Func MatcherName##Loc; \
0427 AST_TYPE_TRAVERSE_MATCHER_DEF(MatcherName, ReturnTypesF)
0428
0429
0430
0431 #define AST_TYPELOC_TRAVERSE_MATCHER(MatcherName, FunctionName, ReturnTypesF) \
0432 namespace internal { \
0433 template <typename T> struct TypeLocMatcher##MatcherName##Getter { \
0434 static TypeLoc (T::*value())() const { return &T::FunctionName##Loc; } \
0435 }; \
0436 } \
0437 const ::clang::ast_matchers::internal::TypeTraversePolymorphicMatcher< \
0438 TypeLoc, \
0439 ::clang::ast_matchers::internal::TypeLocMatcher##MatcherName##Getter, \
0440 ::clang::ast_matchers::internal::TypeLocTraverseMatcher, \
0441 ReturnTypesF>::Func MatcherName##Loc; \
0442 AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName##Type, ReturnTypesF)
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457 #define AST_MATCHER_REGEX(Type, DefineMatcher, Param) \
0458 AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, 0)
0459
0460 #define AST_MATCHER_REGEX_OVERLOAD(Type, DefineMatcher, Param, OverloadId) \
0461 namespace internal { \
0462 class matcher_##DefineMatcher##OverloadId##Matcher \
0463 : public ::clang::ast_matchers::internal::MatcherInterface<Type> { \
0464 public: \
0465 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
0466 std::shared_ptr<llvm::Regex> RE) \
0467 : Param(std::move(RE)) {} \
0468 bool matches(const Type &Node, \
0469 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0470 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0471 *Builder) const override; \
0472 \
0473 private: \
0474 std::shared_ptr<llvm::Regex> Param; \
0475 }; \
0476 } \
0477 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
0478 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
0479 return ::clang::ast_matchers::internal::makeMatcher( \
0480 new internal::matcher_##DefineMatcher##OverloadId##Matcher( \
0481 ::clang::ast_matchers::internal::createAndVerifyRegex( \
0482 Param, RegexFlags, #DefineMatcher))); \
0483 } \
0484 inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
0485 llvm::StringRef Param) { \
0486 return DefineMatcher(Param, llvm::Regex::NoFlags); \
0487 } \
0488 \
0489 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
0490 &DefineMatcher##_Type##OverloadId##Flags)(llvm::StringRef, \
0491 llvm::Regex::RegexFlags); \
0492 typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
0493 &DefineMatcher##_Type##OverloadId)(llvm::StringRef); \
0494 inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
0495 const Type &Node, \
0496 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0497 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) const
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 #define AST_POLYMORPHIC_MATCHER_REGEX(DefineMatcher, ReturnTypesF, Param) \
0508 AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, Param, 0)
0509
0510 #define AST_POLYMORPHIC_MATCHER_REGEX_OVERLOAD(DefineMatcher, ReturnTypesF, \
0511 Param, OverloadId) \
0512 namespace internal { \
0513 template <typename NodeType, typename ParamT> \
0514 class matcher_##DefineMatcher##OverloadId##Matcher \
0515 : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> { \
0516 public: \
0517 explicit matcher_##DefineMatcher##OverloadId##Matcher( \
0518 std::shared_ptr<llvm::Regex> RE) \
0519 : Param(std::move(RE)) {} \
0520 bool matches(const NodeType &Node, \
0521 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0522 ::clang::ast_matchers::internal::BoundNodesTreeBuilder \
0523 *Builder) const override; \
0524 \
0525 private: \
0526 std::shared_ptr<llvm::Regex> Param; \
0527 }; \
0528 } \
0529 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
0530 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0531 std::shared_ptr<llvm::Regex>> \
0532 DefineMatcher(llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
0533 return ::clang::ast_matchers::internal::PolymorphicMatcher< \
0534 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0535 std::shared_ptr<llvm::Regex>>( \
0536 ::clang::ast_matchers::internal::createAndVerifyRegex( \
0537 Param, RegexFlags, #DefineMatcher)); \
0538 } \
0539 inline ::clang::ast_matchers::internal::PolymorphicMatcher< \
0540 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0541 std::shared_ptr<llvm::Regex>> \
0542 DefineMatcher(llvm::StringRef Param) { \
0543 return DefineMatcher(Param, llvm::Regex::NoFlags); \
0544 } \
0545 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
0546 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0547 std::shared_ptr<llvm::Regex>> ( \
0548 &DefineMatcher##_Type##OverloadId##Flags)( \
0549 llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags); \
0550 typedef ::clang::ast_matchers::internal::PolymorphicMatcher< \
0551 internal::matcher_##DefineMatcher##OverloadId##Matcher, ReturnTypesF, \
0552 std::shared_ptr<llvm::Regex>> (&DefineMatcher##_Type##OverloadId)( \
0553 llvm::StringRef Param); \
0554 template <typename NodeType, typename ParamT> \
0555 bool internal:: \
0556 matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
0557 const NodeType &Node, \
0558 ::clang::ast_matchers::internal::ASTMatchFinder *Finder, \
0559 ::clang::ast_matchers::internal::BoundNodesTreeBuilder *Builder) \
0560 const
0561
0562 #endif