[cfe-dev] [Clang Tools] Source-to-source transformations

Michael Kruse via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 5 13:03:36 PST 2019

Am Di., 3. Dez. 2019 um 14:54 Uhr schrieb Marcos Horro Varela
<marcos.horro at udc.es>:
> 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"?

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.


More information about the cfe-dev mailing list