<div dir="ltr"><div class="gmail_default" style>On Thu, Jan 10, 2013 at 10:22 AM, Antoine Trouve <span dir="ltr"><<a href="mailto:trouve@isit.or.jp" target="_blank">trouve@isit.or.jp</a>></span> wrote:<br></div><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Le H.25/01/10 à 18:03, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> a écrit :<br>
<div><div class="h5"><br>
>> On Thu, Jan 10, 2013 at 8:44 AM, Antoine Trouve <<a href="mailto:trouve@isit.or.jp">trouve@isit.or.jp</a>> wrote:<br>
>> Hello everybody,<br>
>><br>
>> I have successfully written a source-to-source translator using LibTooling, and I am now willing to go further and do some source-to-source translation.<br>
>> However, I can't figure out how to output modified code with LibTooling.<br>
>><br>
>> I have used in the past the class "Rewriter", coupled with a "RewriterBuffer" to do this job, but without the LibTooling (I was manipulating "CompilerInstance" object directly).<br>

>> However, a "RewriterBuffer" requires a file ID (that I used to get from a "SourceManager") to be created, and I don't have access to such information anymore, because I'm calling my tool using "Tool.run" from a custom "FrontEndAction".<br>

>><br>
>> I've spotted the example called "loop-convert" in the clang-tools-extra repository, that is using class derived from "RefactoringTool" to do source-to-source transformation. I kind of made sense of this code, but the way it works would require me to change my code deeply in order to fill the so-called replacement list.<br>

>><br>
>> Does someone has any experience on this matter in order to give some advices on the best approach I should adopt ?<br>
><br>
> I'm not 100% sure what you're looking for - as you said, the RefactoringTool is what's meant to be used to write out changed code - I'm open to changes to that interface if it helps your use case, but I don't know your code, so it's hard for me to tell exactly why that would be a deep change, or how to fit it into your project.<br>

><br>
> My intuition would be that at the point at which you would make changes vie the Rewriter, you would instead fill the Replacements...<br>
><br>
> Cheers,<br>
> /Manuel<br>
<br>
</div></div>Thank you for your answer. Basically I would like to know what is the *standard* way to do source-to-source translation in Libtooling.<br>
Should I understand that this is by using "RefactoringTool" ? Updating my code would require some effort for me to understand how the "Replacements" work, so I want to be sure that this is not to find out that there is a better way to do so.<br>

<br>
To answer your question, I detect "for" statements; analyse the body of the loop to extract some metrics; and add a comment after the for with the values of the previously measured metrics. I used to use the "Rewriting" class to add this comment.<br>
</blockquote><div><br></div><div style>Ah, yes, RefactoringTool is the intended "standard" way to do source-to-source with libtooling. I think if you already use the Rewriter, I'll expect it to actually be not hard to change to using the Replacements :)</div>
<div style><br></div><div style>Cheers,</div><div style>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Regards,<br>
<br>
- Antoine<br>
<div class="HOEnZb"><div class="h5"><br>
>> Best regards,<br>
>><br>
>> - Antoine<br>
>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>