[LLVMdev] Parsing C++ headers with Clang bindings for Python

Elliott Slaughter elliottslaughter at gmail.com
Sun Oct 20 21:28:09 PDT 2013


On Sun, Oct 20, 2013 at 3:33 PM, Mark Lacey <mark.lacey at apple.com> wrote:

> Hi Elliott,
>
> On Oct 18, 2013, at 9:29 PM, Elliott Slaughter <elliottslaughter at gmail.com>
> wrote:
>
> Answering my own question:
>
> On Fri, Oct 18, 2013 at 8:51 PM, Elliott Slaughter <
> elliottslaughter at gmail.com> wrote:
>
>> I'd like to parse a C++ header file (say, math.h) with the Clang bindings
>> for Python. (Yes, I know math.h is technically a C header, but for my
>> purposes I want to pretend that it is C++.) For some reason, Clang is able
>> to parse the file as C, but not as C++.
>>
>> Here is an example session:
>>
>> >>> import clang.cindex
>> >>> idx = clang.cindex.Index.create()
>> >>> tu = idx.parse('/usr/include/math.h', ['-x', 'c++-header'])
>> >>> c = tu.cursor
>> >>> for d in c.get_children():
>> ...     print d.kind, d.spelling
>> ...
>> CursorKind.TYPEDEF_DECL __int128_t
>> CursorKind.TYPEDEF_DECL __uint128_t
>> CursorKind.TYPEDEF_DECL __builtin_va_list
>> CursorKind.UNEXPOSED_DECL
>>
>
> It would seem that the contents on the entire module are hidden inside
> this UNEXPOSED_DECL. I'd be interesting in knowing why that is, but for now
> at least I seem to have solved my problem.
>
>
> I am not sure why that is, but cfe-dev at cs.uiuc.edu is the correct place
> to discuss Clang design and implementation, so you should probably try
> asking there.
>

Thanks for the pointer. Sorry about the spam.

-- 
Elliott Slaughter

"Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it." - Alan Kay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131020/205d5f62/attachment.html>


More information about the llvm-dev mailing list