[cfe-dev] Question about Clang Rewriter and white space

Andrew Gozillon via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 12 21:32:37 PST 2017


Hi,


I am currently playing around with a Clang Libtool and I was wondering if there was a way to make the Clang Rewriter remove white space or if there is another utility class that can do this? For example I have an arbitrary set of template parameters:


template <typename X, typename Y>


And I wish to remove the first template parameter using the Rewriter in this case to modify the source code. To do this I remove the typename X and the comma. However, the result ends up like:


template < typename Y>


Which contains some unsightly white space! This persists even if I increase the SourceRange to just before the t of typename Y. So it seems to be ignoring the space.


So in essence is there a way to make the Rewriter consider white space for removal or is there an alternative tool or method (like using a function of Clangs AST) to avoid this? At the moment I work around this by injecting an arbitrary character in the empty space and then I delete it. Which works, but doesn't seem like the ideal solution.


Sorry if this is a silly question and thank you very much for everyone's time.


Best Regards,

Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171213/7384eac7/attachment-0001.html>


More information about the cfe-dev mailing list