This is an archive of the discontinued LLVM Phabricator instance.

[refactor][extract] Initial implementation of variable captures
AcceptedPublic

Authored by arphaman on Nov 6 2017, 3:40 PM.

Details

Summary

This patch adds an initial rudimentary support for capturing variables that should be passed to the extracted function.
The variables are passed to the extracted function if they're used in the extracted code. If they're defined they're ignored for now, but we'll be able to handle variables that defined in extracted code but that are used after extracted code later. The variables are sorted by name when passing them to the extracted function. The exact passing semantics (reference/pointer/const reference/const pointer) are not yet computed.

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman created this revision.Nov 6 2017, 3:40 PM
ioeric edited edge metadata.Nov 8 2017, 7:39 AM

Implementation looks good. Just some nits.

lib/Tooling/Refactoring/Extract/CaptureVariables.cpp
37

and this?

51

nit: s/Detemine/Determine/

It might make more sense to put these FIXME in class-level comment.

lib/Tooling/Refactoring/Extract/CaptureVariables.h
37

Maybe a FIXME here for Kind?

39

Does this include trailing commas? Maybe add an example in the comment?

Same below.

44

Maybe printFunctionCallArg? It's unclear where this is used.

lib/Tooling/Refactoring/Extract/Extract.cpp
154

nit: Capture.index() > 0 to be more explicit.

arphaman updated this revision to Diff 122270.Nov 9 2017, 10:38 AM
arphaman marked 5 inline comments as done.

Address review comments

lib/Tooling/Refactoring/Extract/CaptureVariables.cpp
37

This is a different kind of expression that won't be handled in this method, and there's a fixit for 'this' further down already.

lib/Tooling/Refactoring/Extract/CaptureVariables.h
37

I think this constructor will always set the same kind.

ioeric added inline comments.Nov 10 2017, 10:13 AM
lib/Tooling/Refactoring/Extract/CaptureVariables.cpp
98

A more informative message would be better.

lib/Tooling/Refactoring/Extract/CaptureVariables.h
29

The name is a bit hard to parse. Maybe just CapturedEntity or simply CapturedVar?

37

Then why do you need Kind? Is it changed somewhere else? Please document the behavior,

arphaman updated this revision to Diff 122565.Nov 10 2017, 6:06 PM
arphaman marked 3 inline comments as done.

Address review comments

lib/Tooling/Refactoring/Extract/CaptureVariables.h
37

The kind will be set to a different value by the other constructors that will be added later
I added docs to the enum

ioeric accepted this revision.Nov 27 2017, 3:41 AM

Lg

(Sorry for losing track of this and the delay!)

This revision is now accepted and ready to land.Nov 27 2017, 3:41 AM