When using libclang, how to exclude function from stdio.h ?
When I use the below source to collect only function definitions, then I end up getting all the functions from stdio.h as well.
I read we can pass '-x c-header' kind of arguments while creating index. But does this way of giving arguments applicable in libclang.
tu = index.parse(self.filename, "-x c-header")
After including 'c-header' argument, it wants me to fill in 'unsaved_files' array as well, as per the definition of 'parse' function in 'cindex.py'.
def parse(self, path, args = [], unsaved_files = [], options = 0):
I don't know what is the right way to do this.
def funcdefn_visitor(self, node, parent, userdata):
if node.kind == clang.cindex.CursorKind.FUNCTION_DECL: #gives function definitions
self.func_defn.append(clang.cindex.Cursor_displayname(node))
self.func_defn_line_no.append(node.location.line)
self.func_defn_col_no.append(node.location.column)
print 'Found %s [line=%s, col=%s]' % (
clang.cindex.Cursor_displayname(node),
node.location.line,
node.location.column)
return 2 # means continue visiting recursively
index = clang.cindex.Index.create()
tu = index.parse(self.filename)
#-- link cursor visitor to call back to give function definitions
clang.cindex.Cursor_visit(
tu.cursor,
clang.cindex.Cursor_visit_callback(self.funcdefn_visitor),
None)