如何解决python中的libclang不会解析超过2000 LOC的C文件
我想在python脚本(windows 10 && Ubuntu18.04)中使用libclang来解析一个超过2000行的C文件。该脚本可以运行,但不能完美解析 C 文件。我不知道为什么会这样。源代码中是否有一些参数需要修改?脚本如下:
import clang.cindex
def parse_decl(node):
reference_node = node.get_deFinition()
if node.kind.is_declaration():
if(node.kind.name == 'FUNCTION_DECL'):
if(node.is_deFinition()):
print(node.kind.name,node.location.line,reference_node.displayname)
for ch in node.get_children():
parse_decl(ch)
if __name__ == '__main__':
clang.cindex.Config.set_library_file('***\\clang\\native\\libclang.dll')
index = clang.cindex.Index.create()
trans_unit = index.parse(r'***\linux-fc6a5d0601c5ac1d02f283a46f60b87b2033e5ca\net\bridge\netfilter\ebtables.c',args=['-std=c++11'])#
parse_decl(trans_unit.cursor)
脚本的输出是: enter image description here enter image description here
但是 C 文件有脚本没有检查的其他功能。 enter image description here
你能帮我解决这个问题吗?谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。