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

Andrew Gozillon via cfe-dev cfe-dev at lists.llvm.org
Wed Dec 13 02:21:16 PST 2017


Hi Jonas,


Thank you very much, I was wondering if that was the right way to go about it.


Best Regards,

Andrew


________________________________
From: Jonas Toth <jonas.toth at gmail.com>
Sent: 13 December 2017 08:03:43
To: Andrew Gozillon
Cc: via cfe-dev
Subject: Re: [cfe-dev] Question about Clang Rewriter and white space

Hi Andrew,

white space is a job for clang-format. You can do your rewriting and apply it afterwards to get nice looking code.

Am 13.12.2017 6:32 vorm. schrieb "Andrew Gozillon via cfe-dev" <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>>:

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

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

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


More information about the cfe-dev mailing list