<div dir="ltr">Answering my own question:<br><div><br>On Fri, Oct 18, 2013 at 8:51 PM, Elliott Slaughter <span dir="ltr"><<a href="mailto:elliottslaughter@gmail.com" target="_blank">elliottslaughter@gmail.com</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>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++.<br>

<br></div>Here is an example session:<br><br>>>> import clang.cindex<br>>>> idx = clang.cindex.Index.create()<br>>>> tu = idx.parse('/usr/include/math.h', ['-x', 'c++-header'])<br>

>>> c = tu.cursor<br>>>> for d in c.get_children():<br>...     print d.kind, d.spelling<br>... <br>CursorKind.TYPEDEF_DECL __int128_t<br>CursorKind.TYPEDEF_DECL __uint128_t<br>CursorKind.TYPEDEF_DECL __builtin_va_list<br>

CursorKind.UNEXPOSED_DECL <br></div></div></div></blockquote><div><br></div><div>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.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>>>> print len(tu.diagnostics)<br>0<br><br></div>Now that list clearly does not represent the contents of math.h. However, as you can see, I don't get an error, and the list of diagnostics is empty.<br>

<br></div>When I use C mode, I instead get the list of functions I'm expecting to see:<br><div><div><div><div><br>>>> tu = idx.parse('/usr/include/math.h', ['-x', 'c-header'])<br>>>> c = tu.cursor<br>

>>> for d in c.get_children():<br>...     print d.kind, d.spelling<br>... <br>CursorKind.TYPEDEF_DECL __int128_t<br>CursorKind.TYPEDEF_DECL __uint128_t<br>CursorKind.TYPEDEF_DECL __builtin_va_list<br>[...]<br>CursorKind.FUNCTION_DECL acosf<br>

CursorKind.FUNCTION_DECL acos<br>CursorKind.FUNCTION_DECL acosl<br>[...]<br clear="all"><div><div><br></div><div>Am I doing something obviously wrong (aside from calling math.h a C++ header)? Is there any reasonable way to debug problems like this?<br>

<br></div><div>I'm on Mac OS X 10.8 using the Clang binaries from Xcode (Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)), and Python bindings from Clang 3.2, and Python 2.7.2. (I am unable to test 3.3 because clang_Cursor_isBitField seems to be missing.)<br>

</div><div><br></div><div>Thanks.<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br>-- <br>Elliott Slaughter<br><br>"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay
</div></font></span></div></div></div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>Elliott Slaughter<br><br>"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay
</div></div></div>