This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] Add an `EditGenerator` that applies a rule throughout a bound node.
ClosedPublic

Authored by ymandel on Jul 23 2020, 7:30 AM.

Details

Summary

The new combinator, rewriteDescendants, applies a rewrite rule to all
descendants of a specified bound node. That rewrite rule can refer to nodes
bound by the parent, both in the matcher and in the edits.

Diff Detail

Event Timeline

ymandel created this revision.Jul 23 2020, 7:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2020, 7:30 AM
gribozavr2 accepted this revision.Jul 23 2020, 1:06 PM
gribozavr2 added inline comments.
clang/include/clang/Tooling/Transformer/RewriteRule.h
337

Please use three slashes for doc comments.

clang/lib/Tooling/Transformer/RewriteRule.cpp
194

Wouldn't this line move the same value multiple times?

208

The fix seems trivial -- removing the if statement. Why not do that?

clang/unittests/Tooling/TransformerTest.cpp
422

These tests do not demonstrate that the rewrite is only applied to the descendants of the specified AST node -- would be good to test that.

1169

Any particular reason to add these tests at the end of the file instead of grouped together with the rest of the tests for rewriteDescendants above?

This revision is now accepted and ready to land.Jul 23 2020, 1:06 PM
ymandel updated this revision to Diff 280458.Jul 24 2020, 7:21 AM

addressed comments.

ymandel marked 7 inline comments as done.Jul 24 2020, 7:34 AM
ymandel added inline comments.
clang/include/clang/Tooling/Transformer/RewriteRule.h
337

Done, thanks for catching! Also, added example.

clang/lib/Tooling/Transformer/RewriteRule.cpp
194

good catch!

This revision was automatically updated to reflect the committed changes.
ymandel marked 2 inline comments as done.