I am wondering about libclang. Do you have a working example with libclang somewhere I can look at? It does not need to be a complete tutorial, I just need to see the mechanics behind using clang with libclang.<div><br></div>
<div>- Thanks</div><div>Jeff Kunkel<br><br><div class="gmail_quote">On Sat, Nov 6, 2010 at 1:12 PM, Jeff Kunkel <span dir="ltr"><<a href="mailto:jdkunk3@gmail.com">jdkunk3@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Ok, I will take another look at it. On closer inspection, I see more of the interface I skipped before. <div><br></div><div>So to gain the function declarations, I would hook into TraverseDecl. Would I use TraverseDecl for object definition too? And how do I know what scope I am in?<div>
<div></div><div class="h5"><br>
<br><div class="gmail_quote">On Sat, Nov 6, 2010 at 12:51 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid.kleckner@gmail.com" target="_blank">reid.kleckner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Not true, unless it's changed significantly since I used it.  You only<br>
need to override the methods corresponding to the bits of the AST that<br>
you're interested in.  You should be able to just ignore templates if<br>
you don't care about them.  IMO it's really what you want for walking<br>
the AST.<br>
<font color="#888888"><br>
Reid<br>
</font><div><div></div><div><br>
On Sat, Nov 6, 2010 at 12:26 PM, Jeff Kunkel <<a href="mailto:jdkunk3@gmail.com" target="_blank">jdkunk3@gmail.com</a>> wrote:<br>
> Again, I believe RecursiveASTVisitor is for templates more than anything<br>
> else. Look at the methods defined to be overridden:<br>
> bool shouldVisitTemplateInstantiations()<br>
> bool TraverseDecl(Decl *D)<br>
> bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS)<br>
> bool TraverseTemplateName(TemplateName Template);<br>
> bool TraverseTemplateArgument(const TemplateArgument &Arg);<br>
> bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc);<br>
> bool TraverseTemplateArguments(const TemplateArgument *Args, unsigned<br>
> NumArgs);<br>
> bool TraverseConstructorInitializer(CXXBaseOrMemberInitializer *Init);<br>
> Five out of eight deal with templates. The other ones like constructor<br>
> initialization does not suite my needs and TraverseDecl can be handled by<br>
> the ASTConsumer.<br>
> The other functions have been macroed to a point of un-readability. Those<br>
> macros hang out in "clang/AST/*.def" and were probably created by some<br>
> little language cover all the cases.<br>
> Jeff<br>
><br>
><br>
> On Sat, Nov 6, 2010 at 12:16 PM, Garrison Venn <<a href="mailto:gvenn.cfe.dev@gmail.com" target="_blank">gvenn.cfe.dev@gmail.com</a>><br>
> wrote:<br>
>><br>
>> I believe HandleTopLevelDecl, although a little too low level works, since<br>
>> every thing is a Decl<br>
>> (see <a href="http://clang.llvm.org/doxygen/classclang_1_1Decl.html" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1Decl.html</a>), and from<br>
>> Decls one can get statements<br>
>> and therefore expressions<br>
>> (see <a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html</a> for<br>
>> example).<br>
>> Having said this I believe utilization of a visitor is more practical, and<br>
>> therefore use of RecursiveASTVisitor<br>
>> more viable.<br>
>> Garrison<br>
>> On Nov 6, 2010, at 9:06, Jeff Kunkel wrote:<br>
>><br>
>> The overall goal would be<br>
>> 1: parse the names, return types, and parameters of functions with a given<br>
>> context like a namespace, class, struct or global scope.<br>
>> 2: parse classes, structs, enums, etc for the name, internal objects,<br>
>> members, member methods, virtual overrides, inheritance, etc.<br>
>> 3: The final output would be the boost::python C++ code wrapper with as<br>
>> descriptive an interface as the C++ class itself.<br>
>> Thanks,<br>
>> Jeff Kunkel<br>
>><br>
>> On Sat, Nov 6, 2010 at 12:02 PM, Jeff Kunkel <<a href="mailto:jdkunk3@gmail.com" target="_blank">jdkunk3@gmail.com</a>> wrote:<br>
>>><br>
>>> I've been studying ASTConsumer and RecursiveASTVisitor.  The easiest way<br>
>>> to find objects, structs, class, enums, etc is clearly<br>
>>> "HandleTagDeclDefinition" from ASTConsumer (see the function documentation).<br>
>>> However, I still need to be able to gather global functions or functions<br>
>>> local to a namespace.<br>
>>> I am looking at "HandleTopLevelDecl" within the ASTConsumer, but it seems<br>
>>> to be geared for data declartion like "int x,y;". I am not 100 percent sure<br>
>>> that it handles function definitions as well.<br>
>>> Second, ASTContext is a very general class, and it is a bear to parse<br>
>>> through to find what I need. It seems that I could forgo the methods<br>
>>> described above, and I could just use "HandleTranslationUnit" if I wanted to<br>
>>> parse through the ASTContext.<br>
>>> RecursiveASTVisitor looks geared for<br>
>>> template declarations and instantiations. It does not seem viable for the<br>
>>> common function definitions, and it seems inept to handle class, struct,<br>
>>> etc instantiations.<br>
>>> Any other advice or comments?<br>
>>> - Thanks<br>
>>> - Jeff Kunkel<br>
>>><br>
>>> On Sat, Nov 6, 2010 at 11:33 AM, David Chisnall <<a href="mailto:csdavec@swan.ac.uk" target="_blank">csdavec@swan.ac.uk</a>><br>
>>> wrote:<br>
>>>><br>
>>>> On 5 Nov 2010, at 21:16, Jeff Kunkel wrote:<br>
>>>><br>
>>>> > I need to gather or visit the classes, methods, and functions defined<br>
>>>> > within a give clang compiler instance. Is there a simple interface to<br>
>>>> > accomplish this?<br>
>>>><br>
>>>> This depends on what you wish to accomplish.  The simplest interface is<br>
>>>> via libclang, but it doesn't expose all of the details of the AST.<br>
>>>>  Alternatively, you can use the AST visitor or consumer interfaces.  The<br>
>>>> best approach depends on the level of detail that you need.<br>
>>>><br>
>>>> David<br>
>>><br>
>><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>
>><br>
><br>
><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>
><br>
><br>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>