On Fri, Oct 26, 2012 at 8:32 PM, Eric Schulte <span dir="ltr"><<a href="mailto:schulte.eric@gmail.com" target="_blank">schulte.eric@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> writes:<br>
<br>
> On Fri, Oct 26, 2012 at 5:48 PM, Eric Schulte <<a href="mailto:schulte.eric@gmail.com">schulte.eric@gmail.com</a>>wrote:<br>
><br>
>> Hi,<br>
>><br>
>> I've written a simple command-line code-mutation tool using the Tooling<br>
>> infrastructure [1]. The tooling framework handled many of the difficult<br>
>> portions of this task (handling compilation databases etc...) allowing<br>
>> me to focus on writing a RecursiveASTVisitor -- my thanks to everyone<br>
>> who worked on the tooling setup and on clang in general.<br>
>><br>
><br>
> :)<br>
><br>
> I would now like to expose the functionality of this ASTVisitor as a C<br>
>> library so that I can call these functions programatically and chain<br>
>> multiple ASTConsumers without the overhead of multiple shell calls,<br>
>> repeatedly parsing of the original source, etc...<br>
>><br>
>> Is this possible? Is this difficult? Is there a best practice for<br>
>> transitioning from a command-line Tooling tool to a library? Should I<br>
>> just look though the clang/Tooling source? Any pointers or suggestions<br>
>> would be greatly appreciated.<br>
>><br>
><br>
> I think you're the first one to go this route - one thing I notice is that<br>
> you say "C library". I assume that's a requirement? In general, the way I'd<br>
> go about this is:<br>
> - build a C++ library<br>
> - build a C wrapper that exposes the functionality<br>
><br>
<br>
</div>Great, I'll take this approach. Hopefully it won't be overly difficult<br>
to pull the relevant preparatory code (source -> AST conversion) out of<br>
the existing Tooling libraries.<br>
<div class="im"><br>
><br>
> That's pretty much the way libclang does it (minus some stuff that's only<br>
> in libclang, but we've already noticed some of that stuff would be very<br>
> nice to have in a C++ layer).<br>
><br>
> Your tool is also sufficiently narrow focus currently that I think it might<br>
> make sense to go into clang mainline as a library and be useful from<br>
> libclang, but Doug might have a different opinion.<br>
><br>
<br>
</div>I initially hoped to use libclang for this work but found it did not<br>
include any Code Rewriting functionality. I don't know if my ASTMutate<br>
library is the best abstraction around code rewriting, but I would love<br>
to see some rewriting support in libclang.<br>
<div class="im"><br>
><br>
><br>
>> Thanks,<br>
>><br>
>> Footnotes:<br>
>> [1] <a href="https://github.com/eschulte/clang-mutate" target="_blank">https://github.com/eschulte/clang-mutate</a><br>
><br>
><br>
> Nice! Looks awesome :)<br>
> /me wonders whether it would be a perfect fit for the extra-tools<br>
> repository...<br>
><br>
<br>
</div>This does seem like it could be a nice fit. If the extra-tools repo<br>
would like to include this mutation tool then I'm happy to help with the<br>
integration, just let me know what I can do.<br></blockquote><div><br></div><div><a href="http://clang.llvm.org/docs/ClangTools.html">http://clang.llvm.org/docs/ClangTools.html</a></div><div><br></div><div>Cheers,</div><div>
/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Thanks,<br>
<br>
><br>
> Cheers,<br>
> /Manuel<br>
<div class=""><div class="h5"><br>
--<br>
Eric Schulte<br>
<a href="http://cs.unm.edu/~eschulte" target="_blank">http://cs.unm.edu/~eschulte</a><br>
</div></div></blockquote></div><br></div>