Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:48

0001 //===--- ASTMatchersMacros.h - Structural query framework -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  Defines macros that enable us to define new matchers in a single place.
0010 //  Since a matcher is a function which returns a Matcher<T> object, where
0011 //  T is the type of the actual implementation of the matcher, the macros allow
0012 //  us to write matchers like functions and take care of the definition of the
0013 //  class boilerplate.
0014 //
0015 //  Note that when you define a matcher with an AST_MATCHER* macro, only the
0016 //  function which creates the matcher goes into the current namespace - the
0017 //  class that implements the actual matcher, which gets returned by the
0018 //  generator function, is put into the 'internal' namespace. This allows us
0019 //  to only have the functions (which is all the user cares about) in the
0020 //  'ast_matchers' namespace and hide the boilerplate.
0021 //
0022 //  To define a matcher in user code, put it into your own namespace. This would
0023 //  help to prevent ODR violations in case a matcher with the same name is
0024 //  defined in multiple translation units:
0025 //
0026 //  namespace my_matchers {
0027 //  AST_MATCHER_P(clang::MemberExpr, Member,
0028 //                clang::ast_matchers::internal::Matcher<clang::ValueDecl>,
0029 //                InnerMatcher) {
0030 //    return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder);
0031 //  }
0032 //  } // namespace my_matchers
0033 //
0034 //  Alternatively, an unnamed namespace may be used:
0035 //
0036 //  namespace clang {
0037 //  namespace ast_matchers {
0038 //  namespace {
0039 //  AST_MATCHER_P(MemberExpr, Member,
0040 //                internal::Matcher<ValueDecl>, InnerMatcher) {
0041 //    return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder);
0042 //  }
0043 //  } // namespace
0044 //  } // namespace ast_matchers
0045 //  } // namespace clang
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 /// AST_MATCHER_FUNCTION(ReturnType, DefineMatcher) { ... }
0055 /// defines a zero parameter function named DefineMatcher() that returns a
0056 /// ReturnType object.
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 /// AST_MATCHER_FUNCTION_P(ReturnType, DefineMatcher, ParamType, Param) {
0066 /// ... }
0067 /// defines a single-parameter function named DefineMatcher() that returns a
0068 /// ReturnType object.
0069 ///
0070 /// The code between the curly braces has access to the following variables:
0071 ///
0072 ///   Param:                 the parameter passed to the function; its type
0073 ///                          is ParamType.
0074 ///
0075 /// The code should return an instance of ReturnType.
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 /// AST_MATCHER(Type, DefineMatcher) { ... }
0086 /// defines a zero parameter function named DefineMatcher() that returns a
0087 /// Matcher<Type> object.
0088 ///
0089 /// The code between the curly braces has access to the following variables:
0090 ///
0091 ///   Node:                  the AST node being matched; its type is Type.
0092 ///   Finder:                an ASTMatchFinder*.
0093 ///   Builder:               a BoundNodesTreeBuilder*.
0094 ///
0095 /// The code should return true if 'Node' matches.
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 /// AST_MATCHER_P(Type, DefineMatcher, ParamType, Param) { ... }
0118 /// defines a single-parameter function named DefineMatcher() that returns a
0119 /// Matcher<Type> object.
0120 ///
0121 /// The code between the curly braces has access to the following variables:
0122 ///
0123 ///   Node:                  the AST node being matched; its type is Type.
0124 ///   Param:                 the parameter passed to the function; its type
0125 ///                          is ParamType.
0126 ///   Finder:                an ASTMatchFinder*.
0127 ///   Builder:               a BoundNodesTreeBuilder*.
0128 ///
0129 /// The code should return true if 'Node' matches.
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 /// AST_MATCHER_P2(
0164 ///     Type, DefineMatcher, ParamType1, Param1, ParamType2, Param2) { ... }
0165 /// defines a two-parameter function named DefineMatcher() that returns a
0166 /// Matcher<Type> object.
0167 ///
0168 /// The code between the curly braces has access to the following variables:
0169 ///
0170 ///   Node:                  the AST node being matched; its type is Type.
0171 ///   Param1, Param2:        the parameters passed to the function; their types
0172 ///                          are ParamType1 and ParamType2.
0173 ///   Finder:                an ASTMatchFinder*.
0174 ///   Builder:               a BoundNodesTreeBuilder*.
0175 ///
0176 /// The code should return true if 'Node' matches.
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 /// Construct a type-list to be passed to the AST_POLYMORPHIC_MATCHER*
0216 ///   macros.
0217 ///
0218 /// You can't pass something like \c TypeList<Foo, Bar> to a macro, because it
0219 /// will look at that as two arguments. However, you can pass
0220 /// \c void(TypeList<Foo, Bar>), which works thanks to the parenthesis.
0221 /// The \c PolymorphicMatcherWithParam* classes will unpack the function type to
0222 /// extract the TypeList object.
0223 #define AST_POLYMORPHIC_SUPPORTED_TYPES(...)                                   \
0224   void(::clang::ast_matchers::internal::TypeList<__VA_ARGS__>)
0225 
0226 /// AST_POLYMORPHIC_MATCHER(DefineMatcher) { ... }
0227 /// defines a single-parameter function named DefineMatcher() that is
0228 /// polymorphic in the return type.
0229 ///
0230 /// The variables are the same as for AST_MATCHER, but NodeType will be deduced
0231 /// from the calling context.
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 /// AST_POLYMORPHIC_MATCHER_P(DefineMatcher, ParamType, Param) { ... }
0257 /// defines a single-parameter function named DefineMatcher() that is
0258 /// polymorphic in the return type.
0259 ///
0260 /// The variables are the same as for
0261 /// AST_MATCHER_P, with the addition of NodeType, which specifies the node type
0262 /// of the matcher Matcher<NodeType> returned by the function matcher().
0263 ///
0264 /// FIXME: Pull out common code with above macro?
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 /// AST_POLYMORPHIC_MATCHER_P2(
0309 ///     DefineMatcher, ParamType1, Param1, ParamType2, Param2) { ... }
0310 /// defines a two-parameter function named matcher() that is polymorphic in
0311 /// the return type.
0312 ///
0313 /// The variables are the same as for AST_MATCHER_P2, with the
0314 /// addition of NodeType, which specifies the node type of the matcher
0315 /// Matcher<NodeType> returned by the function DefineMatcher().
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 // FIXME: add a matcher for TypeLoc derived classes using its custom casting
0363 // API (no longer dyn_cast) if/when we need such matching
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 /// AST_TYPE_TRAVERSE_MATCHER(MatcherName, FunctionName) defines
0387 /// the matcher \c MatcherName that can be used to traverse from one \c Type
0388 /// to another.
0389 ///
0390 /// For a specific \c SpecificType, the traversal is done using
0391 /// \c SpecificType::FunctionName. The existence of such a function determines
0392 /// whether a corresponding matcher can be used on \c SpecificType.
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 /// AST_TYPELOC_TRAVERSE_MATCHER(MatcherName, FunctionName) works
0430 /// identical to \c AST_TYPE_TRAVERSE_MATCHER but operates on \c TypeLocs.
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 /// AST_MATCHER_REGEX(Type, DefineMatcher, Param) { ... }
0445 /// defines a function named DefineMatcher() that takes a regular expression
0446 /// string paramater and an optional RegexFlags parameter and returns a
0447 /// Matcher<Type> object.
0448 ///
0449 /// The code between the curly braces has access to the following variables:
0450 ///
0451 ///   Node:                  the AST node being matched; its type is Type.
0452 ///   Param:                 a pointer to an \ref llvm::Regex object
0453 ///   Finder:                an ASTMatchFinder*.
0454 ///   Builder:               a BoundNodesTreeBuilder*.
0455 ///
0456 /// The code should return true if 'Node' matches.
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 /// AST_POLYMORPHIC_MATCHER_REGEX(DefineMatcher, ReturnTypesF, Param) { ... }
0500 /// defines a function named DefineMatcher() that takes a regular expression
0501 /// string paramater and an optional RegexFlags parameter that is polymorphic in
0502 /// the return type.
0503 ///
0504 /// The variables are the same as for
0505 /// AST_MATCHER_REGEX, with the addition of NodeType, which specifies the node
0506 /// type of the matcher Matcher<NodeType> returned by the function matcher().
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 // LLVM_CLANG_ASTMATCHERS_ASTMATCHERSMACROS_H