diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 2c9b3aae0a89..314c89932ae0 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -250,7 +250,7 @@ Example matches f
Matches method declarations.
 
 Example matches y
-  class X { void y() };
+  class X { void y(); };
 
@@ -1311,7 +1311,7 @@ Usable as: Any Matcher -Matcher<*>unlessMatcher<*> InnerMatcher +Matcher<*>unlessMatcher<*>
Matches if the provided matcher does not match.
 
 Example matches Y (matcher = recordDecl(unless(hasName("X"))))
@@ -1352,6 +1352,11 @@ Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
 
+Matcher<CXXConstructExpr>isListInitialization +
Matches a constructor call expression which uses list initialization.
+
+ + Matcher<CXXConstructorDecl>isImplicit
Matches a constructor declaration that has been implicitly added
 by the compiler (eg. implicit defaultcopy constructors).
@@ -1422,6 +1427,18 @@ Given
 
+Matcher<CXXMethodDecl>isPure +
Matches if the given method declaration is pure.
+
+Given
+  class A {
+   public:
+    virtual void x() = 0;
+  };
+  matches A::x
+
+ + Matcher<CXXMethodDecl>isVirtual
Matches if the given method declaration is virtual.
 
@@ -2313,8 +2330,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -2378,6 +2393,16 @@ with withInitializer matching (1)
 
+Matcher<CXXForRangeStmt>hasLoopVariableMatcher<VarDecl> InnerMatcher +
Matches the initialization statement of a for loop.
+
+Example:
+    forStmt(hasLoopVariable(anything()))
+matches 'int x' in
+    for (int x : a) { }
+
+ + Matcher<CXXMemberCallExpr>onMatcher<Expr> InnerMatcher
Matches on the implicit object argument of a member call expression.
 
