[cfe-dev] Proposal: add "replace" functionality to clang-query
Alexander Timin via cfe-dev
cfe-dev at lists.llvm.org
Mon Mar 23 09:45:14 PDT 2020
Hey!
I think that medium-scale medium-complexity C++ refactorings (like
replacing the order of the two arguments of a function across a large
codebase) are much harder that they should be: clang-refactor and
clang-rename do not cover them and writing a full libTooling tool is not
the most time-efficient solution.
I propose extending the functionality of clang-query to cover this use case
and allow generating replacements (which can be then applied by
clang-apply-replacements) from matches:
replace MATCHER NODE PATTERN
for example,
let f = cxxMethodDecl(hasName("Foo"))
let arg1 = hasArgument(0, expr().bind("arg1"))
let arg2 = hasArgument(1, expr().bind("arg2"))
let m = callExpr(on(f), arg1, arg2)
replace m root Foo(${arg2}, ${arg1})
A more detailed design doc is available here
<https://docs.google.com/document/d/1700aqcNmxPIdltiny2_X-xUlwdrJmdPXgnJLauv4wVQ/edit#>
.
An early prototype patch is available here <https://reviews.llvm.org/D76607>
.
A real-life example: the query is here <https://pastebin.com/TDwsGekw>, the
output in the form of a Chromium patch is here
<https://chromium-review.googlesource.com/2115544>.
WDYT?
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200323/380e9df7/attachment-0001.html>
More information about the cfe-dev
mailing list