<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Michael, Yitzhak,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
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. <span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">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"?</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Again, thank you so much.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Best regards,</div>
<div id="Signature">
<div></div>
<div></div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; font-family: Calibri, Helvetica, sans-serif; color: rgb(0, 0, 0);">
<p style="margin-top:0px; margin-bottom:0px; margin-top:0; margin-bottom:0">--</p>
<p style="margin-top:0px; margin-bottom:0px; margin-top:0; margin-bottom:0">Marcos Horro</p>
<p style="margin-top:0px; margin-bottom:0px; margin-top:0; margin-bottom:0">PhD Student<br>
</p>
<p style="margin-top:0px; margin-bottom:0px; margin-top:0; margin-bottom:0">Universidade da Coruņa (UDC)<br>
</p>
<p style="margin-top:0px; margin-bottom:0px; margin-top:0; margin-bottom:0"><a href="http://gac.udc.es/~marcos.horro/" class="OWAAutoLink" style="">http://gac.udc.es/~marcos.horro/</a> <br>
</p>
</div>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
<hr tabindex="-1" style="display:inline-block; width:98%;">
<b>De:</b> Yitzhak Mandelbaum<br>
<b>Enviado:</b> Martes, 03 de decembro de 2019 20:59<br>
<b>Para:</b> Michael Kruse<br>
<b>CC:</b> Marcos Horro Varela; via cfe-dev<br>
<b>Asunto:</b> Re: [cfe-dev] [Clang Tools] Source-to-source transformations
<div><br>
</div>
</div>
<div class="rps_8a6e">
<div>
<div dir="ltr">
<div class="x_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="x_gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<div class="x_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="x_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" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable" 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="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Mon, Dec 2, 2019 at 11:56 AM Michael Kruse via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable" style="">cfe-dev@lists.llvm.org</a>> wrote:<br>
</div>
<blockquote class="x_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" rel="noopener noreferrer" data-auth="NotApplicable" style="">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" rel="noopener noreferrer" data-auth="NotApplicable" style="">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank" rel="noreferrer noopener" data-auth="NotApplicable" style="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote>
</div>
</div>
</div>
</body>
</html>