ASTMatchersInternal.h revision c99a3ad8c2bf29da45a0c64b88d58bfbd2f78ef2
1//===--- ASTMatchersInternal.h - Structural query framework -----*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  Implements the base layer of the matcher framework.
11//
12//  Matchers are methods that return a Matcher<T> which provides a method
13//  Matches(...) which is a predicate on an AST node. The Matches method's
14//  parameters define the context of the match, which allows matchers to recurse
15//  or store the current node as bound to a specific string, so that it can be
16//  retrieved later.
17//
18//  In general, matchers have two parts:
19//  1. A function Matcher<T> MatcherName(<arguments>) which returns a Matcher<T>
20//     based on the arguments and optionally on template type deduction based
21//     on the arguments. Matcher<T>s form an implicit reverse hierarchy
22//     to clang's AST class hierarchy, meaning that you can use a Matcher<Base>
23//     everywhere a Matcher<Derived> is required.
24//  2. An implementation of a class derived from MatcherInterface<T>.
25//
26//  The matcher functions are defined in ASTMatchers.h. To make it possible
27//  to implement both the matcher function and the implementation of the matcher
28//  interface in one place, ASTMatcherMacros.h defines macros that allow
29//  implementing a matcher in a single place.
30//
31//  This file contains the base classes needed to construct the actual matchers.
32//
33//===----------------------------------------------------------------------===//
34
35#ifndef LLVM_CLANG_AST_MATCHERS_AST_MATCHERS_INTERNAL_H
36#define LLVM_CLANG_AST_MATCHERS_AST_MATCHERS_INTERNAL_H
37
38#include "clang/AST/Decl.h"
39#include "clang/AST/DeclCXX.h"
40#include "clang/AST/ExprCXX.h"
41#include "clang/AST/Stmt.h"
42#include "clang/AST/StmtCXX.h"
43#include "clang/AST/Type.h"
44#include "clang/ASTMatchers/ASTTypeTraits.h"
45#include "llvm/ADT/VariadicFunction.h"
46#include "llvm/Support/type_traits.h"
47#include <map>
48#include <string>
49#include <vector>
50
51namespace clang {
52namespace ast_matchers {
53
54/// FIXME: Move into the llvm support library.
55template <bool> struct CompileAssert {};
56#define TOOLING_COMPILE_ASSERT(Expr, Msg) \
57  typedef CompileAssert<(bool(Expr))> Msg[bool(Expr) ? 1 : -1]
58
59class BoundNodes;
60
61namespace internal {
62
63class BoundNodesTreeBuilder;
64/// \brief Internal version of BoundNodes. Holds all the bound nodes.
65class BoundNodesMap {
66public:
67  /// \brief Adds \c Node to the map with key \c ID.
68  ///
69  /// The node's base type should be in NodeBaseType or it will be unaccessible.
70  template <typename T>
71  void addNode(StringRef ID, const T* Node) {
72    NodeMap[ID] = ast_type_traits::DynTypedNode::create(*Node);
73  }
74  void addNode(StringRef ID, ast_type_traits::DynTypedNode Node) {
75    NodeMap[ID] = Node;
76  }
77
78  /// \brief Returns the AST node bound to \c ID.
79  ///
80  /// Returns NULL if there was no node bound to \c ID or if there is a node but
81  /// it cannot be converted to the specified type.
82  template <typename T>
83  const T *getNodeAs(StringRef ID) const {
84    IDToNodeMap::const_iterator It = NodeMap.find(ID);
85    if (It == NodeMap.end()) {
86      return NULL;
87    }
88    return It->second.get<T>();
89  }
90
91  /// \brief Copies all ID/Node pairs to BoundNodesTreeBuilder \c Builder.
92  void copyTo(BoundNodesTreeBuilder *Builder) const;
93
94  /// \brief Copies all ID/Node pairs to BoundNodesMap \c Other.
95  void copyTo(BoundNodesMap *Other) const;
96
97private:
98  /// \brief A map from IDs to the bound nodes.
99  typedef std::map<std::string, ast_type_traits::DynTypedNode> IDToNodeMap;
100
101  IDToNodeMap NodeMap;
102};
103
104/// \brief A tree of bound nodes in match results.
105///
106/// If a match can contain multiple matches on the same node with different
107/// matching subexpressions, BoundNodesTree contains a branch for each of
108/// those matching subexpressions.
109///
110/// BoundNodesTree's are created during the matching process; when a match
111/// is found, we iterate over the tree and create a BoundNodes object containing
112/// the union of all bound nodes on the path from the root to a each leaf.
113class BoundNodesTree {
114public:
115  /// \brief A visitor interface to visit all BoundNodes results for a
116  /// BoundNodesTree.
117  class Visitor {
118  public:
119    virtual ~Visitor() {}
120
121    /// \brief Called multiple times during a single call to VisitMatches(...).
122    ///
123    /// 'BoundNodesView' contains the bound nodes for a single match.
124    virtual void visitMatch(const BoundNodes& BoundNodesView) = 0;
125  };
126
127  BoundNodesTree();
128
129  /// \brief Create a BoundNodesTree from pre-filled maps of bindings.
130  BoundNodesTree(const BoundNodesMap& Bindings,
131                 const std::vector<BoundNodesTree> RecursiveBindings);
132
133  /// \brief Adds all bound nodes to \c Builder.
134  void copyTo(BoundNodesTreeBuilder* Builder) const;
135
136  /// \brief Visits all matches that this BoundNodesTree represents.
137  ///
138  /// The ownership of 'ResultVisitor' remains at the caller.
139  void visitMatches(Visitor* ResultVisitor);
140
141private:
142  void visitMatchesRecursively(
143      Visitor* ResultVistior,
144      BoundNodesMap *AggregatedBindings);
145
146  // FIXME: Find out whether we want to use different data structures here -
147  // first benchmarks indicate that it doesn't matter though.
148
149  BoundNodesMap Bindings;
150
151  std::vector<BoundNodesTree> RecursiveBindings;
152};
153
154/// \brief Creates BoundNodesTree objects.
155///
156/// The tree builder is used during the matching process to insert the bound
157/// nodes from the Id matcher.
158class BoundNodesTreeBuilder {
159public:
160  BoundNodesTreeBuilder();
161
162  /// \brief Add a binding from an id to a node.
163  template <typename T>
164  void setBinding(const std::string &Id, const T *Node) {
165    Bindings.addNode(Id, Node);
166  }
167  void setBinding(const std::string &Id, ast_type_traits::DynTypedNode Node) {
168    Bindings.addNode(Id, Node);
169  }
170
171  /// \brief Adds a branch in the tree.
172  void addMatch(const BoundNodesTree& Bindings);
173
174  /// \brief Returns a BoundNodes object containing all current bindings.
175  BoundNodesTree build() const;
176
177private:
178  BoundNodesTreeBuilder(const BoundNodesTreeBuilder &) LLVM_DELETED_FUNCTION;
179  void operator=(const BoundNodesTreeBuilder &) LLVM_DELETED_FUNCTION;
180
181  BoundNodesMap Bindings;
182
183  std::vector<BoundNodesTree> RecursiveBindings;
184};
185
186class ASTMatchFinder;
187
188/// \brief Generic interface for matchers on an AST node of type T.
189///
190/// Implement this if your matcher may need to inspect the children or
191/// descendants of the node or bind matched nodes to names. If you are
192/// writing a simple matcher that only inspects properties of the
193/// current node and doesn't care about its children or descendants,
194/// implement SingleNodeMatcherInterface instead.
195template <typename T>
196class MatcherInterface : public llvm::RefCountedBaseVPTR {
197public:
198  virtual ~MatcherInterface() {}
199
200  /// \brief Returns true if 'Node' can be matched.
201  ///
202  /// May bind 'Node' to an ID via 'Builder', or recurse into
203  /// the AST via 'Finder'.
204  virtual bool matches(const T &Node,
205                       ASTMatchFinder *Finder,
206                       BoundNodesTreeBuilder *Builder) const = 0;
207};
208
209/// \brief Interface for matchers that only evaluate properties on a single
210/// node.
211template <typename T>
212class SingleNodeMatcherInterface : public MatcherInterface<T> {
213public:
214  /// \brief Returns true if the matcher matches the provided node.
215  ///
216  /// A subclass must implement this instead of Matches().
217  virtual bool matchesNode(const T &Node) const = 0;
218
219private:
220  /// Implements MatcherInterface::Matches.
221  virtual bool matches(const T &Node,
222                       ASTMatchFinder * /* Finder */,
223                       BoundNodesTreeBuilder * /*  Builder */) const {
224    return matchesNode(Node);
225  }
226};
227
228/// \brief Base class for all matchers that works on a \c DynTypedNode.
229///
230/// Matcher implementations will check whether the \c DynTypedNode is
231/// convertible into the respecitve types and then do the actual match
232/// on the actual node, or return false if it is not convertible.
233class DynTypedMatcher {
234public:
235  virtual ~DynTypedMatcher() {}
236
237  /// \brief Returns true if the matcher matches the given \c DynNode.
238  virtual bool matches(const ast_type_traits::DynTypedNode DynNode,
239                       ASTMatchFinder *Finder,
240                       BoundNodesTreeBuilder *Builder) const = 0;
241
242  /// \brief Returns a unique ID for the matcher.
243  virtual uint64_t getID() const = 0;
244};
245
246/// \brief Wrapper of a MatcherInterface<T> *that allows copying.
247///
248/// A Matcher<Base> can be used anywhere a Matcher<Derived> is
249/// required. This establishes an is-a relationship which is reverse
250/// to the AST hierarchy. In other words, Matcher<T> is contravariant
251/// with respect to T. The relationship is built via a type conversion
252/// operator rather than a type hierarchy to be able to templatize the
253/// type hierarchy instead of spelling it out.
254template <typename T>
255class Matcher : public DynTypedMatcher {
256public:
257  /// \brief Takes ownership of the provided implementation pointer.
258  explicit Matcher(MatcherInterface<T> *Implementation)
259      : Implementation(Implementation) {}
260
261  /// \brief Implicitly converts \c Other to a Matcher<T>.
262  ///
263  /// Requires \c T to be derived from \c From.
264  template <typename From>
265  Matcher(const Matcher<From> &Other,
266          typename llvm::enable_if_c<
267            llvm::is_base_of<From, T>::value &&
268            !llvm::is_same<From, T>::value >::type* = 0)
269      : Implementation(new ImplicitCastMatcher<From>(Other)) {}
270
271  /// \brief Implicitly converts \c Matcher<Type> to \c Matcher<QualType>.
272  ///
273  /// The resulting matcher is not strict, i.e. ignores qualifiers.
274  template <typename TypeT>
275  Matcher(const Matcher<TypeT> &Other,
276          typename llvm::enable_if_c<
277            llvm::is_same<T, QualType>::value &&
278            llvm::is_same<TypeT, Type>::value >::type* = 0)
279      : Implementation(new TypeToQualType<TypeT>(Other)) {}
280
281  /// \brief Forwards the call to the underlying MatcherInterface<T> pointer.
282  bool matches(const T &Node,
283               ASTMatchFinder *Finder,
284               BoundNodesTreeBuilder *Builder) const {
285    return Implementation->matches(Node, Finder, Builder);
286  }
287
288  /// \brief Returns an ID that uniquely identifies the matcher.
289  uint64_t getID() const {
290    /// FIXME: Document the requirements this imposes on matcher
291    /// implementations (no new() implementation_ during a Matches()).
292    return reinterpret_cast<uint64_t>(Implementation.getPtr());
293  }
294
295  /// \brief Returns whether the matcher matches on the given \c DynNode.
296  virtual bool matches(const ast_type_traits::DynTypedNode DynNode,
297                       ASTMatchFinder *Finder,
298                       BoundNodesTreeBuilder *Builder) const {
299    const T *Node = DynNode.get<T>();
300    if (!Node) return false;
301    return matches(*Node, Finder, Builder);
302  }
303
304  /// \brief Allows the conversion of a \c Matcher<Type> to a \c
305  /// Matcher<QualType>.
306  ///
307  /// Depending on the constructor argument, the matcher is either strict, i.e.
308  /// does only matches in the absence of qualifiers, or not, i.e. simply
309  /// ignores any qualifiers.
310  template <typename TypeT>
311  class TypeToQualType : public MatcherInterface<QualType> {
312   public:
313    TypeToQualType(const Matcher<TypeT> &InnerMatcher)
314        : InnerMatcher(InnerMatcher) {}
315
316    virtual bool matches(const QualType &Node,
317                         ASTMatchFinder *Finder,
318                         BoundNodesTreeBuilder *Builder) const {
319      if (Node.isNull())
320        return false;
321      return InnerMatcher.matches(*Node, Finder, Builder);
322    }
323   private:
324    const Matcher<TypeT> InnerMatcher;
325  };
326
327private:
328  /// \brief Allows conversion from Matcher<Base> to Matcher<T> if T
329  /// is derived from Base.
330  template <typename Base>
331  class ImplicitCastMatcher : public MatcherInterface<T> {
332  public:
333    explicit ImplicitCastMatcher(const Matcher<Base> &From)
334        : From(From) {}
335
336    virtual bool matches(const T &Node,
337                         ASTMatchFinder *Finder,
338                         BoundNodesTreeBuilder *Builder) const {
339      return From.matches(Node, Finder, Builder);
340    }
341
342  private:
343    const Matcher<Base> From;
344  };
345
346  llvm::IntrusiveRefCntPtr< MatcherInterface<T> > Implementation;
347};  // class Matcher
348
349/// \brief A convenient helper for creating a Matcher<T> without specifying
350/// the template type argument.
351template <typename T>
352inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) {
353  return Matcher<T>(Implementation);
354}
355
356/// \brief Matches declarations for QualType and CallExpr.
357///
358/// Type argument DeclMatcherT is required by PolymorphicMatcherWithParam1 but
359/// not actually used.
360template <typename T, typename DeclMatcherT>
361class HasDeclarationMatcher : public MatcherInterface<T> {
362  TOOLING_COMPILE_ASSERT((llvm::is_same< DeclMatcherT,
363                                         Matcher<Decl> >::value),
364                          instantiated_with_wrong_types);
365public:
366  explicit HasDeclarationMatcher(const Matcher<Decl> &InnerMatcher)
367      : InnerMatcher(InnerMatcher) {}
368
369  virtual bool matches(const T &Node,
370                       ASTMatchFinder *Finder,
371                       BoundNodesTreeBuilder *Builder) const {
372    return matchesSpecialized(Node, Finder, Builder);
373  }
374
375private:
376  /// \brief Extracts the CXXRecordDecl of a QualType and returns whether the
377  /// inner matcher matches on it.
378  bool matchesSpecialized(const QualType &Node, ASTMatchFinder *Finder,
379                          BoundNodesTreeBuilder *Builder) const {
380    /// FIXME: Add other ways to convert...
381    if (Node.isNull())
382      return false;
383    CXXRecordDecl *NodeAsRecordDecl = Node->getAsCXXRecordDecl();
384    return NodeAsRecordDecl != NULL &&
385      InnerMatcher.matches(*NodeAsRecordDecl, Finder, Builder);
386  }
387
388  /// \brief Extracts the Decl of the callee of a CallExpr and returns whether
389  /// the inner matcher matches on it.
390  bool matchesSpecialized(const CallExpr &Node, ASTMatchFinder *Finder,
391                          BoundNodesTreeBuilder *Builder) const {
392    const Decl *NodeAsDecl = Node.getCalleeDecl();
393    return NodeAsDecl != NULL &&
394      InnerMatcher.matches(*NodeAsDecl, Finder, Builder);
395  }
396
397  /// \brief Extracts the Decl of the constructor call and returns whether the
398  /// inner matcher matches on it.
399  bool matchesSpecialized(const CXXConstructExpr &Node,
400                          ASTMatchFinder *Finder,
401                          BoundNodesTreeBuilder *Builder) const {
402    const Decl *NodeAsDecl = Node.getConstructor();
403    return NodeAsDecl != NULL &&
404      InnerMatcher.matches(*NodeAsDecl, Finder, Builder);
405  }
406
407  const Matcher<Decl> InnerMatcher;
408};
409
410/// \brief IsBaseType<T>::value is true if T is a "base" type in the AST
411/// node class hierarchies (i.e. if T is Decl, Stmt, QualType, or
412/// CXXCtorInitializer).
413template <typename T>
414struct IsBaseType {
415  static const bool value =
416      (llvm::is_same<T, Decl>::value ||
417       llvm::is_same<T, Stmt>::value ||
418       llvm::is_same<T, QualType>::value ||
419       llvm::is_same<T, NestedNameSpecifier>::value ||
420       llvm::is_same<T, NestedNameSpecifierLoc>::value ||
421       llvm::is_same<T, CXXCtorInitializer>::value);
422};
423template <typename T>
424const bool IsBaseType<T>::value;
425
426/// \brief Interface that allows matchers to traverse the AST.
427/// FIXME: Find a better name.
428///
429/// This provides three entry methods for each base node type in the AST:
430/// - \c matchesChildOf:
431///   Matches a matcher on every child node of the given node. Returns true
432///   if at least one child node could be matched.
433/// - \c matchesDescendantOf:
434///   Matches a matcher on all descendant nodes of the given node. Returns true
435///   if at least one descendant matched.
436/// - \c matchesAncestorOf:
437///   Matches a matcher on all ancestors of the given node. Returns true if
438///   at least one ancestor matched.
439///
440/// FIXME: Currently we only allow Stmt and Decl nodes to start a traversal.
441/// In the future, we wan to implement this for all nodes for which it makes
442/// sense. In the case of matchesAncestorOf, we'll want to implement it for
443/// all nodes, as all nodes have ancestors.
444class ASTMatchFinder {
445public:
446  /// \brief Defines how we descend a level in the AST when we pass
447  /// through expressions.
448  enum TraversalKind {
449    /// Will traverse any child nodes.
450    TK_AsIs,
451    /// Will not traverse implicit casts and parentheses.
452    TK_IgnoreImplicitCastsAndParentheses
453  };
454
455  /// \brief Defines how bindings are processed on recursive matches.
456  enum BindKind {
457    /// Stop at the first match and only bind the first match.
458    BK_First,
459    /// Create results for all combinations of bindings that match.
460    BK_All
461  };
462
463  /// \brief Defines which ancestors are considered for a match.
464  enum AncestorMatchMode {
465    /// All ancestors.
466    AMM_All,
467    /// Direct parent only.
468    AMM_ParentOnly
469  };
470
471  virtual ~ASTMatchFinder() {}
472
473  /// \brief Returns true if the given class is directly or indirectly derived
474  /// from a base type matching \c base.
475  ///
476  /// A class is considered to be also derived from itself.
477  virtual bool classIsDerivedFrom(const CXXRecordDecl *Declaration,
478                                  const Matcher<NamedDecl> &Base,
479                                  BoundNodesTreeBuilder *Builder) = 0;
480
481  template <typename T>
482  bool matchesChildOf(const T &Node,
483                      const DynTypedMatcher &Matcher,
484                      BoundNodesTreeBuilder *Builder,
485                      TraversalKind Traverse,
486                      BindKind Bind) {
487    TOOLING_COMPILE_ASSERT((llvm::is_base_of<Decl, T>::value ||
488                            llvm::is_base_of<Stmt, T>::value),
489                           only_Decl_or_Stmt_allowed_for_recursive_matching);
490    return matchesChildOf(ast_type_traits::DynTypedNode::create(Node),
491                          Matcher, Builder, Traverse, Bind);
492  }
493
494  template <typename T>
495  bool matchesDescendantOf(const T &Node,
496                           const DynTypedMatcher &Matcher,
497                           BoundNodesTreeBuilder *Builder,
498                           BindKind Bind) {
499    TOOLING_COMPILE_ASSERT((llvm::is_base_of<Decl, T>::value ||
500                            llvm::is_base_of<Stmt, T>::value),
501                           only_Decl_or_Stmt_allowed_for_recursive_matching);
502    return matchesDescendantOf(ast_type_traits::DynTypedNode::create(Node),
503                               Matcher, Builder, Bind);
504  }
505
506  // FIXME: Implement support for BindKind.
507  template <typename T>
508  bool matchesAncestorOf(const T &Node,
509                         const DynTypedMatcher &Matcher,
510                         BoundNodesTreeBuilder *Builder,
511                         AncestorMatchMode MatchMode) {
512    TOOLING_COMPILE_ASSERT((llvm::is_base_of<Decl, T>::value ||
513                            llvm::is_base_of<Stmt, T>::value),
514                           only_Decl_or_Stmt_allowed_for_recursive_matching);
515    return matchesAncestorOf(ast_type_traits::DynTypedNode::create(Node),
516                             Matcher, Builder, MatchMode);
517  }
518
519protected:
520  virtual bool matchesChildOf(const ast_type_traits::DynTypedNode &Node,
521                              const DynTypedMatcher &Matcher,
522                              BoundNodesTreeBuilder *Builder,
523                              TraversalKind Traverse,
524                              BindKind Bind) = 0;
525
526  virtual bool matchesDescendantOf(const ast_type_traits::DynTypedNode &Node,
527                                   const DynTypedMatcher &Matcher,
528                                   BoundNodesTreeBuilder *Builder,
529                                   BindKind Bind) = 0;
530
531  virtual bool matchesAncestorOf(const ast_type_traits::DynTypedNode &Node,
532                                 const DynTypedMatcher &Matcher,
533                                 BoundNodesTreeBuilder *Builder,
534                                 AncestorMatchMode MatchMode) = 0;
535};
536
537/// \brief Converts a \c Matcher<T> to a matcher of desired type \c To by
538/// "adapting" a \c To into a \c T.
539///
540/// The \c ArgumentAdapterT argument specifies how the adaptation is done.
541///
542/// For example:
543///   \c ArgumentAdaptingMatcher<HasMatcher, T>(InnerMatcher);
544/// Given that \c InnerMatcher is of type \c Matcher<T>, this returns a matcher
545/// that is convertible into any matcher of type \c To by constructing
546/// \c HasMatcher<To, T>(InnerMatcher).
547///
548/// If a matcher does not need knowledge about the inner type, prefer to use
549/// PolymorphicMatcherWithParam1.
550template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
551          typename T>
552class ArgumentAdaptingMatcher {
553public:
554  explicit ArgumentAdaptingMatcher(const Matcher<T> &InnerMatcher)
555      : InnerMatcher(InnerMatcher) {}
556
557  template <typename To>
558  operator Matcher<To>() const {
559    return Matcher<To>(new ArgumentAdapterT<To, T>(InnerMatcher));
560  }
561
562private:
563  const Matcher<T> InnerMatcher;
564};
565
566/// \brief A PolymorphicMatcherWithParamN<MatcherT, P1, ..., PN> object can be
567/// created from N parameters p1, ..., pN (of type P1, ..., PN) and
568/// used as a Matcher<T> where a MatcherT<T, P1, ..., PN>(p1, ..., pN)
569/// can be constructed.
570///
571/// For example:
572/// - PolymorphicMatcherWithParam0<IsDefinitionMatcher>()
573///   creates an object that can be used as a Matcher<T> for any type T
574///   where an IsDefinitionMatcher<T>() can be constructed.
575/// - PolymorphicMatcherWithParam1<ValueEqualsMatcher, int>(42)
576///   creates an object that can be used as a Matcher<T> for any type T
577///   where a ValueEqualsMatcher<T, int>(42) can be constructed.
578template <template <typename T> class MatcherT>
579class PolymorphicMatcherWithParam0 {
580public:
581  template <typename T>
582  operator Matcher<T>() const {
583    return Matcher<T>(new MatcherT<T>());
584  }
585};
586
587template <template <typename T, typename P1> class MatcherT,
588          typename P1>
589class PolymorphicMatcherWithParam1 {
590public:
591  explicit PolymorphicMatcherWithParam1(const P1 &Param1)
592      : Param1(Param1) {}
593
594  template <typename T>
595  operator Matcher<T>() const {
596    return Matcher<T>(new MatcherT<T, P1>(Param1));
597  }
598
599private:
600  const P1 Param1;
601};
602
603template <template <typename T, typename P1, typename P2> class MatcherT,
604          typename P1, typename P2>
605class PolymorphicMatcherWithParam2 {
606public:
607  PolymorphicMatcherWithParam2(const P1 &Param1, const P2 &Param2)
608      : Param1(Param1), Param2(Param2) {}
609
610  template <typename T>
611  operator Matcher<T>() const {
612    return Matcher<T>(new MatcherT<T, P1, P2>(Param1, Param2));
613  }
614
615private:
616  const P1 Param1;
617  const P2 Param2;
618};
619
620/// \brief Matches any instance of the given NodeType.
621///
622/// This is useful when a matcher syntactically requires a child matcher,
623/// but the context doesn't care. See for example: anything().
624///
625/// FIXME: Alternatively we could also create a IsAMatcher or something
626/// that checks that a dyn_cast is possible. This is purely needed for the
627/// difference between calling for example:
628///   record()
629/// and
630///   record(SomeMatcher)
631/// In the second case we need the correct type we were dyn_cast'ed to in order
632/// to get the right type for the inner matcher. In the first case we don't need
633/// that, but we use the type conversion anyway and insert a TrueMatcher.
634template <typename T>
635class TrueMatcher : public SingleNodeMatcherInterface<T>  {
636public:
637  virtual bool matchesNode(const T &Node) const {
638    return true;
639  }
640};
641
642/// \brief Provides a MatcherInterface<T> for a Matcher<To> that matches if T is
643/// dyn_cast'able into To and the given Matcher<To> matches on the dyn_cast'ed
644/// node.
645template <typename T, typename To>
646class DynCastMatcher : public MatcherInterface<T> {
647public:
648  explicit DynCastMatcher(const Matcher<To> &InnerMatcher)
649      : InnerMatcher(InnerMatcher) {}
650
651  virtual bool matches(const T &Node,
652                       ASTMatchFinder *Finder,
653                       BoundNodesTreeBuilder *Builder) const {
654    const To *InnerMatchValue = llvm::dyn_cast<To>(&Node);
655    return InnerMatchValue != NULL &&
656      InnerMatcher.matches(*InnerMatchValue, Finder, Builder);
657  }
658
659private:
660  const Matcher<To> InnerMatcher;
661};
662
663/// \brief Matcher<T> that wraps an inner Matcher<T> and binds the matched node
664/// to an ID if the inner matcher matches on the node.
665template <typename T>
666class IdMatcher : public MatcherInterface<T> {
667public:
668  /// \brief Creates an IdMatcher that binds to 'ID' if 'InnerMatcher' matches
669  /// the node.
670  IdMatcher(StringRef ID, const Matcher<T> &InnerMatcher)
671      : ID(ID), InnerMatcher(InnerMatcher) {}
672
673  virtual bool matches(const T &Node,
674                       ASTMatchFinder *Finder,
675                       BoundNodesTreeBuilder *Builder) const {
676    bool Result = InnerMatcher.matches(Node, Finder, Builder);
677    if (Result) {
678      Builder->setBinding(ID, &Node);
679    }
680    return Result;
681  }
682
683private:
684  const std::string ID;
685  const Matcher<T> InnerMatcher;
686};
687
688/// \brief A Matcher that allows binding the node it matches to an id.
689///
690/// BindableMatcher provides a \a bind() method that allows binding the
691/// matched node to an id if the match was successful.
692template <typename T>
693class BindableMatcher : public Matcher<T> {
694public:
695  BindableMatcher(MatcherInterface<T> *Implementation)
696    : Matcher<T>(Implementation) {}
697
698  /// \brief Returns a matcher that will bind the matched node on a match.
699  ///
700  /// The returned matcher is equivalent to this matcher, but will
701  /// bind the matched node on a match.
702  Matcher<T> bind(StringRef ID) const {
703    return Matcher<T>(new IdMatcher<T>(ID, *this));
704  }
705};
706
707/// \brief Matches nodes of type T that have child nodes of type ChildT for
708/// which a specified child matcher matches.
709///
710/// ChildT must be an AST base type.
711template <typename T, typename ChildT>
712class HasMatcher : public MatcherInterface<T> {
713  TOOLING_COMPILE_ASSERT(IsBaseType<ChildT>::value,
714                         has_only_accepts_base_type_matcher);
715public:
716  explicit HasMatcher(const Matcher<ChildT> &ChildMatcher)
717      : ChildMatcher(ChildMatcher) {}
718
719  virtual bool matches(const T &Node,
720                       ASTMatchFinder *Finder,
721                       BoundNodesTreeBuilder *Builder) const {
722    return Finder->matchesChildOf(
723        Node, ChildMatcher, Builder,
724        ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses,
725        ASTMatchFinder::BK_First);
726  }
727
728 private:
729  const Matcher<ChildT> ChildMatcher;
730};
731
732/// \brief Matches nodes of type T that have child nodes of type ChildT for
733/// which a specified child matcher matches. ChildT must be an AST base
734/// type.
735/// As opposed to the HasMatcher, the ForEachMatcher will produce a match
736/// for each child that matches.
737template <typename T, typename ChildT>
738class ForEachMatcher : public MatcherInterface<T> {
739  TOOLING_COMPILE_ASSERT(IsBaseType<ChildT>::value,
740                         for_each_only_accepts_base_type_matcher);
741 public:
742  explicit ForEachMatcher(const Matcher<ChildT> &ChildMatcher)
743      : ChildMatcher(ChildMatcher) {}
744
745  virtual bool matches(const T& Node,
746                       ASTMatchFinder* Finder,
747                       BoundNodesTreeBuilder* Builder) const {
748    return Finder->matchesChildOf(
749      Node, ChildMatcher, Builder,
750      ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses,
751      ASTMatchFinder::BK_All);
752  }
753
754private:
755  const Matcher<ChildT> ChildMatcher;
756};
757
758/// \brief Matches nodes of type T if the given Matcher<T> does not match.
759///
760/// Type argument MatcherT is required by PolymorphicMatcherWithParam1
761/// but not actually used. It will always be instantiated with a type
762/// convertible to Matcher<T>.
763template <typename T, typename MatcherT>
764class NotMatcher : public MatcherInterface<T> {
765public:
766  explicit NotMatcher(const Matcher<T> &InnerMatcher)
767      : InnerMatcher(InnerMatcher) {}
768
769  virtual bool matches(const T &Node,
770                       ASTMatchFinder *Finder,
771                       BoundNodesTreeBuilder *Builder) const {
772    return !InnerMatcher.matches(Node, Finder, Builder);
773  }
774
775private:
776  const Matcher<T> InnerMatcher;
777};
778
779/// \brief Matches nodes of type T for which both provided matchers match.
780///
781/// Type arguments MatcherT1 and MatcherT2 are required by
782/// PolymorphicMatcherWithParam2 but not actually used. They will
783/// always be instantiated with types convertible to Matcher<T>.
784template <typename T, typename MatcherT1, typename MatcherT2>
785class AllOfMatcher : public MatcherInterface<T> {
786public:
787  AllOfMatcher(const Matcher<T> &InnerMatcher1, const Matcher<T> &InnerMatcher2)
788      : InnerMatcher1(InnerMatcher1), InnerMatcher2(InnerMatcher2) {}
789
790  virtual bool matches(const T &Node,
791                       ASTMatchFinder *Finder,
792                       BoundNodesTreeBuilder *Builder) const {
793    return InnerMatcher1.matches(Node, Finder, Builder) &&
794           InnerMatcher2.matches(Node, Finder, Builder);
795  }
796
797private:
798  const Matcher<T> InnerMatcher1;
799  const Matcher<T> InnerMatcher2;
800};
801
802/// \brief Matches nodes of type T for which at least one of the two provided
803/// matchers matches.
804///
805/// Type arguments MatcherT1 and MatcherT2 are
806/// required by PolymorphicMatcherWithParam2 but not actually
807/// used. They will always be instantiated with types convertible to
808/// Matcher<T>.
809template <typename T, typename MatcherT1, typename MatcherT2>
810class AnyOfMatcher : public MatcherInterface<T> {
811public:
812  AnyOfMatcher(const Matcher<T> &InnerMatcher1, const Matcher<T> &InnerMatcher2)
813      : InnerMatcher1(InnerMatcher1), InnertMatcher2(InnerMatcher2) {}
814
815  virtual bool matches(const T &Node,
816                       ASTMatchFinder *Finder,
817                       BoundNodesTreeBuilder *Builder) const {
818    return InnerMatcher1.matches(Node, Finder, Builder) ||
819           InnertMatcher2.matches(Node, Finder, Builder);
820  }
821
822private:
823  const Matcher<T> InnerMatcher1;
824  const Matcher<T> InnertMatcher2;
825};
826
827/// \brief Creates a Matcher<T> that matches if all inner matchers match.
828template<typename T>
829BindableMatcher<T> makeAllOfComposite(
830    ArrayRef<const Matcher<T> *> InnerMatchers) {
831  if (InnerMatchers.empty())
832    return BindableMatcher<T>(new TrueMatcher<T>);
833  MatcherInterface<T> *InnerMatcher = new TrueMatcher<T>;
834  for (int i = InnerMatchers.size() - 1; i >= 0; --i) {
835    InnerMatcher = new AllOfMatcher<T, Matcher<T>, Matcher<T> >(
836      *InnerMatchers[i], makeMatcher(InnerMatcher));
837  }
838  return BindableMatcher<T>(InnerMatcher);
839}
840
841/// \brief Creates a Matcher<T> that matches if
842/// T is dyn_cast'able into InnerT and all inner matchers match.
843///
844/// Returns BindableMatcher, as matchers that use dyn_cast have
845/// the same object both to match on and to run submatchers on,
846/// so there is no ambiguity with what gets bound.
847template<typename T, typename InnerT>
848BindableMatcher<T> makeDynCastAllOfComposite(
849    ArrayRef<const Matcher<InnerT> *> InnerMatchers) {
850  return BindableMatcher<T>(new DynCastMatcher<T, InnerT>(
851    makeAllOfComposite(InnerMatchers)));
852}
853
854/// \brief Matches nodes of type T that have at least one descendant node of
855/// type DescendantT for which the given inner matcher matches.
856///
857/// DescendantT must be an AST base type.
858template <typename T, typename DescendantT>
859class HasDescendantMatcher : public MatcherInterface<T> {
860  TOOLING_COMPILE_ASSERT(IsBaseType<DescendantT>::value,
861                         has_descendant_only_accepts_base_type_matcher);
862public:
863  explicit HasDescendantMatcher(const Matcher<DescendantT> &DescendantMatcher)
864      : DescendantMatcher(DescendantMatcher) {}
865
866  virtual bool matches(const T &Node,
867                       ASTMatchFinder *Finder,
868                       BoundNodesTreeBuilder *Builder) const {
869    return Finder->matchesDescendantOf(
870        Node, DescendantMatcher, Builder, ASTMatchFinder::BK_First);
871  }
872
873 private:
874  const Matcher<DescendantT> DescendantMatcher;
875};
876
877/// \brief Matches nodes of type \c T that have a parent node of type \c ParentT
878/// for which the given inner matcher matches.
879///
880/// \c ParentT must be an AST base type.
881template <typename T, typename ParentT>
882class HasParentMatcher : public MatcherInterface<T> {
883  TOOLING_COMPILE_ASSERT(IsBaseType<ParentT>::value,
884                         has_parent_only_accepts_base_type_matcher);
885public:
886  explicit HasParentMatcher(const Matcher<ParentT> &ParentMatcher)
887      : ParentMatcher(ParentMatcher) {}
888
889  virtual bool matches(const T &Node,
890                       ASTMatchFinder *Finder,
891                       BoundNodesTreeBuilder *Builder) const {
892    return Finder->matchesAncestorOf(
893        Node, ParentMatcher, Builder, ASTMatchFinder::AMM_ParentOnly);
894  }
895
896 private:
897  const Matcher<ParentT> ParentMatcher;
898};
899
900/// \brief Matches nodes of type \c T that have at least one ancestor node of
901/// type \c AncestorT for which the given inner matcher matches.
902///
903/// \c AncestorT must be an AST base type.
904template <typename T, typename AncestorT>
905class HasAncestorMatcher : public MatcherInterface<T> {
906  TOOLING_COMPILE_ASSERT(IsBaseType<AncestorT>::value,
907                         has_ancestor_only_accepts_base_type_matcher);
908public:
909  explicit HasAncestorMatcher(const Matcher<AncestorT> &AncestorMatcher)
910      : AncestorMatcher(AncestorMatcher) {}
911
912  virtual bool matches(const T &Node,
913                       ASTMatchFinder *Finder,
914                       BoundNodesTreeBuilder *Builder) const {
915    return Finder->matchesAncestorOf(
916        Node, AncestorMatcher, Builder, ASTMatchFinder::AMM_All);
917  }
918
919 private:
920  const Matcher<AncestorT> AncestorMatcher;
921};
922
923/// \brief Matches nodes of type T that have at least one descendant node of
924/// type DescendantT for which the given inner matcher matches.
925///
926/// DescendantT must be an AST base type.
927/// As opposed to HasDescendantMatcher, ForEachDescendantMatcher will match
928/// for each descendant node that matches instead of only for the first.
929template <typename T, typename DescendantT>
930class ForEachDescendantMatcher : public MatcherInterface<T> {
931  TOOLING_COMPILE_ASSERT(IsBaseType<DescendantT>::value,
932                         for_each_descendant_only_accepts_base_type_matcher);
933 public:
934  explicit ForEachDescendantMatcher(
935      const Matcher<DescendantT>& DescendantMatcher)
936      : DescendantMatcher(DescendantMatcher) {}
937
938  virtual bool matches(const T& Node,
939                       ASTMatchFinder* Finder,
940                       BoundNodesTreeBuilder* Builder) const {
941    return Finder->matchesDescendantOf(Node, DescendantMatcher, Builder,
942                                       ASTMatchFinder::BK_All);
943  }
944
945private:
946  const Matcher<DescendantT> DescendantMatcher;
947};
948
949/// \brief Matches on nodes that have a getValue() method if getValue() equals
950/// the value the ValueEqualsMatcher was constructed with.
951template <typename T, typename ValueT>
952class ValueEqualsMatcher : public SingleNodeMatcherInterface<T> {
953  TOOLING_COMPILE_ASSERT((llvm::is_base_of<CharacterLiteral, T>::value ||
954                         llvm::is_base_of<CXXBoolLiteralExpr,
955                                          T>::value ||
956                         llvm::is_base_of<FloatingLiteral, T>::value ||
957                         llvm::is_base_of<IntegerLiteral, T>::value),
958                         the_node_must_have_a_getValue_method);
959public:
960  explicit ValueEqualsMatcher(const ValueT &ExpectedValue)
961      : ExpectedValue(ExpectedValue) {}
962
963  virtual bool matchesNode(const T &Node) const {
964    return Node.getValue() == ExpectedValue;
965  }
966
967private:
968  const ValueT ExpectedValue;
969};
970
971template <typename T>
972class IsDefinitionMatcher : public SingleNodeMatcherInterface<T> {
973  TOOLING_COMPILE_ASSERT(
974    (llvm::is_base_of<TagDecl, T>::value) ||
975    (llvm::is_base_of<VarDecl, T>::value) ||
976    (llvm::is_base_of<FunctionDecl, T>::value),
977    is_definition_requires_isThisDeclarationADefinition_method);
978public:
979  virtual bool matchesNode(const T &Node) const {
980    return Node.isThisDeclarationADefinition();
981  }
982};
983
984/// \brief Matches on template instantiations for FunctionDecl, VarDecl or
985/// CXXRecordDecl nodes.
986template <typename T>
987class IsTemplateInstantiationMatcher : public MatcherInterface<T> {
988  TOOLING_COMPILE_ASSERT((llvm::is_base_of<FunctionDecl, T>::value) ||
989                         (llvm::is_base_of<VarDecl, T>::value) ||
990                         (llvm::is_base_of<CXXRecordDecl, T>::value),
991                         requires_getTemplateSpecializationKind_method);
992 public:
993  virtual bool matches(const T& Node,
994                       ASTMatchFinder* Finder,
995                       BoundNodesTreeBuilder* Builder) const {
996    return (Node.getTemplateSpecializationKind() ==
997                TSK_ImplicitInstantiation ||
998            Node.getTemplateSpecializationKind() ==
999                TSK_ExplicitInstantiationDefinition);
1000  }
1001};
1002
1003/// \brief Matches on explicit template specializations for FunctionDecl,
1004/// VarDecl or CXXRecordDecl nodes.
1005template <typename T>
1006class IsExplicitTemplateSpecializationMatcher : public MatcherInterface<T> {
1007  TOOLING_COMPILE_ASSERT((llvm::is_base_of<FunctionDecl, T>::value) ||
1008                         (llvm::is_base_of<VarDecl, T>::value) ||
1009                         (llvm::is_base_of<CXXRecordDecl, T>::value),
1010                         requires_getTemplateSpecializationKind_method);
1011 public:
1012  virtual bool matches(const T& Node,
1013                       ASTMatchFinder* Finder,
1014                       BoundNodesTreeBuilder* Builder) const {
1015    return (Node.getTemplateSpecializationKind() == TSK_ExplicitSpecialization);
1016  }
1017};
1018
1019class IsArrowMatcher : public SingleNodeMatcherInterface<MemberExpr> {
1020public:
1021  virtual bool matchesNode(const MemberExpr &Node) const {
1022    return Node.isArrow();
1023  }
1024};
1025
1026class IsConstQualifiedMatcher
1027    : public SingleNodeMatcherInterface<QualType> {
1028 public:
1029  virtual bool matchesNode(const QualType& Node) const {
1030    return Node.isConstQualified();
1031  }
1032};
1033
1034/// \brief A VariadicDynCastAllOfMatcher<SourceT, TargetT> object is a
1035/// variadic functor that takes a number of Matcher<TargetT> and returns a
1036/// Matcher<SourceT> that matches TargetT nodes that are matched by all of the
1037/// given matchers, if SourceT can be dynamically casted into TargetT.
1038///
1039/// For example:
1040///   const VariadicDynCastAllOfMatcher<
1041///       Decl, CXXRecordDecl> record;
1042/// Creates a functor record(...) that creates a Matcher<Decl> given
1043/// a variable number of arguments of type Matcher<CXXRecordDecl>.
1044/// The returned matcher matches if the given Decl can by dynamically
1045/// casted to CXXRecordDecl and all given matchers match.
1046template <typename SourceT, typename TargetT>
1047class VariadicDynCastAllOfMatcher
1048    : public llvm::VariadicFunction<
1049        BindableMatcher<SourceT>, Matcher<TargetT>,
1050        makeDynCastAllOfComposite<SourceT, TargetT> > {
1051public:
1052  VariadicDynCastAllOfMatcher() {}
1053};
1054
1055/// \brief A \c VariadicAllOfMatcher<T> object is a variadic functor that takes
1056/// a number of \c Matcher<T> and returns a \c Matcher<T> that matches \c T
1057/// nodes that are matched by all of the given matchers.
1058///
1059/// For example:
1060///   const VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier;
1061/// Creates a functor nestedNameSpecifier(...) that creates a
1062/// \c Matcher<NestedNameSpecifier> given a variable number of arguments of type
1063/// \c Matcher<NestedNameSpecifier>.
1064/// The returned matcher matches if all given matchers match.
1065template <typename T>
1066class VariadicAllOfMatcher : public llvm::VariadicFunction<
1067                               BindableMatcher<T>, Matcher<T>,
1068                               makeAllOfComposite<T> > {
1069public:
1070  VariadicAllOfMatcher() {}
1071};
1072
1073/// \brief Matches nodes of type \c TLoc for which the inner
1074/// \c Matcher<T> matches.
1075template <typename TLoc, typename T>
1076class LocMatcher : public MatcherInterface<TLoc> {
1077public:
1078  explicit LocMatcher(const Matcher<T> &InnerMatcher)
1079    : InnerMatcher(InnerMatcher) {}
1080
1081  virtual bool matches(const TLoc &Node,
1082                       ASTMatchFinder *Finder,
1083                       BoundNodesTreeBuilder *Builder) const {
1084    if (!Node)
1085      return false;
1086    return InnerMatcher.matches(*extract(Node), Finder, Builder);
1087  }
1088
1089private:
1090  const NestedNameSpecifier *extract(const NestedNameSpecifierLoc &Loc) const {
1091    return Loc.getNestedNameSpecifier();
1092  }
1093
1094  const Matcher<T> InnerMatcher;
1095};
1096
1097/// \brief Matches \c NestedNameSpecifiers with a prefix matching another
1098/// \c Matcher<NestedNameSpecifier>.
1099class NestedNameSpecifierPrefixMatcher
1100  : public MatcherInterface<NestedNameSpecifier> {
1101public:
1102  explicit NestedNameSpecifierPrefixMatcher(
1103    const Matcher<NestedNameSpecifier> &InnerMatcher)
1104    : InnerMatcher(InnerMatcher) {}
1105
1106  virtual bool matches(const NestedNameSpecifier &Node,
1107                       ASTMatchFinder *Finder,
1108                       BoundNodesTreeBuilder *Builder) const {
1109    NestedNameSpecifier *NextNode = Node.getPrefix();
1110    if (NextNode == NULL)
1111      return false;
1112    return InnerMatcher.matches(*NextNode, Finder, Builder);
1113  }
1114
1115private:
1116  const Matcher<NestedNameSpecifier> InnerMatcher;
1117};
1118
1119/// \brief Matches \c NestedNameSpecifierLocs with a prefix matching another
1120/// \c Matcher<NestedNameSpecifierLoc>.
1121class NestedNameSpecifierLocPrefixMatcher
1122  : public MatcherInterface<NestedNameSpecifierLoc> {
1123public:
1124  explicit NestedNameSpecifierLocPrefixMatcher(
1125    const Matcher<NestedNameSpecifierLoc> &InnerMatcher)
1126    : InnerMatcher(InnerMatcher) {}
1127
1128  virtual bool matches(const NestedNameSpecifierLoc &Node,
1129                       ASTMatchFinder *Finder,
1130                       BoundNodesTreeBuilder *Builder) const {
1131    NestedNameSpecifierLoc NextNode = Node.getPrefix();
1132    if (!NextNode)
1133      return false;
1134    return InnerMatcher.matches(NextNode, Finder, Builder);
1135  }
1136
1137private:
1138  const Matcher<NestedNameSpecifierLoc> InnerMatcher;
1139};
1140
1141/// \brief Matches \c TypeLocs based on an inner matcher matching a certain
1142/// \c QualType.
1143///
1144/// Used to implement the \c loc() matcher.
1145class TypeLocTypeMatcher : public MatcherInterface<TypeLoc> {
1146public:
1147  explicit TypeLocTypeMatcher(const Matcher<QualType> &InnerMatcher)
1148      : InnerMatcher(InnerMatcher) {}
1149
1150  virtual bool matches(const TypeLoc &Node,
1151                       ASTMatchFinder *Finder,
1152                       BoundNodesTreeBuilder *Builder) const {
1153    if (!Node)
1154      return false;
1155    return InnerMatcher.matches(Node.getType(), Finder, Builder);
1156  }
1157
1158private:
1159  const Matcher<QualType> InnerMatcher;
1160};
1161
1162/// \brief Matches nodes of type \c T for which the inner matcher matches on a
1163/// another node of type \c T that can be reached using a given traverse
1164/// function.
1165template <typename T>
1166class TypeTraverseMatcher : public MatcherInterface<T> {
1167public:
1168  explicit TypeTraverseMatcher(const Matcher<QualType> &InnerMatcher,
1169                               QualType (T::*TraverseFunction)() const)
1170      : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {}
1171
1172  virtual bool matches(const T &Node,
1173                       ASTMatchFinder *Finder,
1174                       BoundNodesTreeBuilder *Builder) const {
1175    QualType NextNode = (Node.*TraverseFunction)();
1176    if (NextNode.isNull())
1177      return false;
1178    return InnerMatcher.matches(NextNode, Finder, Builder);
1179  }
1180
1181private:
1182  const Matcher<QualType> InnerMatcher;
1183  QualType (T::*TraverseFunction)() const;
1184};
1185
1186/// \brief Matches nodes of type \c T in a ..Loc hierarchy, for which the inner
1187/// matcher matches on a another node of type \c T that can be reached using a
1188/// given traverse function.
1189template <typename T>
1190class TypeLocTraverseMatcher : public MatcherInterface<T> {
1191public:
1192  explicit TypeLocTraverseMatcher(const Matcher<TypeLoc> &InnerMatcher,
1193                                  TypeLoc (T::*TraverseFunction)() const)
1194      : InnerMatcher(InnerMatcher), TraverseFunction(TraverseFunction) {}
1195
1196  virtual bool matches(const T &Node,
1197                       ASTMatchFinder *Finder,
1198                       BoundNodesTreeBuilder *Builder) const {
1199    TypeLoc NextNode = (Node.*TraverseFunction)();
1200    if (!NextNode)
1201      return false;
1202    return InnerMatcher.matches(NextNode, Finder, Builder);
1203  }
1204
1205private:
1206  const Matcher<TypeLoc> InnerMatcher;
1207  TypeLoc (T::*TraverseFunction)() const;
1208};
1209
1210template <typename T, typename InnerT>
1211T makeTypeAllOfComposite(ArrayRef<const Matcher<InnerT> *> InnerMatchers) {
1212  return T(makeAllOfComposite<InnerT>(InnerMatchers));
1213}
1214
1215} // end namespace internal
1216} // end namespace ast_matchers
1217} // end namespace clang
1218
1219#endif // LLVM_CLANG_AST_MATCHERS_AST_MATCHERS_INTERNAL_H
1220