<br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Mohammad Adil</b> <span dir="ltr"><<a href="mailto:madil90@gmail.com">madil90@gmail.com</a>></span><br>Date: Wed, Oct 17, 2012 at 4:08 PM<br>
Subject: Re: [cfe-dev] Type Information for C++ classes<br>To: Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>><br><br><br>I am analyzing an AST with clang and I have a code which uses "FILE" type. Clang reports FILE type as int rather than FILE. I need to distinguish between FILE and int because both of them behave differently with streams. Is there a way I can distinguish between these two in clang?<div class="HOEnZb">
<div class="h5"><br>
<br><div class="gmail_quote">On Mon, Oct 15, 2012 at 6:53 PM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<div>   When clang parses a source file, how does it include the related header files. e.g lets say i have</div><div><br></div><div>#include "something.h"</div><div><br></div><div>   Does the final AST includes everything in something.h too? What about something.cpp? At which compilation stage does the linker include code from something.cpp, or something.o, if there is any?</div>

<span><font color="#888888">
<div><br></div></font></span><div><span><font color="#888888">Adil</font></span><div><div><br><br><div class="gmail_quote">On Mon, Oct 15, 2012 at 12:27 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_extra"><div>On Mon, Oct 15, 2012 at 8:30 AM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote">


<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">
Sorry to disturb you again. I have found out how to find the member variables of a class. Can you please tell me how to find all instances of a variable usage in a source code? e.g. I create a global variable temp. I want to find out all the places where temp was used or changed?</blockquote>



<div><br></div></div>declRefExpr(to(varDecl(hasName("x"))))<div><div><div class="gmail_extra"><br></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">



<div><div><br>
<br><div class="gmail_quote">On Mon, Oct 15, 2012 at 11:00 AM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br><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">




Hi,<div>   clang provides information about all the unused variables when a flag is provided in the command line. How does clang finds all instances of that variable usage in a source code?</div><div>   I still am not quite sure how to use the matcher to find all member variables of a class? Can you briefly explain how the matchfinder api works and how it can be used to find all variables of a class? e.g.</div>





<div><br></div><div>class A</div><div>{</div><div>    int b,c;</div><div>    double e;</div><div>};</div><div><br></div><div>    I want to find out that the class A has variables named b,c,e? How do I use the matcher in this situation? I will be very grateful for your help</div>





<div><br></div><div>Regards,</div><div>Adil<div><div><br><br><div class="gmail_quote">On Fri, Oct 12, 2012 at 5:23 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>





<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>Is this what you're looking for?</div><a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/tool-template/ToolTemplate.cpp?revision=162624&view=markup" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/tool-template/ToolTemplate.cpp?revision=162624&view=markup</a><br>






<div class="gmail_extra"><br></div><div class="gmail_extra">Cheers,</div><div class="gmail_extra">/Manuel<div><div><br><br><div class="gmail_quote">On Fri, Oct 12, 2012 at 10:50 AM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br>






<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">I am comfortable with clang's internal API at the time, although the abstraction provided in libclang seems much easier to work with. The clang's internal API is much more self-explanatory than libclang. Can you please give me some hints as for how to find the members and methods of a class. I can visit all classes using VisitCXXRecordDecl but there doesn't seem to be any way to find it's members. Is there a way to recursively walk all the children this CXXRecordDecl and figure out which ones are methods and members? Also, I am struggling on how to use the ASTMatcher you mentioned earlier. I have a returnstmt using the VisitStmt method of my visitor. This will give me a return statement. How do I find which function it belongs to? Can you give a small example of how to do it? I am very grateful for your help.<div>






<div><br>
<br><div class="gmail_quote">On Fri, Oct 12, 2012 at 1:13 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><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>On Fri, Oct 12, 2012 at 7:38 AM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote">







<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">
Also, Is it better to use libclang for doing this. My complete purpose is to refactor source code to find all functions, their arguments, return statements, all class members and methods. Can I find all this using libclang? I've heard that clang is unstable while libclang is stable. Which one should I use? I am currently using clang's internal API.</blockquote>








<div><br></div></div><div> <a href="http://clang.llvm.org/docs/Tooling.html" target="_blank">http://clang.llvm.org/docs/Tooling.html</a></div><div><br></div><div>I don't have too much experience with using libclang for something like this; what you want to do is definitely possible with LibTooling. And while the internal clang AST interface is going to change more often than libclang, in practice it is stable enough that you usually don't care unless you want to ship a product (like an IDE) to end users. I'd try to decide more on how much power you need, or what language you'd like to write your integration in.</div>








<div><br></div><div>One good way is to try to start with libclang, and if you see that you're hitting a missing feature, switch to using libtooling.</div><div><br></div><div>Cheers,</div><div>/Manuel</div><div><div>
<div><br></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"><div><div><div><br></div><div><div class="gmail_quote">
On Fri, Oct 12, 2012 at 10:16 AM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br><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">









My purpose is to overload the << operator for all classes if they don't already have one. The basic goal is to make all classes serializable over some stream (ideally a network stream). Is that possible with clang? If yes, How do I find all the member variables and functions of a class or struct?<div>









<div><div>
<br><div class="gmail_quote">On Thu, Oct 11, 2012 at 5:13 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><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">










+cfe-dev<div class="gmail_extra"><br><div class="gmail_quote"><div>On Thu, Oct 11, 2012 at 12:13 PM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br>











<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">Sorry about that. I wasn't correctly changing my language from C to C++. I figured that out. It's working now. I wanted to ask you one more thing. I am trying to find all the return statements in the file. I can do that easily but I know want to find out which function does this return statement belong to? Since funcdecl and return statements are de-coupled, I can't find a way to do so. Is there an easy way to do it?</blockquote>











<div><br></div></div><div>If you're using RecursiveASTVisitor, you can intercept the Traverse* calls to figure out AST child relations. Or you can use the AST matchers (functionDecl(hasDescendant(returnStmt()))).</div>










<div>
<br></div><div>Cheers,</div><div>/Manuel</div><div><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">








<div><div><div class="gmail_quote">
On Wed, Oct 10, 2012 at 8:29 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br>
<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">On Wed, Oct 10, 2012 at 2:05 AM, madil90 <<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>> wrote:<br>













> Hi,<br>
>    I am trying to find the type of a VarDecl. I am currently using the<br>
> VarDecl->getOriginalType(). This function does not work for C++ classes.<br>
> Consider the code below:<br>
<br>
Does getType() not work for you for some reason?<br>
<br>
Cheers,<br>
/Manuel<br>
<br>
><br>
> class Foo<br>
> {<br>
>     int a;<br>
> };<br>
><br>
> int f( Foo foo);<br>
><br>
> When I try to find the type for "foo" in the function decleration, it<br>
> returns "int", while the actual type is Foo. If Foo is a structure, this<br>
> works perfectly fine but not for C++ classes. Can some one please explain<br>
> where the type information for C++ classes is stored?<br>
><br>
><br>
<span><font color="#888888">><br>
> --<br>
> View this message in context: <a href="http://clang-developers.42468.n3.nabble.com/Type-Information-for-C-classes-tp4027266.html" target="_blank">http://clang-developers.42468.n3.nabble.com/Type-Information-for-C-classes-tp4027266.html</a><br>














> Sent from the Clang Developers mailing list archive at Nabble.com.<br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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>
</font></span></blockquote></div><br><br clear="all"><div><br></div></div></div><span><font color="#888888">-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</font></span></blockquote></div></div></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div>
</div></div></blockquote></div></div></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div></div></blockquote></div></div></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div></div></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>