<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">+1 to taking a look at clang::tooling::Transformer, which is the adaptor that ties the libraries in clang::transformer to actual tools. I'm happy to answer questions.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">You should also consider whether your tool can be written as a clang tidy check rather than using ASTFrontendAction, since that saves you from needing to write your own tool around the transformation. However, it also means you're confined to clang-tidy's interface. So, it has pluses and minuses. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">If you decide to go with clang-tidy, you can use the adaptor <a href="https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h" style="font-family:Arial,Helvetica,sans-serif">https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h</a> to tie to clang::transformer. </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 2, 2019 at 11:56 AM Michael Kruse via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am So., 1. Dez. 2019 um 23:23 Uhr schrieb Marcos Horro Varela via<br>
cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>>:<br>
> I have not delved deep in all the FrontendAction subclasses in Clang. For our purpose, is ASTFrontendAction suitable? Are there any other better choices?<br>
<br>
Not an expert, but I think deriving from ASTFontendAction is exactly<br>
intended for such as use case.<br>
<br>
> 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?).<br>
<br>
It is always fine to **not** do something. Indeed, after parsing, the<br>
AST is not supposed to be modified and you would get unexpected<br>
results if you try (some analysis is baked in at this stage, e.g. name<br>
lookup, overload resolution, implicit casts, etc). You can, however,<br>
create a new but modified AST from the parsed one. Template<br>
instantiation uses this via the TreeTransform helper. I still suggest<br>
to avoid this if you don't need to. Instead as you mentioned you can<br>
use clang::Rewriter to directly modify the input source characters<br>
that can be found using SourceLocation. Note there is also<br>
clang::tooling::Transformer to help with this task.<br>
<br>
Michael<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>