[cfe-dev] Refactoring/Rewriter questions
Terry Wilson
twilson at digium.com
Sat Jun 4 19:49:14 PDT 2011
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?
More information about the cfe-dev
mailing list