[PATCH] D102213: [ASTMatchers] Add forCallable(), a generalization of forFunction().

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 10 20:23:25 PDT 2021


NoQ created this revision.
NoQ added reviewers: alexfh, gribozavr2, aaron.ballman, stephenkelly, xazax.hun, vsavchenko.
Herald added subscribers: martong, rnkovacs.
NoQ requested review of this revision.

It additionally covers Objective-C methods and blocks that don't inherit from `FunctionDecl`.

I'm open to suggestions here. For instance, it might make sense to have three different matchers instead (`forFunction()`, `forBlock()`, `forObjCMethod()`) and `anyOf()` them. I don't think it's practical though; most of the time you want any callable and if you don't you can always narrow it down with `forCallable(functionDecl())` or something like that. I guess it might make sense to implement both approaches.

I'm also open to suggestions with respect to the very fact that such matchers exist in the first place. From existing use cases it looks to me that most of the time (including my use case) they're used to avoid the problem with `hasDescendant()` (and similar matchers) digging into nested declarations (eg., inspecting the body of a lambda within a function when you only want it to inspect the function itself). I would be totally satisfied with a better alternative for `hasDescendant()` instead - that only traverses statements; that'd probably be faster as well as more precise and concise. @stephenkelly, IIRC you've voiced some strong opinions on this subject on the mailing list.


Repository:
  rC Clang

https://reviews.llvm.org/D102213

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102213.344278.patch
Type: text/x-patch
Size: 7116 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210511/107e455d/attachment-0001.bin>


More information about the cfe-commits mailing list