[Clang Tools] Source-to-source transformations

Michael, Yitzhak,

Thank you so much for your comments. I think I will go with the ASTFrontendAction in detriment of clang-tidy in order to have more “freedom” when writing the tool. Nonetheless, I am quite concerned regarding my decision of not modifying the AST. Maybe using the TreeTransform helper would be a better decision. On the other hand, I do not see the utility of performing modifications in the AST; could you provide me an example where it is useful rather than “just parsing and replacing code”?
Again, thank you so much.

Best regards,

If you need semantic analysis such as name lookup, overload
resolution, etc. for your changed code. For instance, you want to
replace a type, which might transitively require to change types of
other variables, function result- and parameter types. However, the
AST was not designed with such a use case in mind and you will need to
write a lot of code to handle special situations (e.g. re-do overload
resolution with the new type; however the overload set depends on
clang::Scope which is only available during parsing). I strongly
suggest to pursue the parse-and-replace approach if possible.

Michael

If you need semantic analysis such as name lookup, overload

resolution, etc. for your changed code. For instance, you want to

replace a type, which might transitively require to change types of

other variables, function result- and parameter types. However, the

AST was not designed with such a use case in mind and you will need to

write a lot of code to handle special situations (e.g. re-do overload

resolution with the new type; however the overload set depends on

clang::Scope which is only available during parsing). I strongly

suggest to pursue the parse-and-replace approach if possible.

I see, in my case I think is crystal clear that I do not have to perform modifications in the AST so my life will be easier.
Thanks for the clarification and prompt response.

Bests,