[cfe-dev] Using clang to reformat code.

David Blaikie dblaikie at gmail.com
Fri Jan 24 08:19:42 PST 2014


I don't know of any such tool that does this sort of thing already, though
it is theoretically possible (refer to the Clang Tooling infrastructure,
and possibly the AST Matchers). Getting the right balance of readability
improvements in such a tool wouldn't necessarily be trivial though (just
making larger expressions isn't always the best idea, of course - named
variables can often improve readability)


On Fri, Jan 24, 2014 at 1:25 AM, James Courtier-Dutton <
james.dutton at gmail.com> wrote:

> Hi,
>
> Example input source code:
> int main() {
>   int a,b,c;
>   a = 1;
>   b = a + 3;
>   c = b * 4;
>   printf("Result = %d\n", c);
> }
>
> Desired output source code:
> int main() {
>   int a;
>   a = (1 + 3) * 4;
>   printf("Result = %d\n", a);
> }
>
> I.e. Is there a way to automatically take multi-line basic
> calculations and turn them into a single line of more complex
> calculations.
> I know these sorts of optimizations are done during compiling, but I
> would like the actual source code to be simplified and made easier to
> read.
>
> Example use. The "input source code" is some auto-generated code. I
> wish to process that code to make it easier to read, by producing the
> desired "output source code".
>
> Kind Regards
>
> James
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140124/05fb613a/attachment.html>


More information about the cfe-dev mailing list