Implement new AST matcher hasAnyCapture to match on LambdaExpr captures.
Accepts child matchers cxxThisExpr to match on capture of this and also on varDecl. This is achieved by using the overload macros.
Paths
| Differential D72414
Add new AST matcher `hasAnyCapture` ClosedPublic Authored by rhiro on Jan 8 2020, 1:45 PM.
Details
Summary Implement new AST matcher hasAnyCapture to match on LambdaExpr captures. Accepts child matchers cxxThisExpr to match on capture of this and also on varDecl. This is achieved by using the overload macros.
Diff Detail
Event Timelinerhiro retitled this revision from Implement new AST matchers `hasAnyCapture` and `capturesThis`.
These matchers match on LambdaExpr:
hasAnyCapture - matches if any child VarDecl matcher matches one of the captured vars.
capturesThis - matches if `this` is captured by the LambdaExpr. to Add new AST matchers `hasAnyCapture` and `capturesThis`.Jan 8 2020, 1:50 PM Comment Actions Thank you for this patch! You should also register the matcher(s) in Registry.cpp so that they'll work from clang-query. Also, you need to regenerate the documentation by running clang\docs\tools\dump_ast_matchers.py
Comment Actions
Comment Actions Thanks for the review! I regenerated the docs and switched the this capture case to be an override of hasAnyCapture.
rhiro retitled this revision from Add new AST matchers `hasAnyCapture` and `capturesThis` to Add new AST matcher `hasAnyCapture`.Jan 9 2020, 3:34 PM
Comment Actions Fixed the condition for the varDecl case and made the cxxThisExpr more concise.
This revision is now accepted and ready to land.Jan 10 2020, 12:02 PM Comment Actions
Yes, please.
Revision Contents
Diff 237389 clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
|
I would prefer to see this written as: if (Capture.capturesVariable()) { ... } so it's a bit more resilient to other non-var captures like VLA captures.