This is an archive of the discontinued LLVM Phabricator instance.

Visit lambda capture inits from RecursiveASTVisitor::TraverseLambdaCapture().
ClosedPublic

Authored by mboehme on Aug 5 2016, 6:47 AM.

Details

Summary

rL277342 made RecursiveASTVisitor visit lambda capture initialization
expressions (these are the Exprs in LambdaExpr::capture_inits()).

jdennett identified two issues with rL277342 (see comments there for details):

  • It visits initialization expressions for implicit lambda captures, even if shouldVisitImplicitCode() returns false.
  • It visits initialization expressions for init captures twice (because these were already traveresed in TraverseLambdaCapture() before rL277342)

This patch fixes these issues and moves the code for traversing initialization
expressions into TraverseLambdaCapture().

This patch also makes two changes required for the tests:

  • It adds Lang_CXX14 to the Language enum in TestVisitor.
  • It adds a parameter to ExpectedLocationVisitor::ExpectMatch() that specifies the number of times a match is expected to be seen.

Diff Detail

Event Timeline

mboehme updated this revision to Diff 66942.Aug 5 2016, 6:47 AM
mboehme retitled this revision from to Visit lambda capture inits from RecursiveASTVisitor::TraverseLambdaCapture()..
mboehme updated this object.
mboehme edited subscribers, added: cfe-commits; removed: klimek.
klimek added inline comments.Aug 10 2016, 6:54 AM
include/clang/AST/RecursiveASTVisitor.h
892

I'd rather pass in the offset than doing math with what's semantically a pointer vs an iterator.

unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
236

I'd remove the extra scope.

mboehme updated this revision to Diff 68137.Aug 15 2016, 11:40 PM

Responses to reviewer comments

In particular, changed the interface of TraverseLambdaCapture

mboehme updated this revision to Diff 68139.Aug 15 2016, 11:45 PM

Update to a clean diff.

(Sorry, the last diff included a large number of extraneous changes by others.)

mboehme marked 2 inline comments as done.Aug 15 2016, 11:50 PM
mboehme added inline comments.
include/clang/AST/RecursiveASTVisitor.h
892

I think the cleanest way to do this would be to pass in both the LambdaCapture and the Expr for the corresponding initialization (and handle the offsets in TraverseLambdaExpr).

This will first require transitioning all users of TraverseLambdaCapture to the new interface, which I'll do in a separate patch.

892

I've now decided to do the interface change for TraverseLambdaCapture in this same patch.

There are a few users of TraverseLambdaCapture in clang-tools-extra; the required changes are in D23543. The intent is to wait until the reviews for both patches are complete, then submit them at the same time.

alexfh accepted this revision.Aug 17 2016, 2:44 AM
alexfh edited edge metadata.

LGTM with a couple of nits.

unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
221

nit: Should this be two different tests for simplicity?

228

nit: Remove all the spaces in /*Times=*/2.

239

So, C++14 allows you do that? Wow, TIL something new about C++ ;)

This revision is now accepted and ready to land.Aug 17 2016, 2:44 AM
mboehme updated this revision to Diff 68352.Aug 17 2016, 7:54 AM
mboehme marked an inline comment as done.
mboehme edited edge metadata.

Changes in response to reviewer comments

mboehme marked 3 inline comments as done.Aug 17 2016, 7:55 AM
mboehme added inline comments.
unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
239

;)

This revision was automatically updated to reflect the committed changes.
mboehme marked an inline comment as done.