Refactoring/Rewriter questions

I have a code base of around 1M lines and want to make one of the most used (and fairly huge) structures opaque--adding accessor functions. So basically taking something like:

struct foo {
   char *bar;
   int baz;
   struct foo *other;

struct foo *f;
printf("%d: %s\n", f->baz, get_other_foo(f)->bar);

and turning it into

struct foo *f;
printf("%d: %s\n", get_foo_baz(f), get_foo_bar(get_other_foo(f));

My initial thought was to just write accessor functions, then try to write a clang plugin and call with the -add-plugin option to do the source rewriting to use them as the project compiled. Maybe displaying the recommended change and prompting for oversight. Is this even possible? Difficult? I've been reading over the doxygen docs and the objc rewriter for the last couple of days and it seems like getter functions should be doable. Am I looking in the right places? Anyone have any tips/pointers? Has someone already written a plugin to do something similar that I just haven't found?

Hi Terry,

we've been doing similar code transformations (over bigger code bases)
and I've been working on getting the framework we're using back into
the clang codebase - whether the patches will go in is currently open
for discussion:
An example how you can implement code transformations similar to what
you want:

I'm also working on a follow-up patch, under review here:
which adds support to allow to run those code transformations over
multiple translation units in one process, as that's important to do
the deduplication of changes that appear multiple times (for example
when the same header is included in multiple translation units).

The open issues with that framework are:
- parallelization: currently if we run in one process, we only run one
translation unit at a time; what we're doing so far as a workaround is
output textual representations of the changes, run many tools in
parallel and have a python script that does the deduplication and
application of the changes; for a 1MLOC code base running in serial is
probably on the edge of bearable
- re-layouting: replacing arbitrary text regions can make the code
look broken; we need a clang-based layout tool