當使用libclang時,如何從stdio.h中排除函數?在libclang中如何從stdio.h中排除函數
當我使用下面的源只收集函數定義,然後我最終從stdio.h獲得所有的函數。
我讀過,我們可以在創建索引時傳遞'-x c-header'類型的參數。但是,這種方式是否適用於libclang?
tu = index.parse(self.filename, "-x c-header")
包括「C-頭」參數後,將其要我填「unsaved_files」陣列爲好,如在每「cindex.py」「解析」函數的定義。
def parse(self, path, args = [], unsaved_files = [], options = 0):
我不知道什麼是正確的方法來做到這一點。
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)