[cfe-dev] Using clang to reformat code.

James Courtier-Dutton james.dutton at gmail.com
Fri Jan 24 01:25:04 PST 2014


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



More information about the cfe-dev mailing list