<div dir="ltr">Hi Noah!<br><div><div class="gmail_extra"><br><div class="gmail_quote">On 28 June 2017 at 19:48, Noah L via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think this post refers to the subject of the recent "Cross Translation Unit Support in Clang" thread, but I'm not entirely sure I understand the issue, so I'll start a new thread rather than potentially pollute that one.<br><br>So I've been working on a tool[1], based on libTooling, that automatically translates C code to SaferCPlusPlus (essentially, a memory-safe subset of C++). The problem I have, if I'm understanding it correctly, is that it can only convert one source file (which corresponds to a "translation unit" right?) at a time, due to libTooling's limitation. Right? Does that make sense?<br></div></blockquote><div><br></div><div>That is correct. A translation unit is basically a file that is being compiled and all its dependencies, like headers, precompiled headers, modules. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>Ok, so converting a source file (potentially) modifies the file itself and any included header files as well. The problem is when multiple source files include the same header file, because conversion of a source file requires the included header files to be in their original form. They can't have been modified by a previous conversion of another source file. So after (individually) converting all the source files in a project, you can end up with multiple versions of a header file that were modified in different ways by the conversions of different source files. Right? (An example[2].)<br></div></blockquote><div><br></div><div>Well, as far as I understand, the idiomatic way to handle this right now, is not to apply your modifications to the source files right away. First export all the changes for each translation units into a separate file, and apply all the changes at once after the tool was run. If all your changes are consistent, that should work well. If you would transform a header in a different way in two different translation units that is a problem. I think the best way to solve that right now to make sure all of your edits are consistent. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>So this means to get the final converted version of the header file you have to merge the modifications made by each conversion operation. And sometimes the modifications are made on the same line so the merge tool can't do the merge automatically. (At least meld doesn't.) This is really annoying.<br><br>Now, if libTooling were able to operate on the AST of the entire project at once this problem would go away. Or if you think the AST of the whole project would often be too big, then at least multiple specified translation units at a time would help.<br></div></blockquote><div><br></div><div>This is not the usecase this functionality was designed for. I think you could definitely use it for something like that, but I think the solution I mentioned above is superior right now. The main use case we wanted to cover is the ability to gather some information from other translation units that are required for your tool. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>I'm not sure if this is what's being offered in the "Cross Translation Unit Support in Clang" thread? I would want the Rewriter::<wbr>overwriteChangedFiles() function to apply to all the source translation units of the AST as well.<br><br>Am I making make sense? Feel free to set me straight.<br></div></blockquote><div><br></div><div>I hope I could help.<br><br></div><div>Regards,<br></div><div>Gábor<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br>Noah<br><br>[1] <a href="https://github.com/duneroadrunner/SaferCPlusPlus-AutoTranslation" target="_blank">https://github.com/<wbr>duneroadrunner/SaferCPlusPlus-<wbr>AutoTranslation</a><br>[2] <a href="https://github.com/duneroadrunner/SaferCPlusPlus-AutoTranslation/tree/master/examples/lodepng" target="_blank">https://github.com/<wbr>duneroadrunner/SaferCPlusPlus-<wbr>AutoTranslation/tree/master/<wbr>examples/lodepng</a><br><br></div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div></div>