<div dir="ltr">Hey!<div><br></div><div>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.</div><div><br></div><div>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:</div><div><br></div><div>replace MATCHER NODE PATTERN</div><div><br></div><div>for example,</div><div><br></div><div>let f = cxxMethodDecl(hasName("Foo"))</div><div>let arg1 = hasArgument(0, expr().bind("arg1"))</div><div>let arg2 = hasArgument(1, expr().bind("arg2"))<br></div><div>let m = callExpr(on(f), arg1, arg2)</div><div>replace m root Foo(${arg2}, ${arg1})</div><div><br></div><div>A more detailed design doc <a href="https://docs.google.com/document/d/1700aqcNmxPIdltiny2_X-xUlwdrJmdPXgnJLauv4wVQ/edit#">is available here</a>.</div><div><br></div><div>An early prototype patch is available <a href="https://reviews.llvm.org/D76607">here</a>.<br>A real-life example: the query is <a href="https://pastebin.com/TDwsGekw ">here</a>, the output in the form of a Chromium patch is <a href="https://chromium-review.googlesource.com/2115544">here</a>.<br></div><div><br></div><div>WDYT?</div><div>Alexander</div></div>