python - 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 文件有脚本不检查的其他功能。 在此处输入图像描述
你能帮我解决这个问题吗?谢谢。
解决方案
推荐阅读
- apex - 如何为下面的代码编写包装类的测试类,
- java - 基于来自 JTextField 的输入运行非标准评估(sin、cos、tan)
- spring-boot - postForObject Solr 查询
- r - if-else错误语句`条件长度> 1`在R中?
- c - 获取条件表达式的地址
- macos - SED:匹配后删除 X 行
- arrays - 我可以将 tableViewCell 中 TextField 中的字符串存储到数组中,然后再次使用该数组在 Textfield 中考虑其字符串吗?
- python - python中的循环用于不同的组合
- laravel - 使用 maatwebsite/excel:~2.1.0 在此集合实例上不存在属性 [名称]
- java - 用于 pom 属性的 Apache Maven 过滤器