<div dir="ltr"><div><div>I'm writing a tool to parse generalized attributes that annotate a source file.<br>I'm trying to parse the following code with the libclang python bindings:<br><br></div>test.h:<br><br>=============================<br>
#ifndef test_h<br>#define test_h<br><br>class Foo<br>{<br>public:<br> void foo [[interesting]] ();<br> void bar ();<br>};<br><br>#endif<br>=============================<br><br></div>I'm using the following python code to dump the AST:<br>
<div><br>=============================<div><div><div>import sys<br>import clang.cindex<br><br>def setup():<br> #clang.cindex.Config.set_library_path(r'c:\Program Files (x86)\LLVM 3.4.svn\bin')<br> global ind<br>
ind = clang.cindex.Index.create()<br> tu = ind.parse('test.h', ['-x', 'c++', '-std=c++11'])<br> output_cursor_and_children(tu.cursor)<br><br>def indent(level):<br> return ' '*level<br>
<br>def output_cursor(cursor, level):<br> """ Low level cursor output<br> """<br> spelling = ''<br> displayname = ''<br><br> if cursor.spelling:<br> spelling = cursor.spelling<br>
if cursor.displayname:<br> displayname = cursor.displayname<br> kind = cursor.kind;<br><br> print indent(level) + spelling, '<' + str(kind) + '>'<br> print indent(level+1) + '"' + displayname + '"'<br>
<br>def output_cursor_and_children(cursor, level=0):<br> """ Output this cursor and its children with minimal formatting.<br> """<br> output_cursor(cursor, level)<br> if cursor.kind.is_reference():<br>
print indent(level) + 'reference to:'<br> output_cursor(clang.cindex.Cursor_ref(cursor), level+1)<br><br> # Recurse for children of this cursor<br> has_children = False;<br> for c in cursor.get_children():<br>
if not has_children:<br> print indent(level) + '{'<br> has_children = True<br> output_cursor_and_children(c, level+1)<br><br> if has_children:<br> print indent(level) + '}'<br>
=============================<br><br></div><div>I get the following output:<br><br>=============================<br> <CursorKind.TRANSLATION_UNIT><br> "test.h"<br>{<br> __builtin_va_list <CursorKind.TYPEDEF_DECL><br>
"__builtin_va_list"<br> type_info <CursorKind.CLASS_DECL><br> "type_info"<br> Foo <CursorKind.CLASS_DECL><br> "Foo"<br> {<br> <CursorKind.CXX_ACCESS_SPEC_DECL><br>
""<br> foo <CursorKind.CXX_METHOD><br> "foo()"<br> bar <CursorKind.CXX_METHOD><br> "bar()"<br> }<br>}<br>=============================<br><br></div><div>I would expect to see at least an UNEXPOSED_ATTR somewhere in the output. What am I doing wrong here?<br>
<br></div><div>Tamás<br></div></div></div></div></div>