[PATCH] D56090: Add a matcher for members of an initializer list expression

Hyrum Wright via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 26 13:58:45 PST 2018


hwright created this revision.
hwright added a reviewer: aaron.ballman.
hwright added a project: clang.
Herald added a subscriber: cfe-commits.

Much like `hasArg` for various call expressions, this allows `LibTooling` users to match against a member of an initializer list.

This is currently being used as part of the `abseil-duration-scale` clang-tidy check.


Repository:
  rC Clang

https://reviews.llvm.org/D56090

Files:
  include/clang/ASTMatchers/ASTMatchers.h


Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3514,6 +3514,20 @@
               *Node.getArg(N)->IgnoreParenImpCasts(), Finder, Builder));
 }
 
+/// Matches the n'th item of an initializer list expression.
+///
+/// Example matches y.
+///     (matcher = initListExpr(hasInit(0, expr())))
+/// \code
+///   int x{y}.
+/// \endcode
+AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N,
+               ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
+  return N < Node.getNumInits() &&
+          InnerMatcher.matches(*Node.getInit(N)->IgnoreParenImpCasts(), Finder,
+                               Builder);
+}
+
 /// Matches declaration statements that contain a specific number of
 /// declarations.
 ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56090.179522.patch
Type: text/x-patch
Size: 873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181226/6078442a/attachment.bin>


More information about the cfe-commits mailing list