[cfe-dev] [libclang] Is there any method like get_children (python cindex) available for libclang or alternative to print the tree structure by the traversal method?
David Röthlisberger
david at rothlis.net
Sun Jun 17 01:54:28 PDT 2012
On 17 Jun 2012, at 08:24, Carlos Andrade wrote:
>
> I managed to create a transversal using libclang on C, map it to code and get its types but now I am stuck trying to output it like a tree like it is done at [1]. For some unknown reason [1] crashes here with the warning "Python quit unexpectedly while using libclang.dylib plug-in. (Running on an OS Lion).
>
> [1] https://gist.github.com/2503232
Can you narrow down the failure to a specific line of python + line of
the input translation unit? I suspect it might be something to do with
accessing a property of an invalid type.
> On my C version I can get each node being printed, but what I wanted is what [1] does: Print the structure of the tree (who is child of who) and I was trying to do so by tying to verify if the child is NULL but I cant find any method available to do so. [2] Seems to suggest this doesnt even exist on libclang C.
>
> [2] http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/
Have you considered writing your program in python? I found that using
the ipython shell (with its tab-completion) was really helpful for
exploring the libclang API.
(I apologise for not actually answering your question, but I don't know
enough about the libclang C interface.)
Cheers
Dave.
More information about the cfe-dev
mailing list