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

Marcos Horro Varela via cfe-dev cfe-dev at lists.llvm.org
Sun Dec 1 21:23:08 PST 2019


Hello all,

We are developing a tool for performing some source-to-source transformations. I have some technical questions regarding the approach we are following for this purpose:
As far as I understand, Clang AST is meant to be immutable, therefore once created (for instance with the ASTFrontendAction), I guess no Node (Stmt, Decl, whatever) must be modified.
Thus, our approach is basically to parse the source file and generate its AST, feed our algorithms for generating code using some information of the AST (patterns found with MatcherFinder, variable names, etc.), and then generating code (basically strings) using Replacements and Rewriter.
My main concerns are:

  *   I have not delved deep in all the FrontendAction subclasses in Clang. For our purpose, is ASTFrontendAction suitable? Are there any other better choices?
  *   Is it fine to not modify the original AST when performing source-to-source transformations? My first idea was to modify it until I read the "immutability philosophy". On the other hand, I only care about the AST for parsing, not for the output (I am already performing the modifications with Rewriter, right?).

I am asking this just to be sure that I understand how Clang Tools work or if I am misunderstanding something.
Thank you so much.

Kind regards,


--

Marcos Horro

PhD Student

Universidade da Coruña (UDC)

http://gac.udc.es/~marcos.horro/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191202/40b224aa/attachment.html>


More information about the cfe-dev mailing list