【发布时间】:2014-01-30 19:15:26
【问题描述】:
使用libclang时,如何从stdio.h中排除函数?
当我使用下面的源代码只收集函数定义时,我最终也会从 stdio.h 中获取所有函数。
我读到我们可以在创建索引时传递“-x c-header”类型的参数。但是这种给出参数的方式是否适用于 libclang。
tu = index.parse(self.filename, "-x c-header")
在包含“c-header”参数后,它要我也填写“unsaved_files”数组,按照“cindex.py”中“parse”函数的定义。
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)
【问题讨论】:
标签: python header-files libclang