I need to preprocess some C++ files to automatically insert code for testing and profiling, and I need to do it with the clang API.
Fo
I'm wondering why you want to do this transform on the fly (if I understand you right). This is especially tricky with C++ methods defined in-class, since they're compiled as-if they're defined outside the class (i.e. all class members are usable, even those not declared yet).
Anyway, when you have a RecordDecl, you can access its members via field_begin.
Obviously, when you encounter nexted classes, you'll need to enumerate those as well. In fact, since you can define methods in classes in functions, you'll need to check for nested declarations almost everywhere.