Retrieving comments using python libclang <p>In the following header file I'd like to get the corresponding <code>+reflect</code> comment to the class and member variable:</p> <pre><code>#ifndef __HEADER_FOO #define __HEADER_FOO //+reflect class Foo { public: private: int m_int; //+reflect }; #endif </code></pre> <p>Using the python bindings for libclang and the following script:</p> <pre><code>import sys import clang.cindex def dumpnode(node, indent): print ' ' * indent, node.kind, node.spelling for i in node.get_children(): dumpnode(i, indent+2) def main(): index = clang.cindex.Index.create() tu = index.parse(sys.argv[1], args=['-x', 'c++']) dumpnode(tu.cursor, 0) if __name__ == '__main__': main() </code></pre> <p>Gives me this output:</p> <pre><code>CursorKind.TRANSLATION_UNIT None CursorKind.TYPEDEF_DECL __builtin_va_list CursorKind.CLASS_DECL type_info CursorKind.CLASS_DECL Foo CursorKind.CXX_ACCESS_SPEC_DECL CursorKind.CXX_ACCESS_SPEC_DECL CursorKind.FIELD_DECL m_int </code></pre> <p>The problem is that the comments are missing. Are they stripped by the preprocessor? Is there any way to prevent that?</p>