@@ -2506,8 +2531,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -2647,8 +2670,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -2813,8 +2834,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3034,8 +3053,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3058,8 +3075,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3082,8 +3097,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3290,8 +3303,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3324,8 +3335,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3405,8 +3414,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3417,8 +3424,23 @@ Usable as: Matcher<TemplateArgument>isExprMatcher<Expr> InnerMatcher
+
Matches a sugar TemplateArgument that refers to a certain expression.
+
+Given
+  template<typename T> struct A {};
+  struct B { B* next; };
+  A<&B::next> a;
+templateSpecializationType(hasAnyTemplateArgument(
+  isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next"))))))))
+  matches the specialization A<&B::next> with fieldDecl(...) matching
+    B::next
+
+ + Matcher<TemplateArgument>refersToDeclarationMatcher<Decl> InnerMatcher -
Matches a TemplateArgument that refers to a certain declaration.
+
Matches a canonical TemplateArgument that refers to a certain
+declaration.
 
 Given
   template<typename T> struct A {};
@@ -3444,6 +3466,20 @@ classTemplateSpecializationDecl(hasAnyTemplateArgument(
 
+Matcher<TemplateSpecializationType>hasAnyTemplateArgumentMatcher<TemplateArgument> InnerMatcher +
Matches classTemplateSpecializations that have at least one
+TemplateArgument matching the given InnerMatcher.
+
+Given
+  template<typename T> class A {};
+  template<> class A<double> {};
+  A<int> a;
+classTemplateSpecializationDecl(hasAnyTemplateArgument(
+    refersToType(asString("int"))))
+  matches the specialization A<int>
+
+ + Matcher<TemplateSpecializationType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
 matches the given matcher.
@@ -3456,8 +3492,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3468,6 +3502,20 @@ Usable as: Matcher<TemplateSpecializationType>hasTemplateArgumentunsigned N, Matcher<TemplateArgument> InnerMatcher
+
Matches classTemplateSpecializations where the n'th TemplateArgument
+matches the given InnerMatcher.
+
+Given
+  template<typename T, typename U> class A {};
+  A<bool, int> b;
+  A<int, bool> c;
+classTemplateSpecializationDecl(hasTemplateArgument(
+    1, refersToType(asString("int"))))
+  matches the specialization A<bool, int>
+
+ + Matcher<TemplateTypeParmType>hasDeclarationMatcher<Decl> InnerMatcher
Matches a node if the declaration associated with that node
 matches the given matcher.
@@ -3480,8 +3528,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3525,8 +3571,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
@@ -3567,8 +3611,6 @@ The associated declaration is:
 
 Also usable as Matcher<T> for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
-FIXME: Add all node types for which this is matcher is usable due to
-getDecl().
 
 Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>,
   Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>,
diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py
index 564dc380d648..7f8751ea654d 100644
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -242,12 +242,17 @@ def act_on_decl(declaration, comment, allowed_types):
 
     # Parse Variadic operator matchers.
     m = re.match(
-        r"""^.*VariadicOperatorMatcherFunc\s*([a-zA-Z]*)\s*=\s*{.*};$""",
+        r"""^.*VariadicOperatorMatcherFunc\s*<\s*([^,]+),\s*([^\s>]+)\s*>\s*
+              ([a-zA-Z]*)\s*=\s*{.*};$""",
         declaration, flags=re.X)
     if m:
-      name = m.groups()[0]
-      add_matcher('*', name, 'Matcher<*>, ..., Matcher<*>', comment)
-      return
+      min_args, max_args, name = m.groups()[:3]
+      if max_args == '1':
+        add_matcher('*', name, 'Matcher<*>', comment)
+        return
+      elif max_args == 'UINT_MAX':
+        add_matcher('*', name, 'Matcher<*>, ..., Matcher<*>', comment)
+        return
 
 
     # Parse free standing matcher functions, like:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 167b0fc7906b..81faa922ed2a 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -311,18 +311,6 @@ AST_MATCHER(Decl, isPrivate) {
   return Node.getAccess() == AS_private;
 }
 
-// FIXME: unify ClassTemplateSpecializationDecl and TemplateSpecializationType's
-// APIs for accessing the template argument list.
-inline llvm::ArrayRef
-getTemplateSpecializationArgs(const ClassTemplateSpecializationDecl &D) {
-  return D.getTemplateArgs().asArray();
-}
-
-inline llvm::ArrayRef
-getTemplateSpecializationArgs(const TemplateSpecializationType &T) {
-  return llvm::ArrayRef(T.getArgs(), T.getNumArgs());
-}
-
 /// \brief Matches classTemplateSpecializations that have at least one
 /// TemplateArgument matching the given InnerMatcher.
 ///
@@ -340,7 +328,8 @@ AST_POLYMORPHIC_MATCHER_P(
     AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl,
                                       TemplateSpecializationType),
     internal::Matcher, InnerMatcher) {
-  llvm::ArrayRef List = getTemplateSpecializationArgs(Node);
+  llvm::ArrayRef List =
+      internal::getTemplateSpecializationArgs(Node);
   return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder,
                              Builder);
 }
@@ -439,7 +428,8 @@ AST_POLYMORPHIC_MATCHER_P2(
     AST_POLYMORPHIC_SUPPORTED_TYPES_2(ClassTemplateSpecializationDecl,
                                       TemplateSpecializationType),
     unsigned, N, internal::Matcher, InnerMatcher) {
-  llvm::ArrayRef List = getTemplateSpecializationArgs(Node);
+  llvm::ArrayRef List =
+      internal::getTemplateSpecializationArgs(Node);
   if (List.size() <= N)
     return false;
   return InnerMatcher.matches(List[N], Finder, Builder);
@@ -2320,16 +2310,6 @@ AST_POLYMORPHIC_MATCHER_P(
           InnerMatcher.matches(*Condition, Finder, Builder));
 }
 
-namespace internal {
-struct NotEqualsBoundNodePredicate {
-  bool operator()(const internal::BoundNodesMap &Nodes) const {
-    return Nodes.getNode(ID) != Node;
-  }
-  std::string ID;
-  ast_type_traits::DynTypedNode Node;
-};
-} // namespace internal
-
 /// \brief Matches if a node equals a previously bound node.
 ///
 /// Matches a node if it equals the node previously bound to \p ID.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index e66bf0907161..32a37d2705c9 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1579,6 +1579,26 @@ TypeTraversePolymorphicMatcher<
   return Self(InnerMatchers);
 }
 
+// FIXME: unify ClassTemplateSpecializationDecl and TemplateSpecializationType's
+// APIs for accessing the template argument list.
+inline llvm::ArrayRef
+getTemplateSpecializationArgs(const ClassTemplateSpecializationDecl &D) {
+  return D.getTemplateArgs().asArray();
+}
+
+inline llvm::ArrayRef
+getTemplateSpecializationArgs(const TemplateSpecializationType &T) {
+  return llvm::ArrayRef(T.getArgs(), T.getNumArgs());
+}
+
+struct NotEqualsBoundNodePredicate {
+  bool operator()(const internal::BoundNodesMap &Nodes) const {
+    return Nodes.getNode(ID) != Node;
+  }
+  std::string ID;
+  ast_type_traits::DynTypedNode Node;
+};
+
 } // end namespace internal
 } // end namespace ast_matchers
 } // end namespace clang