I can't modify "createFromArgs" function of CompilerInvocation. I am not sure why it's putting C++ paths at the end. Can you think of any reason?<div><br></div><div>Are there any other examples on Tooling which explore some other Actions etc. I am especially looking for something that enables me to rewrite the code. I am very grateful for your help.</div>
<div><br></div><div>Regards,</div><div>Mohammad Adil</div><div><div><br><div class="gmail_quote">On Thu, Oct 18, 2012 at 10:29 PM, Sean Silva <span dir="ltr"><<a href="mailto:silvas@purdue.edu" target="_blank">silvas@purdue.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">> My use case currently requires me to be able to parse the AST. As I<br>
> mentioned, I almost have the problem solved. I modified the<br>
> "createInvocationFromCommandLine" function and added<br>
> "TheDriver.CCCIsCXX=true". The only problem is that the args in the<br>
> CompilerInvocation object created are not in the correct order. All the C++<br>
> include arguments are put AFTER the source file and so they are not working.<br>
> The "createInvocationFromArgs" is doing this. Is there any way this can be<br>
> remedied?<br>
<br>
</div>If you have copied the function why not just write some code to<br>
rearrange things to be like you want?<br>
<div class="im"><br>
>    On a completely different note, Can this be done using Libtooling? If<br>
> yes, Can you please provide a small example. There is rarely any<br>
> documentation on LibTooling and the Tooling API is much harder to understand<br>
> than normal Clang API which is much more intuitive.<br>
<br>
</div>There is an example at <<a href="http://clang.llvm.org/docs/LibTooling.html" target="_blank">http://clang.llvm.org/docs/LibTooling.html</a>>.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Sean Silva<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, Oct 18, 2012 at 1:05 PM, Mohammad Adil <<a href="mailto:madil90@gmail.com">madil90@gmail.com</a>> wrote:<br>
> My use case currently requires me to be able to parse the AST. As I<br>
> mentioned, I almost have the problem solved. I modified the<br>
> "createInvocationFromCommandLine" function and added<br>
> "TheDriver.CCCIsCXX=true". The only problem is that the args in the<br>
> CompilerInvocation object created are not in the correct order. All the C++<br>
> include arguments are put AFTER the source file and so they are not working.<br>
> The "createInvocationFromArgs" is doing this. Is there any way this can be<br>
> remedied?<br>
><br>
>    On a completely different note, Can this be done using Libtooling? If<br>
> yes, Can you please provide a small example. There is rarely any<br>
> documentation on LibTooling and the Tooling API is much harder to understand<br>
> than normal Clang API which is much more intuitive.<br>
><br>
> Regards,<br>
> Adil<br>
><br>
><br>
> On Thu, Oct 18, 2012 at 9:58 PM, Sean Silva <<a href="mailto:silvas@purdue.edu">silvas@purdue.edu</a>> wrote:<br>
>><br>
>> Another problem that you are likely to run into is that there are some<br>
>> headers like stddef.h which are looked for in a hardcoded path<br>
>> relative to the binary itself, so you must either hardcode the path on<br>
>> your system in some way, or run your tool only in particular<br>
>> directories.<br>
>><br>
>> The problem that you are having is probably the #1 most annoying thing<br>
>> for me about clang. When I was getting started with clang I spent more<br>
>> time than I wish to admit on exactly what you are trying to do now,<br>
>> and basically my conclusion was that Clang does not support this use<br>
>> case currently (i.e., using clang as a library to simply parse an<br>
>> arbitrary C++ file and then do stuff with the AST or whatever).<br>
>> libTooling was not around back then, so libTooling might be a way to<br>
>> accomplish what you want. You are going to waste a lot of time if you<br>
>> try to manually do this though---I certainly did.<br>
>><br>
>> Someday, we may be able to say ParseFile("foo.cpp") which just gives<br>
>> you the ASTContext for the parsed file, but we currently do not, and<br>
>> it is a *really*, **really** hard problem to be able to make something<br>
>> like that "just work".<br>
>><br>
>> A plugin is a way to get around this though, but your tool may or may<br>
>> not fit into the plugin model. If all you want though is to get the<br>
>> ASTContext and do something with it, then a plugin is the way to go<br>
>> currently.<br>
>><br>
>> -- Sean Silva<br>
>><br>
>> On Thu, Oct 18, 2012 at 3:22 AM, Mohammad Adil <<a href="mailto:madil90@gmail.com">madil90@gmail.com</a>> wrote:<br>
>> > I've been looking at the source code of the Driver. What I have<br>
>> > understood<br>
>> > till now is that the driver is created for the platform we are working<br>
>> > on.<br>
>> > The driver  can then build a compilation object from a list of<br>
>> > arguments.<br>
>> > Inside this compilation object, there exists a toolchain specific to the<br>
>> > platform (e.g. Linux in my case) which has the job of inserting correct<br>
>> > system and C++ include paths. Is that correct? Let us say that I have<br>
>> > build<br>
>> > such a compilation object. How can I create a CompilerInvocation or<br>
>> > CompilerInstance out of this such that it includes the information about<br>
>> > all<br>
>> > default C and C++ paths? I see no way of using the driver to just create<br>
>> > an<br>
>> > AST and parse it so the only way is to create a Driver and somehow<br>
>> > create a<br>
>> > CompilerInstance out of it.<br>
>> ><br>
>> ><br>
>> > On Thu, Oct 18, 2012 at 1:09 AM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On Wed, Oct 17, 2012 at 6:50 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>><br>
>> >> wrote:<br>
>> >>><br>
>> >>> (readding cfe-dev)<br>
>> >>><br>
>> >>><br>
>> >>><br>
>> >>> On Wed, Oct 17, 2012 at 9:42 AM, Mohammad Adil <<a href="mailto:madil90@gmail.com">madil90@gmail.com</a>><br>
>> >>> wrote:<br>
>> >>> > What I am trying to do is to make a small program which parses the<br>
>> >>> > AST<br>
>> >>> > and<br>
>> >>> > does some rewriting to output modified code. How will I use the<br>
>> >>> > Driver<br>
>> >>> > in<br>
>> >>> > this case? All I want to do is to parse the AST.<br>
>> >>><br>
>> >>> I don't know off-hand what the best way to integrate the Driver's<br>
>> >>> lib/header discovery is, just that that's where the logic is.<br>
>> >>><br>
>> >>> The focus of Clang development with regard to "tools" like the one you<br>
>> >>> described is the Tooling infrastructure (overview of options & a link<br>
>> >>> to libTooling-specific information can be found here:<br>
>> >>> <a href="http://clang.llvm.org/docs/Tooling.html" target="_blank">http://clang.llvm.org/docs/Tooling.html</a> ). I'm not sure if that meets<br>
>> >>> the "standalone execution" scenario that you seem to be going for -<br>
>> >>> it's ideally meant to integrate with code already building using an<br>
>> >>> existing build system that has been modified to generate a database of<br>
>> >>> compilation commands. I /think/ it should also work standalone & still<br>
>> >>> do all the driver-based discovery, but I could be wrong.<br>
>> >><br>
>> >><br>
>> >> It does not fully do the driver-based discovery, but it'll usually work<br>
>> >> with the same flags that you provide to a normal clang call - and you<br>
>> >> can<br>
>> >> always specify options after "--" if you build the tool like in the<br>
>> >> tutorials.<br>
>> >><br>
>> >> Cheers,<br>
>> >> /Manuel<br>
>> >><br>
>> >>><br>
>> >>><br>
>> >>> > On Wed, Oct 17, 2012 at 9:39 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>><br>
>> >>> > wrote:<br>
>> >>> >><br>
>> >>> >> On Wed, Oct 17, 2012 at 9:29 AM, madil90 <<a href="mailto:madil90@gmail.com">madil90@gmail.com</a>> wrote:<br>
>> >>> >> > Hi,<br>
>> >>> >> >    I am trying to parse a C++ code but clang doesn't recognize<br>
>> >>> >> > the<br>
>> >>> >> > C++<br>
>> >>> >> > types. Consider the following code<br>
>> >>> >> ><br>
>> >>> >> > #include <iostream><br>
>> >>> >> > #include <string><br>
>> >>> >> ><br>
>> >>> >> > int main()<br>
>> >>> >> > {<br>
>> >>> >> >     string str;<br>
>> >>> >> > }<br>
>> >>> >> ><br>
>> >>> >> > clang gives an error at <iostream> and doesn't recognize the<br>
>> >>> >> > string<br>
>> >>> >> > type. To<br>
>> >>> >> > enable C++, I did "langOptions.CPlusPlus=1" and the code<br>
>> >>> >> > recognizes<br>
>> >>> >> > custom<br>
>> >>> >> > C++ classes. So how do I include default C++ paths?<br>
>> >>> >><br>
>> >>> >> I assume you're using clang as a library, rather than actually<br>
>> >>> >> going<br>
>> >>> >> through the clang driver? The driver's where all (most) of the<br>
>> >>> >> header<br>
>> >>> >> search logic is. You can extract the paths by simply asking clang<br>
>> >>> >> what<br>
>> >>> >> command it used to invoke the frontend (I forget offhand, but there<br>
>> >>> >> is<br>
>> >>> >> a verbose/print-commands option to clang) & just pass those in. But<br>
>> >>> >> if<br>
>> >>> >> you want to make a tool using clang as a library & have the same<br>
>> >>> >> header/lib discovery that the clang command line program has, you'd<br>
>> >>> >> need to duplicate or reuse the logic in the driver.<br>
>> >>> >><br>
>> >>> >> - David<br>
>> >>> ><br>
>> >>> ><br>
>> >>> ><br>
>> >>> ><br>
>> >>> > --<br>
>> >>> > Mohammad Adil<br>
>> >>> > LUMS SSE<br>
>> >>> ><br>
>> >>><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>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> > Mohammad Adil<br>
>> > LUMS SSE<br>
>> ><br>
>> ><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>
><br>
><br>
><br>
> --<br>
> Mohammad Adil<br>
> LUMS SSE<br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div></div>