如何解决python libclang绑定,获取无效文件错误
我正在尝试使用 python libclang 绑定解析一些 C++ 文件,为此我制作了这个脚本:
import clang.cindex
def GetDoxygenCommentTokens(translation_unit):
tokens = []
for token in translation_unit.get_tokens(extent=translation_unit.cursor.extent):
if token.kind == clang.cindex.TokenKind.COMMENT:
print(token.spelling)
print(token.cursor.displayname)
print(token.kind)
print(token.cursor.kind)
print(token.cursor.brief_comment)
tokens.append(token)
return tokens
def main():
index = clang.cindex.Index.create()
compdb = clang.cindex.CompilationDatabase.fromDirectory(
"/home/makogan/neverengine/")
source_file_path = '/home/makogan/neverengine/Src/Engine/Geometry/GeometryUtils.cpp'
commands = compdb.getCompileCommands(source_file_path)
file_args = []
for command in commands:
for argument in command.arguments:
file_args.append(argument)
file_args = file_args[3:-3]
translation_unit = index.parse(source_file_path,args=file_args)
comment_tokens = GetDoxygenCommentTokens(translation_unit)
if __name__ == "__main__":
main()
我知道这个文件在它所属的项目中编译。
我得到的错误是打印 CursorKind.INVALID_FILE
时的 cursor.kind
和打印 cursor.displayname
时的空字符串。
这是我实际传递给解析器的参数列表(在删除了一些 g++ 特定标志之后):
['-DVULKAN_HPP_NO_EXCEPTIONS','-DVULKAN_HPP_TYPESAFE_CONVERSION','-DDEBUG','-DTESTING','-I../Src/Engine','-I../libraries/stb','-I../libraries/glm','-I../libraries/Eigen','-I../libraries/imgui','-I../libraries/incbin','-I../libraries/tinygltf','-I../libraries/harfbuzz','-I../libraries/backward-cpp','-I../libraries/libigl/include','-I../libraries/freetype2/include','-I../libraries/benchmark/include','-I../libraries/magic_get/include','-I../libraries/shaderc/libshaderc/include','-I../libraries/VulkanMemoryAllocator/include','-I../libraries/googletest/googletest/include','-I../libraries/shaderc/libshaderc_util/include','-I../libraries/vulkan-sdk/1.2.176.1/source/Vulkan-Headers/include','-Og','-g','-O2']
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。