使用libclang从头文件中自动提取capi
c-api-extract的Python项目详细描述
使用 Python和{a2}。 导出struct、union、enum、typedef、静态变量和函数定义 到JSON文件内容。在
使用
使用命令行界面:
^{pr2}$或者使用Python:
importc_api_extract# `definitions` follow the same format as output JSONdefinitions=c_api_extract.definitions_from_header('header_name.h',['-I/usr/lib/clang/<version>/include','-Dother_clang_args',...])
c\U api公司_提取.py在单个头文件上工作以简化操作。 如果需要处理多个标头,请创建一个新的标头并将其包含在中。在
建议将-I<;path to clang headers>;传递给clang 包括一些标准头,如stddef.h和stdbool.h。在
输出格式
输出是定义的列表,每种定义的格式如下:
# variable definitions{'kind':'var','name':'<name>',# variable name'type':'<type>'# type name as written in source code'source':'<code>'# source C code from read header file}# enum definitions{'kind':'enum','name':'<name>',# enum name, empty for anonymous enums'typedef':'<typedef>',# typedef name, may be empty'type':'<C type>',# enum underlying C type name'values':[# list of declared names and values['<name>',<integervalue>]# ...],'source':'<code>'# source C code from read header file}# struct|union definitions{'kind':'struct'|'union','name':'<name>',# struct|union name, empty for anonymous struct|unions'typedef':'<typedef>',# typedef name, may be empty'fields':[# list of declared fields, empty for opaque struct|unions['<type>','<name>']# ...],'source':'<code>'# source C code from read header file}# typedef definitions{'kind':'typedef','name':'<name>',# name of the typedef'type':'<type>',# name of the underlying type'source':'<code>'# source C code from read header file}# function definitions{'kind':'function','name':'<name>',# name of the function'return_type':'<type>',# return type name'arguments':[# list of arguments['<type>','<name>']# ...],'variadic':true|false,# true if function is variadic'source':'<code>'# source C code from read header file}
托多
- 默认情况下,根据主机操作系统,包括clang标准头
- 添加对使用\define
- 添加对嵌套匿名结构联合的支持
- 添加docstring
- 项目
标签: