Clang and code transformation

Hi,

I would like to find a tool to add some trace inside some C files from GCC.
I tried with some regexp but without success so I would like to know if
clang
would allow me to parse C files and add some frpintf() like this :

c-parser.c:

static void
c_parser_skip_to_end_of_parameter (c_parser *parser)
{
  
  fprintf(stderr, "c-parser.c: c_parser_skip_to_end_of_parameter()\n"); //
ADDED by CLANG
  unsigned nesting_depth = 0;
  ...

}

void
c_parse_file (void)
{
  fprintf(stderr, "c-parser.c: c_parse_file()\n"
  ...
}
Thanks

Another question I am trying to compile clang on winXP/cygwin and it seems
you are using
recent GCC flags :

llvm[3]: Compiling gtest.cc for Debug build
cc1plus: error: unrecognized command line option
"-Wno-missing-field-initializers"
cc1plus: error: unrecognized command line option "-Wno-variadic-macros"

Maybe you should check if it exists ...
How can I remove those flags and will it work ?

Hi,

I would like to find a tool to add some trace inside some C files from

GCC.

I tried with some regexp but without success so I would like to know if
clang
would allow me to parse C files and add some frpintf() like this :

c-parser.c:

static void
c_parser_skip_to_end_of_parameter (c_parser *parser)
{
  
  fprintf(stderr, "c-parser.c: c_parser_skip_to_end_of_parameter()\n");

//

Sure, clang can do this short of thing. It supports rewriting interfaces to insert strings into existing files. Please take a look at the ObjC->C rewriter for some examples.

For example:

$ cat t.m
char * test() { return @encode(int); }
$ clang t.m -rewrite-objc -o -
...
char * test() { return "i"; }

-Chris