This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] In Transformer, allow atomic changes to span multiple files.
ClosedPublic

Authored by ymandel on May 19 2020, 1:39 PM.

Details

Summary

Currently, all changes returned by a single application of a rule must fit in
one atomic change and therefore must apply to one file. However, there are
patterns in which a single rule will want to modify multiple files; for example,
a header and implementation to change a declaration and its definition. This
patch relaxes Transformer, libTooling's interpreter of RewriteRules, to support
multiple changes.

Diff Detail

Event Timeline

ymandel created this revision.May 19 2020, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2020, 1:39 PM
Herald added subscribers: jfb, mgrang. · View Herald Transcript
gribozavr2 accepted this revision.May 23 2020, 12:25 PM
gribozavr2 added a subscriber: gribozavr2.
gribozavr2 added inline comments.
clang/lib/Tooling/Transformer/Transformer.cpp
65–79

The test shows an example transformer that removes code, so the header insertion logic is not triggered there. However, for a change that would be adding code, is it correct to insert the header into every file being edited? I think not necessarily. Or do you prefer to deal with this issue when we have a sample use case?

This revision is now accepted and ready to land.May 23 2020, 12:25 PM
ymandel marked 2 inline comments as done.May 26 2020, 6:03 AM

Thanks for the review.

clang/lib/Tooling/Transformer/Transformer.cpp
65–79

You're right -- these two features don't mix well. Once we support multiple files per transformation, we should change the header manipluation to be change-specific rather than apply to the whole rule. That will require some re-factoring of the APIs.

For now, I'll put in a FIXME, since this is not (yet) a high demand feature and we'll just note the limitations.

ymandel updated this revision to Diff 266190.May 26 2020, 6:18 AM
ymandel marked an inline comment as done.

adds fixme comment

Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2020, 6:18 AM
ymandel updated this revision to Diff 266191.May 26 2020, 6:19 AM

fixes rebase mistake in previous diff

This revision was automatically updated to reflect the committed changes